Files
2024-09-23 12:00:04 -04:00

278 lines
7.1 KiB
C++

/*
* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
*
* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
* and international copyright treaties.
*
* Access to and use of the software is governed by the terms of the applicable OnixS Software
* Services Agreement (the Agreement) and Customer end user license agreements granting
* a non-assignable, non-transferable and non-exclusive license to use the software
* for it's own data processing purposes under the terms defined in the Agreement.
*
* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
* of this source code or associated reference material to any other location for further reproduction
* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
*
* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
* the terms of the Agreement is a violation of copyright law.
*/
#pragma once
#include <string>
#include <OnixS/FIXEngine/ABI.h>
#include <OnixS/FIXEngine/FIX/Numeric.h>
#define ONIXS_MINMAX_ABUSER
namespace OnixS {
namespace FIX {
typedef UInt32 Amount;
typedef UInt64 HugeAmount;
typedef Int32 Interval;
typedef Int64 HugeInterval;
typedef Interval Days;
typedef Interval Hours;
typedef Interval Minutes;
typedef Interval Seconds;
typedef Interval Milliseconds;
typedef Interval Microseconds;
typedef Interval Nanoseconds;
typedef HugeInterval Picoseconds;
typedef HugeInterval TotalSeconds;
typedef HugeInterval TotalMilliseconds;
typedef HugeInterval TotalMicroseconds;
typedef HugeInterval TotalNanoseconds;
typedef HugeInterval TotalPicoseconds;
/// Time related constants.
struct ONIXS_FIXENGINE_API TimeDetails {
static const Hours HoursPerDay;
static const Minutes MinutesPerHour;
static const Seconds SecondsPerMinute;
static const Seconds SecondsPerHour;
static const Seconds SecondsPerDay;
static const Milliseconds MillisecondsPerSecond;
static const Microseconds MicrosecondsPerSecond;
static const Nanoseconds NanosecondsPerSecond;
static const Picoseconds PicosecondsPerNanosecond;
static const Picoseconds PicosecondsPerMicrosecond;
static const Picoseconds PicosecondsPerMillisecond;
static const Picoseconds PicosecondsPerSecond;
};
/// The collection of time span formats supported.
struct ONIXS_FIXENGINE_API TimeSpanFormat {
enum Enum {
/// Indicates the time span in the "HH:MM:SS" format.
HHMMSS,
/// Indicates the time span in the "HH:MM:SS.sss" format.
HHMMSSMsec,
/// Indicates the time span in the "HH:MM:SS.ssssss" format.
HHMMSSUsec,
/// Indicates the time span in the "HH:MM:SS.sssssssss" format.
HHMMSSNsec,
/// Indicates the time span in the "HH:MM:SS.ssssssssssss" format.
HHMMSSPsec
};
};
/// The time span related functionality.
class ONIXS_FIXENGINE_API TimeSpan
{
public:
/// Constructs an uninitialized instance.
TimeSpan();
/// Initializes the TimeSpan from seconds and nanoseconds.
TimeSpan(
TotalSeconds seconds,
Nanoseconds nanoseconds);
/// Initializes the TimeSpan from seconds and picoseconds.
TimeSpan(
TotalSeconds seconds,
Picoseconds picoseconds);
/// Initializes the TimeSpan from hours, minutes and seconds.
TimeSpan(
Hours hours,
Minutes minutes,
Seconds seconds);
/// Initializes the TimeSpan from days, hours, minutes, seconds and nanoseconds.
TimeSpan(
Days days,
Hours hours,
Minutes minutes,
Seconds seconds,
Nanoseconds nanoseconds);
/// Initializes the TimeSpan from days, hours, minutes, seconds and picoseconds.
TimeSpan(
Days days,
Hours hours,
Minutes minutes,
Seconds seconds,
Picoseconds picooseconds);
/// The total number of seconds.
TotalSeconds totalSeconds() const;
/// Current days.
Days days() const;
/// Current hours.
Hours hours() const;
/// Current minutes.
Minutes minutes() const;
/// Current seconds.
Seconds seconds() const;
/// Current milliseconds.
Milliseconds milliseconds() const;
/// Current microseconds.
Microseconds microseconds() const;
/// Current nanoseconds.
Nanoseconds nanoseconds() const;
/// Current nanoseconds.
Picoseconds picoseconds() const;
/// The current absolute time span.
TimeSpan absolute() const;
/// Compares the instance with another one.
bool operator == (const TimeSpan &) const;
/// Compares the instance with another one.
bool operator != (const TimeSpan &) const;
/// Tests whether the instance is less than another one.
bool operator < (const TimeSpan &) const;
/// Increases the instance by another one
TimeSpan & operator += (const TimeSpan &);
/// Decreases the instance by another one
TimeSpan & operator -= (const TimeSpan &);
/// The minimum value of the time span
static TimeSpan min ONIXS_MINMAX_ABUSER();
/// The maximum value of the time span
static TimeSpan max ONIXS_MINMAX_ABUSER();
/// The zero value of the time span
static TimeSpan zero();
/// Returns the time span text presentation in the requested
/// format ("HH:MM:SS.sssssssss" by default).
std::string toString(TimeSpanFormat::Enum = TimeSpanFormat::HHMMSSNsec) const;
void toString(std::string &, TimeSpanFormat::Enum = TimeSpanFormat::HHMMSSNsec) const;
/// Parses time span from its text presentation
static
TimeSpan
parse(const std::string &);
protected:
friend class TimeManager;
TotalSeconds seconds_;
Picoseconds picoseconds_;
void normalize();
};
inline
TotalSeconds
TimeSpan::totalSeconds() const
{
return seconds_;
}
inline
Picoseconds
TimeSpan::picoseconds() const
{
return picoseconds_;
}
class ONIXS_FIXENGINE_API DaySpan : public TimeSpan
{
public:
DaySpan(Days days);
};
/// The hour time span presentation.
class ONIXS_FIXENGINE_API HourSpan : public TimeSpan
{
public:
HourSpan(Hours hours);
};
/// The minute time span presentation.
class ONIXS_FIXENGINE_API MinuteSpan : public TimeSpan
{
public:
MinuteSpan(Minutes minutes);
};
/// The second time span presentation.
class ONIXS_FIXENGINE_API SecondSpan : public TimeSpan
{
public:
SecondSpan(TotalSeconds seconds);
};
/// The millisecond time span presentation.
class ONIXS_FIXENGINE_API MillisecondSpan : public TimeSpan
{
public:
MillisecondSpan(
TotalMilliseconds milliseconds);
};
/// The microsecond time span presentation.
class ONIXS_FIXENGINE_API MicrosecondSpan : public TimeSpan
{
public:
MicrosecondSpan(
TotalMicroseconds microseconds);
};
/// The nanosecond time span presentation.
class ONIXS_FIXENGINE_API NanosecondSpan : public TimeSpan
{
public:
NanosecondSpan(
TotalNanoseconds nanoseconds);
};
/// The picosecond time span presentation.
class ONIXS_FIXENGINE_API PicosecondSpan : public TimeSpan
{
public:
PicosecondSpan(
TotalPicoseconds picoseconds);
};
}
}