API

A fixed-width timespec structure. More...

#include <timespecX.hpp>

Collaboration diagram for flatlogs::timespecX:
Collaboration graph

Public Member Functions

 timespecX ()
 Default c'tor. More...
 
 timespecX (secT s, nanosecT ns)
 Construct with time values. More...
 
 timespecX (const timespec &ts)
 Construct from timespec. More...
 
timespecXoperator= (const timespec &ts)
 Convert a native timespec to a timespecX. More...
 
timespec getTimespec ()
 Get a native timespec from this custom one. More...
 
template<clockid_t clk_id = CLOCK_REALTIME>
void gettime ()
 Fill the the timespecX with the current time. More...
 
int timeStamp (std::string &tstamp)
 Get the filename timestamp for this timespecX. More...
 
std::string timeStamp ()
 Get the filname timestamp for this timespecX. More...
 
std::string ISO8601DateTimeStrX ()
 Get a date-time string in ISO 8601 format for timespecX. More...
 
std::string ISO8601DateTimeStr2MinX ()
 
std::string secondStrX ()
 Get a date-time string with just the second for timespecX. More...
 
int minute ()
 Get the minute from a timespecX. More...
 
double asDouble ()
 Get the time as a double from a timespecX. More...
 

Public Attributes

secT time_s {0}
 Time since the Unix epoch. More...
 
nanosecT time_ns {0}
 Nanoseconds.
More...
 

Detailed Description

A fixed-width timespec structure.

To ensure that binary encoding of time is stable regardless of environment, we use a custom timespec composed of fixed-width types.

Note
This is NOT binary compatible with plain timespec. Use the provided conversions.

Definition at line 34 of file timespecX.hpp.

Constructor & Destructor Documentation

◆ timespecX() [1/3]

flatlogs::timespecX::timespecX ( )
inline

Default c'tor.

Definition at line 40 of file timespecX.hpp.

◆ timespecX() [2/3]

flatlogs::timespecX::timespecX ( secT  s,
nanosecT  ns 
)
inline

Construct with time values.

Definition at line 45 of file timespecX.hpp.

◆ timespecX() [3/3]

flatlogs::timespecX::timespecX ( const timespec &  ts)
inline

Construct from timespec.

Definition at line 50 of file timespecX.hpp.

Member Function Documentation

◆ asDouble()

double flatlogs::timespecX::asDouble ( )
inline

Get the time as a double from a timespecX.

Returns
the time as a double.

Definition at line 231 of file timespecX.hpp.

Referenced by MagAOX::logger::getLogContVal().

◆ gettime()

template<clockid_t clk_id = CLOCK_REALTIME>
void flatlogs::timespecX::gettime ( )
inline

Fill the the timespecX with the current time.

This is based on the usual clock_gettime. clockid_t is a template parameter since we probaby always want CLOCK_REALTIME, but if we don't for some reason it will be passed in the same order as in clock_gettime.

Template Parameters
clk_idspecifies the type.

Definition at line 94 of file timespecX.hpp.

Referenced by flatlogs::clock_gettimeX(), and MagAOX::logger::logManager< _parentT, _logFileT >::createLog().

◆ getTimespec()

timespec flatlogs::timespecX::getTimespec ( )
inline

Get a native timespec from this custom one.

Definition at line 76 of file timespecX.hpp.

◆ ISO8601DateTimeStr2MinX()

std::string flatlogs::timespecX::ISO8601DateTimeStr2MinX ( )
inline

Definition at line 170 of file timespecX.hpp.

◆ ISO8601DateTimeStrX()

std::string flatlogs::timespecX::ISO8601DateTimeStrX ( )
inline

Get a date-time string in ISO 8601 format for timespecX.

Returns a string in the ISO 8601 format:

YYYY-MM-DDTHH:MM:SS.SSSSSSSSS
Return values
std::stringcontaining the formated date/time

Definition at line 153 of file timespecX.hpp.

Referenced by logdump::gettimes(), flatlogs::jsonFormat(), and flatlogs::stdFormat().

◆ minute()

int flatlogs::timespecX::minute ( )
inline

Get the minute from a timespecX.

Returns
the minute part.

Definition at line 216 of file timespecX.hpp.

◆ operator=()

timespecX& flatlogs::timespecX::operator= ( const timespec &  ts)
inline

Convert a native timespec to a timespecX.

Returns
this reference, if values are 0 and 0 then the input was too big or negative.
Todo:
make this use minval and maxval
Parameters
[in]tsthe native timespec from which to get values

Definition at line 59 of file timespecX.hpp.

Referenced by timespecX().

◆ secondStrX()

std::string flatlogs::timespecX::secondStrX ( )
inline

Get a date-time string with just the second for timespecX.

Returns a string in the format:

SS.SSS

which is useful for real-time streams of log entries.

Return values
std::stringcontaining the formated date/time

Definition at line 193 of file timespecX.hpp.

Referenced by flatlogs::stdShortFormat().

◆ timeStamp() [1/2]

std::string flatlogs::timespecX::timeStamp ( )
inline

Get the filname timestamp for this timespecX.

Returns a string with the timestamp encoded as

YYYYMMDDHHMMSSNNNNNNNNN

Definition at line 136 of file timespecX.hpp.

◆ timeStamp() [2/2]

int flatlogs::timespecX::timeStamp ( std::string &  tstamp)
inline

Get the filename timestamp for this timespecX.

Fills in a string with the timestamp encoded as

YYYYMMDDHHMMSSNNNNNNNNN
Parameters
[out]tstampthe string to hold the formatted time

Definition at line 108 of file timespecX.hpp.

Referenced by MagAOX::logger::logFileRaw::createFile().

Member Data Documentation

◆ time_ns

◆ time_s


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