"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/timeval.h" (11 Jul 2020, 955 Bytes) of package /linux/misc/xosview-1.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "timeval.h" see the Fossies "Dox" file reference documentation.

    1 //
    2 //  Copyright (c) 1994, 1995, 2006 by Mike Romberg ( mike.romberg@noaa.gov )
    3 //
    4 //  This file may be distributed under terms of the GPL
    5 //
    6 
    7 #ifndef _TIMEVAL_H_
    8 #define _TIMEVAL_H_
    9 
   10 #include <sys/time.h>
   11 #include <iostream>
   12 
   13 class TimeVal {
   14 public:
   15   TimeVal(unsigned long sec = 0, unsigned long usec = 0) {
   16     _val.tv_sec = (int)sec;
   17     _val.tv_usec = usec;
   18   }
   19   TimeVal(const struct timeval &val) { _val = val; }
   20 
   21   unsigned long sec(void) const { return _val.tv_sec; }
   22   unsigned long usec(void) const { return _val.tv_usec; }
   23   void sec(unsigned long s) { _val.tv_sec = (int)s; }
   24   void usec(unsigned long us) { _val.tv_usec = us; }
   25 
   26   operator struct timeval(void) const { return _val; }
   27 
   28   std::ostream &printOn(std::ostream &os) const {
   29     return os <<"(" <<sec() <<" sec, " <<usec() <<" usec)";
   30   }
   31 
   32 private:
   33   struct timeval _val;
   34 };
   35 
   36 inline std::ostream &operator<<(std::ostream &os, const TimeVal &tv){
   37   return tv.printOn(os);
   38 }
   39 
   40 #endif