Merge branch 'master' into const-tokens

pull/4078/head
Kim Kulling 2021-09-24 13:37:57 +02:00 committed by GitHub
commit 6cb6a6acdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 53 deletions

View File

@ -232,6 +232,12 @@ void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
// Loads a single float value. // Loads a single float value.
void ObjFileMtlImporter::getFloatValue(ai_real &value) { void ObjFileMtlImporter::getFloatValue(ai_real &value) {
m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE); m_DataIt = CopyNextWord<DataArrayIt>(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]); value = (ai_real)fast_atof(&m_buffer[0]);
} }

View File

@ -47,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/BaseImporter.h> #include <assimp/BaseImporter.h>
#include <assimp/DefaultIOSystem.h> #include <assimp/DefaultIOSystem.h>
#include <assimp/ParsingUtils.h> #include <assimp/ParsingUtils.h>
#include <assimp/material.h>
#include <assimp/DefaultLogger.hpp> #include <assimp/DefaultLogger.hpp>
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <cstdlib> #include <cstdlib>
@ -56,7 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Assimp { namespace Assimp {
const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; constexpr char ObjFileParser::DEFAULT_MATERIAL[];
ObjFileParser::ObjFileParser() : ObjFileParser::ObjFileParser() :
m_DataIt(), m_DataIt(),

View File

@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define OBJ_FILEPARSER_H_INC #define OBJ_FILEPARSER_H_INC
#include <assimp/IOStreamBuffer.h> #include <assimp/IOStreamBuffer.h>
#include <assimp/material.h>
#include <assimp/mesh.h> #include <assimp/mesh.h>
#include <assimp/vector2.h> #include <assimp/vector2.h>
#include <assimp/vector3.h> #include <assimp/vector3.h>
@ -140,7 +141,7 @@ private:
// because the class contains pointer to allocated memory // because the class contains pointer to allocated memory
/// Default material name /// Default material name
static const std::string DEFAULT_MATERIAL; static constexpr char DEFAULT_MATERIAL[] = AI_DEFAULT_MATERIAL_NAME;
//! Iterator to current position in buffer //! Iterator to current position in buffer
DataArrayIt m_DataIt; DataArrayIt m_DataIt;
//! Iterator to end position of buffer //! Iterator to end position of buffer

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2021, assimp team
All rights reserved. All rights reserved.
@ -51,57 +51,62 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Assimp { namespace Assimp {
/** @brief Returns true, if the last entry of the buffer is reached. /**
* @param it Iterator of current position. * @brief Returns true, if the last entry of the buffer is reached.
* @param end Iterator with end of buffer. * @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. * @return true, if the end of the buffer is reached.
*/ */
template <class char_t> template <class char_t>
inline bool isEndOfBuffer(char_t it, char_t end) { inline bool isEndOfBuffer(char_t it, char_t end) {
if (it == end) { if (it == end) {
return true; return true;
} else {
--end;
} }
--end;
return (it == end); return (it == end);
} }
/** @brief Returns next word separated by a space /**
* @param pBuffer Pointer to data buffer * @brief Returns next word separated by a space
* @param pEnd Pointer to end of buffer * @param[in] pBuffer Pointer to data buffer
* @param[in] pEnd Pointer to end of buffer
* @return Pointer to next space * @return Pointer to next space
*/ */
template <class Char_T> template <class Char_T>
inline Char_T getNextWord(Char_T pBuffer, Char_T pEnd) { inline Char_T getNextWord(Char_T pBuffer, Char_T pEnd) {
while (!isEndOfBuffer(pBuffer, pEnd)) { while (!isEndOfBuffer(pBuffer, pEnd)) {
if (!IsSpaceOrNewLine(*pBuffer) || IsLineEnd(*pBuffer)) { if (!IsSpaceOrNewLine(*pBuffer) || IsLineEnd(*pBuffer)) {
//if ( *pBuffer != '\\' )
break; break;
} }
pBuffer++; ++pBuffer;
} }
return pBuffer; return pBuffer;
} }
/** @brief Returns pointer a next token /**
* @param pBuffer Pointer to data buffer * @brief Returns pointer a next token
* @param pEnd Pointer to end of buffer * @param[in] pBuffer Pointer to data buffer
* @param[in] pEnd Pointer to end of buffer
* @return Pointer to next token * @return Pointer to next token
*/ */
template <class Char_T> template <class Char_T>
inline Char_T getNextToken(Char_T pBuffer, Char_T pEnd) { inline Char_T getNextToken(Char_T pBuffer, Char_T pEnd) {
while (!isEndOfBuffer(pBuffer, pEnd)) { while (!isEndOfBuffer(pBuffer, pEnd)) {
if (IsSpaceOrNewLine(*pBuffer)) if (IsSpaceOrNewLine(*pBuffer)) {
break; break;
pBuffer++; }
++pBuffer;
} }
return getNextWord(pBuffer, pEnd); return getNextWord(pBuffer, pEnd);
} }
/** @brief Skips a line /**
* @param it Iterator set to current position * @brief Skips a line
* @param end Iterator set to end of scratch buffer for readout * @param[in] it Iterator set to current position
* @param uiLine Current line number in format * @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 * @return Current-iterator with new position
*/ */
template <class char_t> template <class char_t>
@ -122,11 +127,12 @@ inline char_t skipLine(char_t it, char_t end, unsigned int &uiLine) {
return it; 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. * but trim it at the end.
* @param it set to current position * @param[in] it set to current position
* @param end set to end of scratch buffer for readout * @param[in] end set to end of scratch buffer for readout
* @param name Separated name * @param[out] name Separated name
* @return Current-iterator with new position * @return Current-iterator with new position
*/ */
template <class char_t> template <class char_t>
@ -150,15 +156,16 @@ inline char_t getName(char_t it, char_t end, std::string &name) {
++it; ++it;
} }
std::string strName(pStart, &(*it)); std::string strName(pStart, &(*it));
if (strName.empty()) if (!strName.empty()) {
return it;
else
name = strName; name = strName;
}
return it; 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. * in the middle, but trim it at the end.
* @param it set to current position * @param it set to current position
* @param end set to end of scratch buffer for readout * @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; ++it;
} }
std::string strName(pStart, &(*it)); std::string strName(pStart, &(*it));
if (strName.empty()) if (!strName.empty()) {
return it;
else
name = strName; name = strName;
}
return it; return it;
} }
/** @brief Get next word from given line /**
* @param it set to current position * @brief Get next word from given line
* @param end set to end of scratch buffer for readout * @param[in] it set to current position
* @param pBuffer Buffer for next word * @param[in] end set to end of scratch buffer for readout
* @param length Buffer length * @param[in] pBuffer Buffer for next word
* @param[in] length Buffer length
* @return Current-iterator with new position * @return Current-iterator with new position
*/ */
template <class char_t> template <class char_t>
@ -209,19 +216,21 @@ inline char_t CopyNextWord(char_t it, char_t end, char *pBuffer, size_t length)
it = getNextWord<char_t>(it, end); it = getNextWord<char_t>(it, end);
while (!IsSpaceOrNewLine(*it) && !isEndOfBuffer(it, end)) { while (!IsSpaceOrNewLine(*it) && !isEndOfBuffer(it, end)) {
pBuffer[index] = *it; pBuffer[index] = *it;
index++; ++index;
if (index == length - 1) if (index == length - 1) {
break; break;
}
++it; ++it;
} }
pBuffer[index] = '\0'; pBuffer[index] = '\0';
return it; return it;
} }
/** @brief Get next float from given line /**
* @param it set to current position * @brief Get next float from given line
* @param end set to end of scratch buffer for readout * @param[in] it set to current position
* @param value Separated float value. * @param[in] end set to end of scratch buffer for readout
* @param[out] value Separated float value.
* @return Current-iterator with new position * @return Current-iterator with new position
*/ */
template <class char_t> template <class char_t>
@ -234,21 +243,33 @@ inline char_t getFloat(char_t it, char_t end, ai_real &value) {
return it; return it;
} }
/**
* @brief Will remove white-spaces for a string.
* @param[in] str The string to clean
* @return The trimmed string.
*/
template <class string_type> template <class string_type>
string_type trim_whitespaces(string_type str) { inline string_type trim_whitespaces(string_type str) {
while (!str.empty() && IsSpace(str[0])) while (!str.empty() && IsSpace(str[0])) {
str.erase(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); str.erase(str.length() - 1);
}
return str; 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 <class T> template <class T>
bool hasLineEnd(T it, T end) { bool hasLineEnd(T it, T end) {
bool hasLineEnd(false); bool hasLineEnd = false;
while (!isEndOfBuffer(it, end)) { while (!isEndOfBuffer(it, end)) {
it++; ++it;
if (IsLineEnd(it)) { if (IsLineEnd(it)) {
hasLineEnd = true; hasLineEnd = true;
break; break;

View File

@ -59,7 +59,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Public ASSIMP data structures // Public ASSIMP data structures
#include <assimp/types.h> #include <assimp/types.h>
//#include <exception> #include <exception>
namespace Assimp { namespace Assimp {
// ======================================================================= // =======================================================================