root/foundation-apps/grosview-maxx/timeval.h

Revision 2, 1.1 KB (checked in by emasson, 3 years ago)

initial import for the community edition

Line 
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// $Id: timeval.h,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $
8//
9#ifndef _TIMEVAL_H_
10#define _TIMEVAL_H_
11
12#define TIMEVAL_H_CVSID "$Id: timeval.h,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $"
13
14#include <sys/time.h>
15#ifdef HAVE_IOSTREAM
16#include <iostream>
17#else
18#include <iostream.h>
19#endif
20
21class TimeVal {
22public:
23  TimeVal(unsigned long sec = 0, unsigned long usec = 0) {
24    _val.tv_sec = (int)sec;
25    _val.tv_usec = usec;
26  }
27  TimeVal(const struct timeval &val) { _val = val; }
28
29  unsigned long sec(void) const { return _val.tv_sec; }
30  unsigned long usec(void) const { return _val.tv_usec; }
31  void sec(unsigned long s) { _val.tv_sec = (int)s; }
32  void usec(unsigned long us) { _val.tv_usec = us; }
33
34  operator struct timeval(void) const { return _val; }
35
36  std::ostream &printOn(std::ostream &os) const {
37    return os <<"(" <<sec() <<" sec, " <<usec() <<" usec)";
38  }
39
40private:
41  struct timeval _val;
42};
43
44inline std::ostream &operator<<(std::ostream &os, const TimeVal &tv){
45  return tv.printOn(os);
46}
47
48#endif
Note: See TracBrowser for help on using the browser.