diff --git a/code/Importer/IFC/IFCLoader.cpp b/code/Importer/IFC/IFCLoader.cpp index 5acc89545..9faf68cbb 100644 --- a/code/Importer/IFC/IFCLoader.cpp +++ b/code/Importer/IFC/IFCLoader.cpp @@ -583,9 +583,8 @@ typedef std::map Metadata; // ------------------------------------------------------------------------------------------------ void ProcessMetadata(const Schema_2x3::ListOf< Schema_2x3::Lazy< Schema_2x3::IfcProperty >, 1, 0 >& set, ConversionData& conv, Metadata& properties, - const std::string& prefix = "", - unsigned int nest = 0) -{ + const std::string& prefix = "", + unsigned int nest = 0) { for(const Schema_2x3::IfcProperty& property : set) { const std::string& key = prefix.length() > 0 ? (prefix + "." + property.Name) : property.Name; if (const Schema_2x3::IfcPropertySingleValue* const singleValue = property.ToPtr()) { diff --git a/code/ObjExporter.cpp b/code/ObjExporter.cpp index 9beb418f3..d08b5f859 100644 --- a/code/ObjExporter.cpp +++ b/code/ObjExporter.cpp @@ -132,18 +132,18 @@ ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene, bool noMt mOutputMat.precision(16); WriteGeometryFile(noMtl); - if (!noMtl) + if ( !noMtl ) { WriteMaterialFile(); + } } // ------------------------------------------------------------------------------------------------ ObjExporter::~ObjExporter() { - + // empty } // ------------------------------------------------------------------------------------------------ -std::string ObjExporter :: GetMaterialLibName() -{ +std::string ObjExporter::GetMaterialLibName() { // within the Obj file, we use just the relative file name with the path stripped const std::string& s = GetMaterialLibFileName(); std::string::size_type il = s.find_last_of("/\\"); @@ -158,8 +158,9 @@ std::string ObjExporter :: GetMaterialLibName() std::string ObjExporter::GetMaterialLibFileName() { // Remove existing .obj file extension so that the final material file name will be fileName.mtl and not fileName.obj.mtl size_t lastdot = filename.find_last_of('.'); - if (lastdot != std::string::npos) - return filename.substr(0, lastdot) + MaterialExt; + if ( lastdot != std::string::npos ) { + return filename.substr( 0, lastdot ) + MaterialExt; + } return filename + MaterialExt; } @@ -172,8 +173,7 @@ void ObjExporter::WriteHeader(std::ostringstream& out) { } // ------------------------------------------------------------------------------------------------ -std::string ObjExporter::GetMaterialName(unsigned int index) -{ +std::string ObjExporter::GetMaterialName(unsigned int index) { const aiMaterial* const mat = pScene->mMaterials[index]; if ( nullptr == mat ) { static const std::string EmptyStr; @@ -191,8 +191,7 @@ std::string ObjExporter::GetMaterialName(unsigned int index) } // ------------------------------------------------------------------------------------------------ -void ObjExporter::WriteMaterialFile() -{ +void ObjExporter::WriteMaterialFile() { WriteHeader(mOutputMat); for(unsigned int i = 0; i < pScene->mNumMaterials; ++i) { @@ -310,8 +309,9 @@ void ObjExporter::WriteGeometryFile(bool noMtl) { if (!m.name.empty()) { mOutput << "g " << m.name << endl; } - if (!noMtl) + if ( !noMtl ) { mOutput << "usemtl " << m.matname << endl; + } for(const Face& f : m.faces) { mOutput << f.kind << ' '; @@ -382,7 +382,7 @@ void ObjExporter::colIndexMap::getColors( std::vector &colors ) { // ------------------------------------------------------------------------------------------------ void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat) { - mMeshes.push_back(MeshInstance()); + mMeshes.push_back(MeshInstance() ); MeshInstance& mesh = mMeshes.back(); mesh.name = std::string( name.data, name.length ); @@ -436,8 +436,7 @@ void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4 } // ------------------------------------------------------------------------------------------------ -void ObjExporter::AddNode(const aiNode* nd, const aiMatrix4x4& mParent) -{ +void ObjExporter::AddNode(const aiNode* nd, const aiMatrix4x4& mParent) { const aiMatrix4x4& mAbs = mParent * nd->mTransformation; for(unsigned int i = 0; i < nd->mNumMeshes; ++i) { diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 02d6ac581..bce94ebbb 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -207,30 +207,24 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene // Create the root node of the scene pScene->mRootNode = new aiNode; - if ( !pModel->m_ModelName.empty() ) - { + if ( !pModel->m_ModelName.empty() ) { // Set the name of the scene pScene->mRootNode->mName.Set(pModel->m_ModelName); - } - else - { + } else { // This is a fatal error, so break down the application ai_assert(false); } // Create nodes for the whole scene std::vector MeshArray; - for (size_t index = 0; index < pModel->m_Objects.size(); index++) - { + for (size_t index = 0; index < pModel->m_Objects.size(); ++index ) { createNodes(pModel, pModel->m_Objects[ index ], pScene->mRootNode, pScene, MeshArray); } // Create mesh pointer buffer for this scene - if (pScene->mNumMeshes > 0) - { + if (pScene->mNumMeshes > 0) { pScene->mMeshes = new aiMesh*[ MeshArray.size() ]; - for (size_t index =0; index < MeshArray.size(); index++) - { + for (size_t index =0; index < MeshArray.size(); ++index ) { pScene->mMeshes[ index ] = MeshArray[ index ]; } } @@ -261,8 +255,7 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile appendChildToParentNode( pParent, pNode ); } - for ( size_t i=0; i< pObject->m_Meshes.size(); i++ ) - { + for ( size_t i=0; i< pObject->m_Meshes.size(); ++i ) { unsigned int meshId = pObject->m_Meshes[ i ]; aiMesh *pMesh = createTopology( pModel, pObject, meshId ); if( pMesh ) { @@ -275,8 +268,7 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile } // Create all nodes from the sub-objects stored in the current object - if ( !pObject->m_SubObjects.empty() ) - { + if ( !pObject->m_SubObjects.empty() ) { size_t numChilds = pObject->m_SubObjects.size(); pNode->mNumChildren = static_cast( numChilds ); pNode->mChildren = new aiNode*[ numChilds ]; @@ -286,16 +278,14 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model* pModel, const ObjFile // Set mesh instances into scene- and node-instances const size_t meshSizeDiff = MeshArray.size()- oldMeshSize; - if ( meshSizeDiff > 0 ) - { + if ( meshSizeDiff > 0 ) { pNode->mMeshes = new unsigned int[ meshSizeDiff ]; pNode->mNumMeshes = static_cast( meshSizeDiff ); size_t index = 0; - for (size_t i = oldMeshSize; i < MeshArray.size(); i++) - { + for (size_t i = oldMeshSize; i < MeshArray.size(); ++i ) { pNode->mMeshes[ index ] = pScene->mNumMeshes; pScene->mNumMeshes++; - index++; + ++index; } } diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index ae95edbcb..7cd2d36c2 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -612,13 +612,14 @@ void ObjFileParser::getMaterialLib() { if ( '/' != *path.rbegin() ) { path += '/'; } - absName = path + strMatName; + absName += path; + absName += strMatName; } else { absName = strMatName; } - IOStream *pFile = m_pIO->Open( absName ); - if (!pFile ) { + IOStream *pFile = m_pIO->Open( absName ); + if ( nullptr == pFile ) { DefaultLogger::get()->error("OBJ: Unable to locate material file " + strMatName); std::string strMatFallbackName = m_originalObjFileName.substr(0, m_originalObjFileName.length() - 3) + "mtl"; DefaultLogger::get()->info("OBJ: Opening fallback material file " + strMatFallbackName); diff --git a/code/OgreParsingUtils.h b/code/OgreParsingUtils.h index a77b94121..c6b6e0caf 100644 --- a/code/OgreParsingUtils.h +++ b/code/OgreParsingUtils.h @@ -52,27 +52,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -namespace Assimp -{ -namespace Ogre -{ +namespace Assimp { +namespace Ogre { /// Returns a lower cased copy of @s. -static inline std::string ToLower(std::string s) +static AI_FORCE_INLINE +std::string ToLower(std::string s) { std::transform(s.begin(), s.end(), s.begin(), ::tolower); return s; } /// Returns if @c s ends with @c suffix. If @c caseSensitive is false, both strings will be lower cased before matching. -static inline bool EndsWith(const std::string &s, const std::string &suffix, bool caseSensitive = true) -{ - if (s.empty() || suffix.empty()) - { +static AI_FORCE_INLINE +bool EndsWith(const std::string &s, const std::string &suffix, bool caseSensitive = true) { + if (s.empty() || suffix.empty()) { return false; - } - else if (s.length() < suffix.length()) - { + } else if (s.length() < suffix.length()) { return false; } @@ -82,48 +78,43 @@ static inline bool EndsWith(const std::string &s, const std::string &suffix, boo size_t len = suffix.length(); std::string sSuffix = s.substr(s.length()-len, len); + return (ASSIMP_stricmp(sSuffix, suffix) == 0); } // Below trim functions adapted from http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring /// Trim from start -static inline std::string &TrimLeft(std::string &s, bool newlines = true) -{ - if (!newlines) - { +static AI_FORCE_INLINE +std::string &TrimLeft(std::string &s, bool newlines = true) { + if (!newlines) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char c) { return !Assimp::IsSpace(c); })); - } - else - { + } else { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char c) { return !Assimp::IsSpaceOrNewLine(c); })); } return s; } /// Trim from end -static inline std::string &TrimRight(std::string &s, bool newlines = true) -{ - if (!newlines) - { +static AI_FORCE_INLINE +std::string &TrimRight(std::string &s, bool newlines = true) { + if (!newlines) { s.erase(std::find_if(s.rbegin(), s.rend(), [](char c) { return !Assimp::IsSpace(c); }).base(),s.end()); - } - else - { + } else { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char c) { return !Assimp::IsSpaceOrNewLine(c); })); } return s; } /// Trim from both ends -static inline std::string &Trim(std::string &s, bool newlines = true) -{ +static AI_FORCE_INLINE +std::string &Trim(std::string &s, bool newlines = true) { return TrimLeft(TrimRight(s, newlines), newlines); } /// Skips a line from current @ss position until a newline. Returns the skipped part. -static inline std::string SkipLine(std::stringstream &ss) -{ +static AI_FORCE_INLINE +std::string SkipLine(std::stringstream &ss) { std::string skipped; getline(ss, skipped); return skipped; @@ -131,8 +122,8 @@ static inline std::string SkipLine(std::stringstream &ss) /// 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) -{ +static AI_FORCE_INLINE +std::string NextAfterNewLine(std::stringstream &ss, std::string &nextElement) { std::string skipped = SkipLine(ss); ss >> nextElement; return skipped; diff --git a/code/OgreXmlSerializer.cpp b/code/OgreXmlSerializer.cpp index 78acaa7fd..12b2bcbd9 100644 --- a/code/OgreXmlSerializer.cpp +++ b/code/OgreXmlSerializer.cpp @@ -213,18 +213,18 @@ std::string &OgreXmlSerializer::SkipCurrentNode() DefaultLogger::get()->debug("Skipping node <" + m_currentNodeName + ">"); #endif - for(;;) - { - if (!m_reader->read()) - { + for(;;) { + if (!m_reader->read()) { m_currentNodeName = ""; return m_currentNodeName; } - if (m_reader->getNodeType() != irr::io::EXN_ELEMENT_END) + if ( m_reader->getNodeType() != irr::io::EXN_ELEMENT_END ) { continue; - else if (std::string(m_reader->getNodeName()) == m_currentNodeName) + } else if ( std::string( m_reader->getNodeName() ) == m_currentNodeName ) { break; + } } + return NextNode(); } @@ -303,17 +303,16 @@ static const char *anZ = "z"; // Mesh -MeshXml *OgreXmlSerializer::ImportMesh(XmlReader *reader) -{ +MeshXml *OgreXmlSerializer::ImportMesh(XmlReader *reader) { OgreXmlSerializer serializer(reader); MeshXml *mesh = new MeshXml(); serializer.ReadMesh(mesh); + return mesh; } -void OgreXmlSerializer::ReadMesh(MeshXml *mesh) -{ +void OgreXmlSerializer::ReadMesh(MeshXml *mesh) { if (NextNode() != nnMesh) { throw DeadlyImportError("Root node is <" + m_currentNodeName + "> expecting "); } diff --git a/include/assimp/ParsingUtils.h b/include/assimp/ParsingUtils.h index 40e183a5c..4553072db 100644 --- a/include/assimp/ParsingUtils.h +++ b/include/assimp/ParsingUtils.h @@ -115,8 +115,8 @@ bool IsSpaceOrNewLine( char_t in) { // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipSpaces( const char_t* in, const char_t** out) -{ +AI_FORCE_INLINE +bool SkipSpaces( const char_t* in, const char_t** out) { while( *in == ( char_t )' ' || *in == ( char_t )'\t' ) { ++in; } @@ -126,15 +126,15 @@ AI_FORCE_INLINE bool SkipSpaces( const char_t* in, const char_t** out) // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipSpaces( const char_t** inout) -{ +AI_FORCE_INLINE +bool SkipSpaces( const char_t** inout) { return SkipSpaces(*inout,inout); } // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipLine( const char_t* in, const char_t** out) -{ +AI_FORCE_INLINE +bool SkipLine( const char_t* in, const char_t** out) { while( *in != ( char_t )'\r' && *in != ( char_t )'\n' && *in != ( char_t )'\0' ) { ++in; } @@ -149,15 +149,15 @@ AI_FORCE_INLINE bool SkipLine( const char_t* in, const char_t** out) // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipLine( const char_t** inout) -{ +AI_FORCE_INLINE +bool SkipLine( const char_t** inout) { return SkipLine(*inout,inout); } // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipSpacesAndLineEnd( const char_t* in, const char_t** out) -{ +AI_FORCE_INLINE +bool SkipSpacesAndLineEnd( const char_t* in, const char_t** out) { while( *in == ( char_t )' ' || *in == ( char_t )'\t' || *in == ( char_t )'\r' || *in == ( char_t )'\n' ) { ++in; } @@ -167,15 +167,15 @@ AI_FORCE_INLINE bool SkipSpacesAndLineEnd( const char_t* in, const char_t** out) // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool SkipSpacesAndLineEnd( const char_t** inout) -{ +AI_FORCE_INLINE +bool SkipSpacesAndLineEnd( const char_t** inout) { return SkipSpacesAndLineEnd(*inout,inout); } // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool GetNextLine( const char_t*& buffer, char_t out[ BufferSize ] ) -{ +AI_FORCE_INLINE +bool GetNextLine( const char_t*& buffer, char_t out[ BufferSize ] ) { if( ( char_t )'\0' == *buffer ) { return false; } @@ -203,7 +203,8 @@ AI_FORCE_INLINE bool IsNumeric( char_t in) // --------------------------------------------------------------------------------- template -AI_FORCE_INLINE bool TokenMatch(char_t*& in, const char* token, unsigned int len) +AI_FORCE_INLINE +bool TokenMatch(char_t*& in, const char* token, unsigned int len) { if (!::strncmp(token,in,len) && IsSpaceOrNewLine(in[len])) { if (in[len] != '\0') { @@ -223,26 +224,32 @@ AI_FORCE_INLINE bool TokenMatch(char_t*& in, const char* token, unsigned int len * @param token Token to check for * @param len Number of characters to check */ -AI_FORCE_INLINE bool TokenMatchI(const char*& in, const char* token, unsigned int len) -{ +AI_FORCE_INLINE +bool TokenMatchI(const char*& in, const char* token, unsigned int len) { if (!ASSIMP_strincmp(token,in,len) && IsSpaceOrNewLine(in[len])) { in += len+1; return true; } return false; } + // --------------------------------------------------------------------------------- -AI_FORCE_INLINE void SkipToken(const char*& in) -{ +AI_FORCE_INLINE +void SkipToken(const char*& in) { SkipSpaces(&in); - while (!IsSpaceOrNewLine(*in))++in; + while ( !IsSpaceOrNewLine( *in ) ) { + ++in; + } } + // --------------------------------------------------------------------------------- -AI_FORCE_INLINE std::string GetNextToken(const char*& in) -{ +AI_FORCE_INLINE +std::string GetNextToken(const char*& in) { SkipSpacesAndLineEnd(&in); const char* cur = in; - while (!IsSpaceOrNewLine(*in))++in; + while ( !IsSpaceOrNewLine( *in ) ) { + ++in; + } return std::string(cur,(size_t)(in-cur)); } diff --git a/include/assimp/StringComparison.h b/include/assimp/StringComparison.h index 1fada49dd..aea7f001a 100644 --- a/include/assimp/StringComparison.h +++ b/include/assimp/StringComparison.h @@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define INCLUDED_AI_STRING_WORKERS_H #include +#include #include "StringComparison.h" #include @@ -72,8 +73,8 @@ namespace Assimp { * @param number Number to be written * @return Length of the output string, excluding the '\0' */ -inline unsigned int ASSIMP_itoa10( char* out, unsigned int max, int32_t number) -{ +AI_FORCE_INLINE +unsigned int ASSIMP_itoa10( char* out, unsigned int max, int32_t number) { ai_assert(NULL != out); // write the unary minus to indicate we have a negative number @@ -91,7 +92,7 @@ inline unsigned int ASSIMP_itoa10( char* out, unsigned int max, int32_t number) const unsigned int digit = number / cur; if (mustPrint || digit > 0 || 1 == cur) { - // print all future zeroes from now + // print all future zeroe's from now mustPrint = true; *out++ = '0'+static_cast(digit); @@ -116,8 +117,8 @@ inline unsigned int ASSIMP_itoa10( char* out, unsigned int max, int32_t number) * size of the array automatically. */ template -inline unsigned int ASSIMP_itoa10( char(& out)[length], int32_t number) -{ +AI_FORCE_INLINE +unsigned int ASSIMP_itoa10( char(& out)[length], int32_t number) { return ASSIMP_itoa10(out,length,number); } @@ -132,9 +133,10 @@ inline unsigned int ASSIMP_itoa10( char(& out)[length], int32_t number) * @param s2 Second input string * @return 0 if the given strings are identical */ -inline int ASSIMP_stricmp(const char *s1, const char *s2) -{ - ai_assert(NULL != s1 && NULL != s2); +AI_FORCE_INLINE +int ASSIMP_stricmp(const char *s1, const char *s2) { + ai_assert( NULL != s1 ); + ai_assert( NULL != s2 ); #if (defined _MSC_VER) @@ -161,8 +163,8 @@ inline int ASSIMP_stricmp(const char *s1, const char *s2) * @param b Second string * @return 0 if a == b */ -inline int ASSIMP_stricmp(const std::string& a, const std::string& b) -{ +AI_FORCE_INLINE +int ASSIMP_stricmp(const std::string& a, const std::string& b) { int i = (int)b.length()-(int)a.length(); return (i ? i : ASSIMP_stricmp(a.c_str(),b.c_str())); } @@ -179,10 +181,13 @@ inline int ASSIMP_stricmp(const std::string& a, const std::string& b) * @param n Macimum number of characters to compare * @return 0 if the given strings are identical */ -inline int ASSIMP_strincmp(const char *s1, const char *s2, unsigned int n) -{ - ai_assert(NULL != s1 && NULL != s2); - if (!n)return 0; +AI_FORCE_INLINE +int ASSIMP_strincmp(const char *s1, const char *s2, unsigned int n) { + ai_assert( NULL != s1 ); + ai_assert( NULL != s2 ); + if ( !n ) { + return 0; + } #if (defined _MSC_VER) @@ -213,14 +218,16 @@ inline int ASSIMP_strincmp(const char *s1, const char *s2, unsigned int n) * * todo: move somewhere where it fits better in than here */ -inline unsigned int integer_pow (unsigned int base, unsigned int power) -{ +AI_FORCE_INLINE +unsigned int integer_pow( unsigned int base, unsigned int power ) { unsigned int res = 1; - for (unsigned int i = 0; i < power;++i) + for ( unsigned int i = 0; i < power; ++i ) { res *= base; + } return res; } + } // end of namespace #endif // ! AI_STRINGCOMPARISON_H_INC diff --git a/include/assimp/StringUtils.h b/include/assimp/StringUtils.h index 157454126..906898b53 100644 --- a/include/assimp/StringUtils.h +++ b/include/assimp/StringUtils.h @@ -42,6 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef INCLUDED_AI_STRINGUTILS_H #define INCLUDED_AI_STRINGUTILS_H +#include + #include #include #include @@ -55,7 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /// @return The number of written characters if the buffer size was big enough. If an encoding error occurs, a negative number is returned. #if defined(_MSC_VER) && _MSC_VER < 1900 - inline + AI_FORCE_INLINE int c99_ai_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) { int count(-1); if (0 != size) { @@ -68,7 +70,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. return count; } - inline + AI_FORCE_INLINE int ai_snprintf(char *outBuf, size_t size, const char *format, ...) { int count; va_list ap; @@ -89,7 +91,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /// @param value The value to write into the std::string. /// @return The value as a std::string template -inline +AI_FORCE_INLINE std::string to_string( T value ) { std::ostringstream os; os << value; @@ -102,7 +104,7 @@ std::string to_string( T value ) { /// @param begin The first character of the string. /// @param end The last character /// @return The float value, 0.0f in cas of an error. -inline +AI_FORCE_INLINE float ai_strtof( const char *begin, const char *end ) { if ( nullptr == begin ) { return 0.0f; @@ -124,7 +126,7 @@ float ai_strtof( const char *begin, const char *end ) { /// @param toConvert Value to convert /// @return The hexadecimal string, is empty in case of an error. template -inline +AI_FORCE_INLINE std::string DecimalToHexa( T toConvert ) { std::string result; std::stringstream ss;