fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::Tickval Class Reference

#include <tickval.hpp>

Public Types

using f8_clock = std::chrono::high_resolution_clock
 
using f8_time_point = std::chrono::time_point< f8_clock >
 
using ticks = decltype(f8_time_point::min().time_since_epoch().count())
 
using f8_duration = f8_time_point::duration
 

Public Member Functions

 Tickval (bool settonow=false)
 
 Tickval (const Tickval &from)
 
 Tickval (ticks from)
 
 Tickval (f8_time_point from)
 
 Tickval (time_t secs, long nsecs)
 
Tickvaloperator= (const Tickval &that)
 
Tickvaloperator= (ticks that)
 
ticks get_ticks () const
 
Tickvalnow ()
 
time_t secs () const
 
unsigned msecs () const
 
unsigned usecs () const
 
unsigned nsecs () const
 
double todouble () const
 
bool is_errorval () const
 
bool in_range (const Tickval &a, const Tickval &b) const
 
Tickvaladjust (ticks by)
 
struct tm * as_tm (struct tm &result) const
 
struct tm get_tm () const
 
void set (time_t secs, long nsecs)
 
bool operator! () const
 
 operator void * ()
 
 operator Tickval::ticks ()
 
 operator double ()
 

Static Public Member Functions

static const tickserrorticks ()
 
static Tickval get_tickval ()
 
static Tickvalget_tickval (Tickval &to)
 

Static Public Attributes

static const ticks noticks = 0
 
static const ticks thousand = 1000
 
static const ticks million = thousand * thousand
 
static const ticks billion = thousand * million
 
static const ticks second = billion
 
static const ticks minute = 60 * second
 
static const ticks hour = 60 * minute
 
static const ticks day = 24 * hour
 
static const ticks week = 7 * day
 

Private Attributes

f8_time_point _value
 

Friends

Tickval operator- (const Tickval &newtime, const Tickval &oldtime)
 
Tickvaloperator-= (Tickval &oldtime, const Tickval &newtime)
 
Tickval operator+ (const Tickval &newtime, const Tickval &oldtime)
 
Tickvaloperator+= (Tickval &oldtime, const Tickval &newtime)
 
bool operator== (const Tickval &a, const Tickval &b)
 
bool operator!= (const Tickval &a, const Tickval &b)
 
bool operator> (const Tickval &a, const Tickval &b)
 
bool operator< (const Tickval &a, const Tickval &b)
 
bool operator>= (const Tickval &a, const Tickval &b)
 
bool operator<= (const Tickval &a, const Tickval &b)
 
Tickvaloperator+= (Tickval &oldtime, ticks ns)
 
Tickvaloperator-= (Tickval &oldtime, ticks ns)
 
std::ostream & operator<< (std::ostream &os, const Tickval &what)
 
std::ostream & operator>> (std::ostream &os, const Tickval &what)
 

Detailed Description

High resolution time in nanosecond ticks. Thread safe. Portable, based on std::chrono Assumes we support nanosecond resolution. For implementations that don't, there will be inaccuracies: Windows 7 supports up to 15ms resolution only; for Windows 8 it is 100ns. Linux x86_64 is 1ns.

Definition at line 57 of file tickval.hpp.

Member Typedef Documentation

using FIX8::Tickval::f8_clock = std::chrono::high_resolution_clock

Definition at line 63 of file tickval.hpp.

using FIX8::Tickval::f8_duration = f8_time_point::duration

Definition at line 67 of file tickval.hpp.

using FIX8::Tickval::f8_time_point = std::chrono::time_point<f8_clock>

Definition at line 65 of file tickval.hpp.

using FIX8::Tickval::ticks = decltype(f8_time_point::min().time_since_epoch().count())

Definition at line 66 of file tickval.hpp.

Constructor & Destructor Documentation

FIX8::Tickval::Tickval ( bool  settonow = false)
inlineexplicit

Ctor.

Parameters
settonowif true, construct with current time

Definition at line 90 of file tickval.hpp.

Referenced by get_tickval(), and set().

91  : _value(settonow ? f8_clock::now() : f8_time_point(f8_duration::zero())) {}
std::chrono::time_point< f8_clock > f8_time_point
Definition: tickval.hpp:65
f8_time_point _value
Definition: tickval.hpp:85
FIX8::Tickval::Tickval ( const Tickval from)
inline

Copy Ctor.

