Skip to content

Commit

Permalink
Corrected a major bug where reading a file could results in swaping t…
Browse files Browse the repository at this point in the history
…he parameters of 2 groups
  • Loading branch information
pariterre committed Oct 11, 2019
1 parent ee1655f commit c4d7c09
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 31 deletions.
8 changes: 8 additions & 0 deletions include/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ class EZC3D_API ezc3d::ParametersNS::GroupNS::Group{
///
size_t nbParameters() const;

///
/// \brief Return if a parameter of a specific name exists
/// \param parameterName The parameter name to return
/// \return If the parameter exists (true) or not (false)
///
bool isParameter(
const std::string& parameterName) const;

///
/// \brief Get the index of a parameter in the group
/// \param parameterName Name of the parameter
Expand Down
8 changes: 8 additions & 0 deletions include/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ class EZC3D_API ezc3d::ParametersNS::Parameters{
///
size_t nbGroups() const;

///
/// \brief Return if a group of a specific name exists
/// \param groupName The group name to return
/// \return If the group exists (true) or not (false)
///
bool isGroup(
const std::string& groupName) const;

///
/// \brief Get the index of a group in the group holder
/// \param groupName Name of the group
Expand Down
11 changes: 11 additions & 0 deletions src/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ size_t ezc3d::ParametersNS::GroupNS::Group::nbParameters() const {
return _parameters.size();
}

bool ezc3d::ParametersNS::GroupNS::Group::isParameter(
const std::string &parameterName) const
{
try {
parameterIdx(parameterName);
return true;
} catch (std::invalid_argument) {
return false;
}
}

size_t ezc3d::ParametersNS::GroupNS::Group::parameterIdx(
const std::string &parameterName) const {
for (size_t i = 0; i < nbParameters(); ++i)
Expand Down
82 changes: 51 additions & 31 deletions src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,148 +111,157 @@ ezc3d::ParametersNS::Parameters::Parameters(
void ezc3d::ParametersNS::Parameters::setMandatoryParameters() {
// Mandatory groups
{
ezc3d::ParametersNS::GroupNS::Group grp("POINT", "");
{
if (!isGroup("POINT")){
group(ezc3d::ParametersNS::GroupNS::Group ("POINT"));
}

ezc3d::ParametersNS::GroupNS::Group& grp(group("POINT"));
if (!grp.isParameter("USED")){
ezc3d::ParametersNS::GroupNS::Parameter p("USED", "");
p.set(0);
p.lock();
grp.parameter(p);
}
{
if (!grp.isParameter("SCALE")){
ezc3d::ParametersNS::GroupNS::Parameter p("SCALE", "");
p.set(-1.0);
p.lock();
grp.parameter(p);
}
{
if (!grp.isParameter("RATE")){
ezc3d::ParametersNS::GroupNS::Parameter p("RATE", "");
p.set(0.0);
p.lock();
grp.parameter(p);
}
{
if (!grp.isParameter("DATA_START")){
ezc3d::ParametersNS::GroupNS::Parameter p("DATA_START", "");
p.set(0);
p.lock();
grp.parameter(p);
}
{
if (!grp.isParameter("FRAMES")){
ezc3d::ParametersNS::GroupNS::Parameter p("FRAMES", "");
p.set(0);
p.lock();
grp.parameter(p);
}
{
if (!grp.isParameter("LABELS")){
ezc3d::ParametersNS::GroupNS::Parameter p("LABELS", "");
p.set(std::vector<std::string>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("DESCRIPTIONS")){
ezc3d::ParametersNS::GroupNS::Parameter p("DESCRIPTIONS", "");
p.set(std::vector<std::string>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("UNITS")){
ezc3d::ParametersNS::GroupNS::Parameter p("UNITS", "");
p.set(std::vector<std::string>()={});
grp.parameter(p);
}
group(grp);
}
{
ezc3d::ParametersNS::GroupNS::Group grp("ANALOG", "");
{
if (!isGroup("ANALOG")){
group(ezc3d::ParametersNS::GroupNS::Group ("ANALOG"));
}

ezc3d::ParametersNS::GroupNS::Group& grp(group("ANALOG"));
if (!grp.isParameter("USED")){
ezc3d::ParametersNS::GroupNS::Parameter p("USED", "");
p.set(0);
p.lock();
grp.parameter(p);
}
{
if (!grp.isParameter("LABELS")){
ezc3d::ParametersNS::GroupNS::Parameter p("LABELS", "");
p.set(std::vector<std::string>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("DESCRIPTIONS")){
ezc3d::ParametersNS::GroupNS::Parameter p("DESCRIPTIONS", "");
p.set(std::vector<std::string>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("GEN_SCALE")){
ezc3d::ParametersNS::GroupNS::Parameter p("GEN_SCALE", "");
p.set(1.0);
grp.parameter(p);
}
{
if (!grp.isParameter("SCALE")){
ezc3d::ParametersNS::GroupNS::Parameter p("SCALE", "");
p.set(std::vector<float>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("OFFSET")){
ezc3d::ParametersNS::GroupNS::Parameter p("OFFSET", "");
p.set(std::vector<int>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("UNITS")){
ezc3d::ParametersNS::GroupNS::Parameter p("UNITS", "");
p.set(std::vector<std::string>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("RATE")){
ezc3d::ParametersNS::GroupNS::Parameter p("RATE", "");
p.set(0.0);
p.lock();
grp.parameter(p);
}
{
if (!grp.isParameter("FORMAT")){
ezc3d::ParametersNS::GroupNS::Parameter p("FORMAT", "");
p.set(std::vector<std::string>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("BITS")){
ezc3d::ParametersNS::GroupNS::Parameter p("BITS", "");
p.set(std::vector<int>()={});
grp.parameter(p);
}
group(grp);
}
{
ezc3d::ParametersNS::GroupNS::Group grp("FORCE_PLATFORM", "");
{
if (!isGroup("FORCE_PLATFORM")){
group(ezc3d::ParametersNS::GroupNS::Group ("FORCE_PLATFORM"));
}

ezc3d::ParametersNS::GroupNS::Group& grp(group("FORCE_PLATFORM"));
if (!grp.isParameter("USED")){
ezc3d::ParametersNS::GroupNS::Parameter p("USED", "");
p.set(0);
grp.parameter(p);
}
{
if (!grp.isParameter("TYPE")){
ezc3d::ParametersNS::GroupNS::Parameter p("TYPE", "");
p.set(std::vector<int>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("ZERO")){
ezc3d::ParametersNS::GroupNS::Parameter p("ZERO", "");
p.set(std::vector<int>()={1,0});
grp.parameter(p);
}
{
if (!grp.isParameter("CORNERS")){
ezc3d::ParametersNS::GroupNS::Parameter p("CORNERS", "");
p.set(std::vector<float>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("ORIGIN")){
ezc3d::ParametersNS::GroupNS::Parameter p("ORIGIN", "");
p.set(std::vector<float>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("CHANNEL")){
ezc3d::ParametersNS::GroupNS::Parameter p("CHANNEL", "");
p.set(std::vector<int>()={});
grp.parameter(p);
}
{
if (!grp.isParameter("CAL_MATRIX")){
ezc3d::ParametersNS::GroupNS::Parameter p("CAL_MATRIX", "");
p.set(std::vector<float>()={});
grp.parameter(p);
}
group(grp);
}
}

Expand Down Expand Up @@ -324,6 +333,17 @@ size_t ezc3d::ParametersNS::Parameters::nbGroups() const {
return _groups.size();
}

bool ezc3d::ParametersNS::Parameters::isGroup(
const std::string &groupName) const
{
try {
groupIdx(groupName);
return true;
} catch (std::invalid_argument) {
return false;
}
}

size_t ezc3d::ParametersNS::Parameters::groupIdx(
const std::string &groupName) const {
for (size_t i = 0; i < nbGroups(); ++i)
Expand Down

0 comments on commit c4d7c09

Please sign in to comment.