libDwm-0.6.1
DwmTimeInterval64.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.1/include/DwmTimeInterval64.hh 9100 $
3 // @(#) $Id: DwmTimeInterval64.hh 9100 2017-04-14 20:37:08Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2016, 2017
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 PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMTIMEINTERVAL64_HH_
43 #define _DWMTIMEINTERVAL64_HH_
44 
45 extern "C" {
46  #include <assert.h>
47 }
48 
49 #include <utility>
50 
51 #include "DwmTimeValue64.hh"
52 #include "DwmReadable.hh"
53 #include "DwmWritable.hh"
54 #include "DwmGZReadable.hh"
55 #include "DwmGZWritable.hh"
56 #include "DwmBZ2Readable.hh"
57 #include "DwmBZ2Writable.hh"
58 
59 namespace Dwm {
60 
61  //--------------------------------------------------------------------------
63  //--------------------------------------------------------------------------
65  : public Readable, public Writable,
66  public GZReadable, public GZWritable,
67  public BZ2Readable, public BZ2Writable
68  {
69  public:
70  //------------------------------------------------------------------------
72  //------------------------------------------------------------------------
74  : _data()
75  {}
76 
77  //------------------------------------------------------------------------
79  //------------------------------------------------------------------------
80  TimeInterval64(const TimeValue64 & start, const TimeValue64 & end)
81  : _data(start, end)
82  {
83  assert(end >= start);
84  }
85 
86  //------------------------------------------------------------------------
88  //------------------------------------------------------------------------
89  TimeInterval64(const TimeInterval64 & timeInterval)
90  : _data(timeInterval._data)
91  {}
92 
93  //------------------------------------------------------------------------
95  //------------------------------------------------------------------------
96  const TimeValue64 & Start() const
97  {
98  return(_data.first);
99  }
100 
101  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
104  const TimeValue64 & Start(const TimeValue64 & start);
105 
106  //------------------------------------------------------------------------
108  //------------------------------------------------------------------------
109  const TimeValue64 & End() const
110  {
111  return(_data.second);
112  }
113 
114  //------------------------------------------------------------------------
116  //------------------------------------------------------------------------
117  const TimeValue64 & End(const TimeValue64 & end);
118 
119  //------------------------------------------------------------------------
121  //------------------------------------------------------------------------
122  bool operator == (const TimeInterval64 & ti) const;
123 
124  //------------------------------------------------------------------------
126  //------------------------------------------------------------------------
127  TimeValue64 Duration() const
128  {
129  return (_data.second - _data.first);
130  }
131 
132  //------------------------------------------------------------------------
136  //------------------------------------------------------------------------
137  bool Contains(const TimeValue64 & tv) const;
138 
139  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
143  bool Contains(const TimeInterval64 & ti) const;
144 
145  //------------------------------------------------------------------------
147  //------------------------------------------------------------------------
148  bool Overlaps(const TimeInterval64 & ti) const;
149 
150  //------------------------------------------------------------------------
154  //------------------------------------------------------------------------
155  bool Adjacent(const TimeInterval64 & ti) const;
156 
157  //------------------------------------------------------------------------
160  //------------------------------------------------------------------------
161  uint32_t StreamedLength() const;
162 
163  //------------------------------------------------------------------------
165  //------------------------------------------------------------------------
166  std::istream & Read(std::istream & is);
167 
168  //------------------------------------------------------------------------
170  //------------------------------------------------------------------------
171  std::ostream & Write(std::ostream & os) const;
172 
173  //------------------------------------------------------------------------
176  //------------------------------------------------------------------------
177  size_t Read(FILE *f);
178 
179  //------------------------------------------------------------------------
182  //------------------------------------------------------------------------
183  size_t Write(FILE *f) const;
184 
185  //------------------------------------------------------------------------
188  //------------------------------------------------------------------------
189  ssize_t Read(int fd);
190 
191  //------------------------------------------------------------------------
194  //------------------------------------------------------------------------
195  ssize_t Write(int fd) const;
196 
197  //------------------------------------------------------------------------
200  //------------------------------------------------------------------------
201  int Read(gzFile gzf);
202 
203  //------------------------------------------------------------------------
206  //------------------------------------------------------------------------
207  int Write(gzFile gzf) const;
208 
209  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  int BZRead(BZFILE *bzf);
214 
215  //------------------------------------------------------------------------
218  //------------------------------------------------------------------------
219  int BZWrite(BZFILE *bzf) const;
220 
221  private:
222  std::pair<TimeValue64, TimeValue64> _data;
223  };
224 
225 } // namespace Dwm
226 
227 #endif // _DWMTIMEINTERVAL64_HH_
228 
229 //---------------------------- emacs settings -----------------------------
230 // Local Variables:
231 // mode: C++/la
232 // tab-width: 2
233 // indent-tabs-mode: nil
234 // c-basic-offset: 2
235 // End:
236 //-------------------------------------------------------------------------
const TimeValue64 & Start() const
Returns the start time.
Definition: DwmTimeInterval64.hh:96
bool Overlaps(const TimeInterval64 &ti) const
Returns true if ti overlaps the time interval.
bool Adjacent(const TimeInterval64 &ti) const
Returns true if ti is immediately adjacent our time interval, i.e.
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
std::istream & Read(std::istream &is)
Reads the time interval from an istream. Returns the istream.
bool operator==(const TimeInterval64 &ti) const
operator ==
Dwm::Writable pure virtual class definition.
TimeInterval64(const TimeInterval64 &timeInterval)
Copy constructor.
Definition: DwmTimeInterval64.hh:89
Dwm::BZ2Readable pure virtual class definition.
Dwm::GZReadable pure virtual class definition.
TimeInterval64()
Contructor.
Definition: DwmTimeInterval64.hh:73
Dwm::Readable pure virtual class definition.
std::ostream & Write(std::ostream &os) const
Writes the time interval to an ostream. Returns the ostream.
int BZWrite(BZFILE *bzf) const
Writes the time interval to a BZFILE pointer.
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 time interval from a BZFILE pointer.
const TimeValue64 & End() const
Returns the end time.
Definition: DwmTimeInterval64.hh:109
Dwm::BZ2Writable pure virtual class definition.
Definition: DwmBZ2IO.hh:67
uint32_t StreamedLength() const
Returns the length of the time insterval, in bytes.
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
bool Contains(const TimeValue64 &tv) const
Returns true if the TimeValue64 tv falls within the time interval, i.e.
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
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.
TimeInterval64(const TimeValue64 &start, const TimeValue64 &end)
Construct from a start and end time.
Definition: DwmTimeInterval64.hh:80
This class defines an interface for classes that can read their contents from an istream, file descriptor or FILE pointer.
Definition: DwmReadable.hh:58
Dwm::TimeValue64 class definition.
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition: DwmTimeValue64.hh:72
This class encapsulates a time interval.
Definition: DwmTimeInterval64.hh:64