[DEV] remork some bad implementation and base on ememory

This commit is contained in:
Edouard DUPIN 2016-04-11 21:22:58 +02:00
parent ae8598ab35
commit b59936f6e5
19 changed files with 325 additions and 409 deletions

View File

@ -12,9 +12,12 @@ def create(target, module_name):
my_module.set_website_sources("http://github.com/atria-soft/" + module_name) my_module.set_website_sources("http://github.com/atria-soft/" + module_name)
my_module.add_path([ my_module.add_path([
module_name, module_name,
"doc"
]) ])
my_module.add_module_depend([ my_module.add_module_depend([
'etk' 'elog',
'etk',
'ememory'
]) ])
my_module.add_exclude_symbols([ my_module.add_exclude_symbols([
'*operator<<*', '*operator<<*',

View File

@ -10,16 +10,9 @@
#include <exml/debug.h> #include <exml/debug.h>
#include <exml/Document.h> #include <exml/Document.h>
#undef __class__ ememory::SharedPtr<exml::Attribute> exml::Attribute::create(const std::string& _name, const std::string& _value) {
#define __class__ "Attribute" return ememory::SharedPtr<exml::Attribute>(new exml::Attribute(_name, _value));
std::shared_ptr<exml::Attribute> exml::Attribute::create() {
return std::shared_ptr<exml::Attribute>(new exml::Attribute());
} }
std::shared_ptr<exml::Attribute> exml::Attribute::create(const std::string& _name, const std::string& _value) {
return std::shared_ptr<exml::Attribute>(new exml::Attribute(_name, _value));
}
exml::Attribute::Attribute(const std::string& _name, const std::string& _value) : exml::Attribute::Attribute(const std::string& _name, const std::string& _value) :
exml::Node(_value), exml::Node(_value),
@ -27,7 +20,7 @@ exml::Attribute::Attribute(const std::string& _name, const std::string& _value)
} }
bool exml::Attribute::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) { bool exml::Attribute::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'attribute'"); EXML_VERBOSE("start parse : 'attribute'");
m_pos = _filePos; m_pos = _filePos;
// search end of the comment : // search end of the comment :
@ -48,7 +41,7 @@ bool exml::Attribute::iParse(const std::string& _data, int32_t& _pos, bool _case
m_name = etk::tolower(m_name); m_name = etk::tolower(m_name);
} }
// count white space : // count white space :
exml::filePos tmpPos; exml::FilePos tmpPos;
int32_t white = countWhiteChar(_data, lastElementName+1, tmpPos); int32_t white = countWhiteChar(_data, lastElementName+1, tmpPos);
_filePos += tmpPos; _filePos += tmpPos;
if (lastElementName+white+1 >= _data.size()) { if (lastElementName+white+1 >= _data.size()) {

View File

@ -13,25 +13,22 @@
namespace exml { namespace exml {
class Attribute : public exml::Node { class Attribute : public exml::Node {
protected: protected:
/**
* @brief Constructor
*/
Attribute() { };
/** /**
* @brief Constructor * @brief Constructor
* @param[in] _name Name of the attribute. * @param[in] _name Name of the attribute.
* @param[in] _value Value of the attribute. * @param[in] _value Value of the attribute.
*/ */
Attribute(const std::string& _name, const std::string& _value); Attribute(const std::string& _name="", const std::string& _value="");
public: public:
static std::shared_ptr<Attribute> create();
static std::shared_ptr<Attribute> create(const std::string& _name, const std::string& _value);
/** /**
* @brief Destructor * @brief defined factory
* @param[in] _name Name of the attribute
* @param[in] _value Value of the attribute
* @return Shared pointer on the Attribute element
*/ */
virtual ~Attribute() { }; static ememory::SharedPtr<Attribute> create(const std::string& _name="", const std::string& _value="");
protected: protected:
std::string m_name; std::string m_name; //!< Name of the attribute
public: public:
/** /**
* @brief set the name of the attribute * @brief set the name of the attribute
@ -47,19 +44,19 @@ namespace exml {
virtual const std::string& getName() const { virtual const std::string& getName() const {
return m_name; return m_name;
}; };
public: // herited function: public:
virtual enum nodeType getType() const { enum nodeType getType() const override {
return exml::typeAttribute; return exml::typeAttribute;
}; };
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc); bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override;
virtual bool iGenerate(std::string& _data, int32_t _indent) const; bool iGenerate(std::string& _data, int32_t _indent) const override;
virtual std::shared_ptr<exml::Attribute> toAttribute() { ememory::SharedPtr<exml::Attribute> toAttribute() override {
return std::static_pointer_cast<exml::Attribute>(shared_from_this()); return std::static_pointer_cast<exml::Attribute>(shared_from_this());
}; };
virtual std::shared_ptr<const exml::Attribute> toAttribute() const { ememory::SharedPtr<const exml::Attribute> toAttribute() const override {
return std::static_pointer_cast<const exml::Attribute>(shared_from_this()); return std::static_pointer_cast<const exml::Attribute>(shared_from_this());
}; };
virtual void clear(); void clear() override;
}; };
} }

View File

@ -9,21 +9,14 @@
#include <exml/AttributeList.h> #include <exml/AttributeList.h>
#include <exml/debug.h> #include <exml/debug.h>
#undef __class__ ememory::SharedPtr<exml::Attribute> exml::AttributeList::getAttr(int32_t _id) {
#define __class__ "AttributeList"
exml::AttributeList::~AttributeList() {
m_listAttribute.clear();
}
std::shared_ptr<exml::Attribute> exml::AttributeList::getAttr(int32_t _id) {
if (_id <0 || (size_t)_id>m_listAttribute.size()) { if (_id <0 || (size_t)_id>m_listAttribute.size()) {
return nullptr; return nullptr;
} }
return m_listAttribute[_id]; return m_listAttribute[_id];
} }
std::shared_ptr<const exml::Attribute> exml::AttributeList::getAttr(int32_t _id) const { ememory::SharedPtr<const exml::Attribute> exml::AttributeList::getAttr(int32_t _id) const {
if (_id <0 || (size_t)_id>m_listAttribute.size()) { if (_id <0 || (size_t)_id>m_listAttribute.size()) {
return nullptr; return nullptr;
} }
@ -31,7 +24,7 @@ std::shared_ptr<const exml::Attribute> exml::AttributeList::getAttr(int32_t _id)
} }
std::pair<std::string, std::string> exml::AttributeList::getAttrPair(int32_t _id) const { std::pair<std::string, std::string> exml::AttributeList::getAttrPair(int32_t _id) const {
std::shared_ptr<const exml::Attribute> att = getAttr(_id); ememory::SharedPtr<const exml::Attribute> att = getAttr(_id);
if (att == nullptr) { if (att == nullptr) {
return std::make_pair<std::string, std::string>("",""); return std::make_pair<std::string, std::string>("","");
} }
@ -39,7 +32,7 @@ std::pair<std::string, std::string> exml::AttributeList::getAttrPair(int32_t _id
} }
void exml::AttributeList::appendAttribute(const std::shared_ptr<exml::Attribute>& _attr) { void exml::AttributeList::appendAttribute(const ememory::SharedPtr<exml::Attribute>& _attr) {
if (_attr == nullptr) { if (_attr == nullptr) {
EXML_ERROR("Try to set an empty node"); EXML_ERROR("Try to set an empty node");
return; return;
@ -110,7 +103,7 @@ void exml::AttributeList::setAttribute(const std::string& _name, const std::stri
return; return;
} }
} }
std::shared_ptr<exml::Attribute> attr = exml::Attribute::create(_name, _value); ememory::SharedPtr<exml::Attribute> attr = exml::Attribute::create(_name, _value);
if (attr == nullptr) { if (attr == nullptr) {
EXML_ERROR("memory allocation error..."); EXML_ERROR("memory allocation error...");
} }

View File

@ -15,25 +15,16 @@
namespace exml { namespace exml {
class AttributeList : public exml::Node { class AttributeList : public exml::Node {
protected: protected:
/**
* @brief Constructor
*/
AttributeList() { };
/** /**
* @brief Constructor * @brief Constructor
* @param[in] _value Node value; * @param[in] _value Node value;
*/ */
AttributeList(const std::string& _value) : AttributeList(const std::string& _value="") :
exml::Node(_value) { exml::Node(_value) {
}; };
public:
/**
* @brief Destructor
*/
virtual ~AttributeList();
protected: protected:
std::vector<std::shared_ptr<exml::Attribute>> m_listAttribute; //!< list of all attribute std::vector<ememory::SharedPtr<exml::Attribute>> m_listAttribute; //!< list of all attribute
public: public:
/** /**
* @brief get the number of attribute in the Node * @brief get the number of attribute in the Node
@ -46,14 +37,24 @@ namespace exml {
* @brief add attribute on the List * @brief add attribute on the List
* @param[in] _attr Pointer on the attribute * @param[in] _attr Pointer on the attribute
*/ */
void appendAttribute(const std::shared_ptr<exml::Attribute>& _attr); void appendAttribute(const ememory::SharedPtr<exml::Attribute>& _attr);
/** /**
* @brief get attribute whith his ID * @brief get attribute whith his ID
* @param[in] _id Identifier of the attribute 0<= _id < sizeAttribute() * @param[in] _id Identifier of the attribute 0<= _id < sizeAttribute()
* @return Pointer on the attribute or NULL * @return Pointer on the attribute or NULL
*/ */
std::shared_ptr<Attribute> getAttr(int32_t _id); ememory::SharedPtr<Attribute> getAttr(int32_t _id);
std::shared_ptr<const Attribute> getAttr(int32_t _id) const; /**
* @brief get attribute whith his ID
* @param[in] _id Identifier of the attribute 0<= _id < sizeAttribute()
* @return Pointer on the attribute or NULL
*/
ememory::SharedPtr<const Attribute> getAttr(int32_t _id) const;
/**
* @brief get attribute whith his ID
* @param[in] _id Identifier of the attribute 0<= _id < sizeAttribute()
* @return Name and value of the attribute
*/
std::pair<std::string, std::string> getAttrPair(int32_t _id) const; std::pair<std::string, std::string> getAttrPair(int32_t _id) const;
/** /**
* @brief get the attribute value with searching in the List with his name * @brief get the attribute value with searching in the List with his name
@ -80,9 +81,9 @@ namespace exml {
* @return false An error occured. * @return false An error occured.
*/ */
bool removeAttribute(const std::string& _name); bool removeAttribute(const std::string& _name);
public: // herited function: public:
bool iGenerate(std::string& _data, int32_t _indent) const; bool iGenerate(std::string& _data, int32_t _indent) const override;
virtual void clear(); void clear() override;
}; };
} }

View File

@ -10,10 +10,6 @@
#include <exml/debug.h> #include <exml/debug.h>
#include <exml/Document.h> #include <exml/Document.h>
#undef __class__
#define __class__ "Comment"
static bool isWhiteChar(char32_t _val) { static bool isWhiteChar(char32_t _val) {
if( _val == ' ' if( _val == ' '
|| _val == '\t' || _val == '\t'
@ -24,14 +20,14 @@ static bool isWhiteChar(char32_t _val) {
return false; return false;
} }
std::shared_ptr<exml::Comment> exml::Comment::create() { ememory::SharedPtr<exml::Comment> exml::Comment::create() {
return std::shared_ptr<exml::Comment>(new exml::Comment()); return ememory::SharedPtr<exml::Comment>(new exml::Comment());
} }
bool exml::Comment::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) { bool exml::Comment::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'comment'"); EXML_VERBOSE("start parse : 'comment'");
m_pos = _filePos; m_pos = _filePos;
exml::filePos tmpPos; exml::FilePos tmpPos;
int32_t white = countWhiteChar(_data, _pos, tmpPos); int32_t white = countWhiteChar(_data, _pos, tmpPos);
_filePos += tmpPos; _filePos += tmpPos;
// search end of the comment : // search end of the comment :

View File

@ -18,7 +18,11 @@ namespace exml {
*/ */
Comment() { }; Comment() { };
public: public:
static std::shared_ptr<Comment> create(); /**
* @brief defined factory
* @return Shared pointer on the Comment element
*/
static ememory::SharedPtr<exml::Comment> create();
/** /**
* @brief Constructor * @brief Constructor
* @param[in] _value comment value * @param[in] _value comment value
@ -27,20 +31,16 @@ namespace exml {
exml::Node(_value) { exml::Node(_value) {
}; };
/** public:
* @brief Destructor enum nodeType getType() const override {
*/
virtual ~Comment() { };
public: // herited function:
virtual enum nodeType getType() const {
return typeAttribute; return typeAttribute;
}; };
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc); bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override;
virtual bool iGenerate(std::string& _data, int32_t _indent) const; bool iGenerate(std::string& _data, int32_t _indent) const override;
virtual std::shared_ptr<exml::Comment> toComment() { ememory::SharedPtr<exml::Comment> toComment() override {
return std::static_pointer_cast<exml::Comment>(shared_from_this()); return std::static_pointer_cast<exml::Comment>(shared_from_this());
}; };
virtual std::shared_ptr<const exml::Comment> toComment() const { ememory::SharedPtr<const exml::Comment> toComment() const override {
return std::static_pointer_cast<const exml::Comment>(shared_from_this()); return std::static_pointer_cast<const exml::Comment>(shared_from_this());
}; };
}; };

View File

@ -10,9 +10,6 @@
#include <exml/debug.h> #include <exml/debug.h>
#include <exml/Document.h> #include <exml/Document.h>
#undef __class__
#define __class__ "Declaration"
/* basic declaration have 3 attributes: /* basic declaration have 3 attributes:
version version
encoding encoding
@ -20,17 +17,12 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
*/ */
ememory::SharedPtr<exml::Declaration> exml::Declaration::create(const std::string& _name) {
std::shared_ptr<exml::Declaration> exml::Declaration::create() { return ememory::SharedPtr<exml::Declaration>(new exml::Declaration(_name));
return std::shared_ptr<exml::Declaration>(new exml::Declaration());
} }
std::shared_ptr<exml::Declaration> exml::Declaration::create(const std::string& _name) { ememory::SharedPtr<exml::DeclarationXML> exml::DeclarationXML::create(const std::string& _version, const std::string& _format, bool _standalone) {
return std::shared_ptr<exml::Declaration>(new exml::Declaration(_name)); return ememory::SharedPtr<exml::DeclarationXML>(new exml::DeclarationXML(_version, _format, _standalone));
}
std::shared_ptr<exml::DeclarationXML> exml::DeclarationXML::create(const std::string& _version, const std::string& _format, bool _standalone) {
return std::shared_ptr<exml::DeclarationXML>(new exml::DeclarationXML(_version, _format, _standalone));
} }
exml::DeclarationXML::DeclarationXML(const std::string& _version, const std::string& _format, bool _standalone) : exml::DeclarationXML::DeclarationXML(const std::string& _version, const std::string& _format, bool _standalone) :
@ -60,7 +52,7 @@ bool exml::Declaration::iGenerate(std::string& _data, int32_t _indent) const {
return true; return true;
} }
bool exml::Declaration::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) { bool exml::Declaration::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'declaration' : '" << m_value << "'"); EXML_VERBOSE("start parse : 'declaration' : '" << m_value << "'");
m_pos = _filePos; m_pos = _filePos;
// search end of the comment : // search end of the comment :
@ -86,7 +78,7 @@ bool exml::Declaration::iParse(const std::string& _data, int32_t& _pos, bool _ca
} }
if (checkAvaillable(_data[iii], true) == true) { if (checkAvaillable(_data[iii], true) == true) {
// we find an attibute == > create a new and parse it : // we find an attibute == > create a new and parse it :
std::shared_ptr<exml::Attribute> attribute = exml::Attribute::create(); ememory::SharedPtr<exml::Attribute> attribute = exml::Attribute::create();
if (attribute == nullptr) { if (attribute == nullptr) {
CREATE_ERROR(_doc, _data, _pos, _filePos, " Allocation error ..."); CREATE_ERROR(_doc, _data, _pos, _filePos, " Allocation error ...");
return false; return false;

View File

@ -12,35 +12,31 @@
namespace exml { namespace exml {
class Declaration : public exml::AttributeList { class Declaration : public exml::AttributeList {
protected: protected:
/**
* @brief Constructor
*/
Declaration() { };
/** /**
* @brief Constructor * @brief Constructor
* @param[in] _name name of the declaration (xml, xml:xxxx ...) * @param[in] _name name of the declaration (xml, xml:xxxx ...)
*/ */
Declaration(const std::string& _name) : Declaration(const std::string& _name="") :
exml::AttributeList(_name) { exml::AttributeList(_name) {
}; };
public: public:
static std::shared_ptr<Declaration> create();
static std::shared_ptr<Declaration> create(const std::string& _name);
/** /**
* @brief Destructor * @brief Factory to create declaration
* @param[in] _name name of the declaration (xml, xml:xxxx ...)
* @return a structure declaration
*/ */
virtual ~Declaration() { }; static ememory::SharedPtr<Declaration> create(const std::string& _name="");
public: // herited function: public:
virtual enum nodeType getType() const { enum nodeType getType() const override{
return typeAttribute; return typeAttribute;
}; };
virtual bool iGenerate(std::string& _data, int32_t _indent) const; bool iGenerate(std::string& _data, int32_t _indent) const override;
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc); bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override;
virtual std::shared_ptr<exml::Declaration> toDeclaration() { ememory::SharedPtr<exml::Declaration> toDeclaration() override {
return std::static_pointer_cast<exml::Declaration>(shared_from_this()); return std::static_pointer_cast<exml::Declaration>(shared_from_this());
}; };
virtual std::shared_ptr<const exml::Declaration> toDeclaration() const { ememory::SharedPtr<const exml::Declaration> toDeclaration() const override {
return std::static_pointer_cast<const exml::Declaration>(shared_from_this()); return std::static_pointer_cast<const exml::Declaration>(shared_from_this());
}; };
}; };
@ -54,11 +50,14 @@ namespace exml {
*/ */
DeclarationXML(const std::string& _version, const std::string& _format = "UTF-8", bool _standalone = true); DeclarationXML(const std::string& _version, const std::string& _format = "UTF-8", bool _standalone = true);
public: public:
static std::shared_ptr<DeclarationXML> create(const std::string& _version, const std::string& _format = "UTF-8", bool _standalone = true);
/** /**
* @brief Destructor * @brief Factory to create XML declaration
* @param[in] _version Xml version.
* @param[in] _format charset of the XML
* @param[in] _standalone this document is standalone
* @return a structure declaration
*/ */
virtual ~DeclarationXML() { }; static ememory::SharedPtr<DeclarationXML> create(const std::string& _version, const std::string& _format = "UTF-8", bool _standalone = true);
}; };
} }

View File

@ -10,12 +10,8 @@
#include <exml/debug.h> #include <exml/debug.h>
#include <etk/os/FSNode.h> #include <etk/os/FSNode.h>
#undef __class__ ememory::SharedPtr<exml::Document> exml::Document::create() {
#define __class__ "Document" return ememory::SharedPtr<exml::Document>(new exml::Document());
std::shared_ptr<exml::Document> exml::Document::create() {
return std::shared_ptr<exml::Document>(new exml::Document());
} }
exml::Document::Document() : exml::Document::Document() :
@ -41,7 +37,7 @@ bool exml::Document::parse(const std::string& _data) {
EXML_VERBOSE("Start parsing document (type: string) size=" << _data.size()); EXML_VERBOSE("Start parsing document (type: string) size=" << _data.size());
clear(); clear();
// came from char == > force in utf8 ... // came from char == > force in utf8 ...
exml::filePos filePos(1,0); exml::FilePos filePos(1,0);
m_pos = filePos; m_pos = filePos;
int32_t parsePos = 0; int32_t parsePos = 0;
return subParse(_data, parsePos, m_caseSensitive, filePos, *this, true); return subParse(_data, parsePos, m_caseSensitive, filePos, *this, true);
@ -142,7 +138,7 @@ void exml::Document::displayError() {
#endif #endif
} }
void exml::Document::createError(const std::string& _data, int32_t _pos, const exml::filePos& _filePos, const std::string& _comment) { void exml::Document::createError(const std::string& _data, int32_t _pos, const exml::FilePos& _filePos, const std::string& _comment) {
m_comment = _comment; m_comment = _comment;
m_Line = etk::extract_line(_data, _pos); m_Line = etk::extract_line(_data, _pos);
m_filePos = _filePos; m_filePos = _filePos;

View File

@ -17,13 +17,13 @@ namespace exml {
* @brief Constructor * @brief Constructor
*/ */
Document(); Document();
static std::shared_ptr<Document> create();
/** /**
* @brief Destructor * @brief Factory on a document
* @return an local created xml document
*/ */
virtual ~Document() { }; static ememory::SharedPtr<Document> create();
private: private:
bool m_caseSensitive; // check the case sensitive of the nodes and attribute bool m_caseSensitive; //!< check the case sensitive of the nodes and attribute
public: public:
/** /**
* @brief Enable or diasable the case sensitive (must be done before the call of parsing) * @brief Enable or diasable the case sensitive (must be done before the call of parsing)
@ -73,10 +73,10 @@ namespace exml {
*/ */
void display(); void display();
private: private:
bool m_writeErrorWhenDetexted; bool m_writeErrorWhenDetexted; //!< Request print error in parsing just when detected
std::string m_comment; std::string m_comment; //!< Comment on the error
std::string m_Line; std::string m_Line; //!< Parse line error (copy)
exml::filePos m_filePos; exml::FilePos m_filePos; //!< position of the error
public: public:
void displayErrorWhenDetected() { void displayErrorWhenDetected() {
m_writeErrorWhenDetexted = true; m_writeErrorWhenDetexted = true;
@ -85,33 +85,24 @@ namespace exml {
m_writeErrorWhenDetexted = false; m_writeErrorWhenDetexted = false;
}; };
void createError(const std::string& _data, int32_t _pos, const exml::filePos& _filePos, const std::string& _comment); void createError(const std::string& _data, int32_t _pos, const exml::FilePos& _filePos, const std::string& _comment);
void displayError(); void displayError();
public: // herited function: public:
virtual enum nodeType getType() const { enum nodeType getType() const override {
return typeDocument; return typeDocument;
}; };
bool iGenerate(std::string& _data, int32_t _indent) const; bool iGenerate(std::string& _data, int32_t _indent) const override;
virtual std::shared_ptr<exml::Document> toDocument() { ememory::SharedPtr<exml::Document> toDocument() override {
return std::static_pointer_cast<exml::Document>(shared_from_this()); return std::static_pointer_cast<exml::Document>(shared_from_this());
}; };
virtual std::shared_ptr<const exml::Document> toDocument() const { ememory::SharedPtr<const exml::Document> toDocument() const override {
return std::static_pointer_cast<const exml::Document>(shared_from_this()); return std::static_pointer_cast<const exml::Document>(shared_from_this());
}; };
}; };
}; };
/*
#define CREATE_ERROR(doc,data,pos,filePos,comment) \
EXML_ERROR( (pos) << " " << (comment) << "\n" \
<< (data).ExtractLine((pos)) << "\n" \
<< CreatePosPointer((filePos).getCol()) )
*/
#define CREATE_ERROR(doc,data,pos,filePos,comment) \ #define CREATE_ERROR(doc,data,pos,filePos,comment) \
do { \ do { \
EXML_ERROR(comment); \ EXML_ERROR(comment); \
(doc).createError((data),(pos),(filePos),(comment)); \ (doc).createError((data),(pos),(filePos),(comment)); \
} while (0) } while (0)
//__LINE__, __class__, __func__

View File

@ -14,10 +14,6 @@
#include <exml/Declaration.h> #include <exml/Declaration.h>
#include <exml/Document.h> #include <exml/Document.h>
#undef __class__
#define __class__ "Element"
static bool isWhiteChar(char32_t _val) { static bool isWhiteChar(char32_t _val) {
if( _val == ' ' if( _val == ' '
|| _val == '\t' || _val == '\t'
@ -28,41 +24,29 @@ static bool isWhiteChar(char32_t _val) {
return false; return false;
} }
std::shared_ptr<exml::Element> exml::Element::create() { ememory::SharedPtr<exml::Element> exml::Element::create() {
return std::shared_ptr<exml::Element>(new exml::Element()); return ememory::SharedPtr<exml::Element>(new exml::Element());
} }
std::shared_ptr<exml::Element> exml::Element::create(const std::string& _value) { ememory::SharedPtr<exml::Element> exml::Element::create(const std::string& _value) {
return std::shared_ptr<exml::Element>(new exml::Element(_value)); return ememory::SharedPtr<exml::Element>(new exml::Element(_value));
} }
enum exml::nodeType exml::Element::getType(int32_t _id) const {
exml::Element::~Element() { ememory::SharedPtr<const exml::Node> tmpp = getNode(_id);
m_listSub.clear();
}
enum exml::nodeType exml::Element::getType(int32_t _id) {
std::shared_ptr<exml::Node> tmpp = getNode(_id);
if (tmpp == nullptr) {
return exml::typeUnknow;
}
return tmpp->getType();
}
const enum exml::nodeType exml::Element::getType(int32_t _id) const {
std::shared_ptr<const exml::Node> tmpp = getNode(_id);
if (tmpp == nullptr) { if (tmpp == nullptr) {
return exml::typeUnknow; return exml::typeUnknow;
} }
return tmpp->getType(); return tmpp->getType();
} }
std::shared_ptr<exml::Node> exml::Element::getNode(int32_t _id) { ememory::SharedPtr<exml::Node> exml::Element::getNode(int32_t _id) {
if (_id <0 || (size_t)_id>m_listSub.size()) { if (_id <0 || (size_t)_id>m_listSub.size()) {
return nullptr; return nullptr;
} }
return m_listSub[_id]; return m_listSub[_id];
} }
std::shared_ptr<const exml::Node> exml::Element::getNode(int32_t _id) const { ememory::SharedPtr<const exml::Node> exml::Element::getNode(int32_t _id) const {
if (_id <0 || (size_t)_id>m_listSub.size()) { if (_id <0 || (size_t)_id>m_listSub.size()) {
return nullptr; return nullptr;
} }
@ -70,23 +54,23 @@ std::shared_ptr<const exml::Node> exml::Element::getNode(int32_t _id) const {
} }
std::shared_ptr<exml::Element> exml::Element::getElement(int32_t _id) { ememory::SharedPtr<exml::Element> exml::Element::getElement(int32_t _id) {
std::shared_ptr<exml::Node> tmpp = getNode(_id); ememory::SharedPtr<exml::Node> tmpp = getNode(_id);
if (tmpp == nullptr) { if (tmpp == nullptr) {
return nullptr; return nullptr;
} }
return tmpp->toElement(); return tmpp->toElement();
} }
std::shared_ptr<const exml::Element> exml::Element::getElement(int32_t _id) const { ememory::SharedPtr<const exml::Element> exml::Element::getElement(int32_t _id) const {
std::shared_ptr<const exml::Node> tmpp = getNode(_id); ememory::SharedPtr<const exml::Node> tmpp = getNode(_id);
if (tmpp == nullptr) { if (tmpp == nullptr) {
return nullptr; return nullptr;
} }
return tmpp->toElement(); return tmpp->toElement();
} }
std::shared_ptr<exml::Element> exml::Element::getNamed(const std::string& _name) { ememory::SharedPtr<exml::Element> exml::Element::getNamed(const std::string& _name) {
if (_name.size() == 0) { if (_name.size() == 0) {
return nullptr; return nullptr;
} }
@ -103,7 +87,7 @@ std::shared_ptr<exml::Element> exml::Element::getNamed(const std::string& _name)
return nullptr; return nullptr;
} }
std::shared_ptr<const exml::Element> exml::Element::getNamed(const std::string& _name) const { ememory::SharedPtr<const exml::Element> exml::Element::getNamed(const std::string& _name) const {
if (_name.size() == 0) { if (_name.size() == 0) {
return nullptr; return nullptr;
} }
@ -120,7 +104,7 @@ std::shared_ptr<const exml::Element> exml::Element::getNamed(const std::string&
return nullptr; return nullptr;
} }
void exml::Element::append(const std::shared_ptr<exml::Node>& _node) { void exml::Element::append(const ememory::SharedPtr<exml::Node>& _node) {
if (_node == nullptr) { if (_node == nullptr) {
EXML_ERROR("Try to set an empty node"); EXML_ERROR("Try to set an empty node");
return; return;
@ -190,14 +174,14 @@ bool exml::Element::iGenerate(std::string& _data, int32_t _indent) const {
} }
bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc, bool _mainNode) { bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc, bool _mainNode) {
EXML_PARSE_ELEMENT(" start subParse ... " << _pos << " " << _filePos); EXML_PARSE_ELEMENT(" start subParse ... " << _pos << " " << _filePos);
for (size_t iii=_pos; iii<_data.size(); iii++) { for (size_t iii=_pos; iii<_data.size(); iii++) {
_filePos.check(_data[iii]); _filePos.check(_data[iii]);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT #ifdef ENABLE_DISPLAY_PARSED_ELEMENT
drawElementParsed(_data[iii], _filePos); drawElementParsed(_data[iii], _filePos);
#endif #endif
exml::filePos tmpPos; exml::FilePos tmpPos;
if (_data[iii] == '<') { if (_data[iii] == '<') {
int32_t white = countWhiteChar(_data, iii+1, tmpPos); int32_t white = countWhiteChar(_data, iii+1, tmpPos);
if (iii+white+1>=_data.size()) { if (iii+white+1>=_data.size()) {
@ -238,7 +222,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
tmpname = etk::tolower(tmpname); tmpname = etk::tolower(tmpname);
} }
// Find declaration balise // Find declaration balise
std::shared_ptr<exml::Declaration> declaration = exml::Declaration::create(tmpname); ememory::SharedPtr<exml::Declaration> declaration = exml::Declaration::create(tmpname);
if (declaration == nullptr) { if (declaration == nullptr) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation Error..."); CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation Error...");
return false; return false;
@ -271,7 +255,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
} }
++tmpPos; ++tmpPos;
// find comment: // find comment:
std::shared_ptr<exml::Comment> comment = exml::Comment::create(); ememory::SharedPtr<exml::Comment> comment = exml::Comment::create();
if (comment == nullptr) { if (comment == nullptr) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ..."); CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
return false; return false;
@ -300,7 +284,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
} }
tmpPos+=6; tmpPos+=6;
// find text: // find text:
std::shared_ptr<exml::TextCDATA> text = exml::TextCDATA::create(); ememory::SharedPtr<exml::TextCDATA> text = exml::TextCDATA::create();
if (text == nullptr) { if (text == nullptr) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ..."); CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
return false; return false;
@ -389,7 +373,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
} }
//EXML_INFO("find node named : '" << tmpname << "'"); //EXML_INFO("find node named : '" << tmpname << "'");
// find text: // find text:
std::shared_ptr<exml::Element> element = exml::Element::create(tmpname); ememory::SharedPtr<exml::Element> element = exml::Element::create(tmpname);
if (element == nullptr) { if (element == nullptr) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ..."); CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
return false; return false;
@ -420,7 +404,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
// empty spaces == > nothing to do .... // empty spaces == > nothing to do ....
} else { } else {
// find data == > parse it... // find data == > parse it...
std::shared_ptr<exml::Text> text = exml::Text::create(); ememory::SharedPtr<exml::Text> text = exml::Text::create();
if (text == nullptr) { if (text == nullptr) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ..."); CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
return false; return false;
@ -442,7 +426,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
return false; return false;
} }
bool exml::Element::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) { bool exml::Element::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) {
EXML_PARSE_ELEMENT("start parse : 'element' named='" << m_value << "'"); EXML_PARSE_ELEMENT("start parse : 'element' named='" << m_value << "'");
// note : When start parsing the upper element must have set the value of the element and set the position after this one // note : When start parsing the upper element must have set the value of the element and set the position after this one
m_pos=_filePos; m_pos=_filePos;
@ -474,7 +458,7 @@ bool exml::Element::iParse(const std::string& _data, int32_t& _pos, bool _caseSe
} }
if (checkAvaillable(_data[iii], true) == true) { if (checkAvaillable(_data[iii], true) == true) {
// we find an attibute == > create a new and parse it : // we find an attibute == > create a new and parse it :
std::shared_ptr<exml::Attribute> attribute = exml::Attribute::create(); ememory::SharedPtr<exml::Attribute> attribute = exml::Attribute::create();
if (attribute == nullptr) { if (attribute == nullptr) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ..."); CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
return false; return false;

View File

@ -27,14 +27,10 @@ namespace exml {
}; };
public: public:
static std::shared_ptr<Element> create(); static ememory::SharedPtr<Element> create();
static std::shared_ptr<Element> create(const std::string& _value); static ememory::SharedPtr<Element> create(const std::string& _value);
/**
* @brief Destructor
*/
virtual ~Element();
protected: protected:
std::vector<std::shared_ptr<exml::Node>> m_listSub; std::vector<ememory::SharedPtr<exml::Node>> m_listSub; //!< List of subNodes
public: public:
/** /**
* @brief get the number of sub element in the node (can be exml::Comment ; exml::Element ; exml::Text :exml::Declaration). * @brief get the number of sub element in the node (can be exml::Comment ; exml::Element ; exml::Text :exml::Declaration).
@ -47,55 +43,54 @@ namespace exml {
* @brief add a node at the element (not exml::Attribute (move in the attribute automaticly). * @brief add a node at the element (not exml::Attribute (move in the attribute automaticly).
* @param[in] _node Pointer of the node to add. * @param[in] _node Pointer of the node to add.
*/ */
void append(const std::shared_ptr<exml::Node>& _node); void append(const ememory::SharedPtr<exml::Node>& _node);
/** /**
* @brief get the type of the element id. * @brief get the type of the element id.
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @return the Current type of the element or exml::typeUnknow. * @return the Current type of the element or exml::typeUnknow.
*/ */
enum nodeType getType(int32_t _id); enum nodeType getType(int32_t _id) const;
const enum nodeType getType(int32_t _id) const;
/** /**
* @brief get the Node pointer of the element id. * @brief get the Node pointer of the element id.
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @return Pointer on node. * @return Pointer on node.
*/ */
std::shared_ptr<Node> getNode(int32_t _id); ememory::SharedPtr<Node> getNode(int32_t _id);
std::shared_ptr<const Node> getNode(int32_t _id) const; ememory::SharedPtr<const Node> getNode(int32_t _id) const;
/** /**
* @brief get the element casted in Element (if the node is not an element return NULL). * @brief get the element casted in Element (if the node is not an element return NULL).
* @param[in] _id Id of the element. * @param[in] _id Id of the element.
* @return Pointer on the element or NULL. * @return Pointer on the element or NULL.
*/ */
std::shared_ptr<Element> getElement(int32_t _id); ememory::SharedPtr<Element> getElement(int32_t _id);
std::shared_ptr<const Element> getElement(int32_t _id) const; ememory::SharedPtr<const Element> getElement(int32_t _id) const;
/** /**
* @brief get an element with his name (work only with exml::Element) * @brief get an element with his name (work only with exml::Element)
* @param[in] _name Name of the element that is requested * @param[in] _name Name of the element that is requested
* @return Pointer on the element or NULL. * @return Pointer on the element or NULL.
*/ */
std::shared_ptr<Element> getNamed(const std::string& _name); ememory::SharedPtr<Element> getNamed(const std::string& _name);
std::shared_ptr<const Element> getNamed(const std::string& _name) const; ememory::SharedPtr<const Element> getNamed(const std::string& _name) const;
/** /**
* @brief get the internal data of the element (if the element has some sub node thay are converted in xml string == > like this it is not needed to use <![CDATA[...]]> * @brief get the internal data of the element (if the element has some sub node thay are converted in xml string == > like this it is not needed to use <![CDATA[...]]>
* @return the curent data string. if Only one text node, then we get the parssed data (no &amp; ...) if more than one node, then we transform &,",',<,> in xml normal text... * @return the curent data string. if Only one text node, then we get the parssed data (no &amp; ...) if more than one node, then we transform &,",',<,> in xml normal text...
*/ */
std::string getText() const; std::string getText() const;
protected: protected:
bool subParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc, bool _mainNode=false); bool subParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc, bool _mainNode=false);
public: // herited function: public: // herited function:
virtual enum nodeType getType() const { enum nodeType getType() const override {
return typeElement; return typeElement;
}; }
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc); bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override;
virtual bool iGenerate(std::string& _data, int32_t _indent) const; bool iGenerate(std::string& _data, int32_t _indent) const override;
virtual std::shared_ptr<exml::Element> toElement() { ememory::SharedPtr<exml::Element> toElement() override {
return std::static_pointer_cast<exml::Element>(shared_from_this()); return std::static_pointer_cast<exml::Element>(shared_from_this());
}; }
virtual std::shared_ptr<const exml::Element> toElement() const { ememory::SharedPtr<const exml::Element> toElement() const override {
return std::static_pointer_cast<const exml::Element>(shared_from_this()); return std::static_pointer_cast<const exml::Element>(shared_from_this());
}; }
virtual void clear(); void clear() override;
}; };
} }

View File

@ -9,9 +9,6 @@
#include <exml/Node.h> #include <exml/Node.h>
#include <exml/debug.h> #include <exml/debug.h>
#undef __class__
#define __class__ "Node"
static bool isWhiteChar(char32_t _val) { static bool isWhiteChar(char32_t _val) {
if( _val == ' ' if( _val == ' '
|| _val == '\t' || _val == '\t'
@ -22,15 +19,6 @@ static bool isWhiteChar(char32_t _val) {
return false; return false;
} }
std::ostream& exml::operator <<(std::ostream& _os, const exml::filePos& _obj) {
_os << "(l=";
_os << _obj.getLine();
_os << ",c=";
_os << _obj.getCol();
_os << ")";
return _os;
}
exml::Node::Node(const std::string& _value) : exml::Node::Node(const std::string& _value) :
m_pos(0,0), m_pos(0,0),
m_value(_value) { m_value(_value) {
@ -44,7 +32,7 @@ void exml::Node::addIndent(std::string& _data, int32_t _indent) const {
} }
} }
void exml::Node::drawElementParsed(char32_t _val, const exml::filePos& _filePos) const { void exml::Node::drawElementParsed(char32_t _val, const exml::FilePos& _filePos) const {
if (_val == '\n') { if (_val == '\n') {
EXML_DEBUG(_filePos << " parse '\\n'"); EXML_DEBUG(_filePos << " parse '\\n'");
} else if (_val == '\t') { } else if (_val == '\t') {
@ -101,7 +89,7 @@ bool exml::Node::checkAvaillable(char32_t _val, bool _firstChar) const {
} }
int32_t exml::Node::countWhiteChar(const std::string& _data, int32_t _pos, exml::filePos& _filePos) const { int32_t exml::Node::countWhiteChar(const std::string& _data, int32_t _pos, exml::FilePos& _filePos) const {
_filePos.clear(); _filePos.clear();
int32_t white=0; int32_t white=0;
for (size_t iii=_pos; iii<_data.size(); iii++) { for (size_t iii=_pos; iii<_data.size(); iii++) {
@ -116,8 +104,100 @@ int32_t exml::Node::countWhiteChar(const std::string& _data, int32_t _pos, exml:
return white; return white;
} }
bool exml::Node::iGenerate(std::string& _data, int32_t _indent) const {
return true;
}
const exml::FilePos& exml::Node::getPos() const {
return m_pos;
}
void exml::Node::clear() { void exml::Node::clear() {
m_value = ""; m_value = "";
m_pos.clear(); m_pos.clear();
} }
void exml::Node::setValue(std::string _value) {
m_value = _value;
}
const std::string& exml::Node::getValue() const {
return m_value;
}
enum exml::nodeType exml::Node::getType() const {
return typeNode;
}
ememory::SharedPtr<exml::Document> exml::Node::toDocument() {
return nullptr;
}
ememory::SharedPtr<const exml::Document> exml::Node::toDocument() const {
return nullptr;
}
ememory::SharedPtr<exml::Attribute> exml::Node::toAttribute() {
return nullptr;
}
ememory::SharedPtr<const exml::Attribute> exml::Node::toAttribute() const {
return nullptr;
}
ememory::SharedPtr<exml::Comment> exml::Node::toComment() {
return nullptr;
}
ememory::SharedPtr<const exml::Comment> exml::Node::toComment() const {
return nullptr;
}
ememory::SharedPtr<exml::Declaration> exml::Node::toDeclaration() {
return nullptr;
}
ememory::SharedPtr<const exml::Declaration> exml::Node::toDeclaration() const {
return nullptr;
}
ememory::SharedPtr<exml::Element> exml::Node::toElement() {
return nullptr;
}
ememory::SharedPtr<const exml::Element> exml::Node::toElement() const {
return nullptr;
}
ememory::SharedPtr<exml::Text> exml::Node::toText() {
return nullptr;
}
ememory::SharedPtr<const exml::Text> exml::Node::toText() const{
return nullptr;
}
bool exml::Node::isDocument() const {
return getType() == exml::typeDocument;
}
bool exml::Node::isAttribute() const {
return getType() == exml::typeAttribute;
}
bool exml::Node::isComment() const {
return getType() == exml::typeComment;
}
bool exml::Node::isDeclaration() const {
return getType() == exml::typeDeclaration;
}
bool exml::Node::isElement() const {
return getType() == exml::typeElement;
}
bool exml::Node::isText() const {
return getType() == exml::typeText;
}

View File

@ -7,10 +7,14 @@
*/ */
#pragma once #pragma once
#include <memory> #include <ememory/memory.h>
#include <etk/types.h> #include <etk/types.h>
#include <etk/math/Vector2D.h> #include <etk/math/Vector2D.h>
#include <exml/FilePos.h>
/**
* @brief exml namespace containing all function for XML interpretor
*/
namespace exml { namespace exml {
//#define ENABLE_DISPLAY_PARSED_ELEMENT //#define ENABLE_DISPLAY_PARSED_ELEMENT
//#define ENABLE_CRITICAL_WHEN_ERROR //#define ENABLE_CRITICAL_WHEN_ERROR
@ -41,82 +45,10 @@ namespace exml {
typeComment, //!< comment node : <!-- --> typeComment, //!< comment node : <!-- -->
typeText, //!< <XXX> InsideText </XXX> typeText, //!< <XXX> InsideText </XXX>
}; };
/**
class filePos { * @brief Basic main object of all xml elements.
private: */
int32_t m_col; class Node : public ememory::EnableSharedFromThis<Node>{
int32_t m_line;
public:
filePos() :
m_col(0),
m_line(0) {
};
filePos(int32_t _line, int32_t _col) :
m_col(_col),
m_line(_line) {
};
~filePos() { };
filePos& operator ++() {
m_col++;
return *this;
};
filePos& operator --() {
m_col--;
if(m_col<0) {
m_col=0;
}
return *this;
};
const filePos& operator +=(const filePos& _obj) {
if (_obj.m_line == 0) {
m_col += _obj.m_col;
} else {
m_col = _obj.m_col;
m_line += _obj.m_line;
}
return *this;
};
const filePos& operator +=(int32_t _col) {
m_col += _col;
return *this;
};
const filePos& operator= (const filePos& _obj ) {
m_col = _obj.m_col;
m_line = _obj.m_line;
return *this;
}
void newLine() {
m_col=0;
m_line++;
};
bool check(char32_t _val) {
m_col++;
if (_val == '\n') {
newLine();
return true;
}
return false;
}
void set(int32_t _line, int32_t _col) {
m_col = _col;
m_line = _line;
}
void clear() {
m_col = 0;
m_line = 0;
}
int32_t getCol() const {
return m_col;
};
int32_t getLine() const {
return m_line;
};
};
std::ostream& operator <<(std::ostream& _os, const filePos& _obj);
class Node : public std::enable_shared_from_this<Node>{
protected: protected:
/** /**
* @brief basic element of a xml structure * @brief basic element of a xml structure
@ -131,11 +63,10 @@ namespace exml {
*/ */
Node(const std::string& _value); Node(const std::string& _value);
public: public:
//static std::shared_ptr<Node> create(const std::string& _value = "");
/** /**
* @brief destructor * @brief Virtualize destructor
*/ */
virtual ~Node() { }; virtual ~Node() = default;
public: public:
/** /**
* @brief parse the Current node [pure VIRUAL] * @brief parse the Current node [pure VIRUAL]
@ -145,25 +76,21 @@ namespace exml {
* @param[in,out] file parsing position (line x col x) * @param[in,out] file parsing position (line x col x)
* @return false if an error occured. * @return false if an error occured.
*/ */
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) = 0; virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) = 0;
/** /**
* @brief generate a string with the tree of the xml * @brief generate a string with the tree of the xml
* @param[in,out] _data string where to add the elements * @param[in,out] _data string where to add the elements
* @param[in] current indentation of the file * @param[in] current indentation of the file
* @return false if an error occured. * @return false if an error occured.
*/ */
virtual bool iGenerate(std::string& _data, int32_t _indent) const { virtual bool iGenerate(std::string& _data, int32_t _indent) const;
return true;
};
protected: protected:
exml::filePos m_pos; //!< position in the readed file == > not correct when the file is generated exml::FilePos m_pos; //!< position in the readed file == > not correct when the file is generated
public: public:
/** /**
* @brief get the current position where the element is in the file * @brief get the current position where the element is in the file
*/ */
const exml::filePos& getPos() const { const exml::FilePos& getPos() const;
return m_pos;
};
protected: protected:
std::string m_value; //!< value of the node (for element this is the name, for text it is the inside text ...) std::string m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
public: public:
@ -171,24 +98,18 @@ namespace exml {
* @brief set the value of the node. * @brief set the value of the node.
* @param[in] _value New value of the node. * @param[in] _value New value of the node.
*/ */
virtual void setValue(std::string _value) { virtual void setValue(std::string _value);
m_value = _value;
};
/** /**
* @brief get the current element Value. * @brief get the current element Value.
* @return the reference of the string value. * @return the reference of the string value.
*/ */
virtual const std::string& getValue() const { virtual const std::string& getValue() const;
return m_value;
};
public: public:
/** /**
* @brief get the node type. * @brief get the node type.
* @return the type of the Node. * @return the type of the Node.
*/ */
virtual enum nodeType getType() const { virtual enum nodeType getType() const;
return typeNode;
};
protected: protected:
/** /**
* @brief add indentation of the string input. * @brief add indentation of the string input.
@ -201,7 +122,7 @@ namespace exml {
* @param[in] _val Char that is parsed. * @param[in] _val Char that is parsed.
* @param[in] _filePos Position of the char in the file. * @param[in] _filePos Position of the char in the file.
*/ */
void drawElementParsed(char32_t _val, const exml::filePos& _filePos) const; void drawElementParsed(char32_t _val, const exml::FilePos& _filePos) const;
/** /**
* @brief check if an element or attribute is availlable (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \n\t\r and for first char : not -.0123456789). * @brief check if an element or attribute is availlable (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \n\t\r and for first char : not -.0123456789).
* @param[in] _val Value to check the conformity. * @param[in] _val Value to check the conformity.
@ -215,111 +136,99 @@ namespace exml {
* @param[out] _filePos new poistion of te file to add. * @param[out] _filePos new poistion of te file to add.
* @return number of white element. * @return number of white element.
*/ */
int32_t countWhiteChar(const std::string& _data, int32_t _pos, exml::filePos& _filePos) const; int32_t countWhiteChar(const std::string& _data, int32_t _pos, exml::FilePos& _filePos) const;
public: public:
/** /**
* @brief Cast the element in a Document if it is possible. * @brief Cast the element in a Document if it is possible.
* @return pointer on the class or nullptr. * @return pointer on the class or nullptr.
*/ */
virtual std::shared_ptr<exml::Document> toDocument() { virtual ememory::SharedPtr<exml::Document> toDocument();
return nullptr; /**
}; * @brief Cast the element in a Document if it is possible.
virtual std::shared_ptr<const exml::Document> toDocument() const { * @return CONST pointer on the class or nullptr.
return nullptr; */
}; virtual ememory::SharedPtr<const exml::Document> toDocument() const;
/** /**
* @brief Cast the element in a Attribute if it is possible. * @brief Cast the element in a Attribute if it is possible.
* @return pointer on the class or nullptr. * @return pointer on the class or nullptr.
*/ */
virtual std::shared_ptr<exml::Attribute> toAttribute() { virtual ememory::SharedPtr<exml::Attribute> toAttribute();
return nullptr; /**
}; * @brief Cast the element in a Attribute if it is possible.
virtual std::shared_ptr<const exml::Attribute> toAttribute() const { * @return CONST pointer on the class or nullptr.
return nullptr; */
}; virtual ememory::SharedPtr<const exml::Attribute> toAttribute() const;
/** /**
* @brief Cast the element in a Comment if it is possible. * @brief Cast the element in a Comment if it is possible.
* @return pointer on the class or nullptr. * @return pointer on the class or nullptr.
*/ */
virtual std::shared_ptr<exml::Comment> toComment() { virtual ememory::SharedPtr<exml::Comment> toComment();
return nullptr; /**
}; * @brief Cast the element in a Comment if it is possible.
virtual std::shared_ptr<const exml::Comment> toComment() const { * @return CONST pointer on the class or nullptr.
return nullptr; */
}; virtual ememory::SharedPtr<const exml::Comment> toComment() const;
/** /**
* @brief Cast the element in a Declaration if it is possible. * @brief Cast the element in a Declaration if it is possible.
* @return pointer on the class or nullptr. * @return pointer on the class or nullptr.
*/ */
virtual std::shared_ptr<exml::Declaration> toDeclaration() { virtual ememory::SharedPtr<exml::Declaration> toDeclaration();
return nullptr; /**
}; * @brief Cast the element in a Declaration if it is possible.
virtual std::shared_ptr<const exml::Declaration> toDeclaration() const { * @return CONST pointer on the class or nullptr.
return nullptr; */
}; virtual ememory::SharedPtr<const exml::Declaration> toDeclaration() const;
/** /**
* @brief Cast the element in a Element if it is possible. * @brief Cast the element in a Element if it is possible.
* @return pointer on the class or nullptr. * @return pointer on the class or nullptr.
*/ */
virtual std::shared_ptr<exml::Element> toElement() { virtual ememory::SharedPtr<exml::Element> toElement();
return nullptr; /**
}; * @brief Cast the element in a Element if it is possible.
virtual std::shared_ptr<const exml::Element> toElement() const { * @return CONST pointer on the class or nullptr.
return nullptr; */
}; virtual ememory::SharedPtr<const exml::Element> toElement() const;
/** /**
* @brief Cast the element in a Text if it is possible. * @brief Cast the element in a Text if it is possible.
* @return pointer on the class or nullptr. * @return pointer on the class or nullptr.
*/ */
virtual std::shared_ptr<exml::Text> toText() { virtual ememory::SharedPtr<exml::Text> toText();
return nullptr; /**
}; * @brief Cast the element in a Text if it is possible.
virtual std::shared_ptr<const exml::Text> toText() const{ * @return CONST pointer on the class or nullptr.
return nullptr; */
}; virtual ememory::SharedPtr<const exml::Text> toText() const;
/** /**
* @brief check if the node is a exml::Document * @brief check if the node is a exml::Document
* @return true if the node is a exml::Document * @return true if the node is a exml::Document
*/ */
bool isDocument() const { bool isDocument() const;
return getType() == exml::typeDocument;
};
/** /**
* @brief check if the node is a exml::Attribute * @brief check if the node is a exml::Attribute
* @return true if the node is a exml::Attribute * @return true if the node is a exml::Attribute
*/ */
bool isAttribute() const { bool isAttribute() const;
return getType() == exml::typeAttribute;
};
/** /**
* @brief check if the node is a exml::Comment * @brief check if the node is a exml::Comment
* @return true if the node is a exml::Comment * @return true if the node is a exml::Comment
*/ */
bool isComment() const { bool isComment() const;
return getType() == exml::typeComment;
};
/** /**
* @brief check if the node is a exml::Declaration * @brief check if the node is a exml::Declaration
* @return true if the node is a exml::Declaration * @return true if the node is a exml::Declaration
*/ */
bool isDeclaration() const { bool isDeclaration() const;
return getType() == exml::typeDeclaration;
};
/** /**
* @brief check if the node is a exml::Element * @brief check if the node is a exml::Element
* @return true if the node is a exml::Element * @return true if the node is a exml::Element
*/ */
bool isElement() const { bool isElement() const;
return getType() == exml::typeElement;
};
/** /**
* @brief check if the node is a exml::Text * @brief check if the node is a exml::Text
* @return true if the node is a exml::Text * @return true if the node is a exml::Text
*/ */
bool isText() const { bool isText() const;
return getType() == exml::typeText;
};
/** /**
* @brief clear the Node * @brief clear the Node

View File

@ -11,10 +11,6 @@
#include <exml/Document.h> #include <exml/Document.h>
#include <regex> #include <regex>
#undef __class__
#define __class__ "Text"
// transform the Text with : // transform the Text with :
// "&lt;" == "<" // "&lt;" == "<"
// "&gt;" == ">" // "&gt;" == ">"
@ -64,12 +60,12 @@ static bool isWhiteChar(char32_t _val) {
return false; return false;
} }
std::shared_ptr<exml::Text> exml::Text::create() { ememory::SharedPtr<exml::Text> exml::Text::create() {
return std::shared_ptr<exml::Text>(new exml::Text()); return ememory::SharedPtr<exml::Text>(new exml::Text());
} }
std::shared_ptr<exml::Text> exml::Text::create(const std::string& _data) { ememory::SharedPtr<exml::Text> exml::Text::create(const std::string& _data) {
return std::shared_ptr<exml::Text>(new exml::Text(_data)); return ememory::SharedPtr<exml::Text>(new exml::Text(_data));
} }
bool exml::Text::iGenerate(std::string& _data, int32_t _indent) const { bool exml::Text::iGenerate(std::string& _data, int32_t _indent) const {
@ -87,7 +83,7 @@ int32_t exml::Text::countLines() const {
return count; return count;
} }
bool exml::Text::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) { bool exml::Text::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'text'"); EXML_VERBOSE("start parse : 'text'");
m_pos = _filePos; m_pos = _filePos;
// search end of the comment : // search end of the comment :
@ -123,8 +119,8 @@ bool exml::Text::iParse(const std::string& _data, int32_t& _pos, bool _caseSensi
} }
std::shared_ptr<exml::TextCDATA> exml::TextCDATA::create() { ememory::SharedPtr<exml::TextCDATA> exml::TextCDATA::create() {
return std::shared_ptr<exml::TextCDATA>(new exml::TextCDATA()); return ememory::SharedPtr<exml::TextCDATA>(new exml::TextCDATA());
} }
bool exml::TextCDATA::iGenerate(std::string& _data, int32_t _indent) const { bool exml::TextCDATA::iGenerate(std::string& _data, int32_t _indent) const {
@ -132,7 +128,7 @@ bool exml::TextCDATA::iGenerate(std::string& _data, int32_t _indent) const {
return true; return true;
} }
bool exml::TextCDATA::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) { bool exml::TextCDATA::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'text::CDATA'"); EXML_VERBOSE("start parse : 'text::CDATA'");
m_pos = _filePos; m_pos = _filePos;
// search end of the comment : // search end of the comment :

View File

@ -23,27 +23,23 @@ namespace exml {
*/ */
Text(const std::string& _data) : exml::Node(_data) { }; Text(const std::string& _data) : exml::Node(_data) { };
public: public:
static std::shared_ptr<Text> create(); static ememory::SharedPtr<exml::Text> create();
static std::shared_ptr<Text> create(const std::string& _data); static ememory::SharedPtr<exml::Text> create(const std::string& _data);
/**
* @brief Destructor
*/
virtual ~Text() { };
/** /**
* @brief count the number of line in the current text * @brief count the number of line in the current text
* @return The number of lines * @return The number of lines
*/ */
int32_t countLines() const; int32_t countLines() const;
public: // herited function: public:
virtual enum nodeType getType() const { enum nodeType getType() const override{
return typeText; return typeText;
}; };
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc); bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override;
virtual bool iGenerate(std::string& _data, int32_t _indent) const; bool iGenerate(std::string& _data, int32_t _indent) const override;
virtual std::shared_ptr<exml::Text> toText() { ememory::SharedPtr<exml::Text> toText() override {
return std::static_pointer_cast<exml::Text>(shared_from_this()); return std::static_pointer_cast<exml::Text>(shared_from_this());
}; };
virtual std::shared_ptr<const exml::Text> toText() const{ ememory::SharedPtr<const exml::Text> toText() const override {
return std::static_pointer_cast<const exml::Text>(shared_from_this()); return std::static_pointer_cast<const exml::Text>(shared_from_this());
}; };
}; };
@ -54,14 +50,10 @@ namespace exml {
*/ */
TextCDATA() { }; TextCDATA() { };
public: public:
static std::shared_ptr<TextCDATA> create(); static ememory::SharedPtr<TextCDATA> create();
/** public:
* @brief Destructor bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override;
*/ bool iGenerate(std::string& _data, int32_t _indent) const override;
virtual ~TextCDATA() { };
public: // herited function:
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
}; };
} }

View File

@ -26,10 +26,11 @@ def get_version():
def create(target, module_name): def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type()) my_module = module.Module(__file__, module_name, get_type())
my_module.add_module_depend(['etk']) my_module.add_module_depend(['elog', 'etk', 'ememory'])
my_module.add_extra_compile_flags() my_module.add_extra_compile_flags()
my_module.add_src_file([ my_module.add_src_file([
'exml/debug.cpp', 'exml/debug.cpp',
'exml/FilePos.cpp',
'exml/Attribute.cpp', 'exml/Attribute.cpp',
'exml/AttributeList.cpp', 'exml/AttributeList.cpp',
'exml/Comment.cpp', 'exml/Comment.cpp',
@ -40,6 +41,7 @@ def create(target, module_name):
'exml/Text.cpp' 'exml/Text.cpp'
]) ])
my_module.add_header_file([ my_module.add_header_file([
'exml/FilePos.h',
'exml/exml.h', 'exml/exml.h',
'exml/Attribute.h', 'exml/Attribute.h',
'exml/AttributeList.h', 'exml/AttributeList.h',

View File

@ -18,9 +18,6 @@
#include "exmlTestDeclaration.h" #include "exmlTestDeclaration.h"
#include "exmlTestAll.h" #include "exmlTestAll.h"
#undef __class__
#define __class__ "exml::test"
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
// init Google test : // init Google test :
::testing::InitGoogleTest(&argc, const_cast<char **>(argv)); ::testing::InitGoogleTest(&argc, const_cast<char **>(argv));