1 #define EZC3D_API_EXPORTS 15 _description(description),
24 std::cout <<
"parameterName = " << name() << std::endl;
25 std::cout <<
"isLocked = " << isLocked() << std::endl;
28 if (_data_type == DATA_TYPE::CHAR)
29 for (
unsigned int i = 0; i < _param_data_string.size(); ++i)
30 std::cout <<
"param_data_string[" << i <<
"] = " << _param_data_string[i] << std::endl;
31 if (_data_type == DATA_TYPE::BYTE)
32 for (
unsigned int i = 0; i < _param_data_int.size(); ++i)
33 std::cout <<
"param_data[" << i <<
"] = " << _param_data_int[i] << std::endl;
34 if (_data_type == DATA_TYPE::INT)
35 for (
unsigned int i = 0; i < _param_data_int.size(); ++i)
36 std::cout <<
"param_data[" << i <<
"] = " << _param_data_int[i] << std::endl;
37 if (_data_type == DATA_TYPE::FLOAT)
38 for (
unsigned int i = 0; i < _param_data_float.size(); ++i)
39 std::cout <<
"param_data[" << i <<
"] = " << _param_data_float[i] << std::endl;
41 std::cout <<
"description = " << _description << std::endl;
46 int nCharName(static_cast<int>(name().size()));
49 f.write(reinterpret_cast<const char*>(&nCharName), 1*ezc3d::DATA_TYPE::BYTE);
52 f.write(reinterpret_cast<const char*>(&groupIdx), 1*ezc3d::DATA_TYPE::BYTE);
53 f.write(
ezc3d::toUpper(name()).c_str(), nCharName*ezc3d::DATA_TYPE::BYTE);
57 std::streampos pos(f.tellg());
58 f.write(reinterpret_cast<const char*>(&blank), 2*ezc3d::DATA_TYPE::BYTE);
61 f.write(reinterpret_cast<const char*>(&_data_type), 1*ezc3d::DATA_TYPE::BYTE);
62 size_t size_dim(_dimension.size());
64 if (_dimension.size() == 1 && _dimension[0] == 1 && _data_type != DATA_TYPE::CHAR){
66 f.write(reinterpret_cast<const char*>(&_size_dim), 1*ezc3d::DATA_TYPE::BYTE);
69 f.write(reinterpret_cast<const char*>(&size_dim), 1*ezc3d::DATA_TYPE::BYTE);
70 for (
unsigned int i=0; i<_dimension.size(); ++i)
71 f.write(reinterpret_cast<const char*>(&_dimension[i]), 1*ezc3d::DATA_TYPE::BYTE);
75 if (_dimension.size() > 0){
77 for (
unsigned int i=0; i<_dimension.size(); ++i)
78 hasSize *= _dimension[i];
81 if (_data_type == DATA_TYPE::CHAR){
82 if (_dimension.size() == 1){
83 f.write(_param_data_string[0].c_str(), static_cast<int>(_param_data_string[0].size())*static_cast<int>(DATA_TYPE::BYTE));
85 writeImbricatedParameter(f, _dimension, 1);
88 if (!_name.compare(
"DATA_START")){
90 dataStartPosition = f.tellg();
91 f.write(reinterpret_cast<const char*>(&blank), 2*ezc3d::DATA_TYPE::BYTE);
93 writeImbricatedParameter(f, _dimension);
98 int nCharDescription(static_cast<int>(description().size()));
99 f.write(reinterpret_cast<const char*>(&nCharDescription), 1*ezc3d::DATA_TYPE::BYTE);
100 f.write(description().c_str(), nCharDescription*ezc3d::DATA_TYPE::BYTE);
103 std::streampos currentPos(f.tellg());
105 int nCharToNext = int(currentPos - pos);
106 f.write(reinterpret_cast<const char*>(&nCharToNext), 2*ezc3d::DATA_TYPE::BYTE);
111 for (
size_t i=0; i<dim[currentIdx]; ++i)
112 if (currentIdx == dim.size()-1){
113 if (_data_type == DATA_TYPE::BYTE)
114 f.write(reinterpret_cast<const char*>(&(_param_data_int[cmp])), static_cast<int>(_data_type));
115 else if (_data_type == DATA_TYPE::INT)
116 f.write(reinterpret_cast<const char*>(&(_param_data_int[cmp])), static_cast<int>(_data_type));
117 else if (_data_type == DATA_TYPE::FLOAT)
118 f.write(reinterpret_cast<const char*>(&(_param_data_float[cmp])), static_cast<int>(_data_type));
119 else if (_data_type == DATA_TYPE::CHAR){
120 f.write(_param_data_string[cmp].c_str(), static_cast<int>(_param_data_string[cmp].size())*static_cast<int>(DATA_TYPE::BYTE));
121 const char buffer =
' ';
122 for (
size_t j=_param_data_string[cmp].size(); j<_dimension[0]; ++j)
123 f.write(&buffer, static_cast<int>(DATA_TYPE::BYTE));
128 cmp = writeImbricatedParameter(f, dim, currentIdx + 1, cmp);
134 if (nbCharInName < 0)
140 _name =
c3d.
readString(file, static_cast<unsigned int>(abs(nbCharInName) * ezc3d::DATA_TYPE::BYTE));
145 int nextParamByteInFile;
147 nextParamByteInFile = 0;
149 nextParamByteInFile =
static_cast<int>(file.tellg()) + offsetNext - ezc3d::DATA_TYPE::WORD;
153 if (lengthInByte == -1)
154 _data_type = DATA_TYPE::CHAR;
155 else if (lengthInByte == 1)
156 _data_type = DATA_TYPE::BYTE;
157 else if (lengthInByte == 2)
158 _data_type = DATA_TYPE::INT;
159 else if (lengthInByte == 4)
160 _data_type = DATA_TYPE::FLOAT;
162 throw std::ios_base::failure (
"Parameter type unrecognized");
166 if (nDimensions == 0 && _data_type != DATA_TYPE::CHAR)
167 _dimension.push_back(1);
169 for (
int i=0; i<nDimensions; ++i)
173 if (_data_type == DATA_TYPE::CHAR)
175 else if (_data_type == DATA_TYPE::BYTE)
177 else if (_data_type == DATA_TYPE::INT)
179 else if (_data_type == DATA_TYPE::FLOAT)
187 _description =
c3d.
readString(file, static_cast<unsigned int>(nbCharInDesc));
190 return nextParamByteInFile;
210 _description = description;
236 for (
unsigned int i=0; i<dimension.size(); ++i)
238 if (dimension.size() == 0 || dim == 0)
244 size_t dimesionSize(1);
245 for (
unsigned int i=0; i<dimension.size(); ++i)
246 dimesionSize *= dimension[i];
247 if (dataSize == dimesionSize)
260 set(std::vector<int>()={data});
265 set(
static_cast<int>(data));
270 std::vector<size_t> dimensionCopy;
271 if (dimension.size() == 0){
272 dimensionCopy.push_back(data.size());
274 dimensionCopy = dimension;
276 if (!isDimensionConsistent(data.size(), dimensionCopy))
277 throw std::range_error(
"Dimension of the data does not correspond to sent dimensions");
278 _data_type = ezc3d::DATA_TYPE::INT;
279 _param_data_int = data;
280 _dimension = dimensionCopy;
285 set(std::vector<float>()={data});
290 set(std::vector<float>()={
static_cast<float>(data)});
295 std::vector<size_t> dimensionCopy;
296 if (dimension.size() == 0){
297 dimensionCopy.push_back(data.size());
299 dimensionCopy = dimension;
301 if (!isDimensionConsistent(data.size(), dimensionCopy))
302 throw std::range_error(
"Dimension of the data does not correspond to sent dimensions");
303 _data_type = ezc3d::DATA_TYPE::FLOAT;
304 _param_data_float = data;
305 _dimension = dimensionCopy;
310 set(std::vector<std::string>() = {data});
315 std::vector<size_t> dimensionCopy;
316 if (dimension.size() == 0){
317 dimensionCopy.push_back(data.size());
319 dimensionCopy = dimension;
321 if (!isDimensionConsistent(data.size(), dimensionCopy))
322 throw std::range_error(
"Dimension of the data does not correspond to sent dimensions");
325 for (
unsigned int i=0; i<data.size(); ++i)
326 if (data[i].size() > first_dim)
327 first_dim = data[i].size();
328 std::vector<size_t> dimensionWithStrLen = dimensionCopy;
329 dimensionWithStrLen.insert(dimensionWithStrLen.begin(), first_dim);
331 _data_type = ezc3d::DATA_TYPE::CHAR;
332 _param_data_string = data;
333 _dimension = dimensionWithStrLen;
338 if (_data_type != DATA_TYPE::BYTE)
339 throw std::invalid_argument(
"This parameter is not a BYTE");
340 return _param_data_int;
345 if (_data_type != DATA_TYPE::INT)
346 throw std::invalid_argument(
"This parameter is not an INT");
347 return _param_data_int;
352 if (_data_type != DATA_TYPE::FLOAT)
353 throw std::invalid_argument(
"This parameter is not a FLOAT");
354 return _param_data_float;
359 if (_data_type != DATA_TYPE::CHAR)
360 throw std::invalid_argument(
"This parameter is not string");
362 return _param_data_string;
void set(int data)
Set the integer scalar value for the parameter.
const std::vector< int > & valuesAsInt() const
Return the vector of values of the parameter.
bool isDimensionConsistent(size_t dataSize, const std::vector< size_t > &dimension) const
Check if the dimension parameter is consistent with the values.
Group holder of C3D parameters.
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...
void print() const
Print the parameter and its values.
void unlock()
Set the locking status of the parameter to false.
ezc3d::DATA_TYPE type() const
Return the type of the data.
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 dataLengthInB...
Declaration of Parameter class.
const std::vector< size_t > dimension() const
Return the vector mapping the dimension of the parameter matrix.
PROCESSOR_TYPE processorType() const
Get the processor type the file was writen on.
Parameter(const std::string &name="", const std::string &description="")
Create an empty parameter.
const std::string & description() const
Get the description of the parameter.
const std::string & name() const
Get the name of the parameter.
size_t writeImbricatedParameter(std::fstream &f, const std::vector< size_t > &dim, size_t currentIdx=0, size_t cmp=0) const
Write a matrix of parameter to a file.
bool isLocked() const
Get the locking status of the parameter.
Main class for C3D holder.
void write(std::fstream &f, int groupIdx, std::streampos &dataStartPosition) const
Write the parameter to an opened file.
const std::vector< std::string > & valuesAsString() const
Return the vector of values of the parameter.
std::string toUpper(const std::string &str)
Swap all characters of a string to capital letters.
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...
const std::vector< float > & valuesAsFloat() const
Return the vector of values of the parameter.
int read(c3d &c3d, const Parameters ¶ms, std::fstream &file, int nbCharInName)
Read and store a parameter from an opened C3D file.
const std::vector< int > & valuesAsByte() const
Return the vector of values of the parameter.
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...
DATA_TYPE
Enum that describes the size of different types.
void lock()
Set the locking status of the parameter to true.
Declaration of Parameters class.