libDwm-0.6.0
DwmTimeValue64.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmTimeValue64.hh 8536 $
3 // @(#) $Id: DwmTimeValue64.hh 8536 2016-05-14 17:37:12Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2005-2007, 2016
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
33 // PURPOSE, OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMTIMEVALUE64_HH_
43 #define _DWMTIMEVALUE64_HH_
44 
45 extern "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  #include <stdio.h>
54  #include <time.h>
55 }
56 
57 #include <iostream>
58 
59 #include "DwmReadable.hh"
60 #include "DwmWritable.hh"
61 #include "DwmGZReadable.hh"
62 #include "DwmGZWritable.hh"
63 #include "DwmBZ2Readable.hh"
64 #include "DwmBZ2Writable.hh"
65 
66 namespace Dwm {
67 
68  //--------------------------------------------------------------------------
71  //--------------------------------------------------------------------------
73  : public Readable, public Writable,
74  public GZReadable, public GZWritable,
75  public BZ2Readable, public BZ2Writable
76  {
77  public:
78  //------------------------------------------------------------------------
81  //------------------------------------------------------------------------
82  TimeValue64(bool setNow = false);
83 
84  //------------------------------------------------------------------------
86  //------------------------------------------------------------------------
87  TimeValue64(const struct timeval & tv);
88 
89  TimeValue64(const struct timespec & ts);
90 
91  //------------------------------------------------------------------------
93  //------------------------------------------------------------------------
94  TimeValue64(uint64_t secs, uint32_t usecs);
95 
96  //------------------------------------------------------------------------
98  //------------------------------------------------------------------------
99  void SetNow();
100 
101  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
104  void Set(const struct timeval & tv);
105 
106  //------------------------------------------------------------------------
108  //------------------------------------------------------------------------
109  void Set(uint64_t secs, uint32_t usecs);
110 
111  //------------------------------------------------------------------------
113  //------------------------------------------------------------------------
114  uint64_t Secs() const;
115 
116  //------------------------------------------------------------------------
118  //------------------------------------------------------------------------
119  uint32_t Usecs() const;
120 
121  struct tm LocalTime() const;
122 
123  //------------------------------------------------------------------------
125  //------------------------------------------------------------------------
126  bool operator < (const TimeValue64 & tv) const;
127 
128  //------------------------------------------------------------------------
130  //------------------------------------------------------------------------
131  bool operator <= (const TimeValue64 & tv) const;
132 
133  //------------------------------------------------------------------------
135  //------------------------------------------------------------------------
136  bool operator > (const TimeValue64 & tv) const;
137 
138  //------------------------------------------------------------------------
140  //------------------------------------------------------------------------
141  bool operator >= (const TimeValue64 & tv) const;
142 
143  //------------------------------------------------------------------------
145  //------------------------------------------------------------------------
146  bool operator == (const TimeValue64 & tv) const;
147 
148  TimeValue64 & operator += (const TimeValue64 & tv);
149  TimeValue64 & operator -= (const TimeValue64 & tv);
150  TimeValue64 & operator *= (uint32_t x);
151  TimeValue64 & operator /= (uint32_t x);
152 
153  //------------------------------------------------------------------------
156  //------------------------------------------------------------------------
157  uint32_t StreamedLength() const;
158 
159  //------------------------------------------------------------------------
161  //------------------------------------------------------------------------
162  std::istream & Read(std::istream & is);
163 
164  //------------------------------------------------------------------------
166  //------------------------------------------------------------------------
167  std::ostream & Write(std::ostream & os) const;
168 
169  //------------------------------------------------------------------------
172  //------------------------------------------------------------------------
173  size_t Read(FILE *f);
174 
175  //------------------------------------------------------------------------
178  //------------------------------------------------------------------------
179  size_t Write(FILE *f) const;
180 
181  //------------------------------------------------------------------------
184  //------------------------------------------------------------------------
185  ssize_t Read(int fd);
186 
187  //------------------------------------------------------------------------
190  //------------------------------------------------------------------------
191  ssize_t Write(int fd) const;
192 
193  //------------------------------------------------------------------------
196  //------------------------------------------------------------------------
197  int Read(gzFile gzf);
198 
199  //------------------------------------------------------------------------
202  //------------------------------------------------------------------------
203  int Write(gzFile gzf) const;
204 
205  //------------------------------------------------------------------------
208  //------------------------------------------------------------------------
209  int BZRead(BZFILE *bzf);
210 
211  //------------------------------------------------------------------------
214  //------------------------------------------------------------------------
215  int BZWrite(BZFILE *bzf) const;
216 
217  //--------------------------------------------------------------------
219  //--------------------------------------------------------------------
220  operator double () const;
221 
222  private:
223  uint64_t _secs;
224  uint32_t _usecs;
225  };
226 
227 } // namespace Dwm
228 
229 Dwm::TimeValue64 operator + (const Dwm::TimeValue64 & tv1,
230  const Dwm::TimeValue64 & tv2);
231 Dwm::TimeValue64 operator - (const Dwm::TimeValue64 & tv1,
232  const Dwm::TimeValue64 & tv2);
233 
234 #endif // _DWMTIMEVALUE64_HH_
235 
236 //---------------------------- emacs settings -----------------------------
237 // Local Variables:
238 // mode: C++/la
239 // tab-width: 2
240 // indent-tabs-mode: nil
241 // c-basic-offset: 2
242 // End:
243 //-------------------------------------------------------------------------
uint32_t StreamedLength() const
Returns the number of bytes that would be written if one of the Write() members were called...
bool operator>=(const TimeValue64 &tv) const
operator >=
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
bool operator<(const TimeValue64 &tv) const
Less-than operator.
Dwm::Writable pure virtual class definition.
Dwm::BZ2Readable pure virtual class definition.
Dwm::GZReadable pure virtual class definition.
uint32_t Usecs() const
Returns the residual microseconds.
Dwm::Readable pure virtual class definition.
TimeValue64(bool setNow=false)
Constructor.
std::ostream & Write(std::ostream &os) const
Writes the TimeValue64 to an ostream. Returns the ostream.
std::istream & Read(std::istream &is)
Reads the TimeValue64 from an istream. Returns the istream.
bool operator<=(const TimeValue64 &tv) const
operator <=
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmBZ2Readable.hh:57
int BZRead(BZFILE *bzf)
Reads the TimeValue64 from a BZFILE pointer.
Dwm::BZ2Writable pure virtual class definition.
bool operator==(const TimeValue64 &tv) const
Equal-to operator.
Definition: DwmBZ2IO.hh:67
void Set(const struct timeval &tv)
Sets the TimeValue64 from the given struct timeval tv.
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
int BZWrite(BZFILE *bzf) const
Writes the TimeValue64 to a BZFILE pointer.
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
uint64_t Secs() const
Returns the seconds.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmBZ2Writable.hh:57
Dwm::GZWritable pure virtual class definition.
This class defines an interface for classes that can read their contents from an istream, file descriptor or FILE pointer.
Definition: DwmReadable.hh:58
bool operator>(const TimeValue64 &tv) const
Greater-than operator.
void SetNow()
Sets the TimeValue64 to the current time.
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition: DwmTimeValue64.hh:72