ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
clockwerk::Time Class Reference

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

#include <Time.h>

Inheritance diagram for clockwerk::Time:
Collaboration diagram for clockwerk::Time:

Public Member Functions

 Time ()
 Default, copy constructors and default destructor.
 
 Time (const struct timespec &t)
 
 Time (long unsigned int sec, long unsigned int nsec=0)
 
void setTime (const struct timespec &t)
 Function to set the time in the time object.
 
void stepTime (const unsigned long long &nsec)
 Function to step time forward by a set amount of nanoseconds.
 
const timespecasTimespec () const
 Functions to return various time formats.
 
double asDouble () const
 
unsigned long long asMilliseconds () const
 
std::string asString () const
 
void fromFrequency (unsigned int rate_hz)
 Function to set a time object from a frequency, in Hz.
 
void fromDouble (double val)
 Function to set a time object from double.
 
int log (void *logger)
 Function to log data from our Time class.
 
std::vector< std::string > header_info () const
 Function to write header data from our Time class.
 
int add (const Time &a, Time &res) const
 Function to add two times together a + b.
 
int subtract (const Time &b, Time &res) const
 Function to subtract a - b = res.
 
int divide (unsigned int d, Time &res) const
 Function to get half of a struct timespec.
 
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.
 
GraphTreeObjectparent ()
 Functions to get object's parent/children.
 
int parent (GraphTreeObject *new_parent)
 Function to assign the node's parent via pointer.
 
int parent (GraphTreeObject &new_parent)
 Function to assign the node's parent via reference.
 
std::vector< GraphTreeObject * > & children ()
 
unsigned int nChildren ()
 Getters for number of children and descendants.
 
unsigned int nDescendants ()
 
std::string name () const
 Getter and setter for object name.
 
int name (const std::string &new_name)
 
int rank ()
 Getter for the object rank.
 
virtual int 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.
 
std::string address ()
 Getter for object's string address.
 
std::vector< std::string > search (const std::string &address)
 Function to search through the graph tree by string address.
 
GraphTreeObjectgetByAddress (const std::string &address)
 Function to get an object from the graph tree by string address.
 
void dump (bool recursive=false)
 Function to dump the graph node, optionally including descendents.
 
void graphNodeInfo ()
 Function to return all info associated with a given graph node.
 
void recurseGraphNodeInfo (unsigned int counter)
 Function to recurse through graph tree and print all node info.
 
virtual int header (void *logger)
 Function to pass headers for this object to the logger.
 
void findLoggable (std::vector< GraphTreeObject * > &matches)
 Function to find all loggable parameters in this node and its children.
 
void lock (bool recursive=true)
 Function to lock the graph tree object and its children to changes.
 
void unlock (bool recursive=true)
 Function to unlock the graph tree and its children for changes.
 
bool locked ()
 Function to return whether graph tree object is locked.
 

Protected Member Functions

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.
 
std::vector< std::string > decomposeAddress (std::string address)
 Function to decompose a string into a series of substrings via indexing.
 
void findMatches (const std::vector< std::string > &subaddresses, const unsigned int &num_subaddresses, unsigned int index, bool match_found, std::vector< GraphTreeObject * > &matches)
 Function to find all addresses mathcing the set of substrings @parem subaddresses A vector of subaddresses to match.
 
std::vector< GraphTreeObject * > searchNodes (const std::string &address)
 Function to search through the graph tree by string address.
 
int addChild (GraphTreeObject *child)
 Function to add a child to the graph tree object.
 
int removeChild (GraphTreeObject *child)
 Function to remove a child from the graph node's children.
 

Protected Attributes

struct timespec _tspec
 
GraphTreeObject_parent = nullptr
 Pointer to the object's parent – should be null if the object is the root. Is set to null by default.
 
std::vector< GraphTreeObject * > _children
 Pointers to the object's children – automatically set to an empty vector, and can be increased to any size.
 
std::string _name = DEFAULT_NAME
 String name for object.
 
uint16_t _num_descendants = 0
 Total number of descendants (includes children of children) of the tree, again not including the tree itself.
 
uint8_t _num_children = 0
 Number of direct children of the tree (not including the tree itself)
 
uint8_t _rank = 0
 Rank for how far down on the graph tree the object is – starts at zero and maxes out at 256 via variable size.
 
uint8_t _graph_tree_type = BASE_GRAPH_TREE
 Variable to store graph tree object type.
 
bool _locked = false
 Variable to lock the graph tree object and prevent structural updates.
 
bool _loggable = false
 Variable to indicate whether the selected object is loggable. Set to false by default.
 

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.

Member Function Documentation

◆ add()

int clockwerk::Time::add ( const Time a,
Time res 
) const

Function to add two times together a + b.

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

◆ addChild()

int clockwerk::GraphTreeObject::addChild ( GraphTreeObject child)
protectedinherited

Function to add a child to the graph tree object.

Parameters
childA pointer to the graph tree object to add to the tree
Returns
An error code corresponding to success/failure

◆ address()

std::string clockwerk::GraphTreeObject::address ( )
inherited

Getter for object's string address.

Returns
Returns the string address for the object

◆ decomposeAddress()

std::vector< std::string > clockwerk::GraphTreeObject::decomposeAddress ( std::string  address)
protectedinherited

Function to decompose a string into a series of substrings via indexing.

Parameters
addressThe address to be decomposed
Returns
A vector of strings containing each delimeter-separated substring

◆ divide()

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

Function to get half of a struct timespec.

Returns
timespec corresponding to

◆ dump()

void clockwerk::GraphTreeObject::dump ( bool  recursive = false)
inherited