Definition at line 94 of file tickval.hpp.

94 : _value(from._value) {}
f8_time_point _value
Definition: tickval.hpp:85
FIX8::Tickval::Tickval ( ticks  from)
inlineexplicit

Ctor.

Parameters
fromconstruct from raw ticks value (nanoseconds)

Definition at line 98 of file tickval.hpp.

98 : _value(std::chrono::duration_cast<f8_duration>(std::chrono::nanoseconds(from))) {}
f8_time_point _value
Definition: tickval.hpp:85
FIX8::Tickval::Tickval ( f8_time_point  from)
inlineexplicit

Ctor.

Parameters
fromconstruct from time_point value

Definition at line 102 of file tickval.hpp.

102 : _value(from) {}
f8_time_point _value
Definition: tickval.hpp:85
FIX8::Tickval::Tickval ( time_t  secs,
long  nsecs 
)
inline

Ctor.

Parameters
secsseconds
nsecsnanoseconds

Definition at line 107 of file tickval.hpp.

108  : _value(f8_clock::from_time_t(secs) + std::chrono::duration_cast<f8_duration>(std::chrono::nanoseconds(nsecs))) {}
unsigned nsecs() const
Definition: tickval.hpp:159
f8_time_point _value
Definition: tickval.hpp:85
time_t secs() const
Definition: tickval.hpp:141

Member Function Documentation

Tickval& FIX8::Tickval::adjust ( ticks  by)
inline

Adjust Tickval by given value

Parameters
byamount to adjust; if +ve add, if -ve sub
Returns
adjusted Tickval

Definition at line 187 of file tickval.hpp.

Referenced by FIX8::Schedule::test().

187 { return *this += by; }
struct tm* FIX8::Tickval::as_tm ( struct tm &  result) const
inline

Get tickval as struct tm

Parameters
resultref to struct tm to fill
Returns
ptr to result

Definition at line 200 of file tickval.hpp.

Referenced by get_tm().

201  {
202  const time_t insecs(std::chrono::system_clock::to_time_t(_value));
203 #ifdef _MSC_VER
204  gmtime_s(&result, &insecs);
205 #else
206  gmtime_r(&insecs, &result);
207 #endif
208  return &result;
209  }
f8_time_point _value
Definition: tickval.hpp:85
static const ticks& FIX8::Tickval::errorticks ( )
inlinestatic

Definition at line 69 of file tickval.hpp.

Referenced by FIX8::Configuration::get_time_field(), and is_errorval().

70  {
71  static const auto g_ticks(std::chrono::duration_cast<std::chrono::nanoseconds>
72  (f8_time_point::max().time_since_epoch()).count());
73  return g_ticks;
74  }
ticks FIX8::Tickval::get_ticks ( ) const
inline

Get the raw tick value (nanosecs).

Returns
raw ticks

Definition at line 129 of file tickval.hpp.

Referenced by FIX8::Configuration::create_schedule(), FIX8::date_parse(), FIX8::date_time_parse(), is_errorval(), FIX8::Timer< T >::operator()(), FIX8::Schedule::test(), and FIX8::time_parse().

129 { return std::chrono::duration_cast<std::chrono::nanoseconds>(_value.time_since_epoch()).count(); }
f8_time_point _value
Definition: tickval.hpp:85
static Tickval FIX8::Tickval::get_tickval ( )
inlinestatic

Generate a Tickval object, constructed with the current time.

Returns
Tickval

Definition at line 191 of file tickval.hpp.

References Tickval().

Referenced by FIX8::Timer< T >::operator()(), and FIX8::Timer< T >::schedule().

191 { return Tickval(true); }
Tickval(bool settonow=false)
Definition: tickval.hpp:90
static Tickval& FIX8::Tickval::get_tickval ( Tickval to)
inlinestatic

Assign current time to a given Tickval object.

Returns
target Tickval object

Definition at line 195 of file tickval.hpp.

References Tickval().

195 { return to = Tickval(true); }
Tickval(bool settonow=false)
Definition: tickval.hpp:90
struct tm FIX8::Tickval::get_tm ( ) const
inline

Get tickval as struct tm

Returns
tm structure

Definition at line 213 of file tickval.hpp.

References as_tm().

Referenced by FIX8::date_time_format(), and FIX8::Schedule::test().

