ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
clockwerk::DataIO< T > Class Template Reference

Class for inter-object communication. More...

#include <DataIO.hpp>

Inheritance diagram for clockwerk::DataIO< T >:
Collaboration diagram for clockwerk::DataIO< T >:

Public Member Functions

 DataIO (GraphTreeObject *data_parent, std::string data_name, T initial_value)
 Constructor for the DataIO object.
 
 DataIO (GraphTreeObject *data_parent, std::string data_name)
 
 DataIO (GraphTreeObject *data_parent)
 
void mapToPointer (T *data_source)
 Function to map the DataIO object to a pointer, rather than another of its kind.
 
int operator() (const T &new_value)
 Function to set the value of the DataIO object.
 
T * getRootDataPointer ()
 Function to return a handle to the root data held in THIS object.
 
void resetMap ()
 
const T & operator() ()
 Overloaded operator to return value of DataIO object.
 
int log (void *logger)
 Function to log data to a logger.
 
int header (void *logger)
 Function to pass headers for this object to the logger.
 
void allowWrite ()
 Functions to manipulate write permissions on DataIO object.
 
void blockWrite ()
 
bool writeAllowed ()
 
void mapTo (DataIOBase &data_source)
 Function to map DataIO object to new upstream data source.
 
void * writePtr ()
 Function to write value to mapped location – root data or map.
 
void * read ()
 Function to read value from mapped location – root data or map.
 
uint8_t dataType ()
 Function to return the type of data held by the DataIO.
 
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 std::vector< std::string > header_info () const
 
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

template<typename T >
std::enable_if< std::is_integral< T >::value >::type _typeID (T var)
 Overloaded functions to identify type held by DataIO.
 
template<typename T >
std::enable_if< std::is_floating_point< T >::value >::type _typeID (T var)
 
template<typename T >
void _typeID (std::vector< T > var)
 
template<typename T , long unsigned int N>
void _typeID (std::array< T, N > var)
 
template<typename T , unsigned int R, unsigned int C>
void _typeID (Matrix< T, R, C > var)
 
void _typeID (std::string &var)
 
void _typeID (const GraphTreeObject &var)
 
void _typeID (void *var)
 
void _typeID (int var)
 
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

_root_data
 Default data location pointed to by the DataIO object. Note that root data can change if DataIO is mapped to another dataIO object.
 
void * tmp_ptr
 Temporary pointer to hold our stuff internally.
 
DataIOBasedata
 Pointer to data held by the object – by default, this will point internally to _default_data, but can be set to point to another object.
 
void * _data_ptr = nullptr
 Generic pointer to hold any data type – will be resolved to point to actual object in inherited class.
 
bool _writeAllowed
 Variable to indicate whether writing is allowed to this variable Set to false upon mapping by default.
 
bool _root
 Variable to indicate whether variable in question is root data source or not.
 
dataio_types_e _type_id = UNDEFINED
 Variable to store the type of data that the DataIO object is holding. Valid types are documented in the enum and determined at runtime. Runtime determination is necessary because of derived types of GraphTreeObject.
 
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

template<typename T>
class clockwerk::DataIO< T >

Class for inter-object communication.

The data IO object is a flexible input/output object for interfacing between models, tasks, events, and so on. It is templated to work with nearly any data type, provided that type can be passed and returned via function.

DataIO operates by abstracting data using a pointer. It holds an internal value of type T, and a pointer to the data source to use. By default, that data source is itself, but it may point to another DataIO object if commanded to do so via the mapTo function. In that case, DataIO will recursively call DataIO objects until it finds the root object, then return the value held by the root object.

Constructor & Destructor Documentation

◆ DataIO()

template<typename T >
clockwerk::DataIO< T >::DataIO ( GraphTreeObject data_parent,
std::string  data_name,
initial_value 
)

Constructor for the DataIO object.

Parameters
data_parentPointer to parent graph tree object
data_nameString name for the DataIO object
initial_valueThe initial value of the data IO object
Note
Constructor is overloaded – object can be created from many configurations but it is on the developer to ensure it is handled correctly

Member Function Documentation

◆ _typeID()

template<typename T >
std::enable_if< std::is_floating_point< T >::value >::type clockwerk::DataIOBase::_typeID ( var)
protectedinherited

Overloaded functions to identify type held by DataIO.

Parameters
varThe variable used to identify type

◆ 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

◆ dataType()

uint8_t clockwerk::DataIOBase::dataType ( )
inlineinherited

Function to return the type of data held by the DataIO.

Returns
Type of data held by the DataIO according to dataio_types_e

◆ 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

◆ 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

◆ 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

◆ getRootDataPointer()

template<typename T >
T * clockwerk::DataIO< T >::getRootDataPointer ( )

Function to return a handle to the root data held in THIS object.

Returns
A pointer to root data if write is allowed, nullptr if not
Note
DANGER! This method bypasses a lot of safeties in the signal system and breaks traceability on pointer. Using this could allow a write to the wrong location or read from the wrong location. It should be not be used in models and should be reserved exclusively for built-in functions.

◆ header()

template<typename T >
int clockwerk::DataIO< T >::header ( void *  logger)
virtual

Function to pass headers for this object to the logger.

Parameters
loggerPointer to logger
Returns
Error code corresponding to success/failure

Reimplemented from clockwerk::GraphTreeObject.

◆ header_info()

virtual std::vector< std::string > clockwerk::GraphTreeObject::header_info ( ) const
inlinevirtualinherited

Reimplemented in clockwerk::Time.

◆ 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()

template<typename T >
int clockwerk::DataIO< T >::log ( void *  logger)
virtual

Function to log data to a logger.

Parameters
loggerPointer to logger
Returns
Error code corresponding to success/failure

Reimplemented from clockwerk::GraphTreeObject.

◆ mapTo()

void clockwerk::DataIOBase::mapTo ( DataIOBase data_source)
inlineinherited

Function to map DataIO object to new upstream data source.

Parameters
data_sourceNew upstream data source to which object will be mapped
Note
Blocks writing via this DataIO object

◆ mapToPointer()

template<typename T >
void clockwerk::DataIO< T >::mapToPointer ( T *  data_source)
inline

Function to map the DataIO object to a pointer, rather than another of its kind.

Parameters
data_sourceThe pointer to which the DataIO will be mapped

◆ operator()() [1/2]

template<typename T >
const T & clockwerk::DataIO< T >::operator() ( )

Overloaded operator to return value of DataIO object.

Returns
Value pointed to by data – could be internal or external

◆ operator()() [2/2]

template<typename T >
int clockwerk::DataIO< T >::operator() ( const T &  new_value)

Function to set the value of the DataIO object.

Parameters
new_valueValue to set the dataIO object to
Returns
Error code according to success/failure

◆ 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

◆ read()

void * clockwerk::DataIOBase::read ( )
inherited

Function to read value from mapped location – root data or map.

Returns
Void pointer to data held by object

◆ 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

◆ resetMap()

template<typename T >
void clockwerk::DataIO< T >::resetMap ( )
inline
Parameters
Functionto break data mapping and reset object to its own internal data
Note
Data will be reset to the value previously held by this signal prior to mapping
Resets write permission to true

◆ 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

◆ 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

◆ writePtr()

void * clockwerk::DataIOBase::writePtr ( )
inherited

Function to write value to mapped location – root data or map.

Returns
Void pointer to data held by object

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