Node.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <ememory/memory.hpp>
9 #include <etk/types.hpp>
10 #include <etk/math/Vector2D.hpp>
11 #include <exml/FilePos.hpp>
12 #include <exml/nodeType.hpp>
13 
17 namespace exml {
18  namespace internal {
19  //#define ENABLE_DISPLAY_PARSED_ELEMENT
20  //#define ENABLE_CRITICAL_WHEN_ERROR
21  #if 1
22  #define EXML_PARSE_ELEMENT EXML_VERBOSE
24  #else
25  #define EXML_PARSE_ELEMENT EXML_DEBUG
26  #endif
27  #if 1
28  #define EXML_PARSE_ATTRIBUTE EXML_VERBOSE
30  #else
31  #define EXML_PARSE_ATTRIBUTE EXML_DEBUG
32  #endif
33  class Document;
34  class Attribute;
35  class Comment;
36  class Declaration;
37  class Element;
38  class Text;
39 
43  class Node : public ememory::EnableSharedFromThis<Node>{
44  protected:
48  Node() :
49  m_pos(0,0) {
50 
51  };
56  Node(const std::string& _value);
57  public:
61  virtual ~Node() = default;
62  public:
72  virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::FilePos& _filePos, exml::internal::Document& _doc) = 0;
79  virtual bool iGenerate(std::string& _data, int32_t _indent) const;
80  protected:
82  public:
87  const exml::FilePos& getPos() const;
88  protected:
89  std::string m_value;
90  public:
95  virtual void setValue(std::string _value);
100  virtual const std::string& getValue() const;
101  public:
106  virtual enum nodeType getType() const;
107  protected:
113  void addIndent(std::string& _data, int32_t _indent) const;
119  void drawElementParsed(char32_t _val, const exml::FilePos& _filePos) const;
127  bool checkAvaillable(char32_t _val, bool _firstChar) const;
135  int32_t countWhiteChar(const std::string& _data, int32_t _pos, exml::FilePos& _filePos) const;
136  public:
196  virtual const ememory::SharedPtr<exml::internal::Text> toText() const;
197 
202  bool isDocument() const;
207  bool isAttribute() const;
212  bool isComment() const;
217  bool isDeclaration() const;
222  bool isElement() const;
227  bool isText() const;
228 
232  virtual void clear();
233  };
234  }
235 }
bool isText() const
check if the node is a exml::internal::Text
bool isDeclaration() const
check if the node is a exml::internal::Declaration
bool isComment() const
check if the node is a exml::internal::Comment
virtual ememory::SharedPtr< exml::internal::Declaration > toDeclaration()
Cast the element in a Declaration if it is possible.
const exml::FilePos & getPos() const
get the current position where the element is in the file
virtual void clear()
clear the Node
bool checkAvaillable(char32_t _val, bool _firstChar) const
check if an element or attribute is availlable (not : !"#$%&&#39;()*+,/;<=>?@[]^`{|}~ \n\t\r and for firs...
virtual ememory::SharedPtr< exml::internal::Comment > toComment()
Cast the element in a Comment if it is possible.
void addIndent(std::string &_data, int32_t _indent) const
add indentation of the string input.
virtual enum nodeType getType() const
get the node type.
Node()
basic element of a xml structure
Definition: Node.hpp:48
exml namespace containing all function for XML interpretor
Definition: Attribute.hpp:11
virtual ememory::SharedPtr< exml::internal::Element > toElement()
Cast the element in a Element if it is possible.
virtual ememory::SharedPtr< exml::internal::Attribute > toAttribute()
Cast the element in a Attribute if it is possible.
exml::FilePos m_pos
position in the readed file == > not correct when the file is generated
Definition: Node.hpp:81
virtual const std::string & getValue() const
get the current element Value.
virtual ememory::SharedPtr< exml::internal::Text > toText()
Cast the element in a Text if it is possible.
bool isElement() const
check if the node is a exml::internal::Element
virtual bool iGenerate(std::string &_data, int32_t _indent) const
generate a string with the tree of the xml
Basic document element of a document.
Definition: Document.hpp:16
bool isDocument() const
check if the node is a exml::internal::Document
bool isAttribute() const
check if the node is a exml::internal::Attribute
Position in the file of the original data.
Definition: FilePos.hpp:14
virtual ~Node()=default
Virtualize destructor.
Basic main object of all xml elements.
Definition: Node.hpp:43
virtual ememory::SharedPtr< exml::internal::Document > toDocument()
Cast the element in a Document if it is possible.
int32_t countWhiteChar(const std::string &_data, int32_t _pos, exml::FilePos &_filePos) const
count the number of white char in the string from the specify position (stop at the first element tha...
nodeType
Type of the XML elements.
Definition: nodeType.hpp:17
std::string m_value
value of the node (for element this is the name, for text it is the inside text ...)
Definition: Node.hpp:89
virtual bool iParse(const std::string &_data, int32_t &_pos, bool _caseSensitive, exml::FilePos &_filePos, exml::internal::Document &_doc)=0
parse the Current node [pure VIRUAL]
void drawElementParsed(char32_t _val, const exml::FilePos &_filePos) const
Display the cuurent element that is curently parse.
virtual void setValue(std::string _value)
set the value of the node.