[DEV] basic exml parser (not work at all)

This commit is contained in:
Edouard Dupin 2013-06-19 21:23:54 +02:00
commit 7f2ddd4d56
17 changed files with 478 additions and 0 deletions

0
exml/EXmlAttribute.cpp Normal file
View File

28
exml/EXmlAttribute.h Normal file
View File

@ -0,0 +1,28 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_XML_ATTRIBUTE_H__
#define __ETK_XML_ATTRIBUTE_H__
#include <exml/EXmlNode.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlElement : public EXmlNode
{
public:
EXmlElement(void) { };
virtual ~EXmlElement(void) { };
virtual nodeType_te GetType(void) { return typeAttribute; };
};
};
#endif

0
exml/EXmlComment.cpp Normal file
View File

28
exml/EXmlComment.h Normal file
View File

@ -0,0 +1,28 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_XML_COMMENT_H__
#define __ETK_XML_COMMENT_H__
#include <exml/EXmlNode.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlElement : public EXmlNode
{
public:
EXmlElement(void) { };
virtual ~EXmlElement(void) { };
virtual nodeType_te GetType(void) { return typeAttribute; };
};
};
#endif

0
exml/EXmlDeclaration.cpp Normal file
View File

28
exml/EXmlDeclaration.h Normal file
View File

@ -0,0 +1,28 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_XML_DECLARATION_H__
#define __ETK_XML_DECLARATION_H__
#include <exml/EXmlNode.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlDeclaration : public EXmlNode
{
public:
EXmlDeclaration(void) { };
virtual ~EXmlDeclaration(void) { };
virtual nodeType_te GetType(void) { return typeAttribute; };
};
};
#endif

43
exml/EXmlDocument.cpp Normal file
View File

@ -0,0 +1,43 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <exml/EXmlDocument.h>
exml::EXmlDocument::EXmlDocument(void) :
m_charset(unicode::EDN_CHARSET_UNKNOW),
m_caseSensitive(false)
{
}
bool Parse(const etk::UString& _data)
{
// came from char ==> force in utf8 ...
m_charset = unicode::EDN_CHARSET_UTF8;
ivec2 filePos(1,1);
int32_t ret = Parse(_data, 0, m_caseSensitive, filePos);
return false;
}
bool Generate(etk::UString& _data)
{
return false;
}
bool Load(const etk::UString& _file)
{
return false;
}
bool Store(const etk::UString& _file)
{
return false;
}

70
exml/EXmlDocument.h Normal file
View File

@ -0,0 +1,70 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_XML_DOCUMENT_H__
#define __ETK_XML_DOCUMENT_H__
#include <exml/EXmlElement.h>
#include <etk/unicode.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlDocument : exml::EXmlElement
{
public:
EXmlDocument(void);
virtual ~EXmlDocument(void) { };
virtual nodeType_te GetType(void) { return typeDocument; };
private:
unicode::charset_te m_charset;
public:
virtual void SetCharset(unicode::charset_te _charset) { m_charset = _charset; };
virtual unicode::charset_te GetCharset(void) { return m_charset; };
private:
bool m_caseSensitive;
public:
virtual void SetCaseSensitive(bool _val) { m_caseSensitive = _val; };
virtual bool GetCaseSensitive(void) { return m_caseSensitive; };
public:
/**
* @brief Parse a string that contain an XML
* @param[in] _data Data to parse
* @return false : An error occured
* @return true : Parsing is OK
*/
bool Parse(const etk::UString& _data);
/**
* @brief Generate a string that contain the created XML
* @param[out] _data Data where the xml is stored
* @return false : An error occured
* @return true : Parsing is OK
*/
bool Generate(etk::UString& _data);
/**
* @brief Load the file that might contain the xml
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
* @return false : An error occured
* @return true : Parsing is OK
*/
bool Load(const etk::UString& _file);
/**
* @brief Store the Xml in the file
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
* @return false : An error occured
* @return true : Parsing is OK
*/
bool Store(const etk::UString& _file);
};
};
#endif

96
exml/EXmlElement.cpp Normal file
View File

@ -0,0 +1,96 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <exml/EXmlElement.h>
EXmlNode* exml::EXmlElement::GetSub(int32_t _id)
{
if (_id <0 || _id>m_listSub.Size()) {
return NULL;
}
return m_listSub[_id];
}
void exml::EXmlElement::AppendSub(EXmlNode* _node)
{
if (_node == NULL) {
EXML_ERROR("Try to set an empty node");
return;
}
for (int32_t iii=0; iii<m_listSub.Size(); iii++) {
if (m_listSub[iii] == _node) {
EXML_ERROR("Try to add a node that is already added befor !!!");
return;
}
}
m_listSub.PushBack(_node);
}
EXmlAttribute* exml::EXmlElement::GetAttribute(int32_t _id)
{
if (_id <0 || _id>m_listAttribute.Size()) {
return NULL;
}
return m_listAttribute[_id];
}
void exml::EXmlElement::AppendAttribute(EXmlAttribute* _node)
{
if (_node == NULL) {
EXML_ERROR("Try to set an empty node");
return;
}
for (int32_t iii=0; iii<m_listAttribute.Size(); iii++) {
if (m_listAttribute[iii] == _node) {
EXML_ERROR("Try to add a node that is already added befor !!!");
return;
}
}
m_listAttribute.PushBack(_node);
}
int32_t exml::EXmlElement::Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos)
{
for (int32_t iii=_pos; iii<_data.Size(); iii++) {
if (_data[iii] == "<") {
if (iii+1>=_data.Size()) {
// TODO : an error occured ...
return;
}
if (_data[iii+1] == '?') {
// find declaration
// TODO : search end of declaration ...
continue;
}
if(_data[iii+1] == '!') {
if( iii+3>=_data.Size()
|| _data[iii+2] != '-'
|| _data[iii+3] != '-') {
// TODO : an error occured ...
return;
}
// find comment
// TODO : search end of comment ...
continue;
}
// find a normal node ...
} else {
// might to be data text ...
}
}
}
#endif

