Add tinyXML and start parsing file of object ==> faster than previous version

This commit is contained in:
Edouard Dupin 2011-11-25 17:46:14 +01:00
parent bbef8c86d5
commit 763ad9654f
16 changed files with 5960 additions and 241 deletions

View File

@ -168,6 +168,12 @@ MAKE_DEPENDENCE=Makefile
### Files Listes ###
###############################################################################
# tiny XML (extern OPEN Sources) :
CXXFILES += tinyXML/tinyxml.cpp \
tinyXML/tinyxmlparser.cpp \
tinyXML/tinyxmlerror.cpp \
tinyXML/tinystr.cpp
# Ewol Tool Kit :
CXXFILES += etk/Debug.cpp \
etk/DebugInternal.cpp \

View File

@ -103,6 +103,8 @@ int main(int argc, char *argv[])
ewol::SetFontFolder("Font");
ewol::SetDefaultFont("freefont/FreeMono", 14);
ewol::theme::LoadDefault("dataTest/exemple.eol");
ewol::theme::LoadDefault("dataTest/exemple.eol");
exit(0);
Plop * myWindowsExample = new Plop();

View File

@ -98,6 +98,10 @@ etk::String::String(const char* inputData, int32_t len)
void etk::String::Set(const char * inputData, int32_t len)
{
if (NULL == inputData) {
// nothing to add ...
return;
}
// overwrite the len if needed :
if ((-1) == len) {
len = strlen(inputData);
@ -190,6 +194,9 @@ const etk::String& etk::String::operator= (const char * inputData)
{
m_data.Clear();
m_data.PushBack('\0');
if (NULL == inputData) {
return *this;
}
// calculate the size :
uint32_t len = strlen(inputData);
// check the new size ...

View File

@ -22,7 +22,44 @@
*******************************************************************************
*/
#include <ewol/theme/EolBase.h>
#undef __class__
#define __class__ "ewol::theme::EolBase"
ewol::theme::EolBase::EolBase(void)
{
}
ewol::theme::EolBase::~EolBase(void)
{
}
void ewol::theme::EolBase::Parse(TiXmlNode * pNode)
{
m_name = pNode->ToElement()->Attribute("name");
EWOL_INFO("Group name=\"" << m_name << "\" " );
}
etk::String ewol::theme::EolBase::GetName(void)
{
return m_name;
}
void ewol::theme::EolBase::SetName(etk::String & newName)
{
m_name = newName;
}
bool ewol::theme::EolBase::HasName(etk::String & newName)
{
return m_name == newName;
}

View File

@ -30,14 +30,22 @@
#include <etk/Types.h>
#include <etk/String.h>
#include <ewol/OObject.h>
#include <tinyXML/tinyxml.h>
namespace ewol {
namespace theme {
class EolBase {
public:
EolBase(void) { };
virtual ~EolBase(void) { };
EolBase(void);
virtual ~EolBase(void);
void Parse(TiXmlNode * pNode);
etk::String GetName(void);
void SetName(etk::String & newName);
bool HasName(etk::String & newName);
private:
etk::String m_name;
};
};
};

View File

@ -32,19 +32,59 @@
ewol::theme::EolColor::EolColor(void)
{
m_color.red = 0.0;
m_color.green = 0.0;
m_color.blue = 0.0;
m_color.alpha = 1.0;
}
ewol::theme::EolColor::~EolColor(void)
{
}
void ewol::theme::EolColor::Load(const char * data, int32_t len)
void ewol::theme::EolColor::Parse(TiXmlNode * pNode)
{
m_name = pNode->ToElement()->Attribute("name");
const char *color = pNode->ToElement()->Attribute("val");
if (NULL != color) {
if (color[0] == '#') {
// Find a direct Color
unsigned int r=0;
unsigned int v=0;
unsigned int b=0;
unsigned int a=0xFF;
sscanf(color, "#%02x%02x%02x%02x", &r,&v,&b,&a);
m_color.red = (etkFloat_t)r/255.0;
m_color.green = (etkFloat_t)v/255.0;
m_color.blue = (etkFloat_t)b/255.0;
m_color.alpha = (etkFloat_t)a/255.0;
} else if (color[0] == '&') {
//find a reference Color
} else {
// must be a float color
double r=0.0;
double v=0.0;
double b=0.0;
double a=1.0;
sscanf(color, "%lf;%lf;%lf;%lf", &r,&v,&b,&a);
m_color.red = (etkFloat_t)r;
m_color.green = (etkFloat_t)v;
m_color.blue = (etkFloat_t)b;
m_color.alpha = (etkFloat_t)a;
if (m_color.red>1.0) { m_color.red = 1.0; }
if (m_color.green>1.0) { m_color.green = 1.0; }
if (m_color.blue>1.0) { m_color.blue = 1.0; }
if (m_color.alpha>1.0) { m_color.alpha = 1.0; }
}
}
if (NULL != color) {
EWOL_INFO("COLOR name=\"" << m_name << "\" \"" << color << "\" ==> red="<< m_color.red <<" green="<< m_color.green <<" blue="<< m_color.blue <<" alpha="<< m_color.alpha );
} else {
EWOL_INFO("COLOR name=\"" << m_name << "\" \"\"???? ==> red="<< m_color.red <<" green="<< m_color.green <<" blue="<< m_color.blue <<" alpha="<< m_color.alpha );
}
}

View File

@ -31,6 +31,7 @@
#include <etk/String.h>
#include <etk/File.h>
#include <ewol/OObject.h>
#include <tinyXML/tinyxml.h>
namespace ewol {
@ -39,8 +40,8 @@ namespace ewol {
public:
EolColor(void);
virtual ~EolColor(void);
void Load(const char * data, int32_t len);
void Parse(TiXmlNode * pNode);
etk::String GetName(void);
void SetName(etk::String & newName);
bool HasName(etk::String & newName);

View File

@ -22,6 +22,8 @@
*******************************************************************************
*/
#include <tinyXML/tinyxml.h>
#include <ewol/theme/Theme.h>
#undef __class__
@ -40,107 +42,6 @@ ewol::theme::Theme::~Theme(void)
}
static bool IsComment(char * line)
{
for(int32_t iii=0; iii<MAX_LINE_SIZE; iii++) {
if( line[iii]=='\0'
|| line[iii]=='\r'
|| line[iii]=='\n') {
// enpty line ...
return true; //==> same a a comment ...
}
if( line[iii]!='\t'
&& line[iii]!=' ') {
if(line[iii]=='#') {
// find a comment
return true;
} else {
return false;
}
}
}
// empty line ...
return true;
}
static int32_t Offset(char * line)
{
int32_t offset = 0;
int32_t spaceCount = 0;
for(int32_t iii=0; iii<MAX_LINE_SIZE; iii++) {
if( line[iii]=='\0') {
break;
}
if( line[iii]!='\t'
&& line[iii]!=' ') {
break;
} else {
if(line[iii]==' ') {
spaceCount++;
if (spaceCount == 4) {
spaceCount = 0;
offset++;
}
} else {
spaceCount = 0;
offset++;
}
}
}
if (spaceCount != 0) {
return -1;
}
return offset;
}
static int32_t LineLen(char * pointer)
{
int32_t nbElement = 0;
while( *pointer != '\0'
&& *pointer != '\n'
&& *pointer != '\r') {
nbElement++;
pointer++;
}
return nbElement;
}
static char* NextLineStart(char * pointer)
{
bool find = false;
while(*pointer != '\0') {
if( *pointer == '\n'
|| *pointer == '\r') {
find = true;
} else if (true==find){
return pointer;
}
pointer++;
}
return NULL;
}
static int32_t LenSpecificIndent(char * pointer, int32_t identSize)
{
char * pointerStart = pointer;
while(NULL!=pointer) {
// check comment //
if (false == IsComment(pointer)) {
// need to parse the element...
int32_t offset = Offset(pointer);
if (identSize > offset) {
break;
}
}
pointer=NextLineStart(pointer);
}
return pointer - pointerStart;
}
void ewol::theme::Theme::Load(etk::File & newFile, bool defaultTheme)
{
if (newFile.HasExtention() == false) {
@ -155,149 +56,87 @@ void ewol::theme::Theme::Load(etk::File & newFile, bool defaultTheme)
EWOL_ERROR("File does not Exist ... " << newFile);
return;
} else {
int32_t fileSize = newFile.Size();
char * fileData;
int32_t lineID=1;
FILE * file = fopen(newFile.GetCompleateName().c_str(),"r");
if(NULL == file) {
EWOL_ERROR("Can not OPEN the file name=\"" << newFile << "\"");
TiXmlDocument XmlDocument;
// open the curent File
XmlDocument.LoadFile(newFile.GetCompleateName().c_str());
TiXmlElement* root = XmlDocument.FirstChildElement( "eol" );
if (NULL == root ) {
EWOL_ERROR("(l ?) main node not find: \"eol\" in \"" << newFile << "\"");
return;
}
fileData = new char[fileSize+1];
if (NULL == fileData) {
fclose(file);
EWOL_ERROR("Can not Allocate DATA ... file=\"" << newFile << "\"");
return;
}
if (fileSize != (int64_t)fread(fileData, 1, fileSize, file) ) {
fclose(file);
EWOL_ERROR("Error to load file DATA ... file=\"" << newFile << "\"");
return;
}
// end of the string ...
fileData[fileSize] = '\0';
// close unneded open file
fclose(file);
// get the next line :
char * elementLine = fileData;
int32_t lineLen = LineLen(elementLine);
// load all element of the file ...
if( 3 > lineLen
&& ( elementLine[0] != 'e'
|| elementLine[1] != 'o'
|| elementLine[2] != 'l') ) {
EWOL_ERROR("Start file in error " << newFile << " ==> will start with eol \\n");
delete[] fileData;
return;
}
// TODO : On devrait décapitalise le fichier ... pour eviter toutes erreur de CAST ... (A voir ... maais je ne suis pas sur...)
// TODO : Remove comment Lines ...
enum {MODE_UNKNOW, MODE_TEXT, MODE_BINARY} fileMode = MODE_UNKNOW;
bool SupportedVersion=false;
lineID++;
elementLine=NextLineStart(elementLine);
while(NULL!=elementLine) {
// get the current Line lenght:
lineLen = LineLen(elementLine);
// check comment //
if (true == IsComment(elementLine)) {
EWOL_VERBOSE("(l=" << lineID << ") Find a comment : \"" << etk::String(elementLine, lineLen) << "\"");
} else {
// need to parse the element...
int32_t offset = Offset(elementLine);
if (-1 == offset) {
EWOL_ERROR("(l=" << lineID << ") indentation error 4 spaces or 1 tab : \"" << etk::String(elementLine, lineLen) << "\"");
delete[] fileData;
return;
} else if (0==offset) {
if (0==strncmp(elementLine, "Mode=Text", 9)) {
fileMode = MODE_TEXT;
EWOL_INFO("(l=" << lineID << ") getting Mode : Text");
} else if (0==strncmp(elementLine, "Mode=Bin", 8)) {
fileMode = MODE_BINARY;
EWOL_INFO("(l=" << lineID << ") getting Mode : Binary");
} else if (0==strncmp(elementLine, "Version=1.0", 11)) {
SupportedVersion = true;
EWOL_INFO("(l=" << lineID << ") getting Version 1.0");
} else if (lineLen>=3 && elementLine[0] == '<') {
break;
EWOL_INFO("(l=" << lineID << ") getting ELEMENT <> (indent=" << offset << ") : \"" << etk::String(elementLine,lineLen) << "\"");
} else{
EWOL_WARNING("(l=" << lineID << ") Un-Interpreted Line : \"" << etk::String(elementLine, lineLen) << "\"");
}
} else {
EWOL_ERROR("(l=" << lineID << ") Not Permeted before the first <...> : \"" << etk::String(elementLine, lineLen) << "\"");
delete[] fileData;
return;
} else {
for(TiXmlNode * pNode=root->FirstChild(); NULL!=pNode; pNode = pNode->NextSibling()) {
if (pNode->Type()==TiXmlNode::TINYXML_COMMENT) {
continue;
}
}
lineID++;
elementLine=NextLineStart(elementLine);
}
// Check Version And mode ...
if (fileMode != MODE_TEXT || SupportedVersion==false) {
EWOL_ERROR("==> Not Supported Type of file Mode and/or version of file Mode .... ");
delete[] fileData;
return;
}
while(NULL!=elementLine) {
// get the current Line lenght:
lineLen = LineLen(elementLine);
// check comment //
if (true == IsComment(elementLine)) {
EWOL_VERBOSE("(l=" << lineID << ") Find a comment : \"" << etk::String(elementLine, lineLen) << "\"");
} else {
// need to parse the element...
int32_t offset = Offset(elementLine);
if (-1 == offset) {
EWOL_ERROR("(l=" << lineID << ") indentation error 4 spaces or 1 tab : \"" << etk::String(elementLine, lineLen) << "\"");
delete[] fileData;
return;
} else if (0==offset) {
if (lineLen>=3 && elementLine[0] == '<') {
int32_t nbElement = 1;
bool find = false;
while(nbElement < lineLen) {
if (elementLine[nbElement] == '>') {
find = true;
break;
etk::String nodeValue = pNode->Value();
if (nodeValue == "element") {
EWOL_INFO("Find ELEMENT ... ");
// Need to call the sub parser ...
// TODO ...
} else if (nodeValue == "group") {
EWOL_INFO("Find group ... ");
etk::String groupNameTmp = pNode->ToElement()->Attribute("name");
if (groupNameTmp == "") {
EWOL_ERROR("(l " << pNode->Row() << ") Group with NO name ... (not parsed)");
// not added it
} else {
bool findASameName = false;
// check if existed ...
for (int32_t iii=0; iii < m_listGroup.Size(); iii++) {
if(NULL!=m_listGroup[iii]) {
if(m_listGroup[iii]->HasName(groupNameTmp) == true) {
findASameName = true;
EWOL_WARNING("(l " << pNode->Row() << ") Find a Group with the same Name : \"" << groupNameTmp <<"\"");
m_listGroup[iii]->Parse(pNode);
break;
}
}
nbElement++;
}
if (true == find) {
EWOL_INFO("(l=" << lineID << ") getting ELEMENT <" << etk::String(&elementLine[1],nbElement-1)<< ">");
int32_t lenMM = LenSpecificIndent(NextLineStart(elementLine), 1);
EWOL_INFO("(l=" << lineID+1 << ") sub Parse : \"" << etk::String(NextLineStart(elementLine), lenMM)<< "\"");
} else {
EWOL_WARNING("(l=" << lineID << ") Un-Interpreted Line : \"" << etk::String(elementLine, lineLen) << "\"");
if (findASameName == false) {
EWOL_DEBUG("(l " << pNode->Row() << ") Add a new COLOR : \"" << groupNameTmp <<"\"");
ewol::theme::EolBase * myGroupTmp = new ewol::theme::EolBase();
if (NULL != myGroupTmp) {
myGroupTmp->Parse(pNode);
m_listGroup.PushBack(myGroupTmp);
} else {
EWOL_ERROR("(l " << pNode->Row() << ") Error Allocation : \"" << nodeValue <<"\"");
}
}
}
} else if (nodeValue == "color") {
etk::String colorNameTmp = pNode->ToElement()->Attribute("name");
if (colorNameTmp == "") {
EWOL_ERROR("(l " << pNode->Row() << ") Color with NO name ... (not parsed)");
// not added it
} else {
EWOL_WARNING("(l=" << lineID << ") Un-Interpreted Line : \"" << etk::String(elementLine, lineLen) << "\"");
bool findASameName = false;
// check if existed ...
for (int32_t iii=0; iii < m_listColor.Size(); iii++) {
if(NULL!=m_listColor[iii]) {
if(m_listColor[iii]->HasName(colorNameTmp) == true) {
findASameName = true;
EWOL_WARNING("(l " << pNode->Row() << ") Find a color with the same Name : \"" << colorNameTmp <<"\"");
m_listColor[iii]->Parse(pNode);
break;
}
}
}
if (findASameName == false) {
EWOL_DEBUG("(l " << pNode->Row() << ") Add a new COLOR : \"" << colorNameTmp <<"\"");
ewol::theme::EolColor * myColorTmp = new ewol::theme::EolColor();
if (NULL != myColorTmp) {
myColorTmp->Parse(pNode);
m_listColor.PushBack(myColorTmp);
} else {
EWOL_ERROR("(l " << pNode->Row() << ") Error Allocation : \"" << nodeValue <<"\"");
}
}
}
} else {
/*elementLine += offset;
lineLen -= offset:
if (elementLine[0] == '<') {
} else if (elementLine[0] == '[') {
EWOL_INFO("(l=" << lineID << ") getting block [] (indent=" << offset << ") : \"" << etk::String(elementLine,lineLen) << "\"");
} else if (elementLine[0] == '{') {
EWOL_INFO("(l=" << lineID << ") getting drawing basic {} (indent=" << offset << ") : \"" << etk::String(elementLine,lineLen) << "\"");
} else {
EWOL_DEBUG("(l=" << lineID << ") data OTHER ... (indent=" << offset << ") : \"" << etk::String(elementLine,lineLen) << "\"");
}
*/
//EWOL_WARNING("(l=" << lineID << ") Un-Interpreted Line : (indent=" << offset << ") : \"" << etk::String(elementLine,lineLen) << "\"");
EWOL_ERROR("(l " << pNode->Row() << ") node not suported : \"" << nodeValue <<"\" must be [group,color,element]");
}
}
lineID++;
elementLine=NextLineStart(elementLine);
}
delete[] fileData;
}
}

View File

@ -50,7 +50,7 @@ namespace ewol {
int32_t GetObjectId(etk::String name);
private:
etk::VectorType<ewol::theme::EolColor*> m_listColor;
etk::VectorType<ewol::theme::EolBase*> m_listGroup;
etk::VectorType<ewol::theme::EolBase*> m_listGroup; // TODO : we need really to star a frame here ...
etk::VectorType<ewol::theme::EolElement*> m_listElement;
public:
// acces to manage and create object ==> drawing system

116
Sources/tinyXML/tinystr.cpp Normal file
View File

@ -0,0 +1,116 @@
/*
www.sourceforge.net/projects/tinyxml
Original file by Yves Berquin.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
/*
* THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005.
*/
#ifndef TIXML_USE_STL
#include "tinystr.h"
// Error value for find primitive
const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1);
// Null rep.
TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
void TiXmlString::reserve (size_type cap)
{
if (cap > capacity())
{
TiXmlString tmp;
tmp.init(length(), cap);
memcpy(tmp.start(), data(), length());
swap(tmp);
}
}
TiXmlString& TiXmlString::assign(const char* str, size_type len)
{
size_type cap = capacity();
if (len > cap || cap > 3*(len + 8))
{
TiXmlString tmp;
tmp.init(len);
memcpy(tmp.start(), str, len);
swap(tmp);
}
else
{
memmove(start(), str, len);
set_size(len);
}
return *this;
}
TiXmlString& TiXmlString::append(const char* str, size_type len)
{
size_type newsize = length() + len;
if (newsize > capacity())
{
reserve (newsize + capacity());
}
memmove(finish(), str, len);
set_size(newsize);
return *this;
}
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
{
TiXmlString tmp;
tmp.reserve(a.length() + b.length());
tmp += a;
tmp += b;
return tmp;
}
TiXmlString operator + (const TiXmlString & a, const char* b)
{
TiXmlString tmp;
TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
tmp.reserve(a.length() + b_len);
tmp += a;
tmp.append(b, b_len);
return tmp;
}
TiXmlString operator + (const char* a, const TiXmlString & b)
{
TiXmlString tmp;
TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
tmp.reserve(a_len + b.length());
tmp.append(a, a_len);
tmp += b;
return tmp;
}
#endif // TIXML_USE_STL

319
Sources/tinyXML/tinystr.h Normal file
View File

@ -0,0 +1,319 @@
/*
www.sourceforge.net/projects/tinyxml
Original file by Yves Berquin.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
/*
* THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
*
* - completely rewritten. compact, clean, and fast implementation.
* - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
* - fixed reserve() to work as per specification.
* - fixed buggy compares operator==(), operator<(), and operator>()
* - fixed operator+=() to take a const ref argument, following spec.
* - added "copy" constructor with length, and most compare operators.
* - added swap(), clear(), size(), capacity(), operator+().
*/
#ifndef TIXML_USE_STL
#ifndef TIXML_STRING_INCLUDED
#define TIXML_STRING_INCLUDED
#include <assert.h>
#include <string.h>
/* The support for explicit isn't that universal, and it isn't really
required - it is used to check that the TiXmlString class isn't incorrectly
used. Be nice to old compilers and macro it here:
*/
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
// Microsoft visual studio, version 6 and higher.
#define TIXML_EXPLICIT explicit
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
// GCC version 3 and higher.s
#define TIXML_EXPLICIT explicit
#else
#define TIXML_EXPLICIT
#endif
/*
TiXmlString is an emulation of a subset of the std::string template.
Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
Only the member functions relevant to the TinyXML project have been implemented.
The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase
a string and there's no more room, we allocate a buffer twice as big as we need.
*/
class TiXmlString
{
public :
// The size type used
typedef size_t size_type;
// Error value for find primitive
static const size_type npos; // = -1;
// TiXmlString empty constructor
TiXmlString () : rep_(&nullrep_)
{
}
// TiXmlString copy constructor
TiXmlString ( const TiXmlString & copy) : rep_(0)
{
init(copy.length());
memcpy(start(), copy.data(), length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
{
init( static_cast<size_type>( strlen(copy) ));
memcpy(start(), copy, length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
{
init(len);
memcpy(start(), str, len);
}
// TiXmlString destructor
~TiXmlString ()
{
quit();
}
// = operator
TiXmlString& operator = (const char * copy)
{
return assign( copy, (size_type)strlen(copy));
}
// = operator
TiXmlString& operator = (const TiXmlString & copy)
{
return assign(copy.start(), copy.length());
}
// += operator. Maps to append
TiXmlString& operator += (const char * suffix)
{
return append(suffix, static_cast<size_type>( strlen(suffix) ));
}
// += operator. Maps to append
TiXmlString& operator += (char single)
{
return append(&single, 1);
}
// += operator. Maps to append
TiXmlString& operator += (const TiXmlString & suffix)
{
return append(suffix.data(), suffix.length());
}
// Convert a TiXmlString into a null-terminated char *
const char * c_str () const { return rep_->str; }
// Convert a TiXmlString into a char * (need not be null terminated).
const char * data () const { return rep_->str; }
// Return the length of a TiXmlString
size_type length () const { return rep_->size; }
// Alias for length()
size_type size () const { return rep_->size; }
// Checks if a TiXmlString is empty
bool empty () const { return rep_->size == 0; }
// Return capacity of string
size_type capacity () const { return rep_->capacity; }
// single char extraction
const char& at (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// [] operator
char& operator [] (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// find a char in a string. Return TiXmlString::npos if not found
size_type find (char lookup) const
{
return find(lookup, 0);
}
// find a char in a string from an offset. Return TiXmlString::npos if not found
size_type find (char tofind, size_type offset) const
{
if (offset >= length()) return npos;
for (const char* p = c_str() + offset; *p != '\0'; ++p)
{
if (*p == tofind) return static_cast< size_type >( p - c_str() );
}
return npos;
}
void clear ()
{
//Lee:
//The original was just too strange, though correct:
// TiXmlString().swap(*this);
//Instead use the quit & re-init:
quit();
init(0,0);
}
/* Function to reserve a big amount of data when we know we'll need it. Be aware that this
function DOES NOT clear the content of the TiXmlString if any exists.
*/
void reserve (size_type cap);
TiXmlString& assign (const char* str, size_type len);
TiXmlString& append (const char* str, size_type len);
void swap (TiXmlString& other)
{
Rep* r = rep_;
rep_ = other.rep_;
other.rep_ = r;
}
private:
void init(size_type sz) { init(sz, sz); }
void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
char* start() const { return rep_->str; }
char* finish() const { return rep_->str + rep_->size; }
struct Rep
{
size_type size, capacity;
char str[1];
};
void init(size_type sz, size_type cap)
{
if (cap)
{
// Lee: the original form:
// rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
// doesn't work in some cases of new being overloaded. Switching
// to the normal allocation, although use an 'int' for systems
// that are overly picky about structure alignment.
const size_type bytesNeeded = sizeof(Rep) + cap;
const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
rep_->str[ rep_->size = sz ] = '\0';
rep_->capacity = cap;
}
else
{
rep_ = &nullrep_;
}
}
void quit()
{
if (rep_ != &nullrep_)
{
// The rep_ is really an array of ints. (see the allocator, above).
// Cast it back before delete, so the compiler won't incorrectly call destructors.
delete [] ( reinterpret_cast<int*>( rep_ ) );
}
}
Rep * rep_;
static Rep nullrep_;
} ;
inline bool operator == (const TiXmlString & a, const TiXmlString & b)
{
return ( a.length() == b.length() ) // optimization on some platforms
&& ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare
}
inline bool operator < (const TiXmlString & a, const TiXmlString & b)
{
return strcmp(a.c_str(), b.c_str()) < 0;
}
inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; }
inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
TiXmlString operator + (const TiXmlString & a, const char* b);
TiXmlString operator + (const char* a, const TiXmlString & b);
/*
TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString.
Only the operators that we need for TinyXML have been developped.
*/
class TiXmlOutStream : public TiXmlString
{
public :
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const TiXmlString & in)
{
*this += in;
return *this;
}
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const char * in)
{
*this += in;
return *this;
}
} ;
#endif // TIXML_STRING_INCLUDED
#endif // TIXML_USE_STL

1839
Sources/tinyXML/tinyxml.cpp Normal file

File diff suppressed because it is too large Load Diff

1799
Sources/tinyXML/tinyxml.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
/*
www.sourceforge.net/projects/tinyxml
Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "tinyxml.h"
// The goal of the seperate error file is to make the first
// step towards localization. tinyxml (currently) only supports
// english error messages, but the could now be translated.
//
// It also cleans up the code a bit.
//
const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] =
{
"No error",
"Error",
"Failed to open file",
"Error parsing Element.",
"Failed to read Element name",
"Error reading Element value.",
"Error reading Attributes.",
"Error: empty tag.",
"Error reading end tag.",
"Error parsing Unknown.",
"Error parsing Comment.",
"Error parsing Declaration.",
"Error document empty.",
"Error null (0) or unexpected EOF found in input stream.",
"Error parsing CDATA.",
"Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.",
};

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<eol>
<!-- can have "color" and "group" that is consider as global ... -->
<color/>
<color name="MEGAMERDIQUE"/>
<color name="GenBG" val="#FF0000"/>
<color name="GenFG" val="#FF000055"/>
<color name="GenBorder" val="1.0;0.000512;1.0;0.755562535"/>
<color name="GenBorder" val="5.0;0.000512;1.0"/>
<group name="Gen Rect system ... ">
<rect color="..."
position="0.53;0.56"
size="0.22;0.11"
/>
<Line color="..."
positionStart="0.53;0.56"
positionStop="0.22;0.11"
thickness="0.05"
/>
<!-- and more basic display -->
</group>
<!-- example of a single element -->
<element name="plop"