EZC3D
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ezc3d::c3d Class Reference

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 > &param_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 > &param_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 > &param_data)
 Read a matrix of string of dimensions dimension with the first dimension being the length of the strings. More...
 
const ezc3d::Headerheader () const
 The header of the C3D. More...
 
const ezc3d::ParametersNS::Parametersparameters () const
 The parameters of the C3D. More...
 
const ezc3d::DataNS::Datadata () 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 &parameter)
 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 > &param_data_in, std::vector< std::string > &param_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 > &param_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.
 

Detailed Description

Main class for C3D holder.

Definition at line 154 of file ezc3d.h.

Constructor & Destructor Documentation

◆ c3d()

ezc3d::c3d::c3d ( const std::string &  filePath)

Read and store a C3D.

Parameters
filePathThe file path of the C3D file

Definition at line 46 of file ezc3d.cpp.

Member Function Documentation

◆ _dispatchMatrix()

size_t ezc3d::c3d::_dispatchMatrix ( const std::vector< size_t > &  dimension,
const std::vector< std::string > &  param_data_in,
std::vector< std::string > &  param_data_out,
size_t  idxInParam = 0,
size_t  currentIdx = 1 
)
protected

Internal function to dispatch a string array to a matrix of strings.

Parameters
dimensionThe dimensions of the matrix up to 7-dimensions
param_data_inThe input vector of strings
param_data_outThe output matrix of strings
idxInParamInternal counter to keep track where the function is in its recursive calls
currentIdxInternal counter to keep track where the function is in its recursive calls
Returns

Definition at line 310 of file ezc3d.cpp.

◆ _readMatrix()

void ezc3d::c3d::_readMatrix ( std::fstream &  file,
const std::vector< size_t > &  dimension,
std::vector< std::string > &  param_data,
size_t  currentIdx = 0 
)
protected

Internal function to read a string array to a matrix of strings.

Parameters
fileopened file stream to be read
dimensionThe dimensions of the matrix up to 7-dimensions
param_dataThe output matrix of strings
currentIdxInternal counter to keep track where the function is in its recursive calls

Definition at line 330 of file ezc3d.cpp.

◆ analog() [1/3]

void ezc3d::c3d::analog ( const std::string &  name)

Create a channel of analog data to the data set of name name.

Parameters
nameThe 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

Definition at line 495 of file ezc3d.cpp.

◆ analog() [2/3]

void ezc3d::c3d::analog ( std::string  channelName,
const std::vector< ezc3d::DataNS::Frame > &  frames 
)

Add a new channel to the data set.

Parameters
channelNameName of the channel to add
framesThe 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

Definition at line 514 of file ezc3d.cpp.

◆ analog() [3/3]

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.

Parameters
channelNamesName of the channels to add
framesThe 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

Definition at line 521 of file ezc3d.cpp.

◆ channelIdx()

size_t ezc3d::c3d::channelIdx ( const std::string &  channelName) const

Get the index of a analog channel in the subframe.

Parameters
channelNameName of the analog channel
Returns
The index 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

Definition at line 374 of file ezc3d.cpp.

◆ channelNames()

const std::vector< std::string > & ezc3d::c3d::channelNames ( ) const

Get a reference to the names of the analog channels.

Returns
The reference to the names of the analog channels

Definition at line 369 of file ezc3d.cpp.

◆ data()

const ezc3d::DataNS::Data & ezc3d::c3d::data ( ) const

The points and analogous data of the C3D.

Returns
The points and analogous data of the C3D

Definition at line 350 of file ezc3d.cpp.

◆ frame()

void ezc3d::c3d::frame ( const ezc3d::DataNS::Frame frame,
size_t  idx = SIZE_MAX 
)

Add/replace a frame to the data set.

Parameters
frameThe frame to copy to the data
idxThe 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

Definition at line 414 of file ezc3d.cpp.

◆ header()

const ezc3d::Header & ezc3d::c3d::header ( ) const

The header of the C3D.

Returns
The header of the C3D

Definition at line 340 of file ezc3d.cpp.

◆ hex2int()

int ezc3d::c3d::hex2int ( const char *  val,
unsigned int  len 
)
protected

Convert an hexadecimal value to a integer.

Parameters
valThe value to convert
lenThe number of bytes of the val parameter
Returns
The integer value

Definition at line 147 of file ezc3d.cpp.

◆ hex2uint()

unsigned int ezc3d::c3d::hex2uint ( const char *  val,
unsigned int  len 
)
protected

Convert an hexadecimal value to an unsigned integer.

Parameters
valThe value to convert
lenThe number of bytes of the val parameter
Returns
The unsigned integer value

Definition at line 140 of file ezc3d.cpp.

◆ lockGroup()

void ezc3d::c3d::lockGroup ( const std::string &  groupName)

Lock a particular group named groupName.

Parameters
groupNameThe name of the group to lock

Throw a std::invalid_argument exception if the group name does not exist

Definition at line 404 of file ezc3d.cpp.

◆ parameter()

void ezc3d::c3d::parameter ( const std::string &  groupName,
const ezc3d::ParametersNS::GroupNS::Parameter parameter 
)

Add/replace a parameter to a group named groupName.

Parameters
groupNameThe name of the group to add the parameter to
parameterThe 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

Definition at line 384 of file ezc3d.cpp.

◆ parameters()

const ezc3d::ParametersNS::Parameters & ezc3d::c3d::parameters ( ) const

The parameters of the C3D.

Returns
The parameters of the C3D

Definition at line 345 of file ezc3d.cpp.

◆ point() [1/3]

void ezc3d::c3d::point ( const std::string &  name)

