EZC3D
ezc3d.h
Go to the documentation of this file.
1 #ifndef EZC3D_H
2 #define EZC3D_H
3 
37 
38 // dllexport/import declaration
39 #ifdef _WIN32
40 # ifdef EZC3D_API_EXPORTS
41 # define EZC3D_API __declspec(dllexport)
42 # else
43 # define EZC3D_API __declspec(dllimport)
44 # endif
45 #else
46 # define EZC3D_API
47 #endif
48 
49 // Includes for standard library
50 #include <sstream>
51 #include <iostream>
52 #include <fstream>
53 #include <algorithm>
54 #include <vector>
55 #include <string.h>
56 #include <cmath>
57 #include <stdexcept>
58 #include <memory>
59 #ifdef _WIN32
60 #include <string>
61 #endif
62 
68 namespace ezc3d {
69  // ---- UTILS ---- //
73  enum DATA_TYPE{
74  CHAR = -1,
75  BYTE = 1,
76  INT = 2,
77  WORD = 2,
78  FLOAT = 4,
79  NO_DATA_TYPE = 10000
80  };
81 
86  INTEL = 84,
87  DEC = 85,
88  MIPS = 86,
89  NO_PROCESSOR_TYPE = INTEL
90  };
91 
98  EZC3D_API void removeTrailingSpaces(std::string& str);
99 
104  EZC3D_API std::string toUpper(const std::string &str);
105 
106 
107  // ---- FORWARD DECLARATION OF THE WHOLE PROJECT STRUCTURE ----//
108  class c3d;
109  class EZC3D_API Header;
110 
114  namespace ParametersNS {
115  class EZC3D_API Parameters;
116 
120  namespace GroupNS {
121  class EZC3D_API Group;
122  class EZC3D_API Parameter;
123  }
124  }
125 
129  namespace DataNS {
130  class EZC3D_API Data;
131 
132  class Frame;
136  namespace Points3dNS {
137  class EZC3D_API Points;
138  class EZC3D_API Point;
139  }
143  namespace AnalogsNS {
144  class EZC3D_API Analogs;
145  class EZC3D_API SubFrame;
146  class EZC3D_API Channel;
147  }
148  }
149 }
150 
154 class EZC3D_API ezc3d::c3d {
155 protected:
156  std::string _filePath;
157 
158  // ---- CONSTRUCTORS ---- //
159 public:
163  c3d();
164 
169  c3d(const std::string &filePath);
170 
174  virtual ~c3d();
175 
176 
177  //---- STREAM ----//
178 public:
182  void print() const;
183 
188  void write(const std::string &filePath) const;
189 
190 protected:
191  // Internal reading and writting function
192  char * c_float;
193  char * c_float_tp;
194  char * c_int;
195  char * c_int_tp;
196  unsigned int m_nByteToRead_float;
197  unsigned int m_nByteToReadMax_int;
198 
203  void resizeCharHolder(unsigned int nByteToRead);
204 
213  void readFile(
214  std::fstream &file,
215  unsigned int nByteToRead,
216  char * c,
217  int nByteFromPrevious = 0,
218  const std::ios_base::seekdir &pos = std::ios::cur);
219 
226  unsigned int hex2uint(const char * val, unsigned int len);
227 
234  int hex2int(const char * val, unsigned int len);
235 
243  void writeDataStart(std::fstream &file,
244  const std::streampos& dataStartPosition,
245  const DATA_TYPE &type) const;
246 
247 public:
257  int readInt(PROCESSOR_TYPE processorType,
258  std::fstream &file,
259  unsigned int nByteToRead,
260  int nByteFromPrevious = 0,
261  const std::ios_base::seekdir &pos = std::ios::cur);
262 
272  size_t readUint(PROCESSOR_TYPE processorType,
273  std::fstream &file,
274  unsigned int nByteToRead,
275  int nByteFromPrevious = 0,
276  const std::ios_base::seekdir &pos = std::ios::cur);
277 
286  float readFloat(PROCESSOR_TYPE processorType,
287  std::fstream &file,
288  int nByteFromPrevious = 0,
289  const std::ios_base::seekdir &pos = std::ios::cur);
290 
299  std::string readString(std::fstream &file,
300  unsigned int nByteToRead,
301  int nByteFromPrevious = 0,
302  const std::ios_base::seekdir &pos = std::ios::cur);
303 
313  void readParam(PROCESSOR_TYPE processorType,
314  std::fstream &file,
315  unsigned int dataLenghtInBytes,
316  const std::vector<size_t> &dimension,
317  std::vector<int> &param_data,
318  size_t currentIdx = 0);
319 
328  void readParam(PROCESSOR_TYPE processorType,
329  std::fstream &file,
330  const std::vector<size_t> &dimension,
331  std::vector<float> &param_data,
332  size_t currentIdx = 0);
333 
340  void readParam(std::fstream &file,
341  const std::vector<size_t> &dimension,
342  std::vector<std::string> &param_data);
343 
344 protected:
354  size_t _dispatchMatrix(const std::vector<size_t> &dimension,
355  const std::vector<std::string> &param_data_in,
356  std::vector<std::string> &param_data_out,
357  size_t idxInParam = 0,
358  size_t currentIdx = 1);
359 
367  void _readMatrix(std::fstream &file,
368  const std::vector<size_t> &dimension,
369  std::vector<std::string> &param_data,
370  size_t currentIdx = 0);
371 
372 
373  // ---- C3D MAIN STRUCTURE ---- //
374 protected:
375  std::shared_ptr<ezc3d::Header> _header;
376  std::shared_ptr<ezc3d::ParametersNS::Parameters> _parameters;
377  std::shared_ptr<ezc3d::DataNS::Data> _data;
378 
379 public:
384  const ezc3d::Header& header() const;
385 
391 
396  const ezc3d::DataNS::Data& data() const;
397 
398  // ---- PUBLIC GETTER INTERFACE ---- //
399 public:
404  const std::vector<std::string>& pointNames() const;
405 
415  size_t pointIdx(const std::string& pointName) const;
416 
421  const std::vector<std::string>& channelNames() const;
422 
432  size_t channelIdx(const std::string& channelName) const;
433 
434 
435  // ---- PUBLIC C3D MODIFICATION INTERFACE ---- //
436 public:
447  void parameter(const std::string &groupName, const ezc3d::ParametersNS::GroupNS::Parameter &parameter);
448 
455  void lockGroup(const std::string &groupName);
456 
463  void unlockGroup(const std::string &groupName);
464 
486  void frame(const ezc3d::DataNS::Frame &frame, size_t idx = SIZE_MAX);
487 
499  void point(const std::string &name);
500 
514  void point(const std::string &pointName, const std::vector<ezc3d::DataNS::Frame> &frames);
515 
529  void point(const std::vector<std::string> &pointNames, const std::vector<ezc3d::DataNS::Frame> &frames);
530 
542  void analog(const std::string &name);
543 
558  void analog(std::string channelName, const std::vector<ezc3d::DataNS::Frame> &frames);
559 
574  void analog(const std::vector<std::string>& channelNames, const std::vector<ezc3d::DataNS::Frame> &frames);
575 
576 
577  // ---- UPDATER ---- //
578 protected:
582  void updateHeader();
583 
592  void updateParameters(const std::vector<std::string> &newPoints = std::vector<std::string>(), const std::vector<std::string> &newAnalogs = std::vector<std::string>());
593 
594 };
595 
596 #endif
597 
std::shared_ptr< ezc3d::DataNS::Data > _data
Pointer that holds the data of the C3D.
Definition: ezc3d.h:377
std::string _filePath
The file path if the C3D was opened from a file.
Definition: ezc3d.h:156
std::shared_ptr< ezc3d::Header > _header
Pointer that holds the header of the C3D.
Definition: ezc3d.h:375
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.
Definition: ezc3d.cpp:310
void resizeCharHolder(unsigned int nByteToRead)
Resize the too small char to read.
Definition: ezc3d.cpp:122
Analog holder for C3D analogous data.
Definition: Analogs.h:16
Group holder of C3D parameters.
Definition: Parameters.h:16
int hex2int(const char *val, unsigned int len)
Convert an hexadecimal value to a integer.
Definition: ezc3d.cpp:147
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...
Definition: ezc3d.cpp:203
Points holder for C3D data 3D points data.
Definition: Points.h:16
void point(const std::string &name)
Create a point to the data set of name name.
Definition: ezc3d.cpp:452
PROCESSOR_TYPE
The type of processor used to store the data.
Definition: ezc3d.h:85
void unlockGroup(const std::string &groupName)
Unlock a particular group named groupName.
Definition: ezc3d.cpp:409
c3d()
Create a valid minimalistic C3D structure.
Definition: ezc3d.cpp:31
Group of parameter of a C3D file.
Definition: Group.h:16
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.
Definition: ezc3d.cpp:330
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 dataLengthInB...
Definition: ezc3d.cpp:269
char * c_int_tp
Char to be used by the read function with the specific size of a int preventing to allocate it at eac...
Definition: ezc3d.h:195
Header of a C3D file.
Definition: Header.h:16
void parameter(const std::string &groupName, const ezc3d::ParametersNS::GroupNS::Parameter &parameter)
Add/replace a parameter to a group named groupName.
Definition: ezc3d.cpp:384
Namespace ezc3d.
Definition: ezc3d.h:68
void print() const
Print the C3D by calling print method of header, parameter and data.
Definition: ezc3d.cpp:85
Subframe for the analogous data.
Definition: Subframe.h:16
const std::vector< std::string > & pointNames() const
Get a reference to the names of the points.
Definition: ezc3d.cpp:355
char * c_int
Char to be used by the read function with the specific size of a int preventing to allocate it at eac...
Definition: ezc3d.h:194
Channel of an analogous data.
Definition: Channel.h:16
void updateHeader()
Update the header according to the parameters and the data.
Definition: ezc3d.cpp:547
virtual ~c3d()
Destroy the class properly.
Definition: ezc3d.cpp:77
size_t channelIdx(const std::string &channelName) const
Get the index of a analog channel in the subframe.
Definition: ezc3d.cpp:374
std::shared_ptr< ezc3d::ParametersNS::Parameters > _parameters
Pointer that holds the parameters of the C3D.
Definition: ezc3d.h:376
const ezc3d::Header & header() const
The header of the C3D.
Definition: ezc3d.cpp:340
const ezc3d::ParametersNS::Parameters & parameters() const
The parameters of the C3D.
Definition: ezc3d.cpp:345
void frame(const ezc3d::DataNS::Frame &frame, size_t idx=SIZE_MAX)
Add/replace a frame to the data set.
Definition: ezc3d.cpp:414
char * c_float_tp
Char to be used by the read function with the specific size of a float preventing to allocate it at e...
Definition: ezc3d.h:193
Main class for C3D holder.
Definition: ezc3d.h:154
void analog(const std::string &name)
Create a channel of analog data to the data set of name name.
Definition: ezc3d.cpp:495
void lockGroup(const std::string &groupName)
Lock a particular group named groupName.
Definition: ezc3d.cpp:404
const std::vector< std::string > & channelNames() const
Get a reference to the names of the analog channels.
Definition: ezc3d.cpp:369
Data of the C3D file.
Definition: Data.h:18
size_t pointIdx(const std::string &pointName) const
Get the index of a point in the points holder.
Definition: ezc3d.cpp:360
char * c_float
Char to be used by the read function with the specific size of a float preventing to allocate it at e...
Definition: ezc3d.h:192
Frame holder for C3D data.
Definition: Frame.h:17
void write(const std::string &filePath) const
Write the C3D to an opened file by calling write method of header, parameter and data.
Definition: ezc3d.cpp:92
std::string toUpper(const std::string &str)
Swap all characters of a string to capital letters.
Definition: ezc3d.cpp:25
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...
Definition: ezc3d.cpp:179
const ezc3d::DataNS::Data & data() const
The points and analogous data of the C3D.
Definition: ezc3d.cpp:350
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-a...
Definition: ezc3d.cpp:131
unsigned int m_nByteToRead_float
Declaration of the size of a float.
Definition: ezc3d.h:196
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...
Definition: ezc3d.cpp:256
DATA_TYPE
Enum that describes the size of different types.
Definition: ezc3d.h:73
void writeDataStart(std::fstream &file, const std::streampos &dataStartPosition, const DATA_TYPE &type) const
Write the data_start parameter where demanded.
Definition: ezc3d.cpp:166
void removeTrailingSpaces(std::string &str)
Remove the spaces at the end of a string.
Definition: ezc3d.cpp:16
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.
Definition: ezc3d.cpp:581
Parameter of a C3D file.
Definition: Parameter.h:16
unsigned int hex2uint(const char *val, unsigned int len)
Convert an hexadecimal value to an unsigned integer.
Definition: ezc3d.cpp:140
unsigned int m_nByteToReadMax_int
Declaration of the max size of a int.
Definition: ezc3d.h:197
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.
Definition: ezc3d.cpp:228