WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
clockwerk::Time Class Reference

Wrapper to manage and convert time as timespce. More...

#include <Time.h>

Inheritance diagram for clockwerk::Time:

Public Member Functions

 Time (const struct timespec &t)
 Default, copy constructors and default destructor.
 Time (int64 sec=0, int64 nsec=0)
 ~Time ()
int64 sec () const
 Get time seconds.
int64 nsec () const
 Get time nanoseconds.
void setTime (const struct timespec &t)
 Function to set the time in the time object.
void setTime (uint32 sec, uint32 nsec)
 Function to set the time in the time object.
void stepTime (uint64 nsec)
 Function to step time forward by a set amount of nanoseconds.
const timespec & asTimespec () const
 Functions to return various time formats.
floating_point asFloatingPoint () const
unsigned long long asMilliseconds () const
int16 fromStr (const char *str) override
int16 str (char *output, size_t size) const override
 Output time as string.
floating_point asFrequency ()
 Function to convert time to frequency in Hz.
int16 fromFrequency (uint16 rate_hz)
 Function to set a time object from a frequency, in Hz.
void fromFloatingPoint (floating_point val)
 Function to set a time object from floating point.
int16 add (const Time &a, Time &res) const
 Set the time object from a string.
int16 subtract (const Time &b, Time &res) const
 Function to subtract a - b = res.
int16 multiply (unsigned int m, Time &res) const
 Function to multiply time by int.
int16 divide (unsigned int d, Time &res) const
 Function to divide time by int.
bool operator>= (const Time &B) const
 Overloaded operator to compare two time objects.
bool operator<= (const Time &B) const
 Overloaded operator to compare two time objects.
bool operator> (const Time &B) const
 Overloaded operator to compare two time objects.
bool operator< (const Time &B) const
 Overloaded operator to compare two time objects.
bool operator== (const Time &B) const
 Overloaded operator to compare two time objects.
Public Member Functions inherited from clockwerk::GraphTreeObject
 GraphTreeObject (const char *gt_nme="", GraphTreeObject **storage_array=nullptr, uint32 storage_size=0)
 Name-based constructor for GraphTreeObject which will have no children by default.
virtual ~GraphTreeObject ()
 Destructor.
GraphTreeObjectparent ()
 Functions to get object's parent/children.
GraphTreeObject ** children ()
GraphTreeObjectchildAtIndex (uint8 i) const
int16 parent (GraphTreeObject *new_parent)
 Function to assign the node's parent via pointer.
int16 parent (GraphTreeObject &new_parent)
 Function to assign the node's parent via reference.
uint8 nChildren () const
 Getters for number of children and descendants.
uint16 nDescendants () const
uint8 capacity () const
const char * name () const
 Getter and setter for object name.
int16 name (const char *new_name)
uint8 rank ()
 Getter for the object rank.
int8 type ()
 Function to indicate type – -1 by default unless implemented downstream.
bool loggable ()
 Getter for object logability flag – note no setter because should only be set by this or a derived class in its definition.
GraphTreeObjectgetRootDataPointer ()
 Get the pointer to the highest object in the graph tree.

Protected Attributes

struct timespec _tspec
Protected Attributes inherited from clockwerk::GraphTreeObject
GraphTreeObject_parent = nullptr
GraphTreeObject ** _children_ptr = nullptr
uint32 _max_num_children = 0
uint16 _num_descendants = 0
char _name [MAXIMUM_NAME_CHARS] = ""
 String name for object.
uint8 _num_children = 0
 Number of direct children of the tree (not including the tree itself).
uint8 _rank = 0
int8 _graph_tree_type = BASE_GRAPH_TREE
 Variable to store graph tree object type.
bool _loggable = false
 Variable to indicate whether the selected object is loggable. Set to false by default.
uint32 _index = 0
 Index pointing to the next write location for the graph tree children.

Additional Inherited Members

Protected Member Functions inherited from clockwerk::GraphTreeObject
int16 _setStorage (GraphTreeObject **storage_array, uint8 storage_size)
 Getter for object's string address.
void _recalculateDescendants ()
 Function to recursively re-calculate the number of descendants of a given node on the tree.
void _recalculateRank ()
 Function to recursively re-calculate the rank of a given node on the tree.
int16 _addChild (GraphTreeObject *child)
 Function to decompose a string into a series of substrings via indexing.
int16 _removeChild (GraphTreeObject *child)
 Function to remove a child from the graph node's children.

Detailed Description

Wrapper to manage and convert time as timespce.

The time class is a simple wrapper class designed to make working with time simple. It wraps around a struct timespec as its core, and contains functions to perform time math and conversions into various formats.

Note
The time object, while a child of GraphTreeObject, cannot have any children as no space is allocated for them. Therefore it must lie at the end of the tree.

Constructor & Destructor Documentation

◆ Time() [1/2]

clockwerk::Time::Time ( const struct timespec & t)
inline