42
exml/EXmlElement.h Normal file
View File

@ -0,0 +1,42 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_XML_ELEMENT_H__
#define __ETK_XML_ELEMENT_H__
#include <exml/EXmlNode.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlElement : public EXmlNode
{
public:
EXmlElement(void) { };
virtual ~EXmlElement(void) { };
virtual nodeType_te GetType(void) { return typeElement; };
private:
etk::Vector<EXmlNode*> m_listSub;
public:
int32_t SizeSub(void) const { return m_listSub.Size(); };
EXmlNode* GetSub(int32_t _id);
void AppendSub(EXmlNode* _node);
private:
etk::Vector<EXmlAttribute*> m_listAttribute;
public:
int32_t SizeAttribute(void) const { return m_listSub.Size(); };
EXmlAttribute* GetAttribute(int32_t _id);
void AppendAttribute(EXmlAttribute* _node);
protected:
virtual int32_t Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos);
};
};
#endif

0
exml/EXmlNode.cpp Normal file
View File

51
exml/EXmlNode.h Normal file
View File

@ -0,0 +1,51 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_XML_NODE_H__
#define __ETK_XML_NODE_H__
#include <etk/types.h>
#include <etk/UString.h>
namespace exml
{
typedef enum {
typeNode, //!< might be an error ...
typeDocument, //!< all the file main access
typeDeclaration, //!< <?xml ... ?>
typeAttibute, //!< the <Element ATTRIBUTE="ATTRIBUTE_VALUE" />
typeElement, //!< the <XXX> ... </XXX>
typeComment, //!< comment node : <!-- -->
typeText, //!< <XXX> InsideText </XXX>
} nodeType_te;
class EXmlNode
{
public:
EXmlNode(void) { };
virtual ~EXmlNode(void) { };
protected:
/**
* Parse the sub nodes and current nodes ...
*/
virtual int32_t Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos) = 0;
protected:
etk::UString m_name;
public:
virtual void SetName(etk::UString _name) { m_name = _name; };
virtual const etk::UString& GetName(void) { return m_name; };
protected:
etk::UString m_value;
public:
virtual void SetValue(etk::UString _value) { m_value = _value; };
virtual const etk::UString& GetValue(void) { return m_value; };
public:
virtual nodeType_te GetType(void) { return typeNode; };
};
};

0
exml/EXmlText.cpp Normal file
View File

28
exml/EXmlText.h Normal file
View File

@ -0,0 +1,28 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_XML_TEXT_H__
#define __ETK_XML_TEXT_H__
#include <exml/EXmlNode.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlText : public EXmlNode
{
public:
EXmlText(void) { };
virtual ~EXmlText(void) { };
virtual nodeType_te GetType(void) { return typeText; };
};
};
#endif

11
exml/debug.cpp Normal file
View File

@ -0,0 +1,11 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <exml/debug.h>
const char * g_exmlLibName = "exml ";

28
exml/debug.h Normal file
View File

@ -0,0 +1,28 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EXML_DEBUG_H__
#define __EXML_DEBUG_H__
#include <etk/types.h>
#include <etk/Debug.h>
extern const char * g_exmlLibName;
#define EXML_CRITICAL(data) ETK_CRITICAL(g_exmlLibName, data)
#define EXML_WARNING(data) ETK_WARNING(g_exmlLibName, data)
#define EXML_ERROR(data) ETK_ERROR(g_exmlLibName, data)
#define EXML_INFO(data) ETK_INFO(g_exmlLibName, data)
#define EXML_DEBUG(data) ETK_DEBUG(g_exmlLibName, data)
#define EXML_VERBOSE(data) ETK_VERBOSE(g_exmlLibName, data)
#define EXML_ASSERT(cond, data) ETK_ASSERT(g_exmlLibName, cond, data)
#define EXML_CHECK_INOUT(cond) ETK_CHECK_INOUT(g_exmlLibName, cond)
#define EXML_TODO(cond) ETK_TODO(g_exmlLibName, cond)
#endif

25
lutin_exml.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/python
import lutinModule
import lutinTools
def Create(target):
myModule = lutinModule.module(__file__, 'exml', 'LIBRARY')
myModule.AddModuleDepend(['etk'])
myModule.AddSrcFile([
'exml/debug.cpp',
'exml/EXmlAttribute.cpp',
'exml/EXmlComment.cpp',
'exml/EXmlDeclaration.cpp',
'exml/EXmlDocument.cpp',
'exml/EXmlElement.cpp',
'exml/EXmlNode.cpp',
'exml/EXmlText.cpp'])
myModule.AddExportPath(lutinTools.GetCurrentPath(__file__))
# add the currrent module at the
return myModule