libDwm-0.9.45
DwmTimeInterval64.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 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 PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
40//---------------------------------------------------------------------------
41
42#ifndef _DWMTIMEINTERVAL64_HH_
43#define _DWMTIMEINTERVAL64_HH_
44
45#include <cassert>
46#include <utility>
47
48#include "DwmTimeInterval.hh"
49#include "DwmTimeValue64.hh"
50
51namespace Dwm {
52
53 //--------------------------------------------------------------------------
55 //--------------------------------------------------------------------------
57 {
58 public:
59 //------------------------------------------------------------------------
61 //------------------------------------------------------------------------
63 : _data()
64 {}
65
66 //------------------------------------------------------------------------
68 //------------------------------------------------------------------------
69 TimeInterval64(const TimeValue64 & start, const TimeValue64 & end)
70 : _data(start, end)
71 {
72 assert(end >= start);
73 }
74
75 //------------------------------------------------------------------------
77 //------------------------------------------------------------------------
78 TimeInterval64(const TimeInterval64 & timeInterval)
79 : _data(timeInterval._data)
80 {}
81
82 //------------------------------------------------------------------------
84 //------------------------------------------------------------------------
85 TimeInterval64(const TimeInterval & timeInterval)
86 {
87 _data.first = timeInterval.Start();
88 _data.second = timeInterval.End();
89 }
90
91 //------------------------------------------------------------------------
93 //------------------------------------------------------------------------
94 const TimeValue64 & Start() const
95 {
96 return(_data.first);
97 }
98
99 //------------------------------------------------------------------------
101 //------------------------------------------------------------------------
102 const TimeValue64 & Start(const TimeValue64 & start);
103
104 //------------------------------------------------------------------------
106 //------------------------------------------------------------------------
107 const TimeValue64 & End() const
108 {
109 return(_data.second);
110 }
111
112 //------------------------------------------------------------------------
114 //------------------------------------------------------------------------
115 const TimeValue64 & End(const TimeValue64 & end);
116
117 //------------------------------------------------------------------------
119 //------------------------------------------------------------------------
120 bool operator == (const TimeInterval64 & ti) const;
121
122 //------------------------------------------------------------------------
124 //------------------------------------------------------------------------
125 TimeValue64 Duration() const
126 {
127 return (_data.second - _data.first);
128 }
129
130 //------------------------------------------------------------------------
134 //------------------------------------------------------------------------
135 bool Contains(const TimeValue64 & tv) const;
136
137 //------------------------------------------------------------------------
140 //------------------------------------------------------------------------
141 bool Contains(const TimeInterval64 & ti) const;
142
143 //------------------------------------------------------------------------
145 //------------------------------------------------------------------------
146 bool Overlaps(const TimeInterval64 & ti) const;
147
148 //------------------------------------------------------------------------
152 //------------------------------------------------------------------------
153 bool Adjacent(const TimeInterval64 & ti) const;
154
155 //------------------------------------------------------------------------
158 //------------------------------------------------------------------------
159 uint64_t StreamedLength() const;
160
161 //------------------------------------------------------------------------
163 //------------------------------------------------------------------------
164 std::istream & Read(std::istream & is);
165
166 //------------------------------------------------------------------------
168 //------------------------------------------------------------------------
169 std::ostream & Write(std::ostream & os) const;
170
171 //------------------------------------------------------------------------
174 //------------------------------------------------------------------------
175 size_t Read(FILE *f);
176
177 //------------------------------------------------------------------------
180 //------------------------------------------------------------------------
181 size_t Write(FILE *f) const;
182
183 //------------------------------------------------------------------------
186 //------------------------------------------------------------------------
187 ssize_t Read(int fd);
188
189 //------------------------------------------------------------------------
192 //------------------------------------------------------------------------
193 ssize_t Write(int fd) const;
194
195 //------------------------------------------------------------------------
198 //------------------------------------------------------------------------
199 int Read(gzFile gzf);
200
201 //------------------------------------------------------------------------
204 //------------------------------------------------------------------------
205 int Write(gzFile gzf) const;
206
207 //------------------------------------------------------------------------
210 //------------------------------------------------------------------------
211 int BZRead(BZFILE *bzf);
212
213 //------------------------------------------------------------------------
216 //------------------------------------------------------------------------
217 int BZWrite(BZFILE *bzf) const;
218
219 private:
220 std::pair<TimeValue64, TimeValue64> _data;
221 };
222
223} // namespace Dwm
224
225#endif // _DWMTIMEINTERVAL64_HH_
226
227//---------------------------- emacs settings -----------------------------
228// Local Variables:
229// mode: C++
230// tab-width: 2
231// indent-tabs-mode: nil
232// c-basic-offset: 2
233// End:
234//-------------------------------------------------------------------------
Dwm::TimeInterval class definition.
Dwm::TimeValue64 class definition.
This class encapsulates a time interval.
Definition DwmTimeInterval64.hh:57
std::istream & Read(std::istream &is)
Reads the time interval from an istream. Returns the istream.
int Write(gzFile gzf) const
Writes the time interval to a gzFile.
bool Overlaps(const TimeInterval64 &ti) const
Returns true if ti overlaps the time interval.
bool Contains(const TimeInterval64 &ti) const
Returns true if the TimeInterval ti is completely contained within our time interval.
const TimeValue64 & Start(const TimeValue64 &start)
Sets and returns the start time.
TimeInterval64(const TimeInterval64 &timeInterval)
Copy constructor.
Definition DwmTimeInterval64.hh:78
int BZWrite(BZFILE *bzf) const
Writes the time interval to a BZFILE pointer.
bool Adjacent(const TimeInterval64 &ti) const
Returns true if ti is immediately adjacent our time interval, i.e.
size_t Read(FILE *f)
Reads the time interval from a FILE pointer.
int Read(gzFile gzf)
Reads the time interval from a gzFile.
TimeInterval64()
Contructor.
Definition DwmTimeInterval64.hh:62
size_t Write(FILE *f) const
Writes the time interval to a FILE pointer.
ssize_t Read(int fd)
Reads the time interval from a file descriptor.
const TimeValue64 & End(const TimeValue64 &end)
Sets and returns the end time.
bool Contains(const TimeValue64 &tv) const
Returns true if the TimeValue64 tv falls within the time interval, i.e.
TimeInterval64(const TimeValue64 &start, const TimeValue64 &end)
Construct from a start and end time.
Definition DwmTimeInterval64.hh:69
ssize_t Write(int fd) const
Wries the time interval to a file descriptor.
int BZRead(BZFILE *bzf)
Reads the time interval from a BZFILE pointer.
bool operator==(const TimeInterval64 &ti) const
operator ==
const TimeValue64 & End() const
Returns the end time.
Definition DwmTimeInterval64.hh:107
uint64_t StreamedLength() const
Returns the length of the time insterval, in bytes.
std::ostream & Write(std::ostream &os) const
Writes the time interval to an ostream. Returns the ostream.
const TimeValue64 & Start() const
Returns the start time.
Definition DwmTimeInterval64.hh:94
This class encapsulates a time interval.
Definition DwmTimeInterval.hh:56
const TimeValue & End() const
Returns the end time.
Definition DwmTimeInterval.hh:97
const TimeValue & Start() const
Returns the start time.
Definition DwmTimeInterval.hh:84
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition DwmTimeValue64.hh:67