[DEV] remork some bad implementation and base on ememory
This commit is contained in:
parent
ae8598ab35
commit
b59936f6e5
@ -12,9 +12,12 @@ def create(target, module_name):
|
||||
my_module.set_website_sources("http://github.com/atria-soft/" + module_name)
|
||||
my_module.add_path([
|
||||
module_name,
|
||||
"doc"
|
||||
])
|
||||
my_module.add_module_depend([
|
||||
'etk'
|
||||
'elog',
|
||||
'etk',
|
||||
'ememory'
|
||||
])
|
||||
my_module.add_exclude_symbols([
|
||||
'*operator<<*',
|
||||
|
@ -10,16 +10,9 @@
|
||||
#include <exml/debug.h>
|
||||
#include <exml/Document.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Attribute"
|
||||
|
||||
std::shared_ptr<exml::Attribute> exml::Attribute::create() {
|
||||
return std::shared_ptr<exml::Attribute>(new exml::Attribute());
|
||||
ememory::SharedPtr<exml::Attribute> exml::Attribute::create(const std::string& _name, const std::string& _value) {
|
||||
return ememory::SharedPtr<exml::Attribute>(new exml::Attribute(_name, _value));
|
||||
}
|
||||
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::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'");
|
||||
m_pos = _filePos;
|
||||
// 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);
|
||||
}
|
||||
// count white space :
|
||||
exml::filePos tmpPos;
|
||||
exml::FilePos tmpPos;
|
||||
int32_t white = countWhiteChar(_data, lastElementName+1, tmpPos);
|
||||
_filePos += tmpPos;
|
||||
if (lastElementName+white+1 >= _data.size()) {
|
||||
|
@ -13,25 +13,22 @@
|
||||
namespace exml {
|
||||
class Attribute : public exml::Node {
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
Attribute() { };
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _name Name 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:
|
||||
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:
|
||||
std::string m_name;
|
||||
std::string m_name; //!< Name of the attribute
|
||||
public:
|
||||
/**
|
||||
* @brief set the name of the attribute
|
||||
@ -47,19 +44,19 @@ namespace exml {
|
||||
virtual const std::string& getName() const {
|
||||
return m_name;
|
||||
};
|
||||
public: // herited function:
|
||||
virtual enum nodeType getType() const {
|
||||
public:
|
||||
enum nodeType getType() const override {
|
||||
return exml::typeAttribute;
|
||||
};
|
||||
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;
|
||||
virtual std::shared_ptr<exml::Attribute> toAttribute() {
|
||||
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;
|
||||
ememory::SharedPtr<exml::Attribute> toAttribute() override {
|
||||
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());
|
||||
};
|
||||
virtual void clear();
|
||||
void clear() override;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -9,21 +9,14 @@
|
||||
#include <exml/AttributeList.h>
|
||||
#include <exml/debug.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "AttributeList"
|
||||
|
||||
exml::AttributeList::~AttributeList() {
|
||||
m_listAttribute.clear();
|
||||
}
|
||||
|
||||
std::shared_ptr<exml::Attribute> exml::AttributeList::getAttr(int32_t _id) {
|
||||
ememory::SharedPtr<exml::Attribute> exml::AttributeList::getAttr(int32_t _id) {
|
||||
if (_id <0 || (size_t)_id>m_listAttribute.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
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()) {
|
||||
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::shared_ptr<const exml::Attribute> att = getAttr(_id);
|
||||
ememory::SharedPtr<const exml::Attribute> att = getAttr(_id);
|
||||
if (att == nullptr) {
|
||||
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) {
|
||||
EXML_ERROR("Try to set an empty node");
|
||||
return;
|
||||
@ -110,7 +103,7 @@ void exml::AttributeList::setAttribute(const std::string& _name, const std::stri
|
||||
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) {
|
||||
EXML_ERROR("memory allocation error...");
|
||||
}
|
||||
|
@ -15,25 +15,16 @@
|
||||
namespace exml {
|
||||
class AttributeList : public exml::Node {
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
AttributeList() { };
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _value Node value;
|
||||
*/
|
||||
AttributeList(const std::string& _value) :
|
||||
AttributeList(const std::string& _value="") :
|
||||
exml::Node(_value) {
|
||||
|
||||
};
|
||||
public:
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~AttributeList();
|
||||
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:
|
||||
/**
|
||||
* @brief get the number of attribute in the Node
|
||||
@ -46,14 +37,24 @@ namespace exml {
|
||||
* @brief add attribute on the List
|
||||
* @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
|
||||
* @param[in] _id Identifier of the attribute 0<= _id < sizeAttribute()
|
||||
* @return Pointer on the attribute or NULL
|
||||
*/
|
||||
std::shared_ptr<Attribute> getAttr(int32_t _id);
|
||||
std::shared_ptr<const Attribute> getAttr(int32_t _id) const;
|
||||
ememory::SharedPtr<Attribute> getAttr(int32_t _id);
|
||||
/**
|
||||
* @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;
|
||||
/**
|
||||
* @brief get the attribute value with searching in the List with his name
|
||||
@ -80,9 +81,9 @@ namespace exml {
|
||||
* @return false An error occured.
|
||||
*/
|
||||
bool removeAttribute(const std::string& _name);
|
||||
public: // herited function:
|
||||
bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual void clear();
|
||||
public:
|
||||
bool iGenerate(std::string& _data, int32_t _indent) const override;
|
||||
void clear() override;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,6 @@
|
||||
#include <exml/debug.h>
|
||||
#include <exml/Document.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Comment"
|
||||
|
||||
|
||||
static bool isWhiteChar(char32_t _val) {
|
||||
if( _val == ' '
|
||||
|| _val == '\t'
|
||||
@ -24,14 +20,14 @@ static bool isWhiteChar(char32_t _val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<exml::Comment> exml::Comment::create() {
|
||||
return std::shared_ptr<exml::Comment>(new exml::Comment());
|
||||
ememory::SharedPtr<exml::Comment> exml::Comment::create() {
|
||||
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'");
|
||||
m_pos = _filePos;
|
||||
exml::filePos tmpPos;
|
||||
exml::FilePos tmpPos;
|
||||
int32_t white = countWhiteChar(_data, _pos, tmpPos);
|
||||
_filePos += tmpPos;
|
||||
// search end of the comment :
|
||||
|
@ -18,7 +18,11 @@ namespace exml {
|
||||
*/
|
||||
Comment() { };
|
||||
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
|
||||
* @param[in] _value comment value
|
||||
@ -27,20 +31,16 @@ namespace exml {
|
||||
exml::Node(_value) {
|
||||
|
||||
};
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~Comment() { };
|
||||
public: // herited function:
|
||||
virtual enum nodeType getType() const {
|
||||
public:
|
||||
enum nodeType getType() const override {
|
||||
return typeAttribute;
|
||||
};
|
||||
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;
|
||||
virtual std::shared_ptr<exml::Comment> toComment() {
|
||||
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;
|
||||
ememory::SharedPtr<exml::Comment> toComment() override {
|
||||
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());
|
||||
};
|
||||
};
|
||||
|
@ -10,9 +10,6 @@
|
||||
#include <exml/debug.h>
|
||||
#include <exml/Document.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Declaration"
|
||||
|
||||
/* basic declaration have 3 attributes:
|
||||
version
|
||||
encoding
|
||||
@ -20,17 +17,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
*/
|
||||
|
||||
|
||||
std::shared_ptr<exml::Declaration> exml::Declaration::create() {
|
||||
return std::shared_ptr<exml::Declaration>(new exml::Declaration());
|
||||
ememory::SharedPtr<exml::Declaration> exml::Declaration::create(const std::string& _name) {
|
||||
return ememory::SharedPtr<exml::Declaration>(new exml::Declaration(_name));
|
||||
}
|
||||
|
||||
std::shared_ptr<exml::Declaration> exml::Declaration::create(const std::string& _name) {
|
||||
return std::shared_ptr<exml::Declaration>(new exml::Declaration(_name));
|
||||
}
|
||||
|
||||
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));
|
||||
ememory::SharedPtr<exml::DeclarationXML> exml::DeclarationXML::create(const std::string& _version, const std::string& _format, bool _standalone) {
|
||||
return ememory::SharedPtr<exml::DeclarationXML>(new exml::DeclarationXML(_version, _format, _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;
|
||||
}
|
||||
|
||||
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 << "'");
|
||||
m_pos = _filePos;
|
||||
// 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) {
|
||||
// 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) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, " Allocation error ...");
|
||||
return false;
|
||||
|
@ -12,35 +12,31 @@
|
||||
namespace exml {
|
||||
class Declaration : public exml::AttributeList {
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
Declaration() { };
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _name name of the declaration (xml, xml:xxxx ...)
|
||||
*/
|
||||
Declaration(const std::string& _name) :
|
||||
Declaration(const std::string& _name="") :
|
||||
exml::AttributeList(_name) {
|
||||
|
||||
};
|
||||
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() { };
|
||||
public: // herited function:
|
||||
virtual enum nodeType getType() const {
|
||||
static ememory::SharedPtr<Declaration> create(const std::string& _name="");
|
||||
public:
|
||||
enum nodeType getType() const override{
|
||||
return typeAttribute;
|
||||
};
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
|
||||
virtual std::shared_ptr<exml::Declaration> toDeclaration() {
|
||||
bool iGenerate(std::string& _data, int32_t _indent) const override;
|
||||
bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override;
|
||||
ememory::SharedPtr<exml::Declaration> toDeclaration() override {
|
||||
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());
|
||||
};
|
||||
};
|
||||
@ -54,11 +50,14 @@ namespace exml {
|
||||
*/
|
||||
DeclarationXML(const std::string& _version, const std::string& _format = "UTF-8", bool _standalone = true);
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -10,12 +10,8 @@
|
||||
#include <exml/debug.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Document"
|
||||
|
||||
|
||||
std::shared_ptr<exml::Document> exml::Document::create() {
|
||||
return std::shared_ptr<exml::Document>(new exml::Document());
|
||||
ememory::SharedPtr<exml::Document> exml::Document::create() {
|
||||
return ememory::SharedPtr<exml::Document>(new exml::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());
|
||||
clear();
|
||||
// came from char == > force in utf8 ...
|
||||
exml::filePos filePos(1,0);
|
||||
exml::FilePos filePos(1,0);
|
||||
m_pos = filePos;
|
||||
int32_t parsePos = 0;
|
||||
return subParse(_data, parsePos, m_caseSensitive, filePos, *this, true);
|
||||
@ -142,7 +138,7 @@ void exml::Document::displayError() {
|
||||
#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_Line = etk::extract_line(_data, _pos);
|
||||
m_filePos = _filePos;
|
||||
|
@ -17,13 +17,13 @@ namespace exml {
|
||||
* @brief Constructor
|
||||
*/
|
||||
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:
|
||||
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:
|
||||
/**
|
||||
* @brief Enable or diasable the case sensitive (must be done before the call of parsing)
|
||||
@ -73,10 +73,10 @@ namespace exml {
|
||||
*/
|
||||
void display();
|
||||
private:
|
||||
bool m_writeErrorWhenDetexted;
|
||||
std::string m_comment;
|
||||
std::string m_Line;
|
||||
exml::filePos m_filePos;
|
||||
bool m_writeErrorWhenDetexted; //!< Request print error in parsing just when detected
|
||||
std::string m_comment; //!< Comment on the error
|
||||
std::string m_Line; //!< Parse line error (copy)
|
||||
exml::FilePos m_filePos; //!< position of the error
|
||||
public:
|
||||
void displayErrorWhenDetected() {
|
||||
m_writeErrorWhenDetexted = true;
|
||||
@ -85,33 +85,24 @@ namespace exml {
|
||||
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();
|
||||
public: // herited function:
|
||||
virtual enum nodeType getType() const {
|
||||
public:
|
||||
enum nodeType getType() const override {
|
||||
return typeDocument;
|
||||
};
|
||||
bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual std::shared_ptr<exml::Document> toDocument() {
|
||||
bool iGenerate(std::string& _data, int32_t _indent) const override;
|
||||
ememory::SharedPtr<exml::Document> toDocument() override {
|
||||
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());
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
#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) \
|
||||
do { \
|
||||
EXML_ERROR(comment); \
|
||||
(doc).createError((data),(pos),(filePos),(comment)); \
|
||||
} while (0)
|
||||
|
||||
//__LINE__, __class__, __func__
|
||||
|
||||
|
@ -14,10 +14,6 @@
|
||||
#include <exml/Declaration.h>
|
||||
#include <exml/Document.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Element"
|
||||
|
||||
|
||||
static bool isWhiteChar(char32_t _val) {
|
||||
if( _val == ' '
|
||||
|| _val == '\t'
|
||||
@ -28,41 +24,29 @@ static bool isWhiteChar(char32_t _val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<exml::Element> exml::Element::create() {
|
||||
return std::shared_ptr<exml::Element>(new exml::Element());
|
||||
ememory::SharedPtr<exml::Element> exml::Element::create() {
|
||||
return ememory::SharedPtr<exml::Element>(new exml::Element());
|
||||
}
|
||||
std::shared_ptr<exml::Element> exml::Element::create(const std::string& _value) {
|
||||
return std::shared_ptr<exml::Element>(new exml::Element(_value));
|
||||
ememory::SharedPtr<exml::Element> exml::Element::create(const std::string& _value) {
|
||||
return ememory::SharedPtr<exml::Element>(new exml::Element(_value));
|
||||
}
|
||||
|
||||
|
||||
exml::Element::~Element() {
|
||||
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);
|
||||
enum exml::nodeType exml::Element::getType(int32_t _id) const {
|
||||
ememory::SharedPtr<const exml::Node> tmpp = getNode(_id);
|
||||
if (tmpp == nullptr) {
|
||||
return exml::typeUnknow;
|
||||
}
|
||||
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()) {
|
||||
return nullptr;
|
||||
}
|
||||
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()) {
|
||||
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) {
|
||||
std::shared_ptr<exml::Node> tmpp = getNode(_id);
|
||||
ememory::SharedPtr<exml::Element> exml::Element::getElement(int32_t _id) {
|
||||
ememory::SharedPtr<exml::Node> tmpp = getNode(_id);
|
||||
if (tmpp == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return tmpp->toElement();
|
||||
}
|
||||
|
||||
std::shared_ptr<const exml::Element> exml::Element::getElement(int32_t _id) const {
|
||||
std::shared_ptr<const exml::Node> tmpp = getNode(_id);
|
||||
ememory::SharedPtr<const exml::Element> exml::Element::getElement(int32_t _id) const {
|
||||
ememory::SharedPtr<const exml::Node> tmpp = getNode(_id);
|
||||
if (tmpp == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
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) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -103,7 +87,7 @@ std::shared_ptr<exml::Element> exml::Element::getNamed(const std::string& _name)
|
||||
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) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -120,7 +104,7 @@ std::shared_ptr<const exml::Element> exml::Element::getNamed(const std::string&
|
||||
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) {
|
||||
EXML_ERROR("Try to set an empty node");
|
||||
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);
|
||||
for (size_t iii=_pos; iii<_data.size(); iii++) {
|
||||
_filePos.check(_data[iii]);
|
||||
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
|
||||
drawElementParsed(_data[iii], _filePos);
|
||||
#endif
|
||||
exml::filePos tmpPos;
|
||||
exml::FilePos tmpPos;
|
||||
if (_data[iii] == '<') {
|
||||
int32_t white = countWhiteChar(_data, iii+1, tmpPos);
|
||||
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);
|
||||
}
|
||||
// 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) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation Error...");
|
||||
return false;
|
||||
@ -271,7 +255,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
}
|
||||
++tmpPos;
|
||||
// find comment:
|
||||
std::shared_ptr<exml::Comment> comment = exml::Comment::create();
|
||||
ememory::SharedPtr<exml::Comment> comment = exml::Comment::create();
|
||||
if (comment == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
return false;
|
||||
@ -300,7 +284,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
}
|
||||
tmpPos+=6;
|
||||
// find text:
|
||||
std::shared_ptr<exml::TextCDATA> text = exml::TextCDATA::create();
|
||||
ememory::SharedPtr<exml::TextCDATA> text = exml::TextCDATA::create();
|
||||
if (text == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
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 << "'");
|
||||
// find text:
|
||||
std::shared_ptr<exml::Element> element = exml::Element::create(tmpname);
|
||||
ememory::SharedPtr<exml::Element> element = exml::Element::create(tmpname);
|
||||
if (element == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
return false;
|
||||
@ -420,7 +404,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
// empty spaces == > nothing to do ....
|
||||
} else {
|
||||
// find data == > parse it...
|
||||
std::shared_ptr<exml::Text> text = exml::Text::create();
|
||||
ememory::SharedPtr<exml::Text> text = exml::Text::create();
|
||||
if (text == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
return false;
|
||||
@ -442,7 +426,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
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 << "'");
|
||||
// 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;
|
||||
@ -474,7 +458,7 @@ bool exml::Element::iParse(const std::string& _data, int32_t& _pos, bool _caseSe
|
||||
}
|
||||
if (checkAvaillable(_data[iii], true) == true) {
|
||||
// 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) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
return false;
|
||||
|
@ -27,14 +27,10 @@ namespace exml {
|
||||
|
||||
};
|
||||
public:
|
||||
static std::shared_ptr<Element> create();
|
||||
static std::shared_ptr<Element> create(const std::string& _value);
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~Element();
|
||||
static ememory::SharedPtr<Element> create();
|
||||
static ememory::SharedPtr<Element> create(const std::string& _value);
|
||||
protected:
|
||||
std::vector<std::shared_ptr<exml::Node>> m_listSub;
|
||||
std::vector<ememory::SharedPtr<exml::Node>> m_listSub; //!< List of subNodes
|
||||
public:
|
||||
/**
|
||||
* @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).
|
||||
* @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.
|
||||
* @param[in] _id Id of the element.
|
||||
* @return the Current type of the element or exml::typeUnknow.
|
||||
*/
|
||||
enum nodeType getType(int32_t _id);
|
||||
const enum nodeType getType(int32_t _id) const;
|
||||
enum nodeType getType(int32_t _id) const;
|
||||
/**
|
||||
* @brief get the Node pointer of the element id.
|
||||
* @param[in] _id Id of the element.
|
||||
* @return Pointer on node.
|
||||
*/
|
||||
std::shared_ptr<Node> getNode(int32_t _id);
|
||||
std::shared_ptr<const Node> getNode(int32_t _id) const;
|
||||
ememory::SharedPtr<Node> getNode(int32_t _id);
|
||||
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).
|
||||
* @param[in] _id Id of the element.
|
||||
* @return Pointer on the element or NULL.
|
||||
*/
|
||||
std::shared_ptr<Element> getElement(int32_t _id);
|
||||
std::shared_ptr<const Element> getElement(int32_t _id) const;
|
||||
ememory::SharedPtr<Element> getElement(int32_t _id);
|
||||
ememory::SharedPtr<const Element> getElement(int32_t _id) const;
|
||||
/**
|
||||
* @brief get an element with his name (work only with exml::Element)
|
||||
* @param[in] _name Name of the element that is requested
|
||||
* @return Pointer on the element or NULL.
|
||||
*/
|
||||
std::shared_ptr<Element> getNamed(const std::string& _name);
|
||||
std::shared_ptr<const Element> getNamed(const std::string& _name) const;
|
||||
ememory::SharedPtr<Element> getNamed(const std::string& _name);
|
||||
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[...]]>
|
||||
* @return the curent data string. if Only one text node, then we get the parssed data (no & ...) if more than one node, then we transform &,",',<,> in xml normal text...
|
||||
*/
|
||||
std::string getText() const;
|
||||
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:
|
||||
virtual enum nodeType getType() const {
|
||||
enum nodeType getType() const override {
|
||||
return typeElement;
|
||||
};
|
||||
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;
|
||||
virtual std::shared_ptr<exml::Element> toElement() {
|
||||
}
|
||||
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;
|
||||
ememory::SharedPtr<exml::Element> toElement() override {
|
||||
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());
|
||||
};
|
||||
virtual void clear();
|
||||
}
|
||||
void clear() override;
|
||||
};
|
||||
}
|
||||
|
||||
|
108
exml/Node.cpp
108
exml/Node.cpp
@ -9,9 +9,6 @@
|
||||
#include <exml/Node.h>
|
||||
#include <exml/debug.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Node"
|
||||
|
||||
static bool isWhiteChar(char32_t _val) {
|
||||
if( _val == ' '
|
||||
|| _val == '\t'
|
||||
@ -22,15 +19,6 @@ static bool isWhiteChar(char32_t _val) {
|
||||
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) :
|
||||
m_pos(0,0),
|
||||
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') {
|
||||
EXML_DEBUG(_filePos << " parse '\\n'");
|
||||
} 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();
|
||||
int32_t white=0;
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
m_value = "";
|
||||
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;
|
||||
}
|
||||
|
||||
|
215
exml/Node.h
215
exml/Node.h
@ -7,10 +7,14 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <ememory/memory.h>
|
||||
#include <etk/types.h>
|
||||
#include <etk/math/Vector2D.h>
|
||||
#include <exml/FilePos.h>
|
||||
|
||||
/**
|
||||
* @brief exml namespace containing all function for XML interpretor
|
||||
*/
|
||||
namespace exml {
|
||||
//#define ENABLE_DISPLAY_PARSED_ELEMENT
|
||||
//#define ENABLE_CRITICAL_WHEN_ERROR
|
||||
@ -41,82 +45,10 @@ namespace exml {
|
||||
typeComment, //!< comment node : <!-- -->
|
||||
typeText, //!< <XXX> InsideText </XXX>
|
||||
};
|
||||
|
||||
class filePos {
|
||||
private:
|
||||
int32_t m_col;
|
||||
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>{
|
||||
/**
|
||||
* @brief Basic main object of all xml elements.
|
||||
*/
|
||||
class Node : public ememory::EnableSharedFromThis<Node>{
|
||||
protected:
|
||||
/**
|
||||
* @brief basic element of a xml structure
|
||||
@ -131,11 +63,10 @@ namespace exml {
|
||||
*/
|
||||
Node(const std::string& _value);
|
||||
public:
|
||||
//static std::shared_ptr<Node> create(const std::string& _value = "");
|
||||
/**
|
||||
* @brief destructor
|
||||
* @brief Virtualize destructor
|
||||
*/
|
||||
virtual ~Node() { };
|
||||
virtual ~Node() = default;
|
||||
public:
|
||||
/**
|
||||
* @brief parse the Current node [pure VIRUAL]
|
||||
@ -145,25 +76,21 @@ namespace exml {
|
||||
* @param[in,out] file parsing position (line x col x)
|
||||
* @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
|
||||
* @param[in,out] _data string where to add the elements
|
||||
* @param[in] current indentation of the file
|
||||
* @return false if an error occured.
|
||||
*/
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const {
|
||||
return true;
|
||||
};
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
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:
|
||||
/**
|
||||
* @brief get the current position where the element is in the file
|
||||
*/
|
||||
const exml::filePos& getPos() const {
|
||||
return m_pos;
|
||||
};
|
||||
const exml::FilePos& getPos() const;
|
||||
protected:
|
||||
std::string m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
|
||||
public:
|
||||
@ -171,24 +98,18 @@ namespace exml {
|
||||
* @brief set the value of the node.
|
||||
* @param[in] _value New value of the node.
|
||||
*/
|
||||
virtual void setValue(std::string _value) {
|
||||
m_value = _value;
|
||||
};
|
||||
virtual void setValue(std::string _value);
|
||||
/**
|
||||
* @brief get the current element Value.
|
||||
* @return the reference of the string value.
|
||||
*/
|
||||
virtual const std::string& getValue() const {
|
||||
return m_value;
|
||||
};
|
||||
virtual const std::string& getValue() const;
|
||||
public:
|
||||
/**
|
||||
* @brief get the node type.
|
||||
* @return the type of the Node.
|
||||
*/
|
||||
virtual enum nodeType getType() const {
|
||||
return typeNode;
|
||||
};
|
||||
virtual enum nodeType getType() const;
|
||||
protected:
|
||||
/**
|
||||
* @brief add indentation of the string input.
|
||||
@ -201,7 +122,7 @@ namespace exml {
|
||||
* @param[in] _val Char that is parsed.
|
||||
* @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).
|
||||
* @param[in] _val Value to check the conformity.
|
||||
@ -215,111 +136,99 @@ namespace exml {
|
||||
* @param[out] _filePos new poistion of te file to add.
|
||||
* @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:
|
||||
/**
|
||||
* @brief Cast the element in a Document if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual std::shared_ptr<exml::Document> toDocument() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual std::shared_ptr<const exml::Document> toDocument() const {
|
||||
return nullptr;
|
||||
};
|
||||
virtual ememory::SharedPtr<exml::Document> toDocument();
|
||||
/**
|
||||
* @brief Cast the element in a Document if it is possible.
|
||||
* @return CONST pointer on the class or nullptr.
|
||||
*/
|
||||
virtual ememory::SharedPtr<const exml::Document> toDocument() const;
|
||||
/**
|
||||
* @brief Cast the element in a Attribute if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual std::shared_ptr<exml::Attribute> toAttribute() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual std::shared_ptr<const exml::Attribute> toAttribute() const {
|
||||
return nullptr;
|
||||
};
|
||||
virtual ememory::SharedPtr<exml::Attribute> toAttribute();
|
||||
/**
|
||||
* @brief Cast the element in a Attribute if it is possible.
|
||||
* @return CONST pointer on the class or nullptr.
|
||||
*/
|
||||
virtual ememory::SharedPtr<const exml::Attribute> toAttribute() const;
|
||||
/**
|
||||
* @brief Cast the element in a Comment if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual std::shared_ptr<exml::Comment> toComment() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual std::shared_ptr<const exml::Comment> toComment() const {
|
||||
return nullptr;
|
||||
};
|
||||
virtual ememory::SharedPtr<exml::Comment> toComment();
|
||||
/**
|
||||
* @brief Cast the element in a Comment if it is possible.
|
||||
* @return CONST pointer on the class or nullptr.
|
||||
*/
|
||||
virtual ememory::SharedPtr<const exml::Comment> toComment() const;
|
||||
/**
|
||||
* @brief Cast the element in a Declaration if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual std::shared_ptr<exml::Declaration> toDeclaration() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual std::shared_ptr<const exml::Declaration> toDeclaration() const {
|
||||
return nullptr;
|
||||
};
|
||||
virtual ememory::SharedPtr<exml::Declaration> toDeclaration();
|
||||
/**
|
||||
* @brief Cast the element in a Declaration if it is possible.
|
||||
* @return CONST pointer on the class or nullptr.
|
||||
*/
|
||||
virtual ememory::SharedPtr<const exml::Declaration> toDeclaration() const;
|
||||
/**
|
||||
* @brief Cast the element in a Element if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual std::shared_ptr<exml::Element> toElement() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual std::shared_ptr<const exml::Element> toElement() const {
|
||||
return nullptr;
|
||||
};
|
||||
virtual ememory::SharedPtr<exml::Element> toElement();
|
||||
/**
|
||||
* @brief Cast the element in a Element if it is possible.
|
||||
* @return CONST pointer on the class or nullptr.
|
||||
*/
|
||||
virtual ememory::SharedPtr<const exml::Element> toElement() const;
|
||||
/**
|
||||
* @brief Cast the element in a Text if it is possible.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual std::shared_ptr<exml::Text> toText() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual std::shared_ptr<const exml::Text> toText() const{
|
||||
return nullptr;
|
||||
};
|
||||
virtual ememory::SharedPtr<exml::Text> toText();
|
||||
/**
|
||||
* @brief Cast the element in a Text if it is possible.
|
||||
* @return CONST pointer on the class or nullptr.
|
||||
*/
|
||||
virtual ememory::SharedPtr<const exml::Text> toText() const;
|
||||
|
||||
/**
|
||||
* @brief check if the node is a exml::Document
|
||||
* @return true if the node is a exml::Document
|
||||
*/
|
||||
bool isDocument() const {
|
||||
return getType() == exml::typeDocument;
|
||||
};
|
||||
bool isDocument() const;
|
||||
/**
|
||||
* @brief check if the node is a exml::Attribute
|
||||
* @return true if the node is a exml::Attribute
|
||||
*/
|
||||
bool isAttribute() const {
|
||||
return getType() == exml::typeAttribute;
|
||||
};
|
||||
bool isAttribute() const;
|
||||
/**
|
||||
* @brief check if the node is a exml::Comment
|
||||
* @return true if the node is a exml::Comment
|
||||
*/
|
||||
bool isComment() const {
|
||||
return getType() == exml::typeComment;
|
||||
};
|
||||
bool isComment() const;
|
||||
/**
|
||||
* @brief check if the node is a exml::Declaration
|
||||
* @return true if the node is a exml::Declaration
|
||||
*/
|
||||
bool isDeclaration() const {
|
||||
return getType() == exml::typeDeclaration;
|
||||
};
|
||||
bool isDeclaration() const;
|
||||
/**
|
||||
* @brief check if the node is a exml::Element
|
||||
* @return true if the node is a exml::Element
|
||||
*/
|
||||
bool isElement() const {
|
||||
return getType() == exml::typeElement;
|
||||
};
|
||||
bool isElement() const;
|
||||
/**
|
||||
* @brief check if the node is a exml::Text
|
||||
* @return true if the node is a exml::Text
|
||||
*/
|
||||
bool isText() const {
|
||||
return getType() == exml::typeText;
|
||||
};
|
||||
bool isText() const;
|
||||
|
||||
/**
|
||||
* @brief clear the Node
|
||||
|
@ -11,10 +11,6 @@
|
||||
#include <exml/Document.h>
|
||||
#include <regex>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Text"
|
||||
|
||||
|
||||
// transform the Text with :
|
||||
// "<" == "<"
|
||||
// ">" == ">"
|
||||
@ -64,12 +60,12 @@ static bool isWhiteChar(char32_t _val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<exml::Text> exml::Text::create() {
|
||||
return std::shared_ptr<exml::Text>(new exml::Text());
|
||||
ememory::SharedPtr<exml::Text> exml::Text::create() {
|
||||
return ememory::SharedPtr<exml::Text>(new exml::Text());
|
||||
}
|
||||
|
||||
std::shared_ptr<exml::Text> exml::Text::create(const std::string& _data) {
|
||||
return std::shared_ptr<exml::Text>(new exml::Text(_data));
|
||||
ememory::SharedPtr<exml::Text> exml::Text::create(const std::string& _data) {
|
||||
return ememory::SharedPtr<exml::Text>(new exml::Text(_data));
|
||||
}
|
||||
|
||||
bool exml::Text::iGenerate(std::string& _data, int32_t _indent) const {
|
||||
@ -87,7 +83,7 @@ int32_t exml::Text::countLines() const {
|
||||
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'");
|
||||
m_pos = _filePos;
|
||||
// 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() {
|
||||
return std::shared_ptr<exml::TextCDATA>(new exml::TextCDATA());
|
||||
ememory::SharedPtr<exml::TextCDATA> exml::TextCDATA::create() {
|
||||
return ememory::SharedPtr<exml::TextCDATA>(new exml::TextCDATA());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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'");
|
||||
m_pos = _filePos;
|
||||
// search end of the comment :
|
||||
|
32
exml/Text.h
32
exml/Text.h
@ -23,27 +23,23 @@ namespace exml {
|
||||
*/
|
||||
Text(const std::string& _data) : exml::Node(_data) { };
|
||||
public:
|
||||
static std::shared_ptr<Text> create();
|
||||
static std::shared_ptr<Text> create(const std::string& _data);
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~Text() { };
|
||||
static ememory::SharedPtr<exml::Text> create();
|
||||
static ememory::SharedPtr<exml::Text> create(const std::string& _data);
|
||||
/**
|
||||
* @brief count the number of line in the current text
|
||||
* @return The number of lines
|
||||
*/
|
||||
int32_t countLines() const;
|
||||
public: // herited function:
|
||||
virtual enum nodeType getType() const {
|
||||
public:
|
||||
enum nodeType getType() const override{
|
||||
return typeText;
|
||||
};
|
||||
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;
|
||||
virtual std::shared_ptr<exml::Text> toText() {
|
||||
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;
|
||||
ememory::SharedPtr<exml::Text> toText() override {
|
||||
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());
|
||||
};
|
||||
};
|
||||
@ -54,14 +50,10 @@ namespace exml {
|
||||
*/
|
||||
TextCDATA() { };
|
||||
public:
|
||||
static std::shared_ptr<TextCDATA> create();
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
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;
|
||||
static ememory::SharedPtr<TextCDATA> create();
|
||||
public:
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -26,10 +26,11 @@ def get_version():
|
||||
|
||||
def create(target, module_name):
|
||||
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_src_file([
|
||||
'exml/debug.cpp',
|
||||
'exml/FilePos.cpp',
|
||||
'exml/Attribute.cpp',
|
||||
'exml/AttributeList.cpp',
|
||||
'exml/Comment.cpp',
|
||||
@ -40,6 +41,7 @@ def create(target, module_name):
|
||||
'exml/Text.cpp'
|
||||
])
|
||||
my_module.add_header_file([
|
||||
'exml/FilePos.h',
|
||||
'exml/exml.h',
|
||||
'exml/Attribute.h',
|
||||
'exml/AttributeList.h',
|
||||
|
@ -18,9 +18,6 @@
|
||||
#include "exmlTestDeclaration.h"
|
||||
#include "exmlTestAll.h"
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "exml::test"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
// init Google test :
|
||||
::testing::InitGoogleTest(&argc, const_cast<char **>(argv));
|
||||
|
Loading…
x
Reference in New Issue
Block a user