From c9f7abcd96f2decebe4968fe10071c6e861a4d85 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 10 Nov 2013 14:43:25 +0100 Subject: [PATCH] [DEV] codestyle review --- exml/Attribute.cpp | 16 ++--- exml/Attribute.h | 26 +++++--- exml/AttributeList.cpp | 27 +++----- exml/AttributeList.h | 15 +++-- exml/Comment.cpp | 6 +- exml/Comment.h | 23 ++++--- exml/Declaration.cpp | 13 ++-- exml/Declaration.h | 28 ++++---- exml/Document.cpp | 46 +++++-------- exml/Document.h | 44 +++++++++---- exml/Element.cpp | 71 +++++++++----------- exml/Element.h | 31 +++++---- exml/Node.h | 145 ++++++++++++++++++++++++++++++----------- exml/Text.h | 12 +++- exml/test.cpp | 12 ++-- 15 files changed, 298 insertions(+), 217 deletions(-) diff --git a/exml/Attribute.cpp b/exml/Attribute.cpp index aa06713..dea175e 100644 --- a/exml/Attribute.cpp +++ b/exml/Attribute.cpp @@ -14,14 +14,12 @@ #define __class__ "Attribute" exml::Attribute::Attribute(const etk::UString& _name, const etk::UString& _value) : - exml::Node(_value), - m_name(_name) -{ + exml::Node(_value), + m_name(_name) { } -bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) -{ +bool exml::Attribute::iParse(const etk::UString& _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 : @@ -108,8 +106,7 @@ bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _cas return true; } -bool exml::Attribute::iGenerate(etk::UString& _data, int32_t _indent) const -{ +bool exml::Attribute::iGenerate(etk::UString& _data, int32_t _indent) const { _data += " "; _data += m_name; _data += "=\""; @@ -118,10 +115,7 @@ bool exml::Attribute::iGenerate(etk::UString& _data, int32_t _indent) const return true; } - - -void exml::Attribute::clear(void) -{ +void exml::Attribute::clear(void) { m_name=""; } diff --git a/exml/Attribute.h b/exml/Attribute.h index dc0167b..380b48f 100644 --- a/exml/Attribute.h +++ b/exml/Attribute.h @@ -12,10 +12,8 @@ #include #include -namespace exml -{ - class Attribute : public Node - { +namespace exml { + class Attribute : public Node { public: /** * @brief Constructor @@ -38,18 +36,28 @@ namespace exml * @brief set the name of the attribute * @param[in] _name New name of the attribute */ - virtual void setName(etk::UString _name) { m_name = _name; }; + virtual void setName(etk::UString _name) { + m_name = _name; + }; /** * @brief get the current name of the Attribute * @return String of the attribute */ - virtual const etk::UString& getName(void) const { return m_name; }; + virtual const etk::UString& getName(void) const { + return m_name; + }; public: // herited function: - virtual nodeType_te getType(void) const { return exml::typeAttribute; }; + virtual enum nodeType getType(void) const { + return exml::typeAttribute; + }; virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc); virtual bool iGenerate(etk::UString& _data, int32_t _indent) const; - virtual exml::Attribute* toAttribute(void) { return this; }; - virtual const exml::Attribute* toAttribute(void) const { return this; }; + virtual exml::Attribute* toAttribute(void) { + return this; + }; + virtual const exml::Attribute* toAttribute(void) const { + return this; + }; virtual void clear(void); }; }; diff --git a/exml/AttributeList.cpp b/exml/AttributeList.cpp index a0224b3..c594f87 100644 --- a/exml/AttributeList.cpp +++ b/exml/AttributeList.cpp @@ -12,8 +12,7 @@ #undef __class__ #define __class__ "AttributeList" -exml::AttributeList::~AttributeList(void) -{ +exml::AttributeList::~AttributeList(void) { for (int32_t iii=0; iiim_listAttribute.size()) { return NULL; } return m_listAttribute[_id]; } -const exml::Attribute* exml::AttributeList::getAttr(int32_t _id) const -{ +const exml::Attribute* exml::AttributeList::getAttr(int32_t _id) const { if (_id <0 || _id>m_listAttribute.size()) { return NULL; } return m_listAttribute[_id]; } -void exml::AttributeList::appendAttribute(exml::Attribute* _attr) -{ +void exml::AttributeList::appendAttribute(exml::Attribute* _attr) { if (_attr == NULL) { EXML_ERROR("Try to set an empty node"); return; @@ -54,8 +50,7 @@ void exml::AttributeList::appendAttribute(exml::Attribute* _attr) m_listAttribute.pushBack(_attr); } -const etk::UString& exml::AttributeList::getAttribute(const etk::UString& _name) const -{ +const etk::UString& exml::AttributeList::getAttribute(const etk::UString& _name) const { static const etk::UString errorReturn(""); if (_name.size() == 0) { return errorReturn; @@ -69,8 +64,7 @@ const etk::UString& exml::AttributeList::getAttribute(const etk::UString& _name) return errorReturn; } -bool exml::AttributeList::existAttribute(const etk::UString& _name) const -{ +bool exml::AttributeList::existAttribute(const etk::UString& _name) const { if (_name.size() == 0) { return false; } @@ -83,8 +77,7 @@ bool exml::AttributeList::existAttribute(const etk::UString& _name) const return false; } -void exml::AttributeList::setAttribute(const etk::UString& _name, const etk::UString& _value) -{ +void exml::AttributeList::setAttribute(const etk::UString& _name, const etk::UString& _value) { // check if attribute already det : for (int32_t iii=0; iiiiGenerate(_data, _indent); @@ -111,8 +103,7 @@ bool exml::AttributeList::iGenerate(etk::UString& _data, int32_t _indent) const return true; } -void exml::AttributeList::clear(void) -{ +void exml::AttributeList::clear(void) { exml::Node::clear(); for (int32_t iii=0; iii #include -namespace exml -{ - class AttributeList : public Node - { +namespace exml { + class AttributeList : public Node { public: /** * @brief Constructor @@ -26,7 +24,10 @@ namespace exml * @brief Constructor * @param[in] _value Node value; */ - AttributeList(const etk::UString& _value) : exml::Node(_value) { }; + AttributeList(const etk::UString& _value) : + exml::Node(_value) { + + }; /** * @brief Destructor */ @@ -38,7 +39,9 @@ namespace exml * @brief get the number of attribute in the Node * @return Nulber of attribute >=0 */ - int32_t sizeAttribute(void) const { return m_listAttribute.size(); }; + int32_t sizeAttribute(void) const { + return m_listAttribute.size(); + }; /** * @brief add attribute on the List * @param[in] _attr Pointer on the attribute diff --git a/exml/Comment.cpp b/exml/Comment.cpp index 0a8a028..5f0a8fb 100644 --- a/exml/Comment.cpp +++ b/exml/Comment.cpp @@ -13,8 +13,7 @@ #undef __class__ #define __class__ "Comment" -bool exml::Comment::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) -{ +bool exml::Comment::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) { EXML_VERBOSE("start parse : 'comment'"); m_pos = _filePos; exml::filePos tmpPos; @@ -53,8 +52,7 @@ bool exml::Comment::iParse(const etk::UString& _data, int32_t& _pos, bool _caseS return false; } -bool exml::Comment::iGenerate(etk::UString& _data, int32_t _indent) const -{ +bool exml::Comment::iGenerate(etk::UString& _data, int32_t _indent) const { addIndent(_data, _indent); _data += " typeText, //!< InsideText - } nodeType_te; + }; - class filePos - { + class filePos { private: int32_t m_col; int32_t m_line; public: - filePos(void) : m_col(0),m_line(0) { }; - filePos(int32_t _line, int32_t _col) : m_col(_col),m_line(_line) { }; + filePos(void) : + m_col(0), + m_line(0) { + + }; + filePos(int32_t _line, int32_t _col) : + m_col(_col), + m_line(_line) { + + }; ~filePos(void) { }; - filePos& operator ++(void) { m_col++; return *this; }; - filePos& operator --(void) { m_col--; if(m_col<0) { m_col=0;} return *this; }; + filePos& operator ++(void) { + m_col++; + return *this; + }; + filePos& operator --(void) { + 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; @@ -74,7 +90,10 @@ namespace exml m_line = _obj.m_line; return *this; } - void newLine(void) { m_col=0; m_line++; }; + void newLine(void) { + m_col=0; + m_line++; + }; bool check(const etk::UChar& _val) { m_col++; if (_val == '\n') { @@ -91,18 +110,24 @@ namespace exml m_col = 0; m_line = 0; } - int32_t getCol(void) const { return m_col; }; - int32_t getLine(void) const { return m_line; }; + int32_t getCol(void) const { + return m_col; + }; + int32_t getLine(void) const { + return m_line; + }; }; etk::CCout& operator <<(etk::CCout& _os, const filePos& _obj); - class Node - { + class Node { public: /** * @brief basic element of a xml structure */ - Node(void) : m_pos(0,0) { }; + Node(void) : + m_pos(0,0) { + + }; /** * @brief basic element of a xml structure * @param[in] value of the node @@ -128,14 +153,18 @@ namespace exml * @param[in] current indentation of the file * @return false if an error occured. */ - virtual bool iGenerate(etk::UString& _data, int32_t _indent) const { return true; }; + virtual bool iGenerate(etk::UString& _data, int32_t _indent) const { + return true; + }; protected: 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(void) { return m_pos; }; + const exml::filePos& getPos(void) { + return m_pos; + }; protected: etk::UString m_value; //!< value of the node (for element this is the name, for text it is the inside text ...) public: @@ -143,18 +172,24 @@ namespace exml * @brief set the value of the node. * @param[in] _value New value of the node. */ - virtual void setValue(etk::UString _value) { m_value = _value; }; + virtual void setValue(etk::UString _value) { + m_value = _value; + }; /** * @brief get the current element Value. * @return the reference of the string value. */ - virtual const etk::UString& getValue(void) const { return m_value; }; + virtual const etk::UString& getValue(void) const { + return m_value; + }; public: /** * @brief get the node type. * @return the type of the Node. */ - virtual nodeType_te getType(void) const { return typeNode; }; + virtual enum nodeType getType(void) const { + return typeNode; + }; protected: /** * @brief add indentation of the string input. @@ -187,69 +222,105 @@ namespace exml * @brief Cast the element in a Document if it is possible. * @return pointer on the class or NULL. */ - virtual exml::Document* toDocument(void) { return NULL; }; - virtual const exml::Document* toDocument(void) const { return NULL; }; + virtual exml::Document* toDocument(void) { + return NULL; + }; + virtual const exml::Document* toDocument(void) const { + return NULL; + }; /** * @brief Cast the element in a Attribute if it is possible. * @return pointer on the class or NULL. */ - virtual exml::Attribute* toAttribute(void) { return NULL; }; - virtual const exml::Attribute* toAttribute(void) const { return NULL; }; + virtual exml::Attribute* toAttribute(void) { + return NULL; + }; + virtual const exml::Attribute* toAttribute(void) const { + return NULL; + }; /** * @brief Cast the element in a Comment if it is possible. * @return pointer on the class or NULL. */ - virtual exml::Comment* toComment(void) { return NULL; }; - virtual const exml::Comment* toComment(void) const { return NULL; }; + virtual exml::Comment* toComment(void) { + return NULL; + }; + virtual const exml::Comment* toComment(void) const { + return NULL; + }; /** * @brief Cast the element in a Declaration if it is possible. * @return pointer on the class or NULL. */ - virtual exml::Declaration* toDeclaration(void) { return NULL; }; - virtual const exml::Declaration* toDeclaration(void) const { return NULL; }; + virtual exml::Declaration* toDeclaration(void) { + return NULL; + }; + virtual const exml::Declaration* toDeclaration(void) const { + return NULL; + }; /** * @brief Cast the element in a Element if it is possible. * @return pointer on the class or NULL. */ - virtual exml::Element* toElement(void) { return NULL; }; - virtual const exml::Element* toElement(void) const { return NULL; }; + virtual exml::Element* toElement(void) { + return NULL; + }; + virtual const exml::Element* toElement(void) const { + return NULL; + }; /** * @brief Cast the element in a Text if it is possible. * @return pointer on the class or NULL. */ - virtual exml::Text* toText(void) { return NULL; }; - virtual const exml::Text* toText(void) const{ return NULL; }; + virtual exml::Text* toText(void) { + return NULL; + }; + virtual const exml::Text* toText(void) const{ + return NULL; + }; /** * @brief check if the node is a exml::Document * @return true if the node is a exml::Document */ - bool isDocument(void) const { return getType() == exml::typeDocument; }; + bool isDocument(void) const { + return getType() == exml::typeDocument; + }; /** * @brief check if the node is a exml::Attribute * @return true if the node is a exml::Attribute */ - bool isAttribute(void) const { return getType() == exml::typeAttribute; }; + bool isAttribute(void) const { + return getType() == exml::typeAttribute; + }; /** * @brief check if the node is a exml::Comment * @return true if the node is a exml::Comment */ - bool isComment(void) const { return getType() == exml::typeComment; }; + bool isComment(void) const { + return getType() == exml::typeComment; + }; /** * @brief check if the node is a exml::Declaration * @return true if the node is a exml::Declaration */ - bool isDeclaration(void) const { return getType() == exml::typeDeclaration; }; + bool isDeclaration(void) const { + return getType() == exml::typeDeclaration; + }; /** * @brief check if the node is a exml::Element * @return true if the node is a exml::Element */ - bool isElement(void) const { return getType() == exml::typeElement; }; + bool isElement(void) const { + return getType() == exml::typeElement; + }; /** * @brief check if the node is a exml::Text * @return true if the node is a exml::Text */ - bool isText(void) const { return getType() == exml::typeText; }; + bool isText(void) const { + return getType() == exml::typeText; + }; /** * @brief clear the Node diff --git a/exml/Text.h b/exml/Text.h index 56acd8b..1cfd509 100644 --- a/exml/Text.h +++ b/exml/Text.h @@ -34,11 +34,17 @@ namespace exml { */ int32_t countLines(void) const; public: // herited function: - virtual nodeType_te getType(void) const { return typeText; }; + virtual enum nodeType getType(void) const { + return typeText; + }; virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc); virtual bool iGenerate(etk::UString& _data, int32_t _indent) const; - virtual exml::Text* toText(void) { return this; }; - virtual const exml::Text* toText(void) const{ return this; }; + virtual exml::Text* toText(void) { + return this; + }; + virtual const exml::Text* toText(void) const{ + return this; + }; }; class TextCDATA : public Text { public: diff --git a/exml/test.cpp b/exml/test.cpp index 29fd67d..1366740 100644 --- a/exml/test.cpp +++ b/exml/test.cpp @@ -14,15 +14,13 @@ #undef __class__ #define __class__ "test" -class testCheck -{ +class testCheck { public: etk::UString m_ref; etk::UString m_input; int32_t m_errorPos; // -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ???? testCheck(void) {}; - void set(const etk::UString& _ref, int32_t _pos, const etk::UString& _input) - { + void set(const etk::UString& _ref, int32_t _pos, const etk::UString& _input) { m_ref = _ref; m_input = _input; m_errorPos = _pos; @@ -31,8 +29,7 @@ class testCheck etk::Vector l_list; -void init(void) -{ +void init(void) { etk::UString reference; etk::UString input; testCheck check; @@ -281,8 +278,7 @@ void init(void) l_list.pushBack(check); } -int main(int argc, const char *argv[]) -{ +int main(int argc, const char *argv[]) { debug::setGeneralLevel(etk::LOG_LEVEL_VERBOSE); init(); int32_t countError = 0;