From 121e539d018f51cd7db9f1a3b28c837106fbbe9a Mon Sep 17 00:00:00 2001 From: Dharini Dutia Date: Wed, 27 Dec 2023 20:52:25 +0000 Subject: [PATCH] reformat Signed-off-by: Dharini Dutia --- src/SdfEntityCreator.cc | 3 +- src/rendering/MaterialParser/ConfigLoader.cc | 5 +- src/rendering/MaterialParser/ConfigLoader.hh | 229 +++++++++--------- .../MaterialParser/MaterialParser.cc | 12 +- .../MaterialParser/MaterialParser.hh | 46 ++-- 5 files changed, 149 insertions(+), 146 deletions(-) diff --git a/src/SdfEntityCreator.cc b/src/SdfEntityCreator.cc index 4d808804bcf..fef11c96aa4 100644 --- a/src/SdfEntityCreator.cc +++ b/src/SdfEntityCreator.cc @@ -807,7 +807,8 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Visual *_visual) { std::string scriptName = visualMaterial.ScriptName(); - if ((scriptName.find("Gazebo/") == 0u)) { + if ((scriptName.find("Gazebo/") == 0u)) + { // \todo Add documentation page with warning gzwarn << "Using an internal gazebo.material to parse " << scriptName << std::endl; diff --git a/src/rendering/MaterialParser/ConfigLoader.cc b/src/rendering/MaterialParser/ConfigLoader.cc index 0830cb64f9e..1ae21822cb0 100644 --- a/src/rendering/MaterialParser/ConfigLoader.cc +++ b/src/rendering/MaterialParser/ConfigLoader.cc @@ -41,7 +41,6 @@ void ConfigLoader::loadMaterialFiles(ConfigLoader * c) "gazebo.material"); std::ifstream in(installedConfig, std::ios::binary); c->parseScript(in); - } catch(std::filesystem::filesystem_error & e) { @@ -60,7 +59,7 @@ ConfigLoader::~ConfigLoader() void ConfigLoader::clearScriptList() { - for (auto i : m_scriptList) { + for (auto & i : m_scriptList) { delete i.second; } m_scriptList.clear(); @@ -77,7 +76,7 @@ ConfigNode * ConfigLoader::getConfigScript(const std::string & name) } } -std::map < std::string, ConfigNode * > ConfigLoader::getAllConfigScripts() +std::map ConfigLoader::getAllConfigScripts() { return m_scriptList; } diff --git a/src/rendering/MaterialParser/ConfigLoader.hh b/src/rendering/MaterialParser/ConfigLoader.hh index 91601816256..b4ac3d0a7bd 100644 --- a/src/rendering/MaterialParser/ConfigLoader.hh +++ b/src/rendering/MaterialParser/ConfigLoader.hh @@ -19,144 +19,151 @@ #ifndef RENDERING__MATERIALPARSER__CONFIGLOADER_HH_ #define RENDERING__MATERIALPARSER__CONFIGLOADER_HH_ -#include #include -#include #include +#include +#include #include namespace gz { - namespace sim - { - class ConfigNode; +namespace sim +{ +class ConfigNode; - class ConfigLoader - { +class ConfigLoader +{ public: - static void loadMaterialFiles(ConfigLoader * c); + static void loadMaterialFiles(ConfigLoader * c); - ConfigLoader(); + ConfigLoader(); - ~ConfigLoader(); + ~ConfigLoader(); - std::string m_fileEnding; + std::string m_fileEnding; - // For a line like - // entity animals/dog - // { - // ... - // } - // The type is "entity" and the name is "animals/dog" - // Or if animal/dog was not there then name is "" - virtual ConfigNode * getConfigScript(const std::string & name); + // For a line like + // entity animals/dog + // { + // ... + // } + // The type is "entity" and the name is "animals/dog" + // Or if animal/dog was not there then name is "" + virtual ConfigNode * getConfigScript(const std::string & name); - virtual std::map < std::string, ConfigNode * > getAllConfigScripts(); + virtual std::map getAllConfigScripts(); - virtual void parseScript(std::ifstream & stream); + virtual void parseScript(std::ifstream & stream); protected: - float m_LoadOrder; - // like "*.object" + float m_LoadOrder; + // like "*.object" - std::map < std::string, ConfigNode * > m_scriptList; + std::map m_scriptList; - enum Token - { - TOKEN_Text, - TOKEN_NewLine, - TOKEN_OpenBrace, - TOKEN_CloseBrace, - TOKEN_EOF, - }; + enum Token + { + TOKEN_Text, + TOKEN_NewLine, + TOKEN_OpenBrace, + TOKEN_CloseBrace, + TOKEN_EOF, + }; - Token tok, lastTok; - std::string tokVal, lastTokVal; + Token tok, lastTok; + std::string tokVal, lastTokVal; - void _parseNodes(std::ifstream & stream, ConfigNode * parent); - void _nextToken(std::ifstream & stream); - void _skipNewLines(std::ifstream & stream); + void _parseNodes(std::ifstream & stream, ConfigNode * parent); + void _nextToken(std::ifstream & stream); + void _skipNewLines(std::ifstream & stream); - virtual void clearScriptList(); - }; + virtual void clearScriptList(); +}; - class ConfigNode - { +class ConfigNode +{ public: - ConfigNode(ConfigNode * parent, const std::string & name = "untitled"); - ~ConfigNode(); - - inline void setName(const std::string & name) - { - this->m_name = name; - } - - inline std::string & getName() - { - return m_name; - } - - inline void addValue(const std::string & value) - { - m_values.push_back(value); - } - - inline void clearValues() - { - m_values.clear(); - } - - inline std::vector < std::string > & getValues() - { - return m_values; - } - - inline void getValuesInFloat(std::vector < float > & floatValues) - { - for (const auto & str : m_values) { - floatValues.push_back(std::stof(str)); - } - } - - inline const std::string & getValue(unsigned int index = 0) - { - assert(index < m_values.size()); - return m_values[index]; - } - - ConfigNode * addChild(const std::string & name = "untitled", bool replaceExisting = false); - ConfigNode * findChild(const std::string & name, bool recursive = false); - - inline std::vector < ConfigNode * > & getChildren() - { - return m_children; - } - - inline ConfigNode * getChild(unsigned int index = 0) - { - assert(index < m_children.size()); - return m_children[index]; - } - - void setParent(ConfigNode * newParent); - - inline ConfigNode * getParent() - { - return m_parent; - } + explicit ConfigNode(ConfigNode * parent, const std::string & name = "untitled"); + + ~ConfigNode(); + + inline void setName(const std::string & name) + { + this->m_name = name; + } + + inline std::string & getName() + { + return m_name; + } + + inline void addValue(const std::string & value) + { + m_values.push_back(value); + } + + inline void clearValues() + { + m_values.clear(); + } + + inline std::vector & getValues() + { + return m_values; + } + + inline void getValuesInFloat(std::vector & floatValues) + { + for (const auto & str : m_values) { + floatValues.push_back(std::stof(str)); + } + } + + inline const std::string & getValue(unsigned int index = 0) + { + assert(index < m_values.size()); + return m_values[index]; + } + + ConfigNode * addChild(const std::string & name = "untitled", bool replaceExisting = false); + + ConfigNode * findChild(const std::string & name, bool recursive = false); + + inline std::vector & getChildren() + { + return m_children; + } + + inline ConfigNode * getChild(unsigned int index = 0) + { + assert(index < m_children.size()); + return m_children[index]; + } + + void setParent(ConfigNode * newParent); + + inline ConfigNode * getParent() + { + return m_parent; + } private: - std::string m_name; - std::vector < std::string > m_values; - std::vector < ConfigNode * > m_children; - ConfigNode * m_parent; + std::string m_name; + + std::vector m_values; + + std::vector m_children; + + ConfigNode * m_parent; + + // The last child node's index found with a call to findChild() + int m_lastChildFound; - int m_lastChildFound; // The last child node's index found with a call to findChild() + std::vector ::iterator _iter; - std::vector < ConfigNode * > ::iterator _iter; - bool _removeSelf; - }; - } // namespace sim + bool _removeSelf; +}; +} // namespace sim } // namespace gz #endif // RENDERING__MATERIALPARSER__CONFIGLOADER_HH_ diff --git a/src/rendering/MaterialParser/MaterialParser.cc b/src/rendering/MaterialParser/MaterialParser.cc index e98040a570e..240f4b395c4 100644 --- a/src/rendering/MaterialParser/MaterialParser.cc +++ b/src/rendering/MaterialParser/MaterialParser.cc @@ -15,9 +15,9 @@ * */ +#include #include #include -#include #include #include @@ -42,10 +42,10 @@ void MaterialParser::Load() MaterialParser::MaterialValues MaterialParser::GetMaterialValues(const std::string& material) { MaterialValues values; - std::map < std::string, ConfigNode * > scripts = + std::map scripts = this->configLoader.getAllConfigScripts(); - std::map < std::string, ConfigNode * > ::iterator it; + std::map ::iterator it; for (it = scripts.begin(); it != scripts.end(); ++it) { std::string name = it->first; @@ -63,21 +63,21 @@ MaterialParser::MaterialValues MaterialParser::GetMaterialValues(const std::stri ConfigNode * ambientNode = passNode->findChild("ambient"); if (ambientNode) { - std::vector < float > ambientValues; + std::vector ambientValues; ambientNode->getValuesInFloat(ambientValues); values.ambient = gz::math::Color(ambientValues[0], ambientValues[1], ambientValues[2]); } ConfigNode * diffuseNode = passNode->findChild("diffuse"); if (diffuseNode) { - std::vector < float > diffuseValues; + std::vector diffuseValues; diffuseNode->getValuesInFloat(diffuseValues); values.diffuse = gz::math::Color(diffuseValues[0], diffuseValues[1], diffuseValues[2]); } ConfigNode * specularNode = passNode->findChild("specular"); if (specularNode) { - std::vector < float > specularValues; + std::vector specularValues; specularNode->getValuesInFloat(specularValues); // Using first four values for specular as Gazebo doesn't support shininess values.specular = gz::math::Color diff --git a/src/rendering/MaterialParser/MaterialParser.hh b/src/rendering/MaterialParser/MaterialParser.hh index 2478b52de77..5803c7ea99e 100644 --- a/src/rendering/MaterialParser/MaterialParser.hh +++ b/src/rendering/MaterialParser/MaterialParser.hh @@ -18,10 +18,8 @@ #ifndef RENDERING__MATERIALPARSER__MATERIALPARSER_HH_ #define RENDERING__MATERIALPARSER__MATERIALPARSER_HH_ -#include -#include #include -#include +#include #include @@ -29,30 +27,28 @@ namespace gz { - namespace sim - { - class MaterialParser +namespace sim +{ +class MaterialParser +{ + public: + struct MaterialValues { -public: - struct MaterialValues - { - std::optional ambient; - std::optional diffuse; - std::optional specular; - }; -public: - MaterialParser(); - -public: - void Load(); - -public: - MaterialValues GetMaterialValues(const std::string& material); - -private: - ConfigLoader configLoader; + std::optional ambient; + std::optional diffuse; + std::optional specular; }; - } // namespace sim + + MaterialParser(); + + void Load(); + + MaterialValues GetMaterialValues(const std::string& material); + + private: + ConfigLoader configLoader; +}; +} // namespace sim } // namespace gz #endif // RENDERING__MATERIALPARSER__MATERIALPARSER_HH_