1 #define EZC3D_API_EXPORTS 43 throw std::ios_base::failure(
"File must be a valid c3d file");
45 if (processorTypeId == 84)
47 else if (processorTypeId == 85)
49 else if (processorTypeId == 86){
51 throw std::runtime_error(
"MIPS processor type not supported yet, please open a GitHub issue to report that you want this feature!");
54 throw std::runtime_error(
"Could not read the processor type");
57 std::streampos nextParamByteInFile(static_cast<int>(file.tellg()) + static_cast<int>(
_parametersStart) - ezc3d::DATA_TYPE::BYTE);
58 while (nextParamByteInFile)
61 if (file.tellg() != nextParamByteInFile)
62 throw std::ios_base::failure(
"Bad c3d formatting");
66 if (nbCharInName == 0)
71 for (
size_t i =
_groups.size(); i < static_cast<size_t>(abs(
id)); ++i)
76 nextParamByteInFile =
group_nonConst(static_cast<size_t>(abs(
id)-1)).
read(
c3d, *
this, file, nbCharInName);
119 p.
set(std::vector<std::string>()={});
124 p.
set(std::vector<std::string>()={});
129 p.
set(std::vector<std::string>()={});
144 p.
set(std::vector<std::string>()={});
149 p.
set(std::vector<std::string>()={});
159 p.
set(std::vector<float>()={});
164 p.
set(std::vector<int>()={});
169 p.
set(std::vector<std::string>()={});
180 p.
set(std::vector<std::string>()={});
185 p.
set(std::vector<int>()={});
199 p.
set(std::vector<int>()={});
204 p.
set(std::vector<int>()={1,0});
209 p.
set(std::vector<float>()={});
214 p.
set(std::vector<float>()={});
219 p.
set(std::vector<int>()={});
224 p.
set(std::vector<float>()={});
233 std::cout <<
"Parameters header" << std::endl;
234 std::cout <<
"parametersStart = " << parametersStart() << std::endl;
235 std::cout <<
"nbParamBlock = " << nbParamBlock() << std::endl;
236 std::cout <<
"processorType = " << processorType() << std::endl;
238 for (
size_t i = 0; i < nbGroups(); ++i){
239 std::cout <<
"Group " << i << std::endl;
241 std::cout << std::endl;
243 std::cout << std::endl;
249 f.write(reinterpret_cast<const char*>(&_parametersStart), ezc3d::BYTE);
251 f.write(reinterpret_cast<const char*>(&checksum), ezc3d::BYTE);
254 std::streampos pos(f.tellg());
256 f.write(reinterpret_cast<const char*>(&blankValue), ezc3d::BYTE);
257 int processorType = PROCESSOR_TYPE::INTEL;
258 f.write(reinterpret_cast<const char*>(&processorType), ezc3d::BYTE);
261 for (
size_t i=0; i < nbGroups(); ++i)
262 group(i).write(f, -static_cast<int>(i+1), dataStartPosition);
265 std::streampos currentPos(f.tellg());
266 for (
int i=0; i<512 -
static_cast<int>(currentPos) % 512; ++i){
267 f.write(reinterpret_cast<const char*>(&blankValue), ezc3d::BYTE);
270 currentPos = f.tellg();
272 int nBlocksToNext = int(currentPos - pos-2)/512;
273 if (
int(currentPos - pos-2) % 512 > 0)
275 f.write(reinterpret_cast<const char*>(&nBlocksToNext), ezc3d::BYTE);
281 return _parametersStart;
291 return _nbParamBlock;
296 return _processorType;
301 return _groups.size();
306 for (
size_t i = 0; i < nbGroups(); ++i)
307 if (!group(i).name().compare(groupName))
309 throw std::invalid_argument(
"Parameters::groupIdx could not find " + groupName);
315 return _groups.at(idx);
316 }
catch(std::out_of_range) {
317 throw std::out_of_range(
"Parameters::group method is trying to access the group " 318 + std::to_string(idx) +
319 " while the maximum number of groups is " 320 + std::to_string(nbGroups()) +
".");
327 return _groups.at(idx);
328 }
catch(std::out_of_range) {
329 throw std::out_of_range(
"Parameters::group method is trying to access the group " 330 + std::to_string(idx) +
331 " while the maximum number of groups is " 332 + std::to_string(nbGroups()) +
".");
338 return group(groupIdx(groupName));
343 return group_nonConst(groupIdx(groupName));
349 size_t alreadyExtIdx(SIZE_MAX);
350 for (
size_t i = 0; i < nbGroups(); ++i)
351 if (!group(i).name().compare(g.
name()))
353 if (alreadyExtIdx == SIZE_MAX)
354 _groups.push_back(g);
357 _groups[alreadyExtIdx].parameter(g.
parameter(i));
size_t parametersStart() const
Get the byte in the file where the data starts.
size_t nbGroups() const
Get the number of groups.
void set(int data)
Set the integer scalar value for the parameter.
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...
size_t nbParamBlock() const
Get the number of 256-bytes the parameters need in the file.
PROCESSOR_TYPE
The type of processor used to store the data.
size_t nbParameters() const
Get the number of parameters.
Group of parameter of a C3D file.
PROCESSOR_TYPE processorType() const
Get the processor type the file was writen on.
const ezc3d::ParametersNS::GroupNS::Group & group(size_t idx) const
Get a particular group of index idx from the group holder.
std::vector< ezc3d::ParametersNS::GroupNS::Group > _groups
Holder for the group of parameters.
const ezc3d::ParametersNS::GroupNS::Parameter & parameter(size_t idx) const
Get a particular parameter of index idx from the group.
const ezc3d::Header & header() const
The header of the C3D.
ezc3d::ParametersNS::GroupNS::Group & group_nonConst(size_t idx)
Get a particular group of index idx from the group holder in order to be modified by the caller...
Main class for C3D holder.
const std::string & name() const
Get the name of the group.
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< ezc3d::ParametersNS::GroupNS::Group > & groups() const
Get all groups the group holder with read-only access.
void write(std::fstream &f, std::streampos &dataStartPosition) const
Write the groups to an opened file by calling the write method of all the groups. ...
void setMandatoryParameters()
Add all required parameter for a c3d to be valid.
Parameters()
Create a default group holder with minimal groups to have a valid c3d.
size_t checksum() const
Get the checksum of the parameters.
void print() const
Print the groups by calling the print method of all the groups.
size_t groupIdx(const std::string &groupName) const
Get the index of a group in the group holder.
PROCESSOR_TYPE _processorType
int read(ezc3d::c3d &c3d, const Parameters ¶ms, std::fstream &file, int nbCharInName)
Read and store a group of parameter from an opened C3D file.
void lock()
Set the locking status of the parameter to true.
Declaration of Parameters class.