updating irrXml.

pull/2885/head
Kim Kulling 2020-01-17 19:26:58 +01:00
parent 40d882af4f
commit f51b9378b1
7 changed files with 172 additions and 71 deletions

View File

@ -8,16 +8,7 @@
#include "irrXML.h" #include "irrXML.h"
#include "irrString.h" #include "irrString.h"
#include "irrArray.h" #include "irrArray.h"
#include "fast_atof.h"
#include <cassert>
#include <stdlib.h>
#include <cctype>
#include <cstdint>
//using namespace Assimp;
// For locale independent number conversion
#include <sstream>
#include <locale>
#ifdef _DEBUG #ifdef _DEBUG
#define IRR_DEBUGPRINT(x) printf((x)); #define IRR_DEBUGPRINT(x) printf((x));
@ -40,7 +31,7 @@ public:
//! Constructor //! Constructor
CXMLReaderImpl(IFileReadCallBack* callback, bool deleteCallBack = true) CXMLReaderImpl(IFileReadCallBack* callback, bool deleteCallBack = true)
: TextData(0), P(0), TextBegin(0), TextSize(0), CurrentNodeType(EXN_NONE), : TextData(0), P(0), TextSize(0), TextBegin(0), CurrentNodeType(EXN_NONE),
SourceFormat(ETF_ASCII), TargetFormat(ETF_ASCII) SourceFormat(ETF_ASCII), TargetFormat(ETF_ASCII)
{ {
if (!callback) if (!callback)
@ -168,8 +159,7 @@ public:
return 0; return 0;
core::stringc c = attr->Value.c_str(); core::stringc c = attr->Value.c_str();
return static_cast<float>(atof(c.c_str())); return core::fast_atof(c.c_str());
//return fast_atof(c.c_str());
} }
@ -181,11 +171,7 @@ public:
return 0; return 0;
core::stringc c = attrvalue; core::stringc c = attrvalue;
std::istringstream sstr(c.c_str()); return core::fast_atof(c.c_str());
sstr.imbue(std::locale("C")); // Locale free number convert
float fNum;
sstr >> fNum;
return fNum;
} }
@ -228,7 +214,7 @@ private:
{ {
char_type* start = P; char_type* start = P;
// move forward until '<' found // more forward until '<' found
while(*P != L'<' && *P) while(*P != L'<' && *P)
++P; ++P;
@ -438,10 +424,6 @@ private:
while(*P != L'>') while(*P != L'>')
++P; ++P;
// remove trailing whitespace, if any
while( std::isspace( P[-1]))
--P;
NodeName = core::string<char_type>(pBeginClose, (int)(P - pBeginClose)); NodeName = core::string<char_type>(pBeginClose, (int)(P - pBeginClose));
++P; ++P;
} }
@ -676,12 +658,8 @@ private:
TextData = new char_type[sizeWithoutHeader]; TextData = new char_type[sizeWithoutHeader];
// MSVC debugger complains here about loss of data ...
size_t numShift = sizeof( char_type) * 8;
assert(numShift < 64);
const src_char_type cc = (src_char_type)(((uint64_t(1u) << numShift) - 1));
for (int i=0; i<sizeWithoutHeader; ++i) for (int i=0; i<sizeWithoutHeader; ++i)
TextData[i] = char_type( source[i] & cc); TextData[i] = (char_type)source[i];
TextBegin = TextData; TextBegin = TextData;
TextSize = sizeWithoutHeader; TextSize = sizeWithoutHeader;

View File