Default, copy constructors and default destructor.

◆ Time() [2/2]

clockwerk::Time::Time ( int64 sec = 0,
int64 nsec = 0 )
inline

◆ ~Time()

clockwerk::Time::~Time ( )
inline

Member Function Documentation

◆ add()

int16 clockwerk::Time::add ( const Time & a,
Time & res ) const

Set the time object from a string.

Parameters
valString in standard seconds.decimal format
Returns
Error code corresponding to success/failure

Function to add two times together a + b

Parameters
aTime to add
resResult of the addition operation
Returns
Error code corresponding to success/failure

◆ asFloatingPoint()

floating_point clockwerk::Time::asFloatingPoint ( ) const
inline

◆ asFrequency()

floating_point clockwerk::Time::asFrequency ( )

Function to convert time to frequency in Hz.

Returns
Frequency in Hz corresponding to the time

◆ asMilliseconds()

unsigned long long clockwerk::Time::asMilliseconds ( ) const
inline

◆ asTimespec()

const timespec & clockwerk::Time::asTimespec ( ) const
inline

Functions to return various time formats.

◆ divide()

int16 clockwerk::Time::divide ( unsigned int d,
Time & res ) const

Function to divide time by int.

Parameters
dAmount to divide by
resResult of the division operation
Returns
Error code corresponding to success/failure

◆ fromFloatingPoint()

void clockwerk::Time::fromFloatingPoint ( floating_point val)

Function to set a time object from floating point.

Parameters
valThe floating point value to set time from

◆ fromFrequency()

int16 clockwerk::Time::fromFrequency ( uint16 rate_hz)

Function to set a time object from a frequency, in Hz.

Parameters
rate_hzThe rate to be converted to time

◆ fromStr()

int16 clockwerk::Time::fromStr ( const char * str)
overridevirtual

Reimplemented from clockwerk::GraphTreeObject.

◆ multiply()

int16 clockwerk::Time::multiply ( unsigned int m,
Time & res ) const

Function to multiply time by int.

Parameters
mAmount to multiply by
resResult of the multiplication operation
Returns
Error code corresponding to success/failure

◆ nsec()

int64 clockwerk::Time::nsec ( ) const
inline

Get time nanoseconds.

◆ operator<()

bool clockwerk::Time::operator< ( const Time & B) const

Overloaded operator to compare two time objects.

Parameters
BTime value to compare against
Returns
True/false corresponding to greater than calculation

◆ operator<=()

bool clockwerk::Time::operator<= ( const Time & B) const

Overloaded operator to compare two time objects.

Parameters
BTime value to compare against
Returns
True/false corresponding to greater than calculation

◆ operator==()

bool clockwerk::Time::operator== ( const Time & B) const

Overloaded operator to compare two time objects.

Parameters
BTime value to compare against
Returns
True/false corresponding to equals calculation

◆ operator>()

bool clockwerk::Time::operator> ( const Time & B) const

Overloaded operator to compare two time objects.

Parameters
BTime value to compare against
Returns
True/false corresponding to greater than calculation

◆ operator>=()

bool clockwerk::Time::operator>= ( const Time & B) const

Overloaded operator to compare two time objects.

Parameters
BTime value to compare against
Returns
True/false corresponding to greater than calculation

◆ sec()

int64 clockwerk::Time::sec ( ) const
inline

Get time seconds.

◆ setTime() [1/2]

void clockwerk::Time::setTime ( const struct timespec & t)
inline

Function to set the time in the time object.

Parameters
tTimespec to set the time to11

◆ setTime() [2/2]

void clockwerk::Time::setTime ( uint32 sec,
uint32 nsec )
inline

Function to set the time in the time object.

Parameters
secSeconds value
nsecNanoseconds value

◆ stepTime()

void clockwerk::Time::stepTime ( uint64 nsec)

Function to step time forward by a set amount of nanoseconds.

Parameters
nsecNumber of nanoseconds to step by

◆ str()

int16 clockwerk::Time::str ( char * output,
size_t size ) const
overridevirtual

Output time as string.

Returns
Time as a string

Get object represented as string

Parameters
outputThe output string
sizeThe maximum size of the variable to write string to
Note
Should be set in derived class

Reimplemented from clockwerk::GraphTreeObject.

◆ subtract()

int16 clockwerk::Time::subtract ( const Time & b,
Time & res ) const

Function to subtract a - b = res.

Parameters
bTime to subtract
resResult of the subtraction operation
Returns
Error code corresponding to success/failure

Member Data Documentation

◆ _tspec

struct timespec clockwerk::Time::_tspec
protected

The documentation for this class was generated from the following files:
  • /Users/mickey/Documents/Projects/warptwin/warpos/clockwerk/src/architecture/Time.h
  • /Users/mickey/Documents/Projects/warptwin/warpos/clockwerk/src/architecture/Time.cpp