From fcb97bb595bc5dfce46cc636797bc29b5444fcfb Mon Sep 17 00:00:00 2001 From: Jonne Nauha Date: Thu, 1 May 2014 16:49:26 +0300 Subject: [PATCH] OgreImporter: Rename .hpp to .h. Shuffled parsing utils to a single file. --- code/CMakeLists.txt | 4 +-- code/{OgreImporter.hpp => OgreImporter.h} | 2 +- code/OgreMaterial.cpp | 28 ++++--------------- .../{OgreXmlHelper.hpp => OgreParsingUtils.h} | 25 ++++++++++++++--- 4 files changed, 30 insertions(+), 29 deletions(-) rename code/{OgreImporter.hpp => OgreImporter.h} (99%) rename code/{OgreXmlHelper.hpp => OgreParsingUtils.h} (81%) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 561797942..9afbc6c3d 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -320,8 +320,8 @@ SET( Obj_SRCS SOURCE_GROUP( Obj FILES ${Obj_SRCS}) SET( Ogre_SRCS - OgreImporter.hpp - OgreXmlHelper.hpp + OgreImporter.h + OgreParsingUtils.h OgreImporter.cpp OgreMaterial.cpp OgreMesh.cpp diff --git a/code/OgreImporter.hpp b/code/OgreImporter.h similarity index 99% rename from code/OgreImporter.hpp rename to code/OgreImporter.h index b41d85b43..d41e77230 100644 --- a/code/OgreImporter.hpp +++ b/code/OgreImporter.h @@ -1,7 +1,7 @@ #include "BaseImporter.h" -#include "OgreXmlHelper.hpp" #include "irrXMLWrapper.h" +#include "OgreParsingUtils.h" #include diff --git a/code/OgreMaterial.cpp b/code/OgreMaterial.cpp index b8e0a05a0..f19e9ec88 100644 --- a/code/OgreMaterial.cpp +++ b/code/OgreMaterial.cpp @@ -49,12 +49,13 @@ to make it shorter easier to maintain. #include #include -using namespace std; -#include "OgreImporter.hpp" +#include "OgreImporter.h" #include "irrXMLWrapper.h" #include "TinyFormatter.h" +using namespace std; + namespace Assimp { namespace Ogre @@ -64,23 +65,6 @@ static const string partComment = "//"; static const string partBlockStart = "{"; static const string partBlockEnd = "}"; -/// Skips a line from current @ss position until a newline. Returns the skipped part. -std::string SkipLine(stringstream &ss) -{ - string skipped; - getline(ss, skipped); - return skipped; -} - -/// Skips a line and reads next element from @c ss to @c nextElement. -/** @return Skipped line content until newline. */ -std::string NextAfterNewLine(stringstream &ss, std::string &nextElement) -{ - string skipped = SkipLine(ss); - ss >> nextElement; - return skipped; -} - aiMaterial* OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string materialName) { /// @todo Should we return null ptr here or a empty material? @@ -216,7 +200,7 @@ aiMaterial* OgreImporter::ReadMaterial(const std::string &pFile, Assimp::IOSyste if (linePart == partTechnique) { - string techniqueName = trim(SkipLine(ss)); + string techniqueName = Trim(SkipLine(ss)); ReadTechnique(techniqueName, ss, material); } @@ -336,7 +320,7 @@ bool OgreImporter::ReadTechnique(const std::string &techniqueName, stringstream /// @todo Techniques have other attributes than just passes. if (linePart == partPass) { - string passName = trim(SkipLine(ss)); + string passName = Trim(SkipLine(ss)); ReadPass(passName, ss, material); } } @@ -395,7 +379,7 @@ bool OgreImporter::ReadPass(const std::string &passName, stringstream &ss, aiMat } else if (linePart == partTextureUnit) { - string textureUnitName = trim(SkipLine(ss)); + string textureUnitName = Trim(SkipLine(ss)); ReadTextureUnit(textureUnitName, ss, material); } } diff --git a/code/OgreXmlHelper.hpp b/code/OgreParsingUtils.h similarity index 81% rename from code/OgreXmlHelper.hpp rename to code/OgreParsingUtils.h index 79bcf0096..d287f451b 100644 --- a/code/OgreXmlHelper.hpp +++ b/code/OgreParsingUtils.h @@ -89,6 +89,23 @@ inline bool CurrentNodeNameEquals(const XmlReader* reader, const std::string &na return (ASSIMP_stricmp(std::string(reader->getNodeName()), name) == 0); } +/// Skips a line from current @ss position until a newline. Returns the skipped part. +static inline std::string SkipLine(std::stringstream &ss) +{ + std::string skipped; + getline(ss, skipped); + return skipped; +} + +/// Skips a line and reads next element from @c ss to @c nextElement. +/** @return Skipped line content until newline. */ +static inline std::string NextAfterNewLine(std::stringstream &ss, std::string &nextElement) +{ + std::string skipped = SkipLine(ss); + ss >> nextElement; + return skipped; +} + /// Returns a lower cased copy of @s. static inline std::string ToLower(std::string s) { @@ -100,7 +117,7 @@ static inline std::string ToLower(std::string s) // From http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring // trim from start -static inline std::string <rim(std::string &s, bool newlines = true) +static inline std::string &TrimLeft(std::string &s, bool newlines = true) { if (!newlines) s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(Assimp::IsSpace)))); @@ -110,7 +127,7 @@ static inline std::string <rim(std::string &s, bool newlines = true) } // trim from end -static inline std::string &rtrim(std::string &s, bool newlines = true) +static inline std::string &TrimRight(std::string &s, bool newlines = true) { if (!newlines) s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(Assimp::IsSpace))).base(),s.end()); @@ -119,9 +136,9 @@ static inline std::string &rtrim(std::string &s, bool newlines = true) return s; } // trim from both ends -static inline std::string &trim(std::string &s, bool newlines = true) +static inline std::string &Trim(std::string &s, bool newlines = true) { - return ltrim(rtrim(s, newlines), newlines); + return TrimLeft(TrimRight(s, newlines), newlines); } } // Ogre