cheshirekow  v0.1.0
clock.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (josh.bialkowski@gmail.com)
3  *
4  * This file is part of cpp-nix.
5  *
6  * cpp-nix is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * cpp-nix is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with cpp-nix. If not, see <http://www.gnu.org/licenses/>.
18  */
26 #ifndef CPP_NIX_CLOCK_H_
27 #define CPP_NIX_CLOCK_H_
28 
29 #include <ctime>
30 #include "timespec.h"
31 
32 namespace nix {
33 
34 class Clock {
35  public:
36  Clock(clockid_t clock_id)
37  : m_clock_id(clock_id) {
38  }
39 
40  timespec GetRes() {
41  timespec output;
42  int result = clock_getres(m_clock_id, &output);
43  if (!result) {
44  return output;
45  } else {
46  return timespec { result, 0 };
47  }
48  }
49 
50  timespec GetTime() {
51  timespec output;
52  int result = clock_gettime(m_clock_id, &output);
53  if (!result) {
54  return output;
55  } else {
56  return timespec { result, 0 };
57  }
58  }
59 
60  int SetTime(const timespec& time){
61  return clock_settime(m_clock_id,&time);
62  }
63 
64  private:
65  clockid_t m_clock_id;
66 };
67 
68 } // namespace nix
69 
70 #endif // CPP_NIX_CLOCK_H_
timespec GetRes()
Definition: clock.h:40
clockid_t m_clock_id
Definition: clock.h:65
Clock(clockid_t clock_id)
Definition: clock.h:36
timespec GetTime()
Definition: clock.h:50
int SetTime(const timespec &time)
Definition: clock.h:60