libDwm-0.9.45
DwmTimeValue64.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2005-2007, 2016, 2017, 2020, 2024
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
32// PURPOSE, OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
40//---------------------------------------------------------------------------
41
42#ifndef _DWMTIMEVALUE64_HH_
43#define _DWMTIMEVALUE64_HH_
44
45extern "C" {
46 #include <sys/types.h>
47 #include <sys/time.h>
48#if ((! __APPLE__) && (! __linux__))
49 #include <sys/timespec.h>
50#endif
51 #include <sys/uio.h>
52 #include <unistd.h>
53}
54
55#include <cstdint>
56#include <iostream>
57
58#include "DwmTimeValue.hh"
59
60namespace Dwm {
61
62 //--------------------------------------------------------------------------
65 //--------------------------------------------------------------------------
67 {
68 public:
69 //------------------------------------------------------------------------
72 //------------------------------------------------------------------------
73 TimeValue64(bool setNow = false);
74
75 //------------------------------------------------------------------------
77 //------------------------------------------------------------------------
78 TimeValue64(const struct timeval & tv);
79
80 //------------------------------------------------------------------------
82 //------------------------------------------------------------------------
83 TimeValue64(const struct timespec & ts);
84
85 //------------------------------------------------------------------------
87 //------------------------------------------------------------------------
89
90 //------------------------------------------------------------------------
92 //------------------------------------------------------------------------
93 TimeValue64(uint64_t secs, uint32_t usecs);
94
95 //------------------------------------------------------------------------
97 //------------------------------------------------------------------------
98 void SetNow();
99
100 //------------------------------------------------------------------------
102 //------------------------------------------------------------------------
103 void Set(const struct timeval & tv);
104
105 //------------------------------------------------------------------------
107 //------------------------------------------------------------------------
108 void Set(uint64_t secs, uint32_t usecs);
109
110 //------------------------------------------------------------------------
112 //------------------------------------------------------------------------
113 uint64_t Secs() const;
114
115 //------------------------------------------------------------------------
117 //------------------------------------------------------------------------
118 uint32_t Usecs() const;
119
120 struct tm LocalTime() const;
121
122 //------------------------------------------------------------------------
124 //------------------------------------------------------------------------
125 bool operator < (const TimeValue64 & tv) const;
126
127 //------------------------------------------------------------------------
129 //------------------------------------------------------------------------
130 bool operator <= (const TimeValue64 & tv) const;
131
132 //------------------------------------------------------------------------
134 //------------------------------------------------------------------------
135 bool operator > (const TimeValue64 & tv) const;
136
137 //------------------------------------------------------------------------
139 //------------------------------------------------------------------------
140 bool operator >= (const TimeValue64 & tv) const;
141
142 //------------------------------------------------------------------------
144 //------------------------------------------------------------------------
145 bool operator == (const TimeValue64 & tv) const;
146
147 TimeValue64 & operator += (const TimeValue64 & tv);
148 TimeValue64 & operator -= (const TimeValue64 & tv);
149 TimeValue64 & operator *= (uint32_t x);
150 TimeValue64 & operator /= (uint32_t x);
151
152 //------------------------------------------------------------------------
155 //------------------------------------------------------------------------
156 uint64_t StreamedLength() const;
157
158 //------------------------------------------------------------------------
160 //------------------------------------------------------------------------
161 std::istream & Read(std::istream & is);
162
163 //------------------------------------------------------------------------
165 //------------------------------------------------------------------------
166 std::ostream & Write(std::ostream & os) const;
167
168 //------------------------------------------------------------------------
171 //------------------------------------------------------------------------
172 size_t Read(FILE *f);
173
174 //------------------------------------------------------------------------
177 //------------------------------------------------------------------------
178 size_t Write(FILE *f) const;
179
180 //------------------------------------------------------------------------
183 //------------------------------------------------------------------------
184 ssize_t Read(int fd);
185
186 //------------------------------------------------------------------------
189 //------------------------------------------------------------------------
190 ssize_t Write(int fd) const;
191
192 //------------------------------------------------------------------------
195 //------------------------------------------------------------------------
196 int Read(gzFile gzf);
197
198 //------------------------------------------------------------------------
201 //------------------------------------------------------------------------
202 int Write(gzFile gzf) const;
203
204 //------------------------------------------------------------------------
207 //------------------------------------------------------------------------
208 int BZRead(BZFILE *bzf);
209
210 //------------------------------------------------------------------------
213 //------------------------------------------------------------------------
214 int BZWrite(BZFILE *bzf) const;
215
216 //--------------------------------------------------------------------
218 //--------------------------------------------------------------------
219 operator double () const;
220
221 private:
222 uint64_t _secs;
223 uint32_t _usecs;
224 };
225
226} // namespace Dwm
227
228Dwm::TimeValue64 operator + (const Dwm::TimeValue64 & tv1,
229 const Dwm::TimeValue64 & tv2);
230Dwm::TimeValue64 operator - (const Dwm::TimeValue64 & tv1,
231 const Dwm::TimeValue64 & tv2);
232
233#endif // _DWMTIMEVALUE64_HH_
234
235//---------------------------- emacs settings -----------------------------
236// Local Variables:
237// mode: C++
238// tab-width: 2
239// indent-tabs-mode: nil
240// c-basic-offset: 2
241// End:
242//-------------------------------------------------------------------------
Dwm::TimeValue class definition.
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition DwmTimeValue64.hh:67
int Write(gzFile gzf) const
Writes the TimeValue64 to a gzFile.
TimeValue64(const TimeValue &tv)
Construct from a TimeValue.
std::ostream & Write(std::ostream &os) const
Writes the TimeValue64 to an ostream. Returns the ostream.
bool operator<(const TimeValue64 &tv) const
Less-than operator.
int Read(gzFile gzf)
Reads the TimeValue64 from a gzFile.
void Set(uint64_t secs, uint32_t usecs)
Sets the TimeValue64 from the given secs and usecs.
bool operator<=(const TimeValue64 &tv) const
operator <=
TimeValue64(uint64_t secs, uint32_t usecs)
Construct from the given secs and usecs.
bool operator>=(const TimeValue64 &tv) const
operator >=
bool operator>(const TimeValue64 &tv) const
Greater-than operator.
int BZRead(BZFILE *bzf)
Reads the TimeValue64 from a BZFILE pointer.
void SetNow()
Sets the TimeValue64 to the current time.
bool operator==(const TimeValue64 &tv) const
Equal-to operator.
int BZWrite(BZFILE *bzf) const
Writes the TimeValue64 to a BZFILE pointer.
TimeValue64(const struct timeval &tv)
Construct from a struct timeval.
uint64_t StreamedLength() const
Returns the number of bytes that would be written if one of the Write() members were called.
std::istream & Read(std::istream &is)
Reads the TimeValue64 from an istream. Returns the istream.
TimeValue64(const struct timespec &ts)
Construct from a struct timespec.
uint32_t Usecs() const
Returns the residual microseconds.
size_t Read(FILE *f)
Reads the TimeValue64 from a FILE pointer.
TimeValue64(bool setNow=false)
Constructor.
ssize_t Write(int fd) const
Writes the TimeValue64 to a file descriptor.
ssize_t Read(int fd)
Reads the TimeValue64 from a file descriptor.
size_t Write(FILE *f) const
Writes the TimeValue64 to a FILE pointer.
void Set(const struct timeval &tv)
Sets the TimeValue64 from the given struct timeval tv.
uint64_t Secs() const
Returns the seconds.
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition DwmTimeValue.hh:68