Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
ctimespec.h
1 /*
2  * ctimespec.h
3  *
4  * Created on: 04.06.2014
5  * Author: andreas
6  */
7 
8 #ifndef CTIMESPEC_H_
9 #define CTIMESPEC_H_
10 
11 #include <time.h>
12 
13 #include <iostream>
14 #include <sstream>
15 
16 #include "rofl/common/logging.h"
17 #include "rofl/common/croflexception.h"
18 
19 namespace rofl {
20 
25 class ctimespec {
26 public:
27 
31  ctimespec();
32 
36  ctimespec(
37  long tv_sec);
38 
42  ctimespec(
43  long tv_sec, long tv_nsec);
44 
48  ctimespec(
49  const ctimespec& timespec);
50 
54  ctimespec&
55  operator= (
56  const ctimespec& timespec);
57 
61  virtual
62  ~ctimespec();
63 
64 public:
65 
69  static ctimespec
70  now();
71 
75  struct timespec&
76  set_timespec() { return ts; };
77 
81  const struct timespec&
82  get_timespec() const { return ts; };
83 
87  ctimespec
88  operator+ (
89  const ctimespec& t);
90 
94  ctimespec
95  operator- (
96  const ctimespec& t);
97 
101  ctimespec&
102  operator+= (
103  const ctimespec& t);
104 
108  ctimespec&
109  operator-= (
110  const ctimespec& t);
111 
115  bool
116  operator== (
117  const ctimespec& t) const;
118 
122  bool
123  operator!= (
124  const ctimespec& t) const;
125 
129  bool
130  operator< (
131  const ctimespec& t) const;
132 
136  bool
137  operator<= (
138  const ctimespec& t) const;
139 
143  bool
144  operator> (
145  const ctimespec& t) const;
146 
150  bool
151  operator>= (
152  const ctimespec& t) const;
153 
154 
155 public:
156 
157  friend std::ostream&
158  operator<< (std::ostream& os, const ctimespec& timespec) {
159  os << rofl::indent(0) << "<ctimespec ";
160  os << "sec:" << (long int)timespec.ts.tv_sec << " ";
161  os << "nsec:" << (long int)timespec.ts.tv_nsec << " ";
162  os << ">" << std::endl;
163  return os;
164  };
165 
166  std::string
167  str() const {
168  std::stringstream ss;
169  ss << (unsigned long int)ts.tv_sec << "s " << (unsigned long int)ts.tv_nsec << "ns ";
170  return ss.str();
171  };
172 
173 private:
174 
175  static const long CC_TIMER_ONE_SECOND_S = 1;
176  static const long CC_TIMER_ONE_SECOND_NS = 1000000000;
177 
178  struct timespec ts;
179 };
180 
181 }; // end of namespace rofl
182 
183 #endif /* CTIMESPEC_H_ */
Definition: logging.h:76
Time specification used by class rofl::ctimer object.
Definition: ctimespec.h:25