diff --git a/include/Group.h b/include/Group.h index 913be715..05fa149a 100644 --- a/include/Group.h +++ b/include/Group.h @@ -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 diff --git a/include/Parameters.h b/include/Parameters.h index f631e1d9..d8a725cd 100644 --- a/include/Parameters.h +++ b/include/Parameters.h @@ -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 diff --git a/src/Group.cpp b/src/Group.cpp index dff5e356..34a5ab7b 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -146,6 +146,17 @@ size_t ezc3d::ParametersNS::GroupNS::Group::nbParameters() const { return _parameters.size(); } +bool ezc3d::ParametersNS::GroupNS::Group::isParameter( + const std::string ¶meterName) const +{ + try { + parameterIdx(parameterName); + return true; + } catch (std::invalid_argument) { + return false; + } +} + size_t ezc3d::ParametersNS::GroupNS::Group::parameterIdx( const std::string ¶meterName) const { for (size_t i = 0; i < nbParameters(); ++i) diff --git a/src/Parameters.cpp b/src/Parameters.cpp index 489aef8f..7b53d571 100644 --- a/src/Parameters.cpp +++ b/src/Parameters.cpp @@ -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()={}); grp.parameter(p); } - { + if (!grp.isParameter("DESCRIPTIONS")){ ezc3d::ParametersNS::GroupNS::Parameter p("DESCRIPTIONS", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("UNITS")){ ezc3d::ParametersNS::GroupNS::Parameter p("UNITS", ""); p.set(std::vector()={}); 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()={}); grp.parameter(p); } - { + if (!grp.isParameter("DESCRIPTIONS")){ ezc3d::ParametersNS::GroupNS::Parameter p("DESCRIPTIONS", ""); p.set(std::vector()={}); 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()={}); grp.parameter(p); } - { + if (!grp.isParameter("OFFSET")){ ezc3d::ParametersNS::GroupNS::Parameter p("OFFSET", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("UNITS")){ ezc3d::ParametersNS::GroupNS::Parameter p("UNITS", ""); p.set(std::vector()={}); 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()={}); grp.parameter(p); } - { + if (!grp.isParameter("BITS")){ ezc3d::ParametersNS::GroupNS::Parameter p("BITS", ""); p.set(std::vector()={}); 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()={}); grp.parameter(p); } - { + if (!grp.isParameter("ZERO")){ ezc3d::ParametersNS::GroupNS::Parameter p("ZERO", ""); p.set(std::vector()={1,0}); grp.parameter(p); } - { + if (!grp.isParameter("CORNERS")){ ezc3d::ParametersNS::GroupNS::Parameter p("CORNERS", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("ORIGIN")){ ezc3d::ParametersNS::GroupNS::Parameter p("ORIGIN", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("CHANNEL")){ ezc3d::ParametersNS::GroupNS::Parameter p("CHANNEL", ""); p.set(std::vector()={}); grp.parameter(p); } - { + if (!grp.isParameter("CAL_MATRIX")){ ezc3d::ParametersNS::GroupNS::Parameter p("CAL_MATRIX", ""); p.set(std::vector()={}); grp.parameter(p); } - group(grp); } } @@ -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)