Simplify some FBX error code.

pull/3375/head
Malcolm Tyrrell 2020-08-19 17:20:57 +01:00
parent d7c65c36cd
commit 6c2ceb55f8
6 changed files with 21 additions and 30 deletions

View File

@ -127,7 +127,7 @@ namespace {
AI_WONT_RETURN void TokenizeError(const std::string& message, size_t offset) AI_WONT_RETURN_SUFFIX; AI_WONT_RETURN void TokenizeError(const std::string& message, size_t offset) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN void TokenizeError(const std::string& message, size_t offset) AI_WONT_RETURN void TokenizeError(const std::string& message, size_t offset)
{ {
throw DeadlyImportError(Util::AddOffset("FBX-Tokenize",message,offset)); throw DeadlyImportError("FBX-Tokenize", Util::GetOffsetText(offset), message);
} }

View File

@ -61,7 +61,7 @@ namespace Util {
// signal DOM construction error, this is always unrecoverable. Throws DeadlyImportError. // signal DOM construction error, this is always unrecoverable. Throws DeadlyImportError.
void DOMError(const std::string& message, const Token& token) void DOMError(const std::string& message, const Token& token)
{ {
throw DeadlyImportError(Util::AddTokenText("FBX-DOM",message,&token)); throw DeadlyImportError("FBX-DOM", Util::GetTokenText(&token), message);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -79,7 +79,7 @@ void DOMError(const std::string& message, const Element* element /*= nullptr*/)
void DOMWarning(const std::string& message, const Token& token) void DOMWarning(const std::string& message, const Token& token)
{ {
if(DefaultLogger::get()) { if(DefaultLogger::get()) {
ASSIMP_LOG_WARN(Util::AddTokenText("FBX-DOM",message,&token)); ASSIMP_LOG_WARN_F("FBX-DOM", Util::GetTokenText(&token), message);
} }
} }

View File

@ -73,7 +73,7 @@ namespace {
AI_WONT_RETURN void ParseError(const std::string& message, const Token& token) AI_WONT_RETURN_SUFFIX; AI_WONT_RETURN void ParseError(const std::string& message, const Token& token) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN void ParseError(const std::string& message, const Token& token) AI_WONT_RETURN void ParseError(const std::string& message, const Token& token)
{ {
throw DeadlyImportError(Util::AddTokenText("FBX-Parser",message,&token)); throw DeadlyImportError("FBX-Parser", Util::GetTokenText(&token), message);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -90,7 +90,7 @@ namespace {
AI_WONT_RETURN void TokenizeError(const std::string& message, unsigned int line, unsigned int column) AI_WONT_RETURN_SUFFIX; AI_WONT_RETURN void TokenizeError(const std::string& message, unsigned int line, unsigned int column) AI_WONT_RETURN_SUFFIX;
AI_WONT_RETURN void TokenizeError(const std::string& message, unsigned int line, unsigned int column) AI_WONT_RETURN void TokenizeError(const std::string& message, unsigned int line, unsigned int column)
{ {
throw DeadlyImportError(Util::AddLineAndColumn("FBX-Tokenize",message,line,column)); throw DeadlyImportError("FBX-Tokenize", Util::GetLineAndColumnText(line,column), message);
} }

View File

@ -86,32 +86,30 @@ const char* TokenTypeString(TokenType t)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::string AddOffset(const std::string& prefix, const std::string& text, size_t offset) std::string GetOffsetText(size_t offset)
{ {
return static_cast<std::string>( (Formatter::format() << prefix << " (offset 0x" << std::hex << offset << ") " << text) ); return static_cast<std::string>( Formatter::format() << " (offset 0x" << std::hex << offset << ") " );
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::string AddLineAndColumn(const std::string& prefix, const std::string& text, unsigned int line, unsigned int column) std::string GetLineAndColumnText(unsigned int line, unsigned int column)
{ {
return static_cast<std::string>( (Formatter::format() << prefix << " (line " << line << " << col " << column << ") " << text) ); return static_cast<std::string>( Formatter::format() << " (line " << line << " << col " << column << ") " );
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
std::string AddTokenText(const std::string& prefix, const std::string& text, const Token* tok) std::string GetTokenText(const Token* tok)
{ {
if(tok->IsBinary()) { if(tok->IsBinary()) {
return static_cast<std::string>( (Formatter::format() << prefix << return static_cast<std::string>( Formatter::format() <<
" (" << TokenTypeString(tok->Type()) << " (" << TokenTypeString(tok->Type()) <<
", offset 0x" << std::hex << tok->Offset() << ") " << ", offset 0x" << std::hex << tok->Offset() << ") " );
text) );
} }
return static_cast<std::string>( (Formatter::format() << prefix << return static_cast<std::string>( Formatter::format() <<
" (" << TokenTypeString(tok->Type()) << " (" << TokenTypeString(tok->Type()) <<
", line " << tok->Line() << ", line " << tok->Line() <<
", col " << tok->Column() << ") " << ", col " << tok->Column() << ") " );
text) );
} }
// Generated by this formula: T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i; // Generated by this formula: T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i;

View File

@ -73,31 +73,24 @@ const char* TokenTypeString(TokenType t);
/** Format log/error messages using a given offset in the source binary file /** Format log/error messages using a given offset in the source binary file
* *
* @param prefix Message prefix to be preprended to the location info. * @param offset offset within the file
* @param text Message text * @return A string of the following format: " (offset 0x{offset}) "*/
* @param line Line index, 1-based std::string GetOffsetText(size_t offset);
* @param column Column index, 1-based
* @return A string of the following format: {prefix} (offset 0x{offset}) {text}*/
std::string AddOffset(const std::string& prefix, const std::string& text, size_t offset);
/** Format log/error messages using a given line location in the source file. /** Format log/error messages using a given line location in the source file.
* *
* @param prefix Message prefix to be preprended to the location info.
* @param text Message text
* @param line Line index, 1-based * @param line Line index, 1-based
* @param column Column index, 1-based * @param column Column index, 1-based
* @return A string of the following format: {prefix} (line {line}, col {column}) {text}*/ * @return A string of the following format: " (line {line}, col {column}) "*/
std::string AddLineAndColumn(const std::string& prefix, const std::string& text, unsigned int line, unsigned int column); std::string GetLineAndColumnText(unsigned int line, unsigned int column);
/** Format log/error messages using a given cursor token. /** Format log/error messages using a given cursor token.
* *
* @param prefix Message prefix to be preprended to the location info.
* @param text Message text
* @param tok Token where parsing/processing stopped * @param tok Token where parsing/processing stopped
* @return A string of the following format: {prefix} ({token-type}, line {line}, col {column}) {text}*/ * @return A string of the following format: " ({token-type}, line {line}, col {column}) "*/
std::string AddTokenText(const std::string& prefix, const std::string& text, const Token* tok); std::string GetTokenText(const Token* tok);
/** Decode a single Base64-encoded character. /** Decode a single Base64-encoded character.
* *