OnixS C++ FIX Engine  4.12.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 
20 #pragma once
21 
22 #include <string>
23 
24 #include <OnixS/FIXEngine/ABI.h>
26 
27 #define ONIXS_MINMAX_ABUSER
28 
29 namespace OnixS {
30 namespace FIX {
31 typedef UInt32 Amount;
33 
34 typedef Int32 Interval;
36 
37 typedef Interval Days;
38 typedef Interval Hours;
39 typedef Interval Minutes;
40 typedef Interval Seconds;
41 
42 typedef Interval Milliseconds;
43 typedef Interval Microseconds;
44 typedef Interval Nanoseconds;
45 typedef HugeInterval Picoseconds;
46 
47 typedef HugeInterval TotalSeconds;
48 typedef HugeInterval TotalMilliseconds;
49 typedef HugeInterval TotalMicroseconds;
50 typedef HugeInterval TotalNanoseconds;
51 typedef HugeInterval TotalPicoseconds;
52 
53 /// Time related constants.
55  static const Hours HoursPerDay;
56  static const Minutes MinutesPerHour;
57 
58  static const Seconds SecondsPerMinute;
59  static const Seconds SecondsPerHour;
60  static const Seconds SecondsPerDay;
61 
62  static const Milliseconds MillisecondsPerSecond;
63  static const Microseconds MicrosecondsPerSecond;
64  static const Nanoseconds NanosecondsPerSecond;
65 
66  static const Picoseconds PicosecondsPerNanosecond;
67  static const Picoseconds PicosecondsPerMicrosecond;
68  static const Picoseconds PicosecondsPerMillisecond;
69  static const Picoseconds PicosecondsPerSecond;
70 };
71 
72 /// The collection of time span formats supported.
74  enum Enum {
75  /// Indicates the time span in the "HH:MM:SS" format.
77 
78  /// Indicates the time span in the "HH:MM:SS.sss" format.
80 
81  /// Indicates the time span in the "HH:MM:SS.ssssss" format.
83 
84  /// Indicates the time span in the "HH:MM:SS.sssssssss" format.
86 
87  /// Indicates the time span in the "HH:MM:SS.ssssssssssss" format.
88  HHMMSSPsec
89  };
90 };
91 
92 /// The time span related functionality.
94 {
95 public:
96  /// Constructs an uninitialized instance.
97  TimeSpan();
98 
99  /// Initializes the TimeSpan from seconds and nanoseconds.
100  TimeSpan(
101  TotalSeconds seconds,
102  Nanoseconds nanoseconds);
103 
104  /// Initializes the TimeSpan from seconds and picoseconds.
105  TimeSpan(
106  TotalSeconds seconds,
107  Picoseconds picoseconds);
108 
109  /// Initializes the TimeSpan from hours, minutes and seconds.
110  TimeSpan(
111  Hours hours,
112  Minutes minutes,
113  Seconds seconds);
114 
115  /// Initializes the TimeSpan from days, hours, minutes, seconds and nanoseconds.
116  TimeSpan(
117  Days days,
118  Hours hours,
119  Minutes minutes,
120  Seconds seconds,
121  Nanoseconds nanoseconds);
122 
123  /// Initializes the TimeSpan from days, hours, minutes, seconds and picoseconds.
124  TimeSpan(
125  Days days,
126  Hours hours,
127  Minutes minutes,
128  Seconds seconds,
129  Picoseconds picooseconds);
130 
131  /// The total number of seconds.
132  TotalSeconds totalSeconds() const;
133 
134  /// Current days.
135  Days days() const;
136 
137  /// Current hours.
138  Hours hours() const;
139 
140  /// Current minutes.
141  Minutes minutes() const;
142 
143  /// Current seconds.
144  Seconds seconds() const;
145 
146  /// Current milliseconds.
147  Milliseconds milliseconds() const;
148 
149  /// Current microseconds.
150  Microseconds microseconds() const;
151 
152  /// Current nanoseconds.
153  Nanoseconds nanoseconds() const;
154 
155  /// Current nanoseconds.
156  Picoseconds picoseconds() const;
157 
158  /// The current absolute time span.
159  TimeSpan absolute() const;
160 
161  /// Compares the instance with another one.
162  bool operator == (const TimeSpan &) const;
163 
164  /// Compares the instance with another one.
165  bool operator != (const TimeSpan &) const;
166 
167  /// Tests whether the instance is less than another one.
168  bool operator < (const TimeSpan &) const;
169 
170  /// Increases the instance by another one
171  TimeSpan & operator += (const TimeSpan &);
172 
173  /// Decreases the instance by another one
174  TimeSpan & operator -= (const TimeSpan &);
175 
176  /// The minimum value of the time span
177  static TimeSpan min ONIXS_MINMAX_ABUSER();
178 
179  /// The maximum value of the time span
180  static TimeSpan max ONIXS_MINMAX_ABUSER();
181 
182  /// The zero value of the time span
183  static TimeSpan zero();
184 
185  /// Returns the time span text presentation in the requested
186  /// format ("HH:MM:SS.sssssssss" by default).
187  std::string toString(TimeSpanFormat::Enum = TimeSpanFormat::HHMMSSNsec) const;
188  void toString(std::string &, TimeSpanFormat::Enum = TimeSpanFormat::HHMMSSNsec) const;
189 
190  /// Parses time span from its text presentation
191  static
192  TimeSpan
193  parse(const std::string &);
194 
195 protected:
196  friend class TimeManager;
197 
198  TotalSeconds seconds_;
199  Picoseconds picoseconds_;
200 
201  void normalize();
202 };
203 
204 inline
205 TotalSeconds
207 {
208  return seconds_;
209 }
210 
211 inline
212 Picoseconds
214 {
215  return picoseconds_;
216 }
217 
219 {
220 public:
221  DaySpan(Days days);
222 };
223 
224 /// The hour time span presentation.
226 {
227 public:
228  HourSpan(Hours hours);
229 };
230 
231 /// The minute time span presentation.
233 {
234 public:
235  MinuteSpan(Minutes minutes);
236 };
237 
238 /// The second time span presentation.
240 {
241 public:
242  SecondSpan(TotalSeconds seconds);
243 };
244 
245 /// The millisecond time span presentation.
247 {
248 public:
250  TotalMilliseconds milliseconds);
251 };
252 
253 /// The microsecond time span presentation.
255 {
256 public:
258  TotalMicroseconds microseconds);
259 };
260 
261 /// The nanosecond time span presentation.
263 {
264 public:
266  TotalNanoseconds nanoseconds);
267 };
268 
269 /// The picosecond time span presentation.
271 {
272 public:
274  TotalPicoseconds picoseconds);
275 };
276 }
277 }
Indicates the time span in the "HH:MM:SS.sssssssss" format.
Definition: TimeSpan.h:85
static const Picoseconds PicosecondsPerMicrosecond
Definition: TimeSpan.h:67
static const Picoseconds PicosecondsPerMillisecond
Definition: TimeSpan.h:68
Indicates the time span in the "HH:MM:SS" format.
Definition: TimeSpan.h:76
Indicates the time span in the "HH:MM:SS.ssssss" format.
Definition: TimeSpan.h:82
Interval Seconds
Definition: TimeSpan.h:40
Int64 HugeInterval
Definition: TimeSpan.h:35
static const Hours HoursPerDay
Definition: TimeSpan.h:55
Picoseconds picoseconds_
Definition: TimeSpan.h:199
HugeInterval TotalNanoseconds
Definition: TimeSpan.h:50
The picosecond time span presentation.
Definition: TimeSpan.h:270
static const Microseconds MicrosecondsPerSecond
Definition: TimeSpan.h:63
Interval Days
Definition: TimeSpan.h:37
unsigned int UInt32
Definition: Numeric.h:36
long long Int64
Definition: Numeric.h:38
UInt64 HugeAmount
Definition: TimeSpan.h:32
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
Interval Microseconds
Definition: TimeSpan.h:43
#define ONIXS_MINMAX_ABUSER
Definition: TimeSpan.h:27
TotalSeconds seconds_
Definition: TimeSpan.h:198
static const Seconds SecondsPerHour
Definition: TimeSpan.h:59
HugeInterval TotalMicroseconds
Definition: TimeSpan.h:49
HugeInterval Picoseconds
Definition: TimeSpan.h:45
The hour time span presentation.
Definition: TimeSpan.h:225
Interval Milliseconds
Definition: TimeSpan.h:42
HugeInterval TotalMilliseconds
Definition: TimeSpan.h:48
static const Milliseconds MillisecondsPerSecond
Definition: TimeSpan.h:62
static const Nanoseconds NanosecondsPerSecond
Definition: TimeSpan.h:64
Picoseconds picoseconds() const
Current nanoseconds.
Definition: TimeSpan.h:213
HugeInterval TotalPicoseconds
Definition: TimeSpan.h:51
The microsecond time span presentation.
Definition: TimeSpan.h:254
int Int32
Definition: Numeric.h:35
Time related constants.
Definition: TimeSpan.h:54
static const Seconds SecondsPerMinute
Definition: TimeSpan.h:58
UInt32 Amount
Definition: TimeSpan.h:31
The second time span presentation.
Definition: TimeSpan.h:239
unsigned long long UInt64
Definition: Numeric.h:39
TotalSeconds totalSeconds() const
The total number of seconds.
Definition: TimeSpan.h:206
Int32 Interval
Definition: TimeSpan.h:34
The time span related functionality.
Definition: TimeSpan.h:93
HugeInterval TotalSeconds
Definition: TimeSpan.h:47
bool operator==(const FieldValueRef &ref, const std::string &str)
Interval Minutes
Definition: TimeSpan.h:39
static const Picoseconds PicosecondsPerSecond
Definition: TimeSpan.h:69
Interval Hours
Definition: TimeSpan.h:38
static const Minutes MinutesPerHour
Definition: TimeSpan.h:56
Interval Nanoseconds
Definition: TimeSpan.h:44
The millisecond time span presentation.
Definition: TimeSpan.h:246
Indicates the time span in the "HH:MM:SS.sss" format.
Definition: TimeSpan.h:79
static const Seconds SecondsPerDay
Definition: TimeSpan.h:60
The collection of time span formats supported.
Definition: TimeSpan.h:73
The minute time span presentation.
Definition: TimeSpan.h:232
static const Picoseconds PicosecondsPerNanosecond
Definition: TimeSpan.h:66
bool operator!=(const FieldValueRef &ref, const std::string &str)
The nanosecond time span presentation.
Definition: TimeSpan.h:262