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.
void ObjFileMtlImporter::getFloatValue(ai_real &value) {
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]);
}

View File

@ -47,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/BaseImporter.h>
#include <assimp/DefaultIOSystem.h>
#include <assimp/ParsingUtils.h>
#include <assimp/material.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/Importer.hpp>
#include <cstdlib>
@ -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(),

View File

@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define OBJ_FILEPARSER_H_INC
#include <assimp/IOStreamBuffer.h>
#include <assimp/material.h>
#include <assimp/mesh.h>
#include <assimp/vector2.h>
#include <assimp/vector3.h>
@ -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

View File

@ -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 <class char_t>
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 <class Char_T>
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 <class Char_T>
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 <class char_t>
@ -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 <class char_t>
@ -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 <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);
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 <class char_t>
@ -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 <class string_type>
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 <class T>
bool hasLineEnd(T it, T end) {
bool hasLineEnd(false);
bool hasLineEnd = false;
while (!isEndOfBuffer(it, end)) {
it++;
++it;
if (IsLineEnd(it)) {
hasLineEnd = true;
break;

View File

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