Create a point to the data set of name name.

Parameters
nameThe 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

Definition at line 452 of file ezc3d.cpp.

◆ point() [2/3]

void ezc3d::c3d::point ( const std::string &  pointName,
const std::vector< ezc3d::DataNS::Frame > &  frames 
)

Add a new point to the data set.

Parameters
pointNameThe name of the new point
framesThe 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

Definition at line 468 of file ezc3d.cpp.

◆ point() [3/3]

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.

Parameters
pointNamesThe name vector of the new points
framesThe 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

Definition at line 474 of file ezc3d.cpp.

◆ pointIdx()

size_t ezc3d::c3d::pointIdx ( const std::string &  pointName) const

Get the index of a point in the points holder.

Parameters
pointNameName of the point
Returns
The index of the point

Search for the index of a point into points data by the name of this point.

Throw a std::invalid_argument if pointName is not found

Definition at line 360 of file ezc3d.cpp.

◆ pointNames()

const std::vector< std::string > & ezc3d::c3d::pointNames ( ) const

Get a reference to the names of the points.

Returns
The reference to the names of the points

Definition at line 355 of file ezc3d.cpp.

◆ readFile()

void ezc3d::c3d::readFile ( std::fstream &  file,
unsigned int  nByteToRead,
char *  c,
int  nByteFromPrevious = 0,
const std::ios_base::seekdir &  pos = std::ios::cur 
)
protected

The function that reads the file, it returns the value into a generic char pointer that must be pre-allocate.

Parameters
fileopened file stream to be read
nByteToReadThe number of bytes to read
cThe output char
nByteFromPreviousThe number of byte to skip from current position
posThe position to start from

Definition at line 131 of file ezc3d.cpp.

◆ readFloat()

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.

Parameters
processorTypeConvension processor type the file is following
fileopened file stream to be read
nByteFromPreviousThe number of bytes to skip from the current cursor position
posWhere to reposition the cursor
Returns
The float value

Definition at line 228 of file ezc3d.cpp.

◆ readInt()

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.

Parameters
processorTypeConvension processor type the file is following
fileopened file stream to be read
nByteToReadThe number of byte to read to be converted into integer
nByteFromPreviousThe number of bytes to skip from the current cursor position
posWhere to reposition the cursor
Returns
The integer value

Definition at line 179 of file ezc3d.cpp.

◆ readParam() [1/3]

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.

Parameters
processorTypeConvension processor type the file is following
fileopened file stream to be read
dataLenghtInBytesThe number of bytes to read to be converted to int
dimensionThe dimensions of the matrix up to 7-dimensions
param_dataThe output of the function
currentIdxInternal tracker of where the function is in the flow of the recursive calls

Definition at line 269 of file ezc3d.cpp.

◆ readParam() [2/3]

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.

Parameters
processorTypeConvension processor type the file is following
fileopened file stream to be read
dimensionThe dimensions of the matrix up to 7-dimensions
param_dataThe output of the function
currentIdxInternal tracker of where the function is in the flow of the recursive calls

Definition at line 279 of file ezc3d.cpp.

◆ readParam() [3/3]

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.

Parameters
fileopened file stream to be read
dimensionThe dimensions of the matrix up to 7-dimensions. The first dimension is the length of the strings
param_dataThe output of the function

Definition at line 289 of file ezc3d.cpp.

◆ readString()

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.

Parameters
fileopened file stream to be read
nByteToReadThe number of byte to read to be converted into float
nByteFromPreviousThe number of bytes to skip from the current cursor position
posWhere to reposition the cursor
Returns
The float value

Definition at line 256 of file ezc3d.cpp.

◆ readUint()

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.

Parameters
processorTypeConvension processor type the file is following
fileopened file stream to be read
nByteToReadThe number of byte to read to be converted into unsigned integer
nByteFromPreviousThe number of bytes to skip from the current cursor position
posWhere to reposition the cursor
Returns
The unsigned integer value

Definition at line 203 of file ezc3d.cpp.

◆ resizeCharHolder()

void ezc3d::c3d::resizeCharHolder ( unsigned int  nByteToRead)
protected

Resize the too small char to read.

Parameters
nByteToReadThe number of bytes to read

Definition at line 122 of file ezc3d.cpp.

◆ unlockGroup()

void ezc3d::c3d::unlockGroup ( const std::string &  groupName)

Unlock a particular group named groupName.

Parameters
groupNameThe name of the group to unlock

Throw a std::invalid_argument exception if the group name does not exist

Definition at line 409 of file ezc3d.cpp.

◆ updateParameters()

void ezc3d::c3d::updateParameters ( const std::vector< std::string > &  newPoints = std::vector<std::string>(),
const std::vector< std::string > &  newAnalogs = std::vector<std::string>() 
)
protected

Update parameters according to the data.

Parameters
newPointsThe names of the new poits
newAnalogsThe 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.

Definition at line 581 of file ezc3d.cpp.

◆ write()

void ezc3d::c3d::write ( const std::string &  filePath) const

Write the C3D to an opened file by calling write method of header, parameter and data.

Parameters
filePathAlready opened fstream file with write access

Definition at line 92 of file ezc3d.cpp.

◆ writeDataStart()

void ezc3d::c3d::writeDataStart ( std::fstream &  file,
const std::streampos &  dataStartPosition,
const DATA_TYPE type 
) const
protected

Write the data_start parameter where demanded.

Parameters
fileopened file stream to be read
dataPositionThe position in block of the data
paramPositionThe position in byte to write the
typeThe type of data to write

Definition at line 166 of file ezc3d.cpp.


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