ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
DataIOBase.h
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17Data IO Base File
18
19Author: Alex Reynolds
20*/
21#ifndef DATA_IO_BASE_H
22#define DATA_IO_BASE_H
23
24#include <vector>
25#include <array>
26#include <stdint.h>
27
29#include "core/clockwerkerrors.h"
30#include "core/Matrix.hpp"
31
32namespace clockwerk {
33
34 /// This enumeration stores information on the data type held within
35 /// the DataIO object. The storage defines data types primarily for
36 /// logging, which is used in simulation.
37 enum dataio_types_e : unsigned char {
38 INTEGER,
39 FLOATING_POINT,
40 VECTOR,
41 ARRAY,
42 MATRIX,
43 GRAPH_TREE,
44 POINTER,
45 STD_STRING,
46 UNDEFINED
47 };
48
49 /// The Data IO Base class is designed to provide the basic interface
50 /// of the Data IO class (see documentation in DataIO.hpp) without
51 /// requiring templating. This implementation is to allow for generic
52 /// access to Data IO objects without needing to know or declare the
53 /// template in the resulting class.
54 class DataIOBase : public GraphTreeObject {
55 public:
56 /// Default constructor
57 DataIOBase() : data(this), _writeAllowed(true), _root(true) {_graph_tree_type = DATAIO;}
58 ~DataIOBase() {};
59
60 /// Functions to manipulate write permissions on DataIO object
61 void allowWrite() {_writeAllowed = true;}
62 void blockWrite() {_writeAllowed = false;}
63 bool writeAllowed() {return _writeAllowed;}
64
65 /// @brief Function to map DataIO object to new upstream data source
66 /// @param data_source New upstream data source to which object will be mapped
67 /// @note Blocks writing via this DataIO object
68 void mapTo(DataIOBase &data_source) {data = &data_source; _root = false;}
69
70 /// @param Function to break data mapping and reset object to its own internal data
71 /// @note Resets write permission to true
72 void resetMap() {data = this; _writeAllowed = true; _root = true;}
73
74 /// @brief Function to write value to mapped location -- root data or map
75 /// @return Void pointer to data held by object
76 void* writePtr();
77
78 /// @brief Function to read value from mapped location -- root data or map
79 /// @return Void pointer to data held by object
80 void* read();
81
82 /// @brief Function to return the type of data held by the DataIO
83 /// @return Type of data held by the DataIO according to dataio_types_e
84 uint8_t dataType() {return _type_id;}
85 protected:
86 /// @brief Overloaded functions to identify type held by DataIO
87 /// @param var The variable used to identify type
88 template <typename T> typename std::enable_if<std::is_integral<T>::value>::type _typeID(T var);
89 template <typename T> typename std::enable_if<std::is_floating_point<T>::value>::type _typeID(T var);
90 template <typename T> void _typeID(std::vector<T> var);
91 template <typename T, long unsigned int N> void _typeID(std::array<T, N> var);
92 template <typename T, unsigned int R, unsigned int C> void _typeID(Matrix<T, R, C> var);
93 void _typeID(std::string &var);
94 void _typeID(const GraphTreeObject &var);
95 void _typeID(void* var);
96 void _typeID(int var);
97
98 /// Pointer to data held by the object -- by default, this will point internally
99 /// to _default_data, but can be set to point to another object
101
102 /// Generic pointer to hold any data type -- will be resolved to point to actual
103 /// object in inherited class
104 void* _data_ptr = nullptr;
105
106 /// Variable to indicate whether writing is allowed to this variable
107 /// Set to false upon mapping by default
108 bool _writeAllowed;
109
110 /// Variable to indicate whether variable in question is root data source
111 /// or not
112 bool _root;
113
114 /// Variable to store the type of data that the DataIO object is holding.
115 /// Valid types are documented in the enum and determined at runtime.
116 /// Runtime determination is necessary because of derived types of GraphTreeObject
117 dataio_types_e _type_id = UNDEFINED;
118 };
119
120 template <typename T>
121 typename std::enable_if<std::is_integral<T>::value>::type DataIOBase::_typeID(T var) {_type_id = INTEGER;}
122 template <typename T>
123 typename std::enable_if<std::is_floating_point<T>::value>::type DataIOBase::_typeID(T var) {_type_id = FLOATING_POINT;}
124 template <typename T>
125 void DataIOBase::_typeID(std::vector<T> var) {_type_id = VECTOR;}
126 template <typename T, long unsigned int N>
127 void DataIOBase::_typeID(std::array<T, N> var) {_type_id = ARRAY;}
128 template <typename T, unsigned int R, unsigned int C>
129 void DataIOBase::_typeID(Matrix<T, R, C> var) {_type_id = MATRIX;}
130
131}
132
133#endif
The Data IO Base class is designed to provide the basic interface of the Data IO class (see documenta...
Definition DataIOBase.h:54
DataIOBase()
Default constructor.
Definition DataIOBase.h:57
void * writePtr()
Function to write value to mapped location – root data or map.
Definition DataIOBase.cpp:20
void resetMap()
Definition DataIOBase.h:72
bool _root
Variable to indicate whether variable in question is root data source or not.
Definition DataIOBase.h:112
void allowWrite()
Functions to manipulate write permissions on DataIO object.
Definition DataIOBase.h:61
bool _writeAllowed
Variable to indicate whether writing is allowed to this variable Set to false upon mapping by default...
Definition DataIOBase.h:108
DataIOBase * data
Pointer to data held by the object – by default, this will point internally to _default_data,...
Definition DataIOBase.h:100
void mapTo(DataIOBase &data_source)
Function to map DataIO object to new upstream data source.
Definition DataIOBase.h:68
void * _data_ptr
Generic pointer to hold any data type – will be resolved to point to actual object in inherited class...
Definition DataIOBase.h:104
uint8_t dataType()
Function to return the type of data held by the DataIO.
Definition DataIOBase.h:84
void * read()
Function to read value from mapped location – root data or map.
Definition DataIOBase.cpp:32
dataio_types_e _type_id
Variable to store the type of data that the DataIO object is holding. Valid types are documented in t...
Definition DataIOBase.h:117
Base class for object organization.
Definition GraphTreeObject.h:87
uint8_t _graph_tree_type
Variable to store graph tree object type.
Definition GraphTreeObject.h:251
Matrix math implementation.
Definition Matrix.hpp:54