closes https://github.com/assimp/assimp/issues/3975: Use latest version of OpenDDL-Parser

pull/3998/head
Kim Kulling 2021-07-26 11:24:18 +02:00
parent 26538a4f4a
commit 16c3f82222
3 changed files with 39 additions and 13 deletions

View File

@ -132,6 +132,24 @@ OpenDDLParser::~OpenDDLParser() {
clear();
}
void OpenDDLParser::logToStream(FILE *f, LogSeverity severity, const std::string &message) {
if (f) {
const char *tag = "none";
switch (severity) {
case ddl_debug_msg: tag = "debug"; break;
case ddl_info_msg: tag = "info"; break;
case ddl_warn_msg: tag = "warn"; break;
case ddl_error_msg: tag = "error"; break;
}
fprintf(f, "OpenDDLParser: (%5s) %s\n", tag, message.c_str());
}
}
OpenDDLParser::logCallback OpenDDLParser::StdLogCallback (FILE *destination) {
using namespace std::placeholders;
return std::bind(logToStream, destination ? destination : stderr, _1, _2);
}
void OpenDDLParser::setLogCallback(logCallback callback) {
// install user-specific log callback; null = no log callback
m_logCallback = callback;
@ -171,12 +189,8 @@ size_t OpenDDLParser::getBufferSize() const {
void OpenDDLParser::clear() {
m_buffer.resize(0);
if (nullptr != m_context) {
delete m_context;
m_context = nullptr;
}
// DDLNode::releaseNodes();
delete m_context;
m_context = nullptr;
}
bool OpenDDLParser::validate() {
@ -506,7 +520,9 @@ char *OpenDDLParser::parseName(char *in, char *end, Name **name) {
in = parseIdentifier(in, end, &id);
if (id) {
currentName = new Name(ntype, id);
*name = currentName;
if (currentName) {
*name = currentName;
}
}
return in;

View File

@ -113,13 +113,14 @@ Value::~Value() {
if (m_data != nullptr) {
if (m_type == ValueType::ddl_ref) {
Reference *tmp = (Reference *)m_data;
if (tmp != nullptr)
if (tmp != nullptr) {
delete tmp;
} else
}
} else {
delete[] m_data;
}
}
if (m_next != nullptr)
delete m_next;
delete m_next;
}
void Value::setBool(bool value) {

View File

@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string>
#include <vector>
#include <functional>
BEGIN_ODDLPARSER_NS
@ -97,8 +98,8 @@ DLL_ODDLPARSER_EXPORT const char *getTypeToken(Value::ValueType type);
//-------------------------------------------------------------------------------------------------
class DLL_ODDLPARSER_EXPORT OpenDDLParser {
public:
/// @brief The log callback function pointer.
typedef void (*logCallback)(LogSeverity severity, const std::string &msg);
/// @brief The log callback function.
typedef std::function<void (LogSeverity severity, const std::string &msg)> logCallback;
public:
/// @brief The default class constructor.
@ -120,6 +121,11 @@ public:
/// @return The current log callback.
logCallback getLogCallback() const;
/// @brief A default log callback that writes to a FILE.
/// @param destination [in] Output stream. NULL will use stderr.
/// @return A callback that you can pass to setLogCallback.
static logCallback StdLogCallback(FILE *destination = nullptr);
/// @brief Assigns a new buffer to parse.
/// @param buffer [in] The buffer
/// @param len [in] Size of the buffer
@ -192,6 +198,9 @@ private:
typedef std::vector<DDLNode *> DDLNodeStack;
DDLNodeStack m_stack;
Context *m_context;
/// @brief Callback for StdLogCallback(). Not meant to be called directly.
static void logToStream (FILE *, LogSeverity, const std::string &);
};
END_ODDLPARSER_NS