diff --git a/code/AssetLib/Obj/ObjFileMtlImporter.cpp b/code/AssetLib/Obj/ObjFileMtlImporter.cpp index 94e57c26b..6a81fb082 100644 --- a/code/AssetLib/Obj/ObjFileMtlImporter.cpp +++ b/code/AssetLib/Obj/ObjFileMtlImporter.cpp @@ -232,6 +232,12 @@ void ObjFileMtlImporter::getIlluminationModel(int &illum_model) { // Loads a single float value. void ObjFileMtlImporter::getFloatValue(ai_real &value) { m_DataIt = CopyNextWord(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE); + size_t len = std::strlen(&m_buffer[0]); + if (0 == len) { + value = 0.0f; + return; + } + value = (ai_real)fast_atof(&m_buffer[0]); } diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index 767805c10..2e998a815 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -47,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include #include #include @@ -56,7 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; +constexpr char ObjFileParser::DEFAULT_MATERIAL[]; ObjFileParser::ObjFileParser() : m_DataIt(), diff --git a/code/AssetLib/Obj/ObjFileParser.h b/code/AssetLib/Obj/ObjFileParser.h index f3791c549..fbd2f2c89 100644 --- a/code/AssetLib/Obj/ObjFileParser.h +++ b/code/AssetLib/Obj/ObjFileParser.h @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define OBJ_FILEPARSER_H_INC #include +#include #include #include #include @@ -140,7 +141,7 @@ private: // because the class contains pointer to allocated memory /// Default material name - static const std::string DEFAULT_MATERIAL; + static constexpr char DEFAULT_MATERIAL[] = AI_DEFAULT_MATERIAL_NAME; //! Iterator to current position in buffer DataArrayIt m_DataIt; //! Iterator to end position of buffer diff --git a/code/AssetLib/Obj/ObjTools.h b/code/AssetLib/Obj/ObjTools.h index 61efb98b2..9e57a1c84 100644 --- a/code/AssetLib/Obj/ObjTools.h +++ b/code/AssetLib/Obj/ObjTools.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2020, assimp team +Copyright (c) 2006-2021, assimp team All rights reserved. @@ -51,57 +51,62 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -/** @brief Returns true, if the last entry of the buffer is reached. - * @param it Iterator of current position. - * @param end Iterator with end of buffer. +/** + * @brief Returns true, if the last entry of the buffer is reached. + * @param[in] it Iterator of current position. + * @param[in] end Iterator with end of buffer. * @return true, if the end of the buffer is reached. */ template inline bool isEndOfBuffer(char_t it, char_t end) { if (it == end) { return true; - } else { - --end; } + --end; + return (it == end); } -/** @brief Returns next word separated by a space - * @param pBuffer Pointer to data buffer - * @param pEnd Pointer to end of buffer +/** + * @brief Returns next word separated by a space + * @param[in] pBuffer Pointer to data buffer + * @param[in] pEnd Pointer to end of buffer * @return Pointer to next space */ template inline Char_T getNextWord(Char_T pBuffer, Char_T pEnd) { while (!isEndOfBuffer(pBuffer, pEnd)) { if (!IsSpaceOrNewLine(*pBuffer) || IsLineEnd(*pBuffer)) { - //if ( *pBuffer != '\\' ) break; } - pBuffer++; + ++pBuffer; } + return pBuffer; } -/** @brief Returns pointer a next token - * @param pBuffer Pointer to data buffer - * @param pEnd Pointer to end of buffer +/** + * @brief Returns pointer a next token + * @param[in] pBuffer Pointer to data buffer + * @param[in] pEnd Pointer to end of buffer * @return Pointer to next token */ template inline Char_T getNextToken(Char_T pBuffer, Char_T pEnd) { while (!isEndOfBuffer(pBuffer, pEnd)) { - if (IsSpaceOrNewLine(*pBuffer)) + if (IsSpaceOrNewLine(*pBuffer)) { break; - pBuffer++; + } + ++pBuffer; } return getNextWord(pBuffer, pEnd); } -/** @brief Skips a line - * @param it Iterator set to current position - * @param end Iterator set to end of scratch buffer for readout - * @param uiLine Current line number in format +/** + * @brief Skips a line + * @param[in] it Iterator set to current position + * @param[in] end Iterator set to end of scratch buffer for readout + * @param[out] uiLine Current line number in format * @return Current-iterator with new position */ template @@ -122,11 +127,12 @@ inline char_t skipLine(char_t it, char_t end, unsigned int &uiLine) { return it; } -/** @brief Get a name from the current line. Preserve space in the middle, +/** + * @brief Get a name from the current line. Preserve space in the middle, * but trim it at the end. - * @param it set to current position - * @param end set to end of scratch buffer for readout - * @param name Separated name + * @param[in] it set to current position + * @param[in] end set to end of scratch buffer for readout + * @param[out] name Separated name * @return Current-iterator with new position */ template @@ -150,15 +156,16 @@ inline char_t getName(char_t it, char_t end, std::string &name) { ++it; } std::string strName(pStart, &(*it)); - if (strName.empty()) - return it; - else + if (!strName.empty()) { name = strName; + } + return it; } -/** @brief Get a name from the current line. Do not preserve space +/** + * @brief Get a name from the current line. Do not preserve space * in the middle, but trim it at the end. * @param it set to current position * @param end set to end of scratch buffer for readout @@ -188,19 +195,19 @@ inline char_t getNameNoSpace(char_t it, char_t end, std::string &name) { ++it; } std::string strName(pStart, &(*it)); - if (strName.empty()) - return it; - else + if (!strName.empty()) { name = strName; - + } + return it; } -/** @brief Get next word from given line - * @param it set to current position - * @param end set to end of scratch buffer for readout - * @param pBuffer Buffer for next word - * @param length Buffer length +/** + * @brief Get next word from given line + * @param[in] it set to current position + * @param[in] end set to end of scratch buffer for readout + * @param[in] pBuffer Buffer for next word + * @param[in] length Buffer length * @return Current-iterator with new position */ template @@ -209,19 +216,21 @@ inline char_t CopyNextWord(char_t it, char_t end, char *pBuffer, size_t length) it = getNextWord(it, end); while (!IsSpaceOrNewLine(*it) && !isEndOfBuffer(it, end)) { pBuffer[index] = *it; - index++; - if (index == length - 1) + ++index; + if (index == length - 1) { break; + } ++it; } pBuffer[index] = '\0'; return it; } -/** @brief Get next float from given line - * @param it set to current position - * @param end set to end of scratch buffer for readout - * @param value Separated float value. +/** + * @brief Get next float from given line + * @param[in] it set to current position + * @param[in] end set to end of scratch buffer for readout + * @param[out] value Separated float value. * @return Current-iterator with new position */ template @@ -234,21 +243,33 @@ inline char_t getFloat(char_t it, char_t end, ai_real &value) { return it; } - +/** + * @brief Will remove white-spaces for a string. + * @param[in] str The string to clean + * @return The trimmed string. + */ template -string_type trim_whitespaces(string_type str) { - while (!str.empty() && IsSpace(str[0])) +inline string_type trim_whitespaces(string_type str) { + while (!str.empty() && IsSpace(str[0])) { str.erase(0); - while (!str.empty() && IsSpace(str[str.length() - 1])) + } + while (!str.empty() && IsSpace(str[str.length() - 1])) { str.erase(str.length() - 1); + } return str; } +/** + * @brief Checks for a line-end. + * @param[in] it Current iterator in string. + * @param[in] end End of the string. + * @return The trimmed string. + */ template bool hasLineEnd(T it, T end) { - bool hasLineEnd(false); + bool hasLineEnd = false; while (!isEndOfBuffer(it, end)) { - it++; + ++it; if (IsLineEnd(it)) { hasLineEnd = true; break; diff --git a/include/assimp/Importer.hpp b/include/assimp/Importer.hpp index 97f34090e..09b5b6883 100644 --- a/include/assimp/Importer.hpp +++ b/include/assimp/Importer.hpp @@ -59,7 +59,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Public ASSIMP data structures #include -//#include +#include namespace Assimp { // =======================================================================