Qt Virtual Chart Table (QVCT)
CDataTime.hpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 #ifndef QVCT_CDATATIME_HPP
20 #define QVCT_CDATATIME_HPP
21 
22 // C/C++
23 #include <time.h>
24 
25 // QT
26 class QDataStream;
27 
28 
30 
35 class CDataTime
36 {
37 
38  //------------------------------------------------------------------------------
39  // CONSTANTS / STATIC
40  //------------------------------------------------------------------------------
41 
42 public:
44  static constexpr double UNDEFINED_TIME = -9999999;
46  static const CDataTime UNDEFINED;
47 
48 
49  //------------------------------------------------------------------------------
50  // FIELDS
51  //------------------------------------------------------------------------------
52 
53 private:
55 
56  double fdTime;
57 
58 
59  //------------------------------------------------------------------------------
60  // CONSTRUCTORS / DESTRUCTOR
61  //------------------------------------------------------------------------------
62 
63 public:
65  CDataTime( double _fdTime = UNDEFINED_TIME );
66  CDataTime( const CDataTime& _roDataTime );
67  virtual ~CDataTime() {};
68 
69 
70  //------------------------------------------------------------------------------
71  // METHODS
72  //------------------------------------------------------------------------------
73 
74  // SETTERS
75 public:
77  void setTime( double _fdTime );
79  void setTime( time_t _tSeconds, long _lNanoSeconds );
81  void setTime( const CDataTime& _roDataTime );
83 
85 
86  // GETTERS
87 public:
89  double getTime() const { return fdTime; };
90 
91  // OTHER
92 public:
94  void serialize( QDataStream& _rqDataStream ) const;
96  void unserialize( QDataStream& _rqDataStream );
97 
98 
99  // OPERATORS
100 public:
102 
104  bool operator==( const CDataTime& _roTime ) const;
106 
108  bool operator!=( const CDataTime& _roTime ) const;
109 
110  // COMPARATORS
111 public:
113  static bool compareTimeAscending( const CDataTime& _roTime1, const CDataTime& _roTime2 );
115  static bool compareTimeDescending( const CDataTime& _roTime1, const CDataTime& _roTime2 );
116 
117 };
118 
119 #endif // QVCT_CDATATIME_HPP
Time data.
Definition: CDataTime.hpp:36
static const CDataTime UNDEFINED
Specific value for an undefined time object.
Definition: CDataTime.hpp:46
bool operator==(const CDataTime &_roTime) const
Equality operator.
Definition: CDataTime.cpp:98
static bool compareTimeDescending(const CDataTime &_roTime1, const CDataTime &_roTime2)
Time (descending sort) comparison operator.
Definition: CDataTime.cpp:117
void unserialize(QDataStream &_rqDataStream)
Unserializes (restore) this object's data from binary format.
Definition: CDataTime.cpp:90
CDataTime(double _fdTime=UNDEFINED_TIME)
Definition: CDataTime.cpp:41
void setTime(double _fdTime)
Sets the time, in seconds from Unix epoch.
Definition: CDataTime.cpp:60
static bool compareTimeAscending(const CDataTime &_roTime1, const CDataTime &_roTime2)
Time (ascending sort) comparison operator.
Definition: CDataTime.cpp:112
virtual ~CDataTime()
Definition: CDataTime.hpp:67
bool operator!=(const CDataTime &_roTime) const
Inequality operator.
Definition: CDataTime.cpp:103
double getTime() const
Returns this time's time, in seconds from Unix epoch.
Definition: CDataTime.hpp:89
void serialize(QDataStream &_rqDataStream) const
Serializes (store) this object's data to binary format.
Definition: CDataTime.cpp:85
static constexpr double UNDEFINED_TIME
Specific value for an undefined time.
Definition: CDataTime.hpp:44
double fdTime
Time, in seconds from Unix epoch.
Definition: CDataTime.hpp:56
void resetTime()
Resets the time (to an undefined Time)
Definition: CDataTime.hpp:84