@ -0,0 +1,139 @@
// Copyright (C) 2002-2005 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine" and the "irrXML" project.
// For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h
#ifndef __FAST_A_TO_F_H_INCLUDED__
#define __FAST_A_TO_F_H_INCLUDED__
#include <stdlib.h>
#include <math.h>
namespace irr
{
namespace core
{
const float fast_atof_table[] = {
0.f,
0.1f,
0.01f,
0.001f,
0.0001f,
0.00001f,
0.000001f,
0.0000001f,
0.00000001f,
0.000000001f,
0.0000000001f,
0.00000000001f,
0.000000000001f,
0.0000000000001f,
0.00000000000001f,
0.000000000000001f
};
//! Provides a fast function for converting a string into a float,
//! about 6 times faster than atof in win32.
// If you find any bugs, please send them to me, niko (at) irrlicht3d.org.
inline char* fast_atof_move(char* c, float& out)
{
bool inv = false;
char *t;
float f;
if (*c=='-')
{
c++;
inv = true;
}
f = (float)strtol(c, &t, 10);
c = t;
if (*c == '.')
{
c++;
float pl = (float)strtol(c, &t, 10);
pl *= fast_atof_table[t-c];
f += pl;
c = t;
if (*c == 'e')
{
++c;
float exp = (float)strtol(c, &t, 10);
f *= (float)pow(10.0f, exp);
c = t;
}
}
if (inv)
f *= -1.0f;
out = f;
return c;
}
//! Provides a fast function for converting a string into a float,
//! about 6 times faster than atof in win32.
// If you find any bugs, please send them to me, niko (at) irrlicht3d.org.
inline const char* fast_atof_move_const(const char* c, float& out)
{
bool inv = false;
char *t;
float f;
if (*c=='-')
{
c++;
inv = true;
}
f = (float)strtol(c, &t, 10);
c = t;
if (*c == '.')
{
c++;
float pl = (float)strtol(c, &t, 10);
pl *= fast_atof_table[t-c];
f += pl;
c = t;
if (*c == 'e')
{
++c;
f32 exp = (f32)strtol(c, &t, 10);
f *= (f32)powf(10.0f, exp);
c = t;
}
}
if (inv)
f *= -1.0f;
out = f;
return c;
}
inline float fast_atof(const char* c)
{
float ret;
fast_atof_move_const(c, ret);
return ret;
}
} // end namespace core
}// end namespace irr
#endif

View File

