[DOC] Basic documentation done

This commit is contained in:
Edouard DUPIN 2016-04-11 21:57:33 +02:00
parent b59936f6e5
commit 753c0c0db2
11 changed files with 139 additions and 54 deletions

View File

@ -11,6 +11,9 @@
#include <vector> #include <vector>
namespace exml { namespace exml {
/**
* @brief Single attribute element
*/
class Attribute : public exml::Node { class Attribute : public exml::Node {
protected: protected:
/** /**
@ -46,7 +49,7 @@ namespace exml {
}; };
public: public:
enum nodeType getType() const override { enum nodeType getType() const override {
return exml::typeAttribute; return exml::nodeType_attribute;
}; };
bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override; 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; bool iGenerate(std::string& _data, int32_t _indent) const override;

View File

@ -13,6 +13,9 @@
#include <utility> #include <utility>
namespace exml { namespace exml {
/**
* @brief List of all attribute element in a node
*/
class AttributeList : public exml::Node { class AttributeList : public exml::Node {
protected: protected:
/** /**

View File

@ -11,6 +11,9 @@
#include <vector> #include <vector>
namespace exml { namespace exml {
/**
* @brief Comment node: &lt;!-- ... --&gt;
*/
class Comment : public exml::Node { class Comment : public exml::Node {
protected: protected:
/** /**
@ -30,19 +33,19 @@ namespace exml {
Comment(const std::string& _value) : Comment(const std::string& _value) :
exml::Node(_value) { exml::Node(_value) {
}; }
public: public:
enum nodeType getType() const override { enum nodeType getType() const override {
return typeAttribute; return nodeType_attribute;
}; }
bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override; 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; bool iGenerate(std::string& _data, int32_t _indent) const override;
ememory::SharedPtr<exml::Comment> toComment() override { ememory::SharedPtr<exml::Comment> toComment() override {
return std::static_pointer_cast<exml::Comment>(shared_from_this()); return std::static_pointer_cast<exml::Comment>(shared_from_this());
}; }
ememory::SharedPtr<const exml::Comment> toComment() const override { ememory::SharedPtr<const exml::Comment> toComment() const override {
return std::static_pointer_cast<const exml::Comment>(shared_from_this()); return std::static_pointer_cast<const exml::Comment>(shared_from_this());
}; }
}; };
} }

View File

@ -10,6 +10,9 @@
#include <exml/AttributeList.h> #include <exml/AttributeList.h>
namespace exml { namespace exml {
/**
* @brief Declaration node: &lt;?XXXXXX ... &gt;
*/
class Declaration : public exml::AttributeList { class Declaration : public exml::AttributeList {
protected: protected:
/** /**
@ -29,7 +32,7 @@ namespace exml {
static ememory::SharedPtr<Declaration> create(const std::string& _name=""); static ememory::SharedPtr<Declaration> create(const std::string& _name="");
public: public:
enum nodeType getType() const override{ enum nodeType getType() const override{
return typeAttribute; return nodeType_attribute;
}; };
bool iGenerate(std::string& _data, int32_t _indent) const override; 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; bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override;
@ -40,6 +43,9 @@ namespace exml {
return std::static_pointer_cast<const exml::Declaration>(shared_from_this()); return std::static_pointer_cast<const exml::Declaration>(shared_from_this());
}; };
}; };
/**
* @brief Declaration node: &lt;?XML ... &gt;
*/
class DeclarationXML : public exml::Declaration { class DeclarationXML : public exml::Declaration {
public: public:
/** /**

View File

@ -11,6 +11,9 @@
#include <vector> #include <vector>
namespace exml { namespace exml {
/**
* @brief Basic document element of a document
*/
class Document : public exml::Element { class Document : public exml::Element {
public: public:
/** /**
@ -78,26 +81,41 @@ namespace exml {
std::string m_Line; //!< Parse line error (copy) std::string m_Line; //!< Parse line error (copy)
exml::FilePos m_filePos; //!< position of the error exml::FilePos m_filePos; //!< position of the error
public: public:
/**
* @brief Request display error when detected (not print only at the end ...)
*/
void displayErrorWhenDetected() { void displayErrorWhenDetected() {
m_writeErrorWhenDetexted = true; m_writeErrorWhenDetexted = true;
}; }
/**
* @brief Request NOT display error when detected.
*/
void notDisplayErrorWhenDetected() { void notDisplayErrorWhenDetected() {
m_writeErrorWhenDetexted = false; m_writeErrorWhenDetexted = false;
}; }
/**
* @brief Create an error in the parsing (call by the syetm for error management)
* @param[in] _data string of chat is wrong
* @param[in] _pos Position in the file
* @param[in] _filePos human position of the error
* @param[in] _comment Error string to display
*/
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);
/**
* @brief request display in log of the error
*/
void displayError(); void displayError();
public: public:
enum nodeType getType() const override { enum nodeType getType() const override {
return typeDocument; return nodeType_document;
}; }
bool iGenerate(std::string& _data, int32_t _indent) const override; bool iGenerate(std::string& _data, int32_t _indent) const override;
ememory::SharedPtr<exml::Document> toDocument() override { ememory::SharedPtr<exml::Document> toDocument() override {
return std::static_pointer_cast<exml::Document>(shared_from_this()); return std::static_pointer_cast<exml::Document>(shared_from_this());
}; }
ememory::SharedPtr<const exml::Document> toDocument() const override { ememory::SharedPtr<const exml::Document> toDocument() const override {
return std::static_pointer_cast<const exml::Document>(shared_from_this()); return std::static_pointer_cast<const exml::Document>(shared_from_this());
}; }
}; };
}; };

View File

@ -24,9 +24,6 @@ static bool isWhiteChar(char32_t _val) {
return false; return false;
} }
ememory::SharedPtr<exml::Element> exml::Element::create() {
return ememory::SharedPtr<exml::Element>(new exml::Element());
}
ememory::SharedPtr<exml::Element> exml::Element::create(const std::string& _value) { ememory::SharedPtr<exml::Element> exml::Element::create(const std::string& _value) {
return ememory::SharedPtr<exml::Element>(new exml::Element(_value)); return ememory::SharedPtr<exml::Element>(new exml::Element(_value));
} }
@ -34,7 +31,7 @@ ememory::SharedPtr<exml::Element> exml::Element::create(const std::string& _valu
enum exml::nodeType exml::Element::getType(int32_t _id) const { enum exml::nodeType exml::Element::getType(int32_t _id) const {
ememory::SharedPtr<const exml::Node> tmpp = getNode(_id); ememory::SharedPtr<const exml::Node> tmpp = getNode(_id);
if (tmpp == nullptr) { if (tmpp == nullptr) {
return exml::typeUnknow; return exml::nodeType_unknow;
} }
return tmpp->getType(); return tmpp->getType();
} }
@ -76,7 +73,7 @@ ememory::SharedPtr<exml::Element> exml::Element::getNamed(const std::string& _na
} }
for (size_t iii=0; iii<m_listSub.size(); iii++) { for (size_t iii=0; iii<m_listSub.size(); iii++) {
if( m_listSub[iii] != nullptr if( m_listSub[iii] != nullptr
&& m_listSub[iii]->getType() == exml::typeElement && m_listSub[iii]->getType() == exml::nodeType_element
&& m_listSub[iii]->getValue() == _name) { && m_listSub[iii]->getValue() == _name) {
if (m_listSub[iii] == nullptr) { if (m_listSub[iii] == nullptr) {
return nullptr; return nullptr;
@ -93,7 +90,7 @@ ememory::SharedPtr<const exml::Element> exml::Element::getNamed(const std::strin
} }
for (size_t iii=0; iii<m_listSub.size(); iii++) { for (size_t iii=0; iii<m_listSub.size(); iii++) {
if( m_listSub[iii] != nullptr if( m_listSub[iii] != nullptr
&& m_listSub[iii]->getType() == exml::typeElement && m_listSub[iii]->getType() == exml::nodeType_element
&& m_listSub[iii]->getValue() == _name) { && m_listSub[iii]->getValue() == _name) {
if (m_listSub[iii] == nullptr) { if (m_listSub[iii] == nullptr) {
return nullptr; return nullptr;
@ -109,7 +106,7 @@ void exml::Element::append(const ememory::SharedPtr<exml::Node>& _node) {
EXML_ERROR("Try to set an empty node"); EXML_ERROR("Try to set an empty node");
return; return;
} }
if (_node->getType() == exml::typeAttribute) { if (_node->getType() == exml::nodeType_attribute) {
appendAttribute(_node->toAttribute()); appendAttribute(_node->toAttribute());
return; return;
} }
@ -125,7 +122,7 @@ void exml::Element::append(const ememory::SharedPtr<exml::Node>& _node) {
std::string exml::Element::getText() const { std::string exml::Element::getText() const {
std::string res; std::string res;
if (m_listSub.size() == 1) { if (m_listSub.size() == 1) {
if (m_listSub[0]->getType() == typeText) { if (m_listSub[0]->getType() == nodeType_text) {
res = m_listSub[0]->getValue(); res = m_listSub[0]->getValue();
} else { } else {
m_listSub[0]->iGenerate(res, 0); m_listSub[0]->iGenerate(res, 0);
@ -149,7 +146,7 @@ bool exml::Element::iGenerate(std::string& _data, int32_t _indent) const {
if (m_listSub.size()>0) { if (m_listSub.size()>0) {
if( m_listSub.size() == 1 if( m_listSub.size() == 1
&& m_listSub[0] != nullptr && m_listSub[0] != nullptr
&& m_listSub[0]->getType() == exml::typeText && m_listSub[0]->getType() == exml::nodeType_text
&& std::dynamic_pointer_cast<exml::Text>(m_listSub[0])->countLines() == 1) { && std::dynamic_pointer_cast<exml::Text>(m_listSub[0])->countLines() == 1) {
_data += ">"; _data += ">";
m_listSub[0]->iGenerate(_data,0); m_listSub[0]->iGenerate(_data,0);

View File

@ -12,6 +12,9 @@
#include <exml/AttributeList.h> #include <exml/AttributeList.h>
namespace exml { namespace exml {
/**
* @brief Basic element Node of an XML document &lt;YYYYY&gt;
*/
class Element : public exml::AttributeList { class Element : public exml::AttributeList {
protected: protected:
/** /**
@ -27,8 +30,12 @@ namespace exml {
}; };
public: public:
static ememory::SharedPtr<Element> create(); /**
static ememory::SharedPtr<Element> create(const std::string& _value); * @brief factory of an exml::Element
* @param[in] _value Name of the node.
* @return Shared pointer on the Element
*/
static ememory::SharedPtr<Element> create(const std::string& _value="");
protected: protected:
std::vector<ememory::SharedPtr<exml::Node>> m_listSub; //!< List of subNodes std::vector<ememory::SharedPtr<exml::Node>> m_listSub; //!< List of subNodes
public: public:
@ -56,6 +63,11 @@ namespace exml {
* @return Pointer on node. * @return Pointer on node.
*/ */
ememory::SharedPtr<Node> getNode(int32_t _id); ememory::SharedPtr<Node> getNode(int32_t _id);
/**
* @brief get the Node pointer of the element id.
* @param[in] _id Id of the element.
* @return Pointer on node.
*/
ememory::SharedPtr<const Node> getNode(int32_t _id) const; ememory::SharedPtr<const Node> getNode(int32_t _id) const;
/** /**
* @brief get the element casted in Element (if the node is not an element return NULL). * @brief get the element casted in Element (if the node is not an element return NULL).
@ -63,6 +75,11 @@ namespace exml {
* @return Pointer on the element or NULL. * @return Pointer on the element or NULL.
*/ */
ememory::SharedPtr<Element> getElement(int32_t _id); ememory::SharedPtr<Element> getElement(int32_t _id);
/**
* @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.
*/
ememory::SharedPtr<const Element> getElement(int32_t _id) const; ememory::SharedPtr<const Element> getElement(int32_t _id) const;
/** /**
* @brief get an element with his name (work only with exml::Element) * @brief get an element with his name (work only with exml::Element)
@ -70,6 +87,11 @@ namespace exml {
* @return Pointer on the element or NULL. * @return Pointer on the element or NULL.
*/ */
ememory::SharedPtr<Element> getNamed(const std::string& _name); ememory::SharedPtr<Element> getNamed(const std::string& _name);
/**
* @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.
*/
ememory::SharedPtr<const Element> getNamed(const std::string& _name) const; ememory::SharedPtr<const Element> getNamed(const std::string& _name) const;
/** /**
* @brief get the internal data of the element (if the element has some sub node thay are converted in xml string == > like this it is not needed to use <![CDATA[...]]> * @brief get the internal data of the element (if the element has some sub node thay are converted in xml string == > like this it is not needed to use <![CDATA[...]]>
@ -77,10 +99,26 @@ namespace exml {
*/ */
std::string getText() const; std::string getText() const;
protected: protected:
bool subParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc, bool _mainNode=false); /**
public: // herited function: * @brief Parse sub node string
* @param[in] _data all file string data
* @param[in,out] _pos Position to start parsing in the file and return the end of parsing
* @param[in] _caseSensitive Case sensitive parsing (usefull for html)
* @param[in] _filePos Current File position of the parsing
* @param[in] _doc Document base reference
* @param[in] _mainNode if true, this is the first root node
* @return true parsing is done OK
* @return false An error appear in the parsing
*/
bool subParse(const std::string& _data,
int32_t& _pos,
bool _caseSensitive,
exml::FilePos& _filePos,
exml::Document& _doc,
bool _mainNode=false);
public:
enum nodeType getType() const override { enum nodeType getType() const override {
return typeElement; return nodeType_element;
} }
bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override; 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; bool iGenerate(std::string& _data, int32_t _indent) const override;

View File

@ -126,7 +126,7 @@ const std::string& exml::Node::getValue() const {
} }
enum exml::nodeType exml::Node::getType() const { enum exml::nodeType exml::Node::getType() const {
return typeNode; return nodeType_node;
} }
ememory::SharedPtr<exml::Document> exml::Node::toDocument() { ememory::SharedPtr<exml::Document> exml::Node::toDocument() {
@ -178,26 +178,26 @@ ememory::SharedPtr<const exml::Text> exml::Node::toText() const{
} }
bool exml::Node::isDocument() const { bool exml::Node::isDocument() const {
return getType() == exml::typeDocument; return getType() == exml::nodeType_document;
} }
bool exml::Node::isAttribute() const { bool exml::Node::isAttribute() const {
return getType() == exml::typeAttribute; return getType() == exml::nodeType_attribute;
} }
bool exml::Node::isComment() const { bool exml::Node::isComment() const {
return getType() == exml::typeComment; return getType() == exml::nodeType_comment;
} }
bool exml::Node::isDeclaration() const { bool exml::Node::isDeclaration() const {
return getType() == exml::typeDeclaration; return getType() == exml::nodeType_declaration;
} }
bool exml::Node::isElement() const { bool exml::Node::isElement() const {
return getType() == exml::typeElement; return getType() == exml::nodeType_element;
} }
bool exml::Node::isText() const { bool exml::Node::isText() const {
return getType() == exml::typeText; return getType() == exml::nodeType_text;
} }

View File

@ -35,15 +35,18 @@ namespace exml {
class Element; class Element;
class Text; class Text;
/**
* @brief Type of the XML elements.
*/
enum nodeType { enum nodeType {
typeUnknow, //!< might be an error ... nodeType_unknow, //!< might be an error ...
typeNode, //!< might be an error ... nodeType_node, //!< might be an error ...
typeDocument, //!< all the file main access nodeType_document, //!< all the file main access
typeDeclaration, //!< <?xml ... ?> nodeType_declaration, //!< &lt;?xml ... ?&gt;
typeAttribute, //!< the <Element ATTRIBUTE="ATTRIBUTE_VALUE" /> nodeType_attribute, //!< the &lt;Element ATTRIBUTE="ATTRIBUTE_VALUE" /&gt;
typeElement, //!< the <XXX> ... </XXX> nodeType_element, //!< the &lt;XXX&gt; ... &lt;/XXX&gt;
typeComment, //!< comment node : <!-- --> nodeType_comment, //!< comment node : &lt;!-- --&gt;
typeText, //!< <XXX> InsideText </XXX> nodeType_text, //!< &lt;XXX&gt; InsideText &lt;/XXX&gt;
}; };
/** /**
* @brief Basic main object of all xml elements. * @brief Basic main object of all xml elements.
@ -59,7 +62,7 @@ namespace exml {
}; };
/** /**
* @brief basic element of a xml structure * @brief basic element of a xml structure
* @param[in] value of the node * @param[in] _value value of the node
*/ */
Node(const std::string& _value); Node(const std::string& _value);
public: public:
@ -73,14 +76,15 @@ namespace exml {
* @param[in] _data data string to parse. * @param[in] _data data string to parse.
* @param[in,out] _pos position in the string to start parse, return the position end of parsing. * @param[in,out] _pos position in the string to start parse, return the position end of parsing.
* @param[in] _caseSensitive Request a parsion of element that is not case sensitive (all element is in low case) * @param[in] _caseSensitive Request a parsion of element that is not case sensitive (all element is in low case)
* @param[in,out] file parsing position (line x col x) * @param[in,out] _filePos file parsing position (line x col x)
* @param[in,out] _doc Base document reference
* @return false if an error occured. * @return false if an error occured.
*/ */
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) = 0; virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) = 0;
/** /**
* @brief generate a string with the tree of the xml * @brief generate a string with the tree of the xml
* @param[in,out] _data string where to add the elements * @param[in,out] _data string where to add the elements
* @param[in] current indentation of the file * @param[in] _indent current indentation of the file
* @return false if an error occured. * @return false if an error occured.
*/ */
virtual bool iGenerate(std::string& _data, int32_t _indent) const; virtual bool iGenerate(std::string& _data, int32_t _indent) const;
@ -89,6 +93,7 @@ namespace exml {
public: public:
/** /**
* @brief get the current position where the element is in the file * @brief get the current position where the element is in the file
* @return The file position reference
*/ */
const exml::FilePos& getPos() const; const exml::FilePos& getPos() const;
protected: protected:
@ -124,9 +129,11 @@ namespace exml {
*/ */
void drawElementParsed(char32_t _val, const exml::FilePos& _filePos) const; void drawElementParsed(char32_t _val, const exml::FilePos& _filePos) const;
/** /**
* @brief check if an element or attribute is availlable (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \n\t\r and for first char : not -.0123456789). * @brief check if an element or attribute is availlable (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \\n\\t\\r and for first char : not -.0123456789).
* @param[in] _val Value to check the conformity. * @param[in] _val Value to check the conformity.
* @param[in] _firstChar True if the element check is the first char. * @param[in] _firstChar True if the element check is the first char.
* @return true The value can be a part of attribute name
* @return false The value can NOT be a part of attribute name
*/ */
bool checkAvaillable(char32_t _val, bool _firstChar) const; bool checkAvaillable(char32_t _val, bool _firstChar) const;
/** /**

View File

@ -60,10 +60,6 @@ static bool isWhiteChar(char32_t _val) {
return false; return false;
} }
ememory::SharedPtr<exml::Text> exml::Text::create() {
return ememory::SharedPtr<exml::Text>(new exml::Text());
}
ememory::SharedPtr<exml::Text> exml::Text::create(const std::string& _data) { ememory::SharedPtr<exml::Text> exml::Text::create(const std::string& _data) {
return ememory::SharedPtr<exml::Text>(new exml::Text(_data)); return ememory::SharedPtr<exml::Text>(new exml::Text(_data));
} }

View File

@ -11,6 +11,9 @@
#include <vector> #include <vector>
namespace exml { namespace exml {
/**
* @brief Text node interface (internal data between two balise : &lt;XXX&gt; ALL here &lt;/XXX&gt;
*/
class Text : public exml::Node { class Text : public exml::Node {
protected: protected:
/** /**
@ -23,8 +26,12 @@ namespace exml {
*/ */
Text(const std::string& _data) : exml::Node(_data) { }; Text(const std::string& _data) : exml::Node(_data) { };
public: public:
static ememory::SharedPtr<exml::Text> create(); /**
static ememory::SharedPtr<exml::Text> create(const std::string& _data); * @brief defined factory
* @param[in] _data Data in the Text area
* @return Shared pointer on the Text element
*/
static ememory::SharedPtr<exml::Text> create(const std::string& _data="");
/** /**
* @brief count the number of line in the current text * @brief count the number of line in the current text
* @return The number of lines * @return The number of lines
@ -32,7 +39,7 @@ namespace exml {
int32_t countLines() const; int32_t countLines() const;
public: public:
enum nodeType getType() const override{ enum nodeType getType() const override{
return typeText; return nodeType_text;
}; };
bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override; 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; bool iGenerate(std::string& _data, int32_t _indent) const override;
@ -43,6 +50,9 @@ namespace exml {
return std::static_pointer_cast<const exml::Text>(shared_from_this()); return std::static_pointer_cast<const exml::Text>(shared_from_this());
}; };
}; };
/**
* @brief Text node interface for balise CDATA &lt;![CDATA[*******]]&gt;
*/
class TextCDATA : public exml::Text { class TextCDATA : public exml::Text {
protected: protected:
/** /**
@ -50,6 +60,10 @@ namespace exml {
*/ */
TextCDATA() { }; TextCDATA() { };
public: public:
/**
* @brief defined factory
* @return Shared pointer on the Text CDATA element
*/
static ememory::SharedPtr<TextCDATA> create(); static ememory::SharedPtr<TextCDATA> create();
public: public:
bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override; bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::Document& _doc) override;