Function to dump the graph node, optionally including descendents.

Parameters
recursiveParameter indicating whether to dump only one node (default/false) or the entire tree (true)
Note
Recursive dumps the whole tree... be careful what you wish for

◆ findLoggable()

void clockwerk::GraphTreeObject::findLoggable ( std::vector< GraphTreeObject * > &  matches)
inherited

Function to find all loggable parameters in this node and its children.

Parameters
matchesExpandable vector to hold all matches in the tree

◆ findMatches()

void clockwerk::GraphTreeObject::findMatches ( const std::vector< std::string > &  subaddresses,
const unsigned int num_subaddresses,
unsigned int  index,
bool  match_found,
std::vector< GraphTreeObject * > &  matches 
)
protectedinherited

Function to find all addresses mathcing the set of substrings @parem subaddresses A vector of subaddresses to match.

Parameters
num_subaddressesThe number of subaddresses to match
indexThe index of subaddresses to search in
match_foundVariable indicating whether a match was found higher in the tree
matchesImplicit return of all matches to the specified address

◆ fromDouble()

void clockwerk::Time::fromDouble ( double  val)

Function to set a time object from double.

Parameters
valThe double value to set time from

◆ fromFrequency()

void clockwerk::Time::fromFrequency ( unsigned int  rate_hz)

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

Parameters
rate_hzThe rate to be converted to time

◆ getByAddress()

GraphTreeObject * clockwerk::GraphTreeObject::getByAddress ( const std::string &  address)
inherited

Function to get an object from the graph tree by string address.

Parameters
addressThe exact string address to access the variable with
Returns
Pointer to the graph tree object at the address, or nullptr if address is not valid or returns

◆ header()

◆ header_info()

std::vector< std::string > clockwerk::Time::header_info ( ) const
inlinevirtual

Function to write header data from our Time class.

Note
Overwrites virtual function

Reimplemented from clockwerk::GraphTreeObject.

◆ lock()

void clockwerk::GraphTreeObject::lock ( bool  recursive = true)
inherited

Function to lock the graph tree object and its children to changes.

Parameters
recursiveFlag to indicate whether lock should be recursive

◆ log()

int clockwerk::Time::log ( void logger)
inlinevirtual

Function to log data from our Time class.

Parameters
loggerPointer to the logger to write to
Note
Overwrites virtual function

Reimplemented from clockwerk::GraphTreeObject.

◆ operator<()

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

Overloaded operator to compare two time objects.

Returns
True/false corresponding to greater than calculation

◆ operator<=()

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

Overloaded operator to compare two time objects.

Returns
True/false corresponding to greater than calculation

◆ operator==()

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

Overloaded operator to compare two time objects.

Returns
True/false corresponding to equals calculation

◆ operator>()

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

Overloaded operator to compare two time objects.

Returns
True/false corresponding to greater than calculation

◆ operator>=()

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

Overloaded operator to compare two time objects.

Returns
True/false corresponding to greater than calculation

◆ parent() [1/2]

int clockwerk::GraphTreeObject::parent ( GraphTreeObject new_parent)
inherited

Function to assign the node's parent via reference.

Parameters
new_parentThe new parent to assign the node to
Returns
Error code corresponding to success/failure
Note
This function is the only method to ADD or REMOVE a node from a tree. To add, pass the address to a GraphTreeObject to this function. To remove, pass a nullptr. Note that parents for objects on an existing tree can be reassigned

◆ parent() [2/2]

int clockwerk::GraphTreeObject::parent ( GraphTreeObject new_parent)
inherited

Function to assign the node's parent via pointer.

Parameters
new_parentThe new parent to assign the node to
Returns
Error code corresponding to success/failure
Note
This function is the only method to ADD or REMOVE a node from a tree. To add, pass the address to a GraphTreeObject to this function. To remove, pass a nullptr. Note that parents for objects on an existing tree can be reassigned

◆ recurseGraphNodeInfo()

void clockwerk::GraphTreeObject::recurseGraphNodeInfo ( unsigned int  counter)
inherited

Function to recurse through graph tree and print all node info.

Returns
String containing all recursive graph node information in tab cascade format

◆ removeChild()

int clockwerk::GraphTreeObject::removeChild ( GraphTreeObject child)
protectedinherited

Function to remove a child from the graph node's children.

Parameters
childThe child to remove
Returns
Success/fail error code based on whether the child is present

◆ search()

std::vector< std::string > clockwerk::GraphTreeObject::search ( const std::string &  address)
inherited

Function to search through the graph tree by string address.

Parameters
address`The address or address chunk to search for
Returns
A vector of string addresses meeting the criteria specified by address

◆ searchNodes()

std::vector< GraphTreeObject * > clockwerk::GraphTreeObject::searchNodes ( const std::string &  address)
protectedinherited

Function to search through the graph tree by string address.

Parameters
address`The address or address chunk to search for
Returns
A vector of objects addresses meeting the criteria specified by address

◆ setTime()

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

◆ stepTime()

void clockwerk::Time::stepTime ( const unsigned long long nsec)

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

Parameters
nsecNumber of nanoseconds to step by

◆ subtract()

int 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

◆ type()

virtual int clockwerk::GraphTreeObject::type ( )
inlinevirtualinherited

Function to indicate type – -1 by default unless implemented downstream.

Returns
Int indicating frame type – unimplemented always -1

◆ unlock()

void clockwerk::GraphTreeObject::unlock ( bool  recursive = true)
inherited

Function to unlock the graph tree and its children for changes.

Parameters
recursiveFlag to indicate whether unlock should be recursive

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