EZC3D
|
Main class for C3D holder. More...
#include <ezc3d.h>
Public Member Functions | |
c3d () | |
Create a valid minimalistic C3D structure. | |
c3d (const std::string &filePath) | |
Read and store a C3D. More... | |
virtual | ~c3d () |
Destroy the class properly. | |
void | print () const |
Print the C3D by calling print method of header, parameter and data. | |
void | write (const std::string &filePath) const |
Write the C3D to an opened file by calling write method of header, parameter and data. More... | |
int | readInt (PROCESSOR_TYPE processorType, std::fstream &file, unsigned int nByteToRead, int nByteFromPrevious=0, const std::ios_base::seekdir &pos=std::ios::cur) |
Read an integer of nByteToRead bytes at the position current + nByteFromPrevious from a file. More... | |
size_t | readUint (PROCESSOR_TYPE processorType, std::fstream &file, unsigned int nByteToRead, int nByteFromPrevious=0, const std::ios_base::seekdir &pos=std::ios::cur) |
Read a unsigned integer of nByteToRead bytes at the position current + nByteFromPrevious from a file. More... | |
float | readFloat (PROCESSOR_TYPE processorType, std::fstream &file, int nByteFromPrevious=0, const std::ios_base::seekdir &pos=std::ios::cur) |
Read a float at the position current + nByteFromPrevious from a file. More... | |
std::string | readString (std::fstream &file, unsigned int nByteToRead, int nByteFromPrevious=0, const std::ios_base::seekdir &pos=std::ios::cur) |
Read a string (array of char of nByteToRead bytes) at the position current + nByteFromPrevious from a file. More... | |
void | readParam (PROCESSOR_TYPE processorType, std::fstream &file, unsigned int dataLenghtInBytes, const std::vector< size_t > &dimension, std::vector< int > ¶m_data, size_t currentIdx=0) |
Read a matrix of integer parameters of dimensions dimension with each integer of length dataLengthInByte. More... | |
void | readParam (PROCESSOR_TYPE processorType, std::fstream &file, const std::vector< size_t > &dimension, std::vector< float > ¶m_data, size_t currentIdx=0) |
Read a matrix of float parameters of dimensions dimension. More... | |
void | readParam (std::fstream &file, const std::vector< size_t > &dimension, std::vector< std::string > ¶m_data) |
Read a matrix of string of dimensions dimension with the first dimension being the length of the strings. More... | |
const ezc3d::Header & | header () const |
The header of the C3D. More... | |
const ezc3d::ParametersNS::Parameters & | parameters () const |
The parameters of the C3D. More... | |
const ezc3d::DataNS::Data & | data () const |
The points and analogous data of the C3D. More... | |
const std::vector< std::string > & | pointNames () const |
Get a reference to the names of the points. More... | |
size_t | pointIdx (const std::string &pointName) const |
Get the index of a point in the points holder. More... | |
const std::vector< std::string > & | channelNames () const |
Get a reference to the names of the analog channels. More... | |
size_t | channelIdx (const std::string &channelName) const |
Get the index of a analog channel in the subframe. More... | |
void | parameter (const std::string &groupName, const ezc3d::ParametersNS::GroupNS::Parameter ¶meter) |
Add/replace a parameter to a group named groupName. More... | |
void | lockGroup (const std::string &groupName) |
Lock a particular group named groupName. More... | |
void | unlockGroup (const std::string &groupName) |
Unlock a particular group named groupName. More... | |
void | frame (const ezc3d::DataNS::Frame &frame, size_t idx=SIZE_MAX) |
Add/replace a frame to the data set. More... | |
void | point (const std::string &name) |
Create a point to the data set of name name. More... | |
void | point (const std::string &pointName, const std::vector< ezc3d::DataNS::Frame > &frames) |
Add a new point to the data set. More... | |
void | point (const std::vector< std::string > &pointNames, const std::vector< ezc3d::DataNS::Frame > &frames) |
Add a new point to the data set. More... | |
void | analog (const std::string &name) |
Create a channel of analog data to the data set of name name. More... | |
void | analog (std::string channelName, const std::vector< ezc3d::DataNS::Frame > &frames) |
Add a new channel to the data set. More... | |
void | analog (const std::vector< std::string > &channelNames, const std::vector< ezc3d::DataNS::Frame > &frames) |
Add a new channel to the data set. More... | |
Protected Member Functions | |
void | resizeCharHolder (unsigned int nByteToRead) |
Resize the too small char to read. More... | |
void | readFile (std::fstream &file, unsigned int nByteToRead, char *c, int nByteFromPrevious=0, const std::ios_base::seekdir &pos=std::ios::cur) |
The function that reads the file, it returns the value into a generic char pointer that must be pre-allocate. More... | |
unsigned int | hex2uint (const char *val, unsigned int len) |
Convert an hexadecimal value to an unsigned integer. More... | |
int | hex2int (const char *val, unsigned int len) |
Convert an hexadecimal value to a integer. More... | |
void | writeDataStart (std::fstream &file, const std::streampos &dataStartPosition, const DATA_TYPE &type) const |
Write the data_start parameter where demanded. More... | |
size_t | _dispatchMatrix (const std::vector< size_t > &dimension, const std::vector< std::string > ¶m_data_in, std::vector< std::string > ¶m_data_out, size_t idxInParam=0, size_t currentIdx=1) |
Internal function to dispatch a string array to a matrix of strings. More... | |
void | _readMatrix (std::fstream &file, const std::vector< size_t > &dimension, std::vector< std::string > ¶m_data, size_t currentIdx=0) |
Internal function to read a string array to a matrix of strings. More... | |
void | updateHeader () |
Update the header according to the parameters and the data. | |
void | updateParameters (const std::vector< std::string > &newPoints=std::vector< std::string >(), const std::vector< std::string > &newAnalogs=std::vector< std::string >()) |
Update parameters according to the data. More... | |
Protected Attributes | |
std::string | _filePath |
The file path if the C3D was opened from a file. | |
char * | c_float |
Char to be used by the read function with the specific size of a float preventing to allocate it at each calls. | |
char * | c_float_tp |
Char to be used by the read function with the specific size of a float preventing to allocate it at each calls (allow for copy of c_float) | |
char * | c_int |
Char to be used by the read function with the specific size of a int preventing to allocate it at each calls. | |
char * | c_int_tp |
Char to be used by the read function with the specific size of a int preventing to allocate it at each calls (allow for copy of c_int) | |
unsigned int | m_nByteToRead_float |
Declaration of the size of a float. | |
unsigned int | m_nByteToReadMax_int |
Declaration of the max size of a int. | |
std::shared_ptr< ezc3d::Header > | _header |
Pointer that holds the header of the C3D. | |
std::shared_ptr< ezc3d::ParametersNS::Parameters > | _parameters |
Pointer that holds the parameters of the C3D. | |
std::shared_ptr< ezc3d::DataNS::Data > | _data |
Pointer that holds the data of the C3D. | |
ezc3d::c3d::c3d | ( | const std::string & | filePath | ) |
|
protected |
Internal function to dispatch a string array to a matrix of strings.
dimension | The dimensions of the matrix up to 7-dimensions |
param_data_in | The input vector of strings |
param_data_out | The output matrix of strings |
idxInParam | Internal counter to keep track where the function is in its recursive calls |
currentIdx | Internal counter to keep track where the function is in its recursive calls |
|
protected |
Internal function to read a string array to a matrix of strings.
file | opened file stream to be read |
dimension | The dimensions of the matrix up to 7-dimensions |
param_data | The output matrix of strings |
currentIdx | Internal counter to keep track where the function is in its recursive calls |
void ezc3d::c3d::analog | ( | const std::string & | name | ) |
Create a channel of analog data to the data set of name name.
name | The name of the channel to create |
If, for some reason, you want to add a new channel to a pre-existing data set, you must declare this channel before, otherwise it rejects it because parameter ANALOG:LABELS doesn't fit. This function harmonize the parameter structure with the data structure in advance in order to add the channel.
Throw the same errors as updateParameter as it calls it after the channel is created
void ezc3d::c3d::analog | ( | std::string | channelName, |
const std::vector< ezc3d::DataNS::Frame > & | frames | ||
) |
Add a new channel to the data set.
channelName | Name of the channel to add |
frames | The array of frames to add |
Append a new channel to the data set.
Throw a std::invalid_argument if the size of the std::vector of frames/subframes is not equal to the number of frames/subframes already present in the data set. Obviously it throws the same error if no channel were sent or if the channel was already in the data set.
Moreover it throws the same errors as updateParameter as it calls it after the channel is added
void ezc3d::c3d::analog | ( | const std::vector< std::string > & | channelNames, |
const std::vector< ezc3d::DataNS::Frame > & | frames | ||
) |
Add a new channel to the data set.
channelNames | Name of the channels to add |
frames | The array of frames to add |
Append a new channel to the data set.
Throw a std::invalid_argument if the size of the std::vector of frames/subframes is not equal to the number of frames/subframes already present in the data set. Obviously it throws the same error if no channel were sent or if the channel was already in the data set.
Moreover it throws the same errors as updateParameter as it calls it after the channel is added
size_t ezc3d::c3d::channelIdx | ( | const std::string & | channelName | ) | const |
Get the index of a analog channel in the subframe.
channelName | Name of the analog channel |
Search for the index of a analog channel into subframe by the name of this channel.
Throw a std::invalid_argument if channelName is not found
const std::vector< std::string > & ezc3d::c3d::channelNames | ( | ) | const |
const ezc3d::DataNS::Data & ezc3d::c3d::data | ( | ) | const |
void ezc3d::c3d::frame | ( | const ezc3d::DataNS::Frame & | frame, |
size_t | idx = SIZE_MAX |
||
) |
Add/replace a frame to the data set.
frame | The frame to copy to the data |
idx | The index of the frame in the data set |
Add or replace a frame to the data set.
If no idx is sent, then the frame is appended to the data set. If the idx correspond to a pre-existing frame, it replaces it. If idx is larger than the number of frames, it resize the frames accordingly and add the frame where it belongs but leaves the other created frames empty.
Throw a std::runtime_error if the number of points defined in POINT:USED parameter doesn't correspond to the number of point in the frame.
Throw a std::invalid_argument if the point names in the frame don't correspond to the name of the points as defined in POINT:LABELS group
Throw a std::runtime_error if at least a point was added to the frame but POINT:RATE is equal to 0 and/or if at least an analog data was added to the frame and ANALOG:RATE is equal to 0
const ezc3d::Header & ezc3d::c3d::header | ( | ) | const |
|
protected |
|
protected |
void ezc3d::c3d::lockGroup | ( | const std::string & | groupName | ) |
void ezc3d::c3d::parameter | ( | const std::string & | groupName, |
const ezc3d::ParametersNS::GroupNS::Parameter & | parameter | ||
) |
Add/replace a parameter to a group named groupName.
groupName | The name of the group to add the parameter to |
parameter | The parameter to add |
Add a parameter to a group. If the the group does not exist in the C3D, it is created. If the parameter already exists in the group, it is replaced.
Throw a std::invalid_argument if the name of the parameter is not specified
const ezc3d::ParametersNS::Parameters & ezc3d::c3d::parameters | ( | ) | const |
void ezc3d::c3d::point | ( | const std::string & | name | ) |
Create a point to the data set of name name.
name | The name of the point to create |
If, for some reason, you want to add a new point to a pre-existing data set, you must declare this point before, otherwise it rejects it because parameter POINT:LABELS doesn't fit. This function harmonize the parameter structure with the data structure in advance in order to add the point.
Throw the same errors as updateParameter as it calls it after the point is created
void ezc3d::c3d::point | ( | const std::string & | pointName, |
const std::vector< ezc3d::DataNS::Frame > & | frames | ||
) |
Add a new point to the data set.
pointName | The name of the new point |
frames | The array of frames to add |
Append a new point to the data set.
Throw a std::invalid_argument if the size of the std::vector of frames is not equal to the number of frames already present in the data set. Obviously it throws the same error if no point were sent or if the point was already in the data set.
Moreover it throws the same errors as updateParameter as it calls it after the point is added
void ezc3d::c3d::point | ( | const std::vector< std::string > & | pointNames, |
const std::vector< ezc3d::DataNS::Frame > & | frames | ||
) |
Add a new point to the data set.
pointNames | The name vector of the new points |
frames | The array of frames to add |
Append a new point to the data set.
Throw a std::invalid_argument if the size of the std::vector of frames is not equal to the number of frames already present in the data set. Obviously it throws the same error if no point were sent or if the point was already in the data set.
Moreover it throws the same errors as updateParameter as it calls it after the point is added
size_t ezc3d::c3d::pointIdx | ( | const std::string & | pointName | ) | const |
const std::vector< std::string > & ezc3d::c3d::pointNames | ( | ) | const |
|
protected |
The function that reads the file, it returns the value into a generic char pointer that must be pre-allocate.
file | opened file stream to be read |
nByteToRead | The number of bytes to read |
c | The output char |
nByteFromPrevious | The number of byte to skip from current position |
pos | The position to start from |
float ezc3d::c3d::readFloat | ( | PROCESSOR_TYPE | processorType, |
std::fstream & | file, | ||
int | nByteFromPrevious = 0 , |
||
const std::ios_base::seekdir & | pos = std::ios::cur |
||
) |
Read a float at the position current + nByteFromPrevious from a file.
processorType | Convension processor type the file is following |
file | opened file stream to be read |
nByteFromPrevious | The number of bytes to skip from the current cursor position |
pos | Where to reposition the cursor |
int ezc3d::c3d::readInt | ( | PROCESSOR_TYPE | processorType, |
std::fstream & | file, | ||
unsigned int | nByteToRead, | ||
int | nByteFromPrevious = 0 , |
||
const std::ios_base::seekdir & | pos = std::ios::cur |
||
) |
Read an integer of nByteToRead bytes at the position current + nByteFromPrevious from a file.
processorType | Convension processor type the file is following |
file | opened file stream to be read |
nByteToRead | The number of byte to read to be converted into integer |
nByteFromPrevious | The number of bytes to skip from the current cursor position |
pos | Where to reposition the cursor |
void ezc3d::c3d::readParam | ( | PROCESSOR_TYPE | processorType, |
std::fstream & | file, | ||
unsigned int | dataLenghtInBytes, | ||
const std::vector< size_t > & | dimension, | ||
std::vector< int > & | param_data, | ||
size_t | currentIdx = 0 |
||
) |
Read a matrix of integer parameters of dimensions dimension with each integer of length dataLengthInByte.
processorType | Convension processor type the file is following |
file | opened file stream to be read |
dataLenghtInBytes | The number of bytes to read to be converted to int |
dimension | The dimensions of the matrix up to 7-dimensions |
param_data | The output of the function |
currentIdx | Internal tracker of where the function is in the flow of the recursive calls |
void ezc3d::c3d::readParam | ( | PROCESSOR_TYPE | processorType, |
std::fstream & | file, | ||
const std::vector< size_t > & | dimension, | ||
std::vector< float > & | param_data, | ||
size_t | currentIdx = 0 |
||
) |
Read a matrix of float parameters of dimensions dimension.
processorType | Convension processor type the file is following |
file | opened file stream to be read |
dimension | The dimensions of the matrix up to 7-dimensions |
param_data | The output of the function |
currentIdx | Internal tracker of where the function is in the flow of the recursive calls |
void ezc3d::c3d::readParam | ( | std::fstream & | file, |
const std::vector< size_t > & | dimension, | ||
std::vector< std::string > & | param_data | ||
) |
Read a matrix of string of dimensions dimension with the first dimension being the length of the strings.
file | opened file stream to be read |
dimension | The dimensions of the matrix up to 7-dimensions. The first dimension is the length of the strings |
param_data | The output of the function |
std::string ezc3d::c3d::readString | ( | std::fstream & | file, |
unsigned int | nByteToRead, | ||
int | nByteFromPrevious = 0 , |
||
const std::ios_base::seekdir & | pos = std::ios::cur |
||
) |
Read a string (array of char of nByteToRead bytes) at the position current + nByteFromPrevious from a file.
file | opened file stream to be read |
nByteToRead | The number of byte to read to be converted into float |
nByteFromPrevious | The number of bytes to skip from the current cursor position |
pos | Where to reposition the cursor |
size_t ezc3d::c3d::readUint | ( | PROCESSOR_TYPE | processorType, |
std::fstream & | file, | ||
unsigned int | nByteToRead, | ||
int | nByteFromPrevious = 0 , |
||
const std::ios_base::seekdir & | pos = std::ios::cur |
||
) |
Read a unsigned integer of nByteToRead bytes at the position current + nByteFromPrevious from a file.
processorType | Convension processor type the file is following |
file | opened file stream to be read |
nByteToRead | The number of byte to read to be converted into unsigned integer |
nByteFromPrevious | The number of bytes to skip from the current cursor position |
pos | Where to reposition the cursor |
|
protected |
void ezc3d::c3d::unlockGroup | ( | const std::string & | groupName | ) |
|
protected |
Update parameters according to the data.
newPoints | The names of the new poits |
newAnalogs | The names of the new analogs |
Throw a std::runtime_error if newPoints or newAnalogs was added while the data set is not empty. If you want to add a new point after having data in the data set, you must use the frame method.
void ezc3d::c3d::write | ( | const std::string & | filePath | ) | const |
|
protected |