libDwm-0.6.0
DwmTimeInterval.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmTimeInterval.hh 8401 $
3 // @(#) $Id: DwmTimeInterval.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2005-2007
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 _DWMTIMEINTERVAL_HH_
43 #define _DWMTIMEINTERVAL_HH_
44 
45 extern "C" {
46  #include <assert.h>
47 }
48 
49 #include <utility>
50 
51 #include "DwmTimeValue.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  TimeInterval(const TimeValue & start, const TimeValue & end)
81  : _data(start, end)
82  {
83  assert(end >= start);
84  }
85 
86  //------------------------------------------------------------------------
88  //------------------------------------------------------------------------
89  TimeInterval(const TimeInterval & timeInterval)
90  : _data(timeInterval._data)
91  {}
92 
93  //------------------------------------------------------------------------
95  //------------------------------------------------------------------------
96  const TimeValue & Start() const
97  {
98  return(_data.first);
99  }
100 
101  //------------------------------------------------------------------------
103  //------------------------------------------------------------------------
104  const TimeValue & Start(const TimeValue & start);
105 
106  //------------------------------------------------------------------------
108  //------------------------------------------------------------------------
109  const TimeValue & End() const
110  {
111  return(_data.second);
112  }
113 
114  //------------------------------------------------------------------------
116  //------------------------------------------------------------------------
117  const TimeValue & End(const TimeValue & end);
118 
119  //------------------------------------------------------------------------
121  //------------------------------------------------------------------------
122  bool operator == (const TimeInterval & ti) const;
123 
124  //------------------------------------------------------------------------
126  //------------------------------------------------------------------------
127  TimeValue Duration() const
128  {
129  return (_data.second - _data.first);
130  }
131 
132  //------------------------------------------------------------------------
136  //------------------------------------------------------------------------
137  bool Contains(const TimeValue & tv) const;
138 
139  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
143  bool Contains(const TimeInterval & ti) const;
144 
145  //------------------------------------------------------------------------
147  //------------------------------------------------------------------------
148  bool Overlaps(const TimeInterval & ti) const;
149 
150  //------------------------------------------------------------------------
154  //------------------------------------------------------------------------
155  bool Adjacent(const TimeInterval & 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<TimeValue, TimeValue> _data;
223  };
224 
225 } // namespace Dwm
226 
227 #endif // _DWMTIMEINTERVAL_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 //-------------------------------------------------------------------------
This class encapsulates a time interval.
Definition: DwmTimeInterval.hh:64
int BZWrite(BZFILE *bzf) const
Writes the time interval to a BZFILE pointer.
TimeInterval(const TimeValue &start, const TimeValue &end)
Construct from a start and end time.
Definition: DwmTimeInterval.hh:80
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
TimeInterval()
Contructor.
Definition: DwmTimeInterval.hh:73
This class encapsulates a time value beyond the UNIX epoch, with microsecond granularity.
Definition: DwmTimeValue.hh:72
const TimeValue & End() const
Returns the end time.
Definition: DwmTimeInterval.hh:109
Dwm::Writable pure virtual class definition.
Dwm::BZ2Readable pure virtual class definition.
Dwm::GZReadable pure virtual class definition.
Dwm::Readable pure virtual class definition.
bool Adjacent(const TimeInterval &ti) const
Returns true if ti is immediately adjacent our time interval, i.e.
bool operator==(const TimeInterval &ti) const
operator ==
std::ostream & Write(std::ostream &os) const
Writes the time interval to an ostream. Returns the ostream.
const TimeValue & Start() const
Returns the start time.
Definition: DwmTimeInterval.hh:96
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmBZ2Readable.hh:57
Dwm::TimeValue class definition.
std::istream & Read(std::istream &is)
Reads the time interval from an istream. Returns the istream.
Dwm::BZ2Writable pure virtual class definition.
Definition: DwmBZ2IO.hh:67
This class is a pure virtual class, defining an interface for classes that can read their contents fr...
Definition: DwmGZReadable.hh:57
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
TimeInterval(const TimeInterval &timeInterval)
Copy constructor.
Definition: DwmTimeInterval.hh:89
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 Overlaps(const TimeInterval &ti) const
Returns true if ti overlaps the time interval.
uint32_t StreamedLength() const
Returns the length of the time insterval, in bytes.
bool Contains(const TimeValue &tv) const
Returns true if the TimeValue tv falls within the time interval, i.e.
int BZRead(BZFILE *bzf)
Reads the time interval from a BZFILE pointer.