libDwm-0.9.45
DwmTimeInterval.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2005-2007, 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 _DWMTIMEINTERVAL_HH_
43#define _DWMTIMEINTERVAL_HH_
44
45#include <cassert>
46#include <utility>
47
48#include "DwmTimeValue.hh"
49
50namespace Dwm {
51
52 //--------------------------------------------------------------------------
54 //--------------------------------------------------------------------------
56 {
57 public:
58 //------------------------------------------------------------------------
60 //------------------------------------------------------------------------
62 : _data()
63 {}
64
65 //------------------------------------------------------------------------
67 //------------------------------------------------------------------------
68 TimeInterval(const TimeValue & start, const TimeValue & end)
69 : _data(start, end)
70 {
71 assert(end >= start);
72 }
73
74 //------------------------------------------------------------------------
76 //------------------------------------------------------------------------
77 TimeInterval(const TimeInterval & timeInterval)
78 : _data(timeInterval._data)
79 {}
80
81 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
84 const TimeValue & Start() const
85 {
86 return(_data.first);
87 }
88
89 //------------------------------------------------------------------------
91 //------------------------------------------------------------------------
92 const TimeValue & Start(const TimeValue & start);
93
94 //------------------------------------------------------------------------
96 //------------------------------------------------------------------------
97 const TimeValue & End() const
98 {
99 return(_data.second);
100 }
101
102 //------------------------------------------------------------------------
104 //------------------------------------------------------------------------
105 const TimeValue & End(const TimeValue & end);
106
107 //------------------------------------------------------------------------
109 //------------------------------------------------------------------------
110 bool operator == (const TimeInterval & ti) const;
111
112 //------------------------------------------------------------------------
114 //------------------------------------------------------------------------
115 TimeValue Duration() const
116 {
117 return (_data.second - _data.first);
118 }
119
120 //------------------------------------------------------------------------
124 //------------------------------------------------------------------------
125 bool Contains(const TimeValue & tv) const;
126
127 //------------------------------------------------------------------------
130 //------------------------------------------------------------------------
131 bool Contains(const TimeInterval & ti) const;
132
133 //------------------------------------------------------------------------
135 //------------------------------------------------------------------------
136 bool Overlaps(const TimeInterval & ti) const;
137
138 //------------------------------------------------------------------------
142 //------------------------------------------------------------------------
143 bool Adjacent(const TimeInterval & ti) const;
144
145 //------------------------------------------------------------------------
148 //------------------------------------------------------------------------
149 uint64_t StreamedLength() const;
150
151 //------------------------------------------------------------------------
153 //------------------------------------------------------------------------
154 std::istream & Read(std::istream & is);
155
156 //------------------------------------------------------------------------
158 //------------------------------------------------------------------------
159 std::ostream & Write(std::ostream & os) const;
160
161 //------------------------------------------------------------------------
164 //------------------------------------------------------------------------
165 size_t Read(FILE *f);
166
167 //------------------------------------------------------------------------
170 //------------------------------------------------------------------------
171 size_t Write(FILE *f) const;
172
173 //------------------------------------------------------------------------
176 //------------------------------------------------------------------------
177 ssize_t Read(int fd);
178
179 //------------------------------------------------------------------------
182 //------------------------------------------------------------------------
183 ssize_t Write(int fd) const;
184
185 //------------------------------------------------------------------------
188 //------------------------------------------------------------------------
189 int Read(gzFile gzf);
190
191 //------------------------------------------------------------------------
194 //------------------------------------------------------------------------
195 int Write(gzFile gzf) const;
196
197 //------------------------------------------------------------------------
200 //------------------------------------------------------------------------
201 int BZRead(BZFILE *bzf);
202
203 //------------------------------------------------------------------------
206 //------------------------------------------------------------------------
207 int BZWrite(BZFILE *bzf) const;
208
209 private:
210 std::pair<TimeValue, TimeValue> _data;
211 };
212
213} // namespace Dwm
214
215#endif // _DWMTIMEINTERVAL_HH_
216
217//---------------------------- emacs settings -----------------------------
218// Local Variables:
219// mode: C++
220// tab-width: 2
221// indent-tabs-mode: nil
222// c-basic-offset: 2
223// End:
224//-------------------------------------------------------------------------
Dwm::TimeValue class definition.
This class encapsulates a time interval.
Definition DwmTimeInterval.hh:56
TimeInterval(const TimeValue &start, const TimeValue &end)
Construct from a start and end time.
Definition DwmTimeInterval.hh:68
std::istream & Read(std::istream &is)
Reads the time interval from an istream. Returns the istream.
bool Overlaps(const TimeInterval &ti) const
Returns true if ti overlaps the time interval.
size_t Write(FILE *f) const
Writes the time interval to a FILE pointer.
const TimeValue & End(const TimeValue &end)
Sets and returns the end time.
const TimeValue & End() const
Returns the end time.
Definition DwmTimeInterval.hh:97
std::ostream & Write(std::ostream &os) const
Writes the time interval to an ostream. Returns the ostream.
int Write(gzFile gzf) const
Writes the time interval to a gzFile.
const TimeValue & Start() const
Returns the start time.
Definition DwmTimeInterval.hh:84
bool Contains(const TimeValue &tv) const
Returns true if the TimeValue tv falls within the time interval, i.e.
bool operator==(const TimeInterval &ti) const
operator ==
ssize_t Write(int fd) const
Wries the time interval to a file descriptor.
uint64_t StreamedLength() const
Returns the length of the time insterval, in bytes.
TimeInterval(const TimeInterval &timeInterval)
Copy constructor.
Definition DwmTimeInterval.hh:77
ssize_t Read(int fd)
Reads the time interval from a file descriptor.
int BZWrite(BZFILE *bzf) const
Writes the time interval to a BZFILE pointer.
TimeInterval()
Contructor.
Definition DwmTimeInterval.hh:61
size_t Read(FILE *f)
Reads the time interval from a FILE pointer.
int BZRead(BZFILE *bzf)
Reads the time interval from a BZFILE pointer.
int Read(gzFile gzf)
Reads the time interval from a gzFile.
bool Adjacent(const TimeInterval &ti) const
Returns true if ti is immediately adjacent our time interval, i.e.
const TimeValue & Start(const TimeValue &start)
Sets and returns the start time.
bool Contains(const TimeInterval &ti) const
Returns true if the TimeInterval ti is completely contained within our time interval.
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition DwmTimeValue.hh:68