@ -21,8 +21,9 @@ class array
{ {
public: public:
array()
: data(0), allocated(0), used(0), array()
: data(0), used(0), allocated(0),
free_when_destroyed(true), is_sorted(true) free_when_destroyed(true), is_sorted(true)
{ {
} }
@ -30,7 +31,7 @@ public:
//! Constructs a array and allocates an initial chunk of memory. //! Constructs a array and allocates an initial chunk of memory.
//! \param start_count: Amount of elements to allocate. //! \param start_count: Amount of elements to allocate.
array(u32 start_count) array(u32 start_count)
: data(0), allocated(0), used(0), : data(0), used(0), allocated(0),
free_when_destroyed(true), is_sorted(true) free_when_destroyed(true), is_sorted(true)
{ {
reallocate(start_count); reallocate(start_count);

View File

@ -19,7 +19,7 @@ so you can assign unicode to string<c8> and ascii to string<wchar_t>
Note that the conversation between both is not done using an encoding. Note that the conversation between both is not done using an encoding.
Known bugs: Known bugs:
Special characters like 'Ă„', 'Ăś' and 'Ă–' are ignored in the Special characters like 'Ă„', 'Ăś' and 'Ă–' are ignored in the
methods make_upper, make_lower and equals_ignore_case. methods make_upper, make_lower and equals_ignore_case.
*/ */
template <class T> template <class T>
@ -29,7 +29,7 @@ public:
//! Default constructor //! Default constructor
string() string()
: array(0), allocated(1), used(1) : allocated(1), used(1), array(0)
{ {
array = new T[1]; array = new T[1];
array[0] = 0x0; array[0] = 0x0;
@ -39,7 +39,7 @@ public:
//! Constructor //! Constructor
string(const string<T>& other) string(const string<T>& other)
: array(0), allocated(0), used(0) : allocated(0), used(0), array(0)
{ {
*this = other; *this = other;
} }
@ -47,7 +47,7 @@ public:
//! Constructs a string from an int //! Constructs a string from an int
string(int number) string(int number)
: array(0), allocated(0), used(0) : allocated(0), used(0), array(0)
{ {
// store if negative and make positive // store if negative and make positive
@ -98,7 +98,7 @@ public:
//! Constructor for copying a string from a pointer with a given lenght //! Constructor for copying a string from a pointer with a given lenght
template <class B> template <class B>
string(const B* c, s32 lenght) string(const B* c, s32 lenght)
: array(0), allocated(0), used(0) : allocated(0), used(0), array(0)
{ {
if (!c) if (!c)
return; return;
@ -117,7 +117,7 @@ public:
//! Constructor for unicode and ascii strings //! Constructor for unicode and ascii strings
template <class B> template <class B>
string(const B* c) string(const B* c)
: array(0),allocated(0), used(0) : allocated(0), used(0), array(0)
{ {
*this = c; *this = c;
} }

View File

@ -79,13 +79,8 @@ typedef unsigned short wchar_t;
#endif // microsoft compiler #endif // microsoft compiler
//! define a break macro for debugging only in Win32 mode. //! define a break macro for debugging only in Win32 mode.
// WORKAROUND (assimp): remove __asm #if !defined(_WIN64) && defined(WIN32) && defined(_MSC_VER) && defined(_DEBUG)
#if defined(WIN32) && defined(_MSC_VER) && defined(_DEBUG) #define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) if (_CONDITION_) {_asm int 3}
#if defined(_M_IX86)
#define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) /*if (_CONDITION_) {_asm int 3}*/
#else
#define _IRR_DEBUG_BREAK_IF( _CONDITION_ )
#endif
#else #else
#define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) #define _IRR_DEBUG_BREAK_IF( _CONDITION_ )
#endif #endif
@ -96,10 +91,8 @@ When you call unmanaged code that returns a bool type value of false from manage
the return value may appear as true. See the return value may appear as true. See
http://support.microsoft.com/default.aspx?kbid=823071 for details. http://support.microsoft.com/default.aspx?kbid=823071 for details.
Compiler version defines: VC6.0 : 1200, VC7.0 : 1300, VC7.1 : 1310, VC8.0 : 1400*/ Compiler version defines: VC6.0 : 1200, VC7.0 : 1300, VC7.1 : 1310, VC8.0 : 1400*/
#if !defined(_WIN64) && defined(WIN32) && defined(_MSC_VER) && (_MSC_VER > 1299) && (_MSC_VER < 1400)
// WORKAROUND (assimp): remove __asm #define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX __asm mov eax,100
#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER > 1299) && (_MSC_VER < 1400)
#define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX /*__asm mov eax,100*/
#else #else
#define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX #define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX
#endif // _IRR_MANAGED_MARSHALLING_BUGFIX #endif // _IRR_MANAGED_MARSHALLING_BUGFIX

View File

@ -2,14 +2,10 @@
// This file is part of the "Irrlicht Engine" and the "irrXML" project. // This file is part of the "Irrlicht Engine" and the "irrXML" project.
// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h // For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
// Need to include Assimp, too. We're using Assimp's version of fast_atof
// so we need stdint.h. But no PCH.
#include "irrXML.h" #include "irrXML.h"
#include "irrString.h" #include "irrString.h"
#include "irrArray.h" #include "irrArray.h"
//#include <assimp/fast_atof.h> #include "fast_atof.h"
#include "CXMLReaderImpl.h" #include "CXMLReaderImpl.h"
namespace irr namespace irr
@ -18,7 +14,7 @@ namespace io
{ {
//! Implementation of the file read callback for ordinary files //! Implementation of the file read callback for ordinary files
class IRRXML_API CFileReadCallBack : public IFileReadCallBack class CFileReadCallBack : public IFileReadCallBack
{ {
public: public:

View File

@ -7,12 +7,6 @@
#include <stdio.h> #include <stdio.h>
#ifdef _WIN32
# define IRRXML_API __declspec(dllexport)
#else
# define IRRXML_API __attribute__ ((visibility("default")))
#endif // _WIN32
/** \mainpage irrXML 1.2 API documentation /** \mainpage irrXML 1.2 API documentation
<div align="center"><img src="logobig.png" ></div> <div align="center"><img src="logobig.png" ></div>
@ -178,7 +172,7 @@ namespace io
ETF_UTF32_BE, ETF_UTF32_BE,
//! UTF-32 format, little endian //! UTF-32 format, little endian
ETF_UTF32_LE ETF_UTF32_LE,
}; };
@ -215,7 +209,7 @@ namespace io
two methods to read your data and give a pointer to an instance of two methods to read your data and give a pointer to an instance of
your implementation when calling createIrrXMLReader(), your implementation when calling createIrrXMLReader(),
createIrrXMLReaderUTF16() or createIrrXMLReaderUTF32() */ createIrrXMLReaderUTF16() or createIrrXMLReaderUTF32() */
class IRRXML_API IFileReadCallBack class IFileReadCallBack
{ {
public: public:
@ -415,7 +409,7 @@ namespace io
\return Returns a pointer to the created xml parser. This pointer should be \return Returns a pointer to the created xml parser. This pointer should be
deleted using 'delete' after no longer needed. Returns 0 if an error occured deleted using 'delete' after no longer needed. Returns 0 if an error occured
and the file could not be opened. */ and the file could not be opened. */
IRRXML_API IrrXMLReader* createIrrXMLReader(const char* filename); IrrXMLReader* createIrrXMLReader(const char* filename);
//! Creates an instance of an UFT-8 or ASCII character xml parser. //! Creates an instance of an UFT-8 or ASCII character xml parser.
/** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
@ -427,7 +421,7 @@ namespace io
\return Returns a pointer to the created xml parser. This pointer should be \return Returns a pointer to the created xml parser. This pointer should be
deleted using 'delete' after no longer needed. Returns 0 if an error occured deleted using 'delete' after no longer needed. Returns 0 if an error occured
and the file could not be opened. */ and the file could not be opened. */
IRRXML_API IrrXMLReader* createIrrXMLReader(FILE* file); IrrXMLReader* createIrrXMLReader(FILE* file);
//! Creates an instance of an UFT-8 or ASCII character xml parser. //! Creates an instance of an UFT-8 or ASCII character xml parser.
/** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
@ -440,7 +434,7 @@ namespace io
\return Returns a pointer to the created xml parser. This pointer should be \return Returns a pointer to the created xml parser. This pointer should be
deleted using 'delete' after no longer needed. Returns 0 if an error occured deleted using 'delete' after no longer needed. Returns 0 if an error occured
and the file could not be opened. */ and the file could not be opened. */
IRRXML_API IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback); IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback);
//! Creates an instance of an UFT-16 xml parser. //! Creates an instance of an UFT-16 xml parser.
/** This means that /** This means that
@ -452,7 +446,7 @@ namespace io
\return Returns a pointer to the created xml parser. This pointer should be \return Returns a pointer to the created xml parser. This pointer should be
deleted using 'delete' after no longer needed. Returns 0 if an error occured deleted using 'delete' after no longer needed. Returns 0 if an error occured
and the file could not be opened. */ and the file could not be opened. */
IRRXML_API IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename); IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename);
//! Creates an instance of an UFT-16 xml parser. //! Creates an instance of an UFT-16 xml parser.
/** This means that all character data will be returned in UTF-16. The file to read can /** This means that all character data will be returned in UTF-16. The file to read can
@ -464,7 +458,7 @@ namespace io
\return Returns a pointer to the created xml parser. This pointer should be \return Returns a pointer to the created xml parser. This pointer should be
deleted using 'delete' after no longer needed. Returns 0 if an error occured deleted using 'delete' after no longer needed. Returns 0 if an error occured
and the file could not be opened. */ and the file could not be opened. */
IRRXML_API IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file); IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file);
//! Creates an instance of an UFT-16 xml parser. //! Creates an instance of an UFT-16 xml parser.
/** This means that all character data will be returned in UTF-16. The file to read can /** This means that all character data will be returned in UTF-16. The file to read can
@ -477,7 +471,7 @@ namespace io
\return Returns a pointer to the created xml parser. This pointer should be \return Returns a pointer to the created xml parser. This pointer should be
deleted using 'delete' after no longer needed. Returns 0 if an error occured deleted using 'delete' after no longer needed. Returns 0 if an error occured
and the file could not be opened. */ and the file could not be opened. */
IRRXML_API IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback); IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback);
//! Creates an instance of an UFT-32 xml parser. //! Creates an instance of an UFT-32 xml parser.
@ -489,7 +483,7 @@ namespace io
\return Returns a pointer to the created xml parser. This pointer should be \return Returns a pointer to the created xml parser. This pointer should be
deleted using 'delete' after no longer needed. Returns 0 if an error occured deleted using 'delete' after no longer needed. Returns 0 if an error occured
and the file could not be opened. */ and the file could not be opened. */
IRRXML_API IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename); IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename);
//! Creates an instance of an UFT-32 xml parser. //! Creates an instance of an UFT-32 xml parser.
/** This means that all character data will be returned in UTF-32. The file to read can /** This means that all character data will be returned in UTF-32. The file to read can
@ -501,7 +495,7 @@ namespace io
\return Returns a pointer to the created xml parser. This pointer should be \return Returns a pointer to the created xml parser. This pointer should be
deleted using 'delete' after no longer needed. Returns 0 if an error occured deleted using 'delete' after no longer needed. Returns 0 if an error occured
and the file could not be opened. */ and the file could not be opened. */
IRRXML_API IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file); IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file);
//! Creates an instance of an UFT-32 xml parser. //! Creates an instance of an UFT-32 xml parser.
/** This means that /** This means that
@ -515,7 +509,7 @@ namespace io
\return Returns a pointer to the created xml parser. This pointer should be \return Returns a pointer to the created xml parser. This pointer should be
deleted using 'delete' after no longer needed. Returns 0 if an error occured deleted using 'delete' after no longer needed. Returns 0 if an error occured
and the file could not be opened. */ and the file could not be opened. */
IRRXML_API IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback); IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback);
/*! \file irrxml.h /*! \file irrxml.h