libshevek
Main Page
Classes
Files
File List
src
time.hh
1
/* time.hh - class definitions to work with time.
2
* Copyright 2003-2006 Bas Wijnen <wijnen@debian.org>
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#ifndef SHEVEK_TIME_HH
19
#define SHEVEK_TIME_HH
20
21
#include <iostream>
22
#include <glibmm.h>
23
24
namespace
shevek
25
{
27
sigc::connection schedule (sigc::slot0 <void> callback,
int
prio = Glib::PRIORITY_HIGH_IDLE, Glib::RefPtr <Glib::MainContext> context = Glib::MainContext::get_default () );
28
30
typedef
int64_t timetype;
31
class
relative_time;
32
34
36
class
absolute_time
37
{
38
// number of seconds since epoch.
39
timetype m_seconds;
40
// number of nanoseconds. Should be less than 1000 000 000.
41
unsigned
m_nanoseconds;
42
static
bool
l_schedule (sigc::slot0 <void> callback);
43
// let schedule use l_schedule
44
friend
45
sigc::connection
schedule
(sigc::slot0 <void> callback,
int
prio,
46
Glib::RefPtr <Glib::MainContext> context);
47
static
unsigned
s_digits;
48
public
:
50
53
absolute_time
();
55
58
absolute_time
(
unsigned
years,
unsigned
months,
unsigned
days
,
unsigned
hours,
unsigned
minutes,
unsigned
seconds,
unsigned
nanoseconds
= 0);
60
63
absolute_time
(timetype seconds,
unsigned
nanoseconds
);
65
67
static
absolute_time
create_from_local
(
unsigned
years,
unsigned
months,
unsigned
days,
unsigned
hours,
unsigned
minutes,
unsigned
seconds,
unsigned
nanoseconds = 0);
69
static
void
set_digits
(
unsigned
num);
71
static
unsigned
get_digits
();
73
absolute_time
operator+
(
relative_time
that)
const
;
75
absolute_time
operator-
(
relative_time
that)
const
;
77
relative_time
operator-
(
absolute_time
that)
const
;
79
absolute_time
&
operator+=
(
relative_time
that);
81
absolute_time
&
operator-=
(
relative_time
that);
83
bool
operator<
(
absolute_time
that)
const
;
85
bool
operator>
(
absolute_time
that)
const
;
87
bool
operator<=
(
absolute_time
that)
const
;
89
bool
operator>=
(
absolute_time
that)
const
;
91
94
bool
operator==
(
absolute_time
that)
const
;
96
99
bool
operator!=
(
absolute_time
that)
const
;
101
unsigned
nanoseconds
()
const
;
103
unsigned
local_second
()
const
;
105
unsigned
local_minute
()
const
;
107
unsigned
local_hour
()
const
;
109
unsigned
local_days
()
const
;
111
unsigned
local_day
()
const
;
113
unsigned
local_weekday
()
const
;
115
unsigned
local_month
()
const
;
117
unsigned
local_year
()
const
;
119
unsigned
second
()
const
;
121
unsigned
minute
()
const
;
123
unsigned
hour
()
const
;
125
unsigned
days
()
const
;
127
unsigned
day
()
const
;
129
unsigned
weekday
()
const
;
131
unsigned
month
()
const
;
133
unsigned
year
()
const
;
135
timetype
total
()
const
;
137
sigc::connection
schedule
(sigc::slot0 <void> callback, Glib::RefPtr <Glib::MainContext> context = Glib::MainContext::get_default ());
139
friend
std::ostream &
operator<<
(std::ostream &s,
absolute_time
t);
140
};
141
143
class
relative_time
144
{
145
// number of seconds.
146
timetype m_seconds;
147
// number of nanoseconds. Should be less than 1000000000.
148
int
m_nanoseconds;
149
static
unsigned
s_digits;
150
public
:
152
relative_time
();
154
relative_time
(timetype
days
,
int
hours
,
int
minutes
,
int
seconds
,
int
nanoseconds
= 0);
156
159
relative_time
(timetype seconds,
unsigned
nanoseconds
);
161
static
void
set_digits
(
unsigned
num);
163
static
unsigned
get_digits
();
165
relative_time
operator+
(
relative_time
that)
const
;
167
absolute_time
operator+
(
absolute_time
that)
const
;
169
relative_time
operator-
(
relative_time
that)
const
;
171
relative_time
operator-
()
const
;
173
relative_time
operator*
(
float
c)
const
;
175
relative_time
operator/
(
float
c)
const
;
177
relative_time
operator%
(
relative_time
that)
const
;
179
double
operator/
(
relative_time
that)
const
;
181
relative_time
&
operator+=
(
relative_time
that);
183
relative_time
&
operator-=
(
relative_time
that);
185
relative_time
&
operator*=
(
float
c);
187
relative_time
&
operator/=
(
float
c);
189
relative_time
&
operator%=
(
relative_time
that);
191
bool
operator<
(
relative_time
that)
const
;
193
bool
operator>
(
relative_time
that)
const
;
195
bool
operator<=
(
relative_time
that)
const
;
197
bool
operator>=
(
relative_time
that)
const
;
200
bool
operator==
(
relative_time
that)
const
;
203
bool
operator!=
(
relative_time
that)
const
;
205
unsigned
nanoseconds
()
const
;
207
unsigned
seconds
()
const
;
209
unsigned
minutes
()
const
;
211
unsigned
hours
()
const
;
213
unsigned
days
()
const
;
215
bool
isnegative
()
const
;
217
timetype
total
()
const
;
219
friend
std::ostream &
operator<<
(std::ostream &s,
relative_time
t);
220
private
:
221
// internal function to clean the seconds/nanoseconds
222
void
l_clean ();
223
};
225
std::istream &operator>> (std::istream &s,
absolute_time
&t);
227
std::istream &operator>> (std::istream &s,
relative_time
&t);
228
}
229
230
231
#endif
Generated on Thu Mar 27 2014 07:30:53 for libshevek by
1.8.1.2