diff --git a/doxy_exml.py b/doxy_exml.py index b2d6d38..e09941d 100644 --- a/doxy_exml.py +++ b/doxy_exml.py @@ -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<<*', diff --git a/exml/Attribute.cpp b/exml/Attribute.cpp index b995100..7caee71 100644 --- a/exml/Attribute.cpp +++ b/exml/Attribute.cpp @@ -10,16 +10,9 @@ #include #include -#undef __class__ -#define __class__ "Attribute" - -std::shared_ptr exml::Attribute::create() { - return std::shared_ptr(new exml::Attribute()); +ememory::SharedPtr exml::Attribute::create(const std::string& _name, const std::string& _value) { + return ememory::SharedPtr(new exml::Attribute(_name, _value)); } -std::shared_ptr exml::Attribute::create(const std::string& _name, const std::string& _value) { - return std::shared_ptr(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()) { diff --git a/exml/Attribute.h b/exml/Attribute.h index a8cf807..80311df 100644 --- a/exml/Attribute.h +++ b/exml/Attribute.h @@ -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 create(); - static std::shared_ptr 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 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 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 toAttribute() override { return std::static_pointer_cast(shared_from_this()); }; - virtual std::shared_ptr toAttribute() const { + ememory::SharedPtr toAttribute() const override { return std::static_pointer_cast(shared_from_this()); }; - virtual void clear(); + void clear() override; }; } diff --git a/exml/AttributeList.cpp b/exml/AttributeList.cpp index 98e5c41..4b5483b 100644 --- a/exml/AttributeList.cpp +++ b/exml/AttributeList.cpp @@ -9,21 +9,14 @@ #include #include -#undef __class__ -#define __class__ "AttributeList" - -exml::AttributeList::~AttributeList() { - m_listAttribute.clear(); -} - -std::shared_ptr exml::AttributeList::getAttr(int32_t _id) { +ememory::SharedPtr exml::AttributeList::getAttr(int32_t _id) { if (_id <0 || (size_t)_id>m_listAttribute.size()) { return nullptr; } return m_listAttribute[_id]; } -std::shared_ptr exml::AttributeList::getAttr(int32_t _id) const { +ememory::SharedPtr 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 exml::AttributeList::getAttr(int32_t _id) } std::pair exml::AttributeList::getAttrPair(int32_t _id) const { - std::shared_ptr att = getAttr(_id); + ememory::SharedPtr att = getAttr(_id); if (att == nullptr) { return std::make_pair("",""); } @@ -39,7 +32,7 @@ std::pair exml::AttributeList::getAttrPair(int32_t _id } -void exml::AttributeList::appendAttribute(const std::shared_ptr& _attr) { +void exml::AttributeList::appendAttribute(const ememory::SharedPtr& _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 attr = exml::Attribute::create(_name, _value); + ememory::SharedPtr attr = exml::Attribute::create(_name, _value); if (attr == nullptr) { EXML_ERROR("memory allocation error..."); } diff --git a/exml/AttributeList.h b/exml/AttributeList.h index 7d874e0..5ad9d10 100644 --- a/exml/AttributeList.h +++ b/exml/AttributeList.h @@ -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> m_listAttribute; //!< list of all attribute + std::vector> 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& _attr); + void appendAttribute(const ememory::SharedPtr& _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 getAttr(int32_t _id); - std::shared_ptr getAttr(int32_t _id) const; + ememory::SharedPtr 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 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 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; }; } diff --git a/exml/Comment.cpp b/exml/Comment.cpp index e0c55a5..41e0b55 100644 --- a/exml/Comment.cpp +++ b/exml/Comment.cpp @@ -10,10 +10,6 @@ #include #include -#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::create() { - return std::shared_ptr(new exml::Comment()); +ememory::SharedPtr exml::Comment::create() { + return ememory::SharedPtr(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 : diff --git a/exml/Comment.h b/exml/Comment.h index 1d9716b..b61121f 100644 --- a/exml/Comment.h +++ b/exml/Comment.h @@ -18,7 +18,11 @@ namespace exml { */ Comment() { }; public: - static std::shared_ptr create(); + /** + * @brief defined factory + * @return Shared pointer on the Comment element + */ + static ememory::SharedPtr 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 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 toComment() override { return std::static_pointer_cast(shared_from_this()); }; - virtual std::shared_ptr toComment() const { + ememory::SharedPtr toComment() const override { return std::static_pointer_cast(shared_from_this()); }; }; diff --git a/exml/Declaration.cpp b/exml/Declaration.cpp index 7755a4c..f8b0f7e 100644 --- a/exml/Declaration.cpp +++ b/exml/Declaration.cpp @@ -10,9 +10,6 @@ #include #include -#undef __class__ -#define __class__ "Declaration" - /* basic declaration have 3 attributes: version encoding @@ -20,17 +17,12 @@ */ - -std::shared_ptr exml::Declaration::create() { - return std::shared_ptr(new exml::Declaration()); +ememory::SharedPtr exml::Declaration::create(const std::string& _name) { + return ememory::SharedPtr(new exml::Declaration(_name)); } -std::shared_ptr exml::Declaration::create(const std::string& _name) { - return std::shared_ptr(new exml::Declaration(_name)); -} - -std::shared_ptr exml::DeclarationXML::create(const std::string& _version, const std::string& _format, bool _standalone) { - return std::shared_ptr(new exml::DeclarationXML(_version, _format, _standalone)); +ememory::SharedPtr exml::DeclarationXML::create(const std::string& _version, const std::string& _format, bool _standalone) { + return ememory::SharedPtr(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 attribute = exml::Attribute::create(); + ememory::SharedPtr attribute = exml::Attribute::create(); if (attribute == nullptr) { CREATE_ERROR(_doc, _data, _pos, _filePos, " Allocation error ..."); return false; diff --git a/exml/Declaration.h b/exml/Declaration.h index 35df242..52c29d5 100644 --- a/exml/Declaration.h +++ b/exml/Declaration.h @@ -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 create(); - static std::shared_ptr 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 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 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 toDeclaration() override { return std::static_pointer_cast(shared_from_this()); }; - virtual std::shared_ptr toDeclaration() const { + ememory::SharedPtr toDeclaration() const override { return std::static_pointer_cast(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 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 create(const std::string& _version, const std::string& _format = "UTF-8", bool _standalone = true); }; } diff --git a/exml/Document.cpp b/exml/Document.cpp index 1be5921..fff6d6d 100644 --- a/exml/Document.cpp +++ b/exml/Document.cpp @@ -10,12 +10,8 @@ #include #include -#undef __class__ -#define __class__ "Document" - - -std::shared_ptr exml::Document::create() { - return std::shared_ptr(new exml::Document()); +ememory::SharedPtr exml::Document::create() { + return ememory::SharedPtr(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; diff --git a/exml/Document.h b/exml/Document.h index d168594..c278182 100644 --- a/exml/Document.h +++ b/exml/Document.h @@ -17,13 +17,13 @@ namespace exml { * @brief Constructor */ Document(); - static std::shared_ptr create(); /** - * @brief Destructor + * @brief Factory on a document + * @return an local created xml document */ - virtual ~Document() { }; + static ememory::SharedPtr 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 toDocument() { + bool iGenerate(std::string& _data, int32_t _indent) const override; + ememory::SharedPtr toDocument() override { return std::static_pointer_cast(shared_from_this()); }; - virtual std::shared_ptr toDocument() const { + ememory::SharedPtr toDocument() const override { return std::static_pointer_cast(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__ - diff --git a/exml/Element.cpp b/exml/Element.cpp index 0ccbac4..309155d 100644 --- a/exml/Element.cpp +++ b/exml/Element.cpp @@ -14,10 +14,6 @@ #include #include -#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::create() { - return std::shared_ptr(new exml::Element()); +ememory::SharedPtr exml::Element::create() { + return ememory::SharedPtr(new exml::Element()); } -std::shared_ptr exml::Element::create(const std::string& _value) { - return std::shared_ptr(new exml::Element(_value)); +ememory::SharedPtr exml::Element::create(const std::string& _value) { + return ememory::SharedPtr(new exml::Element(_value)); } - -exml::Element::~Element() { - m_listSub.clear(); -} - -enum exml::nodeType exml::Element::getType(int32_t _id) { - std::shared_ptr 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 tmpp = getNode(_id); +enum exml::nodeType exml::Element::getType(int32_t _id) const { + ememory::SharedPtr tmpp = getNode(_id); if (tmpp == nullptr) { return exml::typeUnknow; } return tmpp->getType(); } -std::shared_ptr exml::Element::getNode(int32_t _id) { +ememory::SharedPtr exml::Element::getNode(int32_t _id) { if (_id <0 || (size_t)_id>m_listSub.size()) { return nullptr; } return m_listSub[_id]; } -std::shared_ptr exml::Element::getNode(int32_t _id) const { +ememory::SharedPtr 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 exml::Element::getNode(int32_t _id) const { } -std::shared_ptr exml::Element::getElement(int32_t _id) { - std::shared_ptr tmpp = getNode(_id); +ememory::SharedPtr exml::Element::getElement(int32_t _id) { + ememory::SharedPtr tmpp = getNode(_id); if (tmpp == nullptr) { return nullptr; } return tmpp->toElement(); } -std::shared_ptr exml::Element::getElement(int32_t _id) const { - std::shared_ptr tmpp = getNode(_id); +ememory::SharedPtr exml::Element::getElement(int32_t _id) const { + ememory::SharedPtr tmpp = getNode(_id); if (tmpp == nullptr) { return nullptr; } return tmpp->toElement(); } -std::shared_ptr exml::Element::getNamed(const std::string& _name) { +ememory::SharedPtr exml::Element::getNamed(const std::string& _name) { if (_name.size() == 0) { return nullptr; } @@ -103,7 +87,7 @@ std::shared_ptr exml::Element::getNamed(const std::string& _name) return nullptr; } -std::shared_ptr exml::Element::getNamed(const std::string& _name) const { +ememory::SharedPtr exml::Element::getNamed(const std::string& _name) const { if (_name.size() == 0) { return nullptr; } @@ -120,7 +104,7 @@ std::shared_ptr exml::Element::getNamed(const std::string& return nullptr; } -void exml::Element::append(const std::shared_ptr& _node) { +void exml::Element::append(const ememory::SharedPtr& _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 declaration = exml::Declaration::create(tmpname); + ememory::SharedPtr 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 comment = exml::Comment::create(); + ememory::SharedPtr 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 text = exml::TextCDATA::create(); + ememory::SharedPtr 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 element = exml::Element::create(tmpname); + ememory::SharedPtr 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 text = exml::Text::create(); + ememory::SharedPtr 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 attribute = exml::Attribute::create(); + ememory::SharedPtr attribute = exml::Attribute::create(); if (attribute == nullptr) { CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ..."); return false; diff --git a/exml/Element.h b/exml/Element.h index aee2025..ac104a4 100644 --- a/exml/Element.h +++ b/exml/Element.h @@ -27,14 +27,10 @@ namespace exml { }; public: - static std::shared_ptr create(); - static std::shared_ptr create(const std::string& _value); - /** - * @brief Destructor - */ - virtual ~Element(); + static ememory::SharedPtr create(); + static ememory::SharedPtr create(const std::string& _value); protected: - std::vector> m_listSub; + std::vector> 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& _node); + void append(const ememory::SharedPtr& _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 getNode(int32_t _id); - std::shared_ptr getNode(int32_t _id) const; + ememory::SharedPtr getNode(int32_t _id); + ememory::SharedPtr 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 getElement(int32_t _id); - std::shared_ptr getElement(int32_t _id) const; + ememory::SharedPtr getElement(int32_t _id); + ememory::SharedPtr 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 getNamed(const std::string& _name); - std::shared_ptr getNamed(const std::string& _name) const; + ememory::SharedPtr getNamed(const std::string& _name); + ememory::SharedPtr 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 * @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 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 toElement() override { return std::static_pointer_cast(shared_from_this()); - }; - virtual std::shared_ptr toElement() const { + } + ememory::SharedPtr toElement() const override { return std::static_pointer_cast(shared_from_this()); - }; - virtual void clear(); + } + void clear() override; }; } diff --git a/exml/Node.cpp b/exml/Node.cpp index 2c1e301..2f249e8 100644 --- a/exml/Node.cpp +++ b/exml/Node.cpp @@ -9,9 +9,6 @@ #include #include -#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::Node::toDocument() { + return nullptr; +} + +ememory::SharedPtr exml::Node::toDocument() const { + return nullptr; +} + +ememory::SharedPtr exml::Node::toAttribute() { + return nullptr; +} + +ememory::SharedPtr exml::Node::toAttribute() const { + return nullptr; +} + +ememory::SharedPtr exml::Node::toComment() { + return nullptr; +} + +ememory::SharedPtr exml::Node::toComment() const { + return nullptr; +} + +ememory::SharedPtr exml::Node::toDeclaration() { + return nullptr; +} + +ememory::SharedPtr exml::Node::toDeclaration() const { + return nullptr; +} + +ememory::SharedPtr exml::Node::toElement() { + return nullptr; +} + +ememory::SharedPtr exml::Node::toElement() const { + return nullptr; +} + +ememory::SharedPtr exml::Node::toText() { + return nullptr; +} + +ememory::SharedPtr 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; +} + diff --git a/exml/Node.h b/exml/Node.h index 817b284..94b34ab 100644 --- a/exml/Node.h +++ b/exml/Node.h @@ -7,10 +7,14 @@ */ #pragma once -#include +#include #include #include +#include +/** + * @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, //!< InsideText }; - - 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{ + /** + * @brief Basic main object of all xml elements. + */ + class Node : public ememory::EnableSharedFromThis{ protected: /** * @brief basic element of a xml structure @@ -131,11 +63,10 @@ namespace exml { */ Node(const std::string& _value); public: - //static std::shared_ptr 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 toDocument() { - return nullptr; - }; - virtual std::shared_ptr toDocument() const { - return nullptr; - }; + virtual ememory::SharedPtr toDocument(); + /** + * @brief Cast the element in a Document if it is possible. + * @return CONST pointer on the class or nullptr. + */ + virtual ememory::SharedPtr toDocument() const; /** * @brief Cast the element in a Attribute if it is possible. * @return pointer on the class or nullptr. */ - virtual std::shared_ptr toAttribute() { - return nullptr; - }; - virtual std::shared_ptr toAttribute() const { - return nullptr; - }; + virtual ememory::SharedPtr toAttribute(); + /** + * @brief Cast the element in a Attribute if it is possible. + * @return CONST pointer on the class or nullptr. + */ + virtual ememory::SharedPtr toAttribute() const; /** * @brief Cast the element in a Comment if it is possible. * @return pointer on the class or nullptr. */ - virtual std::shared_ptr toComment() { - return nullptr; - }; - virtual std::shared_ptr toComment() const { - return nullptr; - }; + virtual ememory::SharedPtr toComment(); + /** + * @brief Cast the element in a Comment if it is possible. + * @return CONST pointer on the class or nullptr. + */ + virtual ememory::SharedPtr toComment() const; /** * @brief Cast the element in a Declaration if it is possible. * @return pointer on the class or nullptr. */ - virtual std::shared_ptr toDeclaration() { - return nullptr; - }; - virtual std::shared_ptr toDeclaration() const { - return nullptr; - }; + virtual ememory::SharedPtr toDeclaration(); + /** + * @brief Cast the element in a Declaration if it is possible. + * @return CONST pointer on the class or nullptr. + */ + virtual ememory::SharedPtr toDeclaration() const; /** * @brief Cast the element in a Element if it is possible. * @return pointer on the class or nullptr. */ - virtual std::shared_ptr toElement() { - return nullptr; - }; - virtual std::shared_ptr toElement() const { - return nullptr; - }; + virtual ememory::SharedPtr toElement(); + /** + * @brief Cast the element in a Element if it is possible. + * @return CONST pointer on the class or nullptr. + */ + virtual ememory::SharedPtr toElement() const; /** * @brief Cast the element in a Text if it is possible. * @return pointer on the class or nullptr. */ - virtual std::shared_ptr toText() { - return nullptr; - }; - virtual std::shared_ptr toText() const{ - return nullptr; - }; + virtual ememory::SharedPtr toText(); + /** + * @brief Cast the element in a Text if it is possible. + * @return CONST pointer on the class or nullptr. + */ + virtual ememory::SharedPtr 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 diff --git a/exml/Text.cpp b/exml/Text.cpp index 1ebfe0c..71cf91e 100644 --- a/exml/Text.cpp +++ b/exml/Text.cpp @@ -11,10 +11,6 @@ #include #include -#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::create() { - return std::shared_ptr(new exml::Text()); +ememory::SharedPtr exml::Text::create() { + return ememory::SharedPtr(new exml::Text()); } -std::shared_ptr exml::Text::create(const std::string& _data) { - return std::shared_ptr(new exml::Text(_data)); +ememory::SharedPtr exml::Text::create(const std::string& _data) { + return ememory::SharedPtr(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::create() { - return std::shared_ptr(new exml::TextCDATA()); +ememory::SharedPtr exml::TextCDATA::create() { + return ememory::SharedPtr(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 : diff --git a/exml/Text.h b/exml/Text.h index 51ebf7b..c3773f7 100644 --- a/exml/Text.h +++ b/exml/Text.h @@ -23,27 +23,23 @@ namespace exml { */ Text(const std::string& _data) : exml::Node(_data) { }; public: - static std::shared_ptr create(); - static std::shared_ptr create(const std::string& _data); - /** - * @brief Destructor - */ - virtual ~Text() { }; + static ememory::SharedPtr create(); + static ememory::SharedPtr 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 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 toText() override { return std::static_pointer_cast(shared_from_this()); }; - virtual std::shared_ptr toText() const{ + ememory::SharedPtr toText() const override { return std::static_pointer_cast(shared_from_this()); }; }; @@ -54,14 +50,10 @@ namespace exml { */ TextCDATA() { }; public: - static std::shared_ptr 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 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; }; } diff --git a/lutin_exml.py b/lutin_exml.py index 4639f72..0527c32 100644 --- a/lutin_exml.py +++ b/lutin_exml.py @@ -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', diff --git a/test/main.cpp b/test/main.cpp index 8b4ff67..c934b85 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -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(argv));