OnixS C++ SGX Titan OUCH Trading Handler  1.2.0
API documentation
TimeSpan.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 #pragma once
20 
21 #include <string>
22 
25 
27 
28 /// Time span formats supported.
29 struct ONIXS_SGXTITAN_OUCH_API TimeSpanFormats
30 {
31  enum Enum
32  {
33  /// HH:MM:SS.
35 
36  /// HH:MM:SS.sss.
38 
39  /// HH:MM:SS.sssssssss.
40  SDHHMMSSnsec
41  };
42 };
43 
44 /// Time span format.
46 
47 /// Represents time interval. Used primarily to
48 /// present time-only stamps and to measure time
49 /// intervals between two timestamps.
50 class ONIXS_SGXTITAN_OUCH_API TimeSpan
51 {
52  public:
53  /// Initializes zero span.
54  TimeSpan();
55 
56  /// Initializes with given set of values.
57  /// Input parameters are treated as quantities,
58  /// but not as a time stamp. Therefore, there's
59  /// no requirement to fit in a certain range like
60  /// hours must fit into [0, 24) range. After
61  /// initialization time span will be normalized.
62  TimeSpan (int hours, int minutes, int seconds, int nanoseconds = 0);
63 
64  /// Initializes with given set of values.
65  /// Input parameters are treated as quantities,
66  /// but not as a time stamp. Therefore, there's
67  /// no requirement to fit in a certain range like
68  /// hours must fit into [0, 24) range. After
69  /// initialization time span will be normalized.
70  TimeSpan (int days, int hours, int minutes, int seconds, int nanoseconds);
71 
72  /// Initializes time interval from total number
73  /// seconds and its fractional (nanosecond) part.
74  TimeSpan (long long totalSeconds, int nanoseconds);
75 
76  /// Initializes as clone of other instance.
77  TimeSpan (const TimeSpan& other);
78 
79  /// Whole number of seconds in time interval.
80  long long totalSeconds() const;
81 
82  /// Days component of time interval.
83  /// Whole number of days in time interval.
84  int days() const;
85 
86  /// Hours component of time interval.
87  /// Values are in range from -23 through 23.
88  int hours() const;
89 
90  /// Minutes component of time interval.
91  /// Values are in range from -59 through 59.
92  int minutes() const;
93 
94  /// Seconds component of time interval.
95  /// Values are in range from -59 through 59.
96  int seconds() const;
97 
98  /// Milliseconds component of time interval.
99  /// Values are in range from -999 through 999.
100  int milliseconds() const;
101 
102  /// Microseconds component of time interval.
103  /// Values are in range from -999999 through 999999.
104  int microseconds() const;
105 
106  /// Nanoseconds component of time interval.
107  /// Values are in range from -999999999 through 999999999.
108  int nanoseconds() const;
109 
110  /// Compares with other instance for equality.
111  bool operator == (const TimeSpan& other) const;
112 
113  /// Compares with other instance for in-equality.
114  bool operator != (const TimeSpan& other) const;
115 
116  /// Checks whether time interval less than other one.
117  bool operator < (const TimeSpan& other) const;
118 
119  /// Checks whether time interval greater than other one.
120  bool operator >(const TimeSpan& other) const;
121 
122  /// Adds time interval to current one.
123  TimeSpan& operator += (const TimeSpan& other);
124 
125  /// Subtracts time interval from current one.
126  TimeSpan& operator -= (const TimeSpan& other);
127 
128  /// Re-assigns time interval from other one.
129  TimeSpan& operator = (const TimeSpan& other);
130 
131  /// Serializes time stamp into text presentation
132  /// using specified time-span presentation format.
133  void toString (std::string& str, TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
134 
135  /// Serializes time stamp into text presentation
136  /// using specified time-span presentation format.
137  std::string toString (TimeSpanFormat format = TimeSpanFormats::SDHHMMSSnsec) const;
138 
139  /// De-serializes time interval from its text presentation.
140  static TimeSpan deserialize (const std::string& str);
141 
142  /// Time interval of zero length.
143  static const TimeSpan Zero;
144 
145  private:
146  long long seconds_;
147  int nanoseconds_;
148 };
149 
150 inline long long TimeSpan::totalSeconds() const
151 {
152  return seconds_;
153 }
154 
155 inline int TimeSpan::nanoseconds() const
156 {
157  return nanoseconds_;
158 }
159 
160 inline std::string TimeSpan::toString (TimeSpanFormat format) const
161 {
162  std::string str;
163 
164  toString (str, format);
165 
166  return str;
167 }
168 
bool operator<(const StrRef &left, const StrRef &right)
Establishes order over string refs.
Definition: String.h:415
Time span formats supported.
Definition: TimeSpan.h:29
static const TimeSpan Zero
Time interval of zero length.
Definition: TimeSpan.h:143
bool operator!=(const StrRef &left, const StrRef &right)
Compares with another instance.
Definition: String.h:325
#define ONIXS_SGXTITAN_OUCH_NAMESPACE_END
Definition: Bootstrap.h:31
#define ONIXS_SGXTITAN_OUCH_NAMESPACE_BEGIN
Definition: Bootstrap.h:27
bool operator>(const StrRef &left, const StrRef &right)
Establishes order over string refs.
Definition: String.h:441
bool operator==(const StrRef &left, const StrRef &right)
Compares StrRef instance with another one.
Definition: String.h:311
TimeSpanFormats::Enum TimeSpanFormat
Time span format.
Definition: TimeSpan.h:45