214  {
215  struct tm result;
216  return *as_tm(result);
217  }
struct tm * as_tm(struct tm &result) const
Definition: tickval.hpp:200
bool FIX8::Tickval::in_range ( const Tickval a,
const Tickval b 
) const
inline

See if this Tickval is within the range given

Parameters
alower boundary
bupper boundary; if an error value, ignore upper range
Returns
true if in range

Definition at line 179 of file tickval.hpp.

References is_errorval().

Referenced by FIX8::Schedule::test().

180  {
181  return !b.is_errorval() ? a <= *this && *this <= b : a <= *this;
182  }
bool FIX8::Tickval::is_errorval ( ) const
inline

See if this Tickval holds an error value

Returns
true if an error value

Definition at line 173 of file tickval.hpp.

References errorticks(), and get_ticks().

Referenced by FIX8::Configuration::create_schedule(), in_range(), and FIX8::Schedule::is_valid().

173 { return get_ticks() == errorticks(); }
static const ticks & errorticks()
Definition: tickval.hpp:69
ticks get_ticks() const
Definition: tickval.hpp:129
unsigned FIX8::Tickval::msecs ( ) const
inline

Get the current number of elapsed milliseconds (excluding secs)

Returns
value in milliseconds

Definition at line 145 of file tickval.hpp.

Referenced by FIX8::date_time_format(), FIX8::Logger::process_logline(), and FIX8::XmlFileLogger::process_logline().

146  {
147  return std::chrono::duration_cast<std::chrono::milliseconds>(_value.time_since_epoch()).count() % std::milli::den;
148  }
f8_time_point _value
Definition: tickval.hpp:85
Tickval& FIX8::Tickval::now ( )
inline

Assign the current time to this object.

Returns
current object

Definition at line 133 of file tickval.hpp.

Referenced by FIX8::GetTimeAsStringMini(), FIX8::GetTimeAsStringMS(), FIX8::Session::heartbeat_service(), FIX8::IntervalTimer::Reset(), FIX8::Session::send_process(), FIX8::Session::update_received(), and FIX8::Session::update_sent().

134  {
135  _value = f8_clock::now();
136  return *this;
137  }
f8_time_point _value
Definition: tickval.hpp:85
unsigned FIX8::Tickval::nsecs ( ) const
inline

Get the current number of elapsed nanoseconds (excluding secs)

Returns
value in nanoseconds

Definition at line 159 of file tickval.hpp.

Referenced by FIX8::GetTimeAsStringMS().

160  {
161  return std::chrono::duration_cast<std::chrono::nanoseconds>(_value.time_since_epoch()).count() % std::nano::den;
162  }
f8_time_point _value
Definition: tickval.hpp:85
FIX8::Tickval::operator double ( )
inline

Cast to double.

Returns
ticks as double

Definition at line 238 of file tickval.hpp.

References todouble().

238 { return todouble(); }
double todouble() const
Definition: tickval.hpp:166
FIX8::Tickval::operator Tickval::ticks ( )
inline

Cast to unsigned long long.

Returns
ticks as unsigned long long

Definition at line 234 of file tickval.hpp.

234 { return _value.time_since_epoch().count(); }
f8_time_point _value
Definition: tickval.hpp:85
FIX8::Tickval::operator void * ( )
inline

Not 0 operator

Returns
true if ticks

Definition at line 230 of file tickval.hpp.

230 { return _value.time_since_epoch() == std::chrono::nanoseconds::zero() ? nullptr : this; }
f8_time_point _value
Definition: tickval.hpp:85
bool FIX8::Tickval::operator! ( ) const
inline

Not operator

Returns
true if no ticks (0)

Definition at line 226 of file tickval.hpp.

226 { return _value.time_since_epoch() == std::chrono::nanoseconds::zero(); }
f8_time_point _value
Definition: tickval.hpp:85
Tickval& FIX8::Tickval::operator= ( const Tickval that)
inline

Assignment operator.

Definition at line 111 of file tickval.hpp.

References _value.

112  {
113  if (this != &that)
114  _value = that._value;
115  return *this;
116  }
f8_time_point _value
Definition: tickval.hpp:85
Tickval& FIX8::Tickval::operator= ( ticks  that)
inline

Assignment operator from ticks

Parameters
thatticks to assign from
Returns
*this

Definition at line 121 of file tickval.hpp.

122  {
123  _value = f8_time_point(std::chrono::duration_cast<f8_duration>(std::chrono::nanoseconds(that)));
124  return *this;
125  }
std::chrono::time_point< f8_clock > f8_time_point
Definition: tickval.hpp:65
f8_time_point _value
Definition: tickval.hpp:85
time_t FIX8::Tickval::secs ( ) const
inline

Get the current number of elapsed seconds

Returns
value in seconds

Definition at line 141 of file tickval.hpp.

Referenced by FIX8::GetTimeAsStringMini(), FIX8::GetTimeAsStringMS(), FIX8::Session::heartbeat_service(), FIX8::Logger::process_logline(), and FIX8::XmlFileLogger::process_logline().

141 { return std::chrono::duration_cast<std::chrono::seconds>(_value.time_since_epoch()).count(); }
f8_time_point _value
Definition: tickval.hpp:85
void FIX8::Tickval::set ( time_t  secs,
long  nsecs 
)
inline

Set from secs/nsecs

Parameters
secsseconds
nsecsnanoseconds

Definition at line 222 of file tickval.hpp.

References Tickval().

222 { _value = Tickval(secs, nsecs)._value; }
unsigned nsecs() const
Definition: tickval.hpp:159
f8_time_point _value
Definition: tickval.hpp:85
time_t secs() const
Definition: tickval.hpp:141
Tickval(bool settonow=false)
Definition: tickval.hpp:90
double FIX8::Tickval::todouble ( ) const
inline

Get the current tickval as a double.

Returns
value as a double

Definition at line 166 of file tickval.hpp.

Referenced by FIX8::IntervalTimer::AsDouble(), and operator double().

167  {
168  return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(_value.time_since_epoch()).count()) / std::nano::den;
169  }
f8_time_point _value
Definition: tickval.hpp:85
unsigned FIX8::Tickval::usecs ( ) const
inline

Get the current number of elapsed microseconds (excluding secs)

Returns
value in microseconds

Definition at line 152 of file tickval.hpp.

153  {
154  return std::chrono::duration_cast<std::chrono::microseconds>(_value.time_since_epoch()).count() % std::micro::den;
155  }
f8_time_point _value
Definition: tickval.hpp:85

Friends And Related Function Documentation

bool operator!= ( const Tickval a,
const Tickval b 
)
friend

Inequivalence operator.

Parameters
alhs Tickval
brhs Tickval
Returns
true if not equal

Definition at line 284 of file tickval.hpp.

284 { return a._value != b._value; }
Tickval operator+ ( const Tickval newtime,
const Tickval oldtime 
)
friend

Binary addition operator.

Parameters
newtimeTickval to add to
oldtimeTickval to add
Returns
Result as Tickval

Definition at line 261 of file tickval.hpp.

262  { return Tickval(newtime._value + oldtime._value.time_since_epoch()); }
Tickval(bool settonow=false)
Definition: tickval.hpp:90
Tickval& operator+= ( Tickval oldtime,
const Tickval newtime 
)
friend

Binary addition operator.

Parameters
newtimeTickval to add to
oldtimeTickval to add
Returns
resulting oldtime

Definition at line 268 of file tickval.hpp.

269  {
270  oldtime._value += newtime._value.time_since_epoch();
271  return oldtime;
272  }
Tickval& operator+= ( Tickval oldtime,
ticks  ns 
)
friend

Binary addition operator.

Parameters
oldtimeTickval to add to
nsticks to add
Returns
oldtime as Tickval

Definition at line 314 of file tickval.hpp.

315  {
316  oldtime._value += std::chrono::duration_cast<f8_duration>(std::chrono::nanoseconds(ns));
317  return oldtime;
318  }
f8_time_point::duration f8_duration
Definition: tickval.hpp:67
Tickval operator- ( const Tickval newtime,
const Tickval oldtime 
)
friend

Binary negate operator.

Parameters
newtimeTickval to subtract from
oldtimeTickval to subtract
Returns
Result as Tickval

Definition at line 244 of file tickval.hpp.

245  { return Tickval(newtime._value - oldtime._value.time_since_epoch()); }
Tickval(bool settonow=false)
Definition: tickval.hpp:90
Tickval& operator-= ( Tickval oldtime,
const Tickval newtime 
)
friend

Binary negate operator.

Parameters
newtimeTickval to subtract from
oldtimeTickval to subtract
Returns
resulting oldtime

Definition at line 251 of file tickval.hpp.

252  {
253  oldtime._value -= newtime._value.time_since_epoch();
254  return oldtime;
255  }
Tickval& operator-= ( Tickval oldtime,
ticks  ns 
)
friend

Binary negate operator.

Parameters
oldtimeTickval to subtract from
nsTickval to subtract
Returns
oldtime as Tickval

Definition at line 324 of file tickval.hpp.

325  {
326  oldtime._value -= std::chrono::duration_cast<f8_duration>(std::chrono::nanoseconds(ns));
327  return oldtime;
328  }
f8_time_point::duration f8_duration
Definition: tickval.hpp:67
bool operator< ( const Tickval a,
const Tickval b 
)
friend

Less than operator.

Parameters
alhs Tickval
brhs Tickval
Returns
true if a is less than b

Definition at line 296 of file tickval.hpp.

296 { return a._value < b._value; }
std::ostream& operator<< ( std::ostream &  os,
const Tickval what 
)
friend

ostream inserter friend; Tickval printer, localtime

Parameters
osstream to insert into
whatTickval to insert
Returns
ostream object

Definition at line 334 of file tickval.hpp.

335  {
336  std::string result;
337  return os << GetTimeAsStringMS(result, &what, 9, false);
338  }
F8API const std::string & GetTimeAsStringMS(std::string &result, const class Tickval *tv=0, const unsigned dplaces=6, bool use_gm=false)
bool operator<= ( const Tickval a,
const Tickval b 
)
friend

Less than or equal to operator.

Parameters
alhs Tickval
brhs Tickval
Returns
true if a is less than or equal to b

Definition at line 308 of file tickval.hpp.

308 { return a._value <= b._value; }
bool operator== ( const Tickval a,
const Tickval b 
)
friend

Equivalence operator.

Parameters
alhs Tickval
brhs Tickval
Returns
true if equal

Definition at line 278 of file tickval.hpp.

278 { return a._value == b._value; }
bool operator> ( const Tickval a,
const Tickval b 
)
friend

Greater than operator.

Parameters
alhs Tickval
brhs Tickval
Returns
true if a is greater than b

Definition at line 290 of file tickval.hpp.

290 { return a._value > b._value; }
bool operator>= ( const Tickval a,
const Tickval b 
)
friend

Greater than or equal to operator.

Parameters
alhs Tickval
brhs Tickval
Returns
true if a is greater than or equal to b

Definition at line 302 of file tickval.hpp.

302 { return a._value >= b._value; }
std::ostream& operator>> ( std::ostream &  os,
const Tickval what 
)
friend

ostream inserter friend; Tickval printer, gmtime

Parameters
osstream to insert into
whatTickval to insert
Returns
ostream object

Definition at line 344 of file tickval.hpp.

345  {
346  std::string result;
347  return os << GetTimeAsStringMS(result, &what, 9, true);
348  }
F8API const std::string & GetTimeAsStringMS(std::string &result, const class Tickval *tv=0, const unsigned dplaces=6, bool use_gm=false)

Member Data Documentation

f8_time_point FIX8::Tickval::_value
private

Definition at line 85 of file tickval.hpp.

Referenced by operator=().

const ticks FIX8::Tickval::billion = thousand * million
static

Definition at line 77 of file tickval.hpp.

Referenced by FIX8::date_parse(), FIX8::date_time_parse(), and FIX8::time_parse().

const ticks FIX8::Tickval::day = 24 * hour
static

Definition at line 81 of file tickval.hpp.

Referenced by FIX8::Schedule::test().

const ticks FIX8::Tickval::hour = 60 * minute
static

Definition at line 80 of file tickval.hpp.

const ticks FIX8::Tickval::million = thousand * thousand
static
const ticks FIX8::Tickval::minute = 60 * second
static

Definition at line 79 of file tickval.hpp.

Referenced by FIX8::Configuration::create_schedule().

const ticks FIX8::Tickval::noticks = 0
static

Definition at line 68 of file tickval.hpp.

Referenced by FIX8::date_time_parse(), and FIX8::time_parse().

const ticks FIX8::Tickval::second = billion
static

Definition at line 78 of file tickval.hpp.

const ticks FIX8::Tickval::thousand = 1000
static

Definition at line 75 of file tickval.hpp.

const ticks FIX8::Tickval::week = 7 * day
static

Definition at line 82 of file tickval.hpp.


The documentation for this class was generated from the following file: