Value.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <etk/types.hpp>
9 #include <ememory/memory.hpp>
10 #include <ejson/FilePos.hpp>
11 #include <ejson/valueType.hpp>
12 
16 namespace ejson {
17  //#define ENABLE_DISPLAY_PARSED_ELEMENT
18  #if 1
19  #define EJSON_PARSE_ELEMENT EJSON_VERBOSE
20  #else
21  #define EJSON_PARSE_ELEMENT EJSON_DEBUG
22  #endif
23  #if 1
24  #define EJSON_PARSE_ATTRIBUTE EJSON_VERBOSE
25  #else
26  #define EJSON_PARSE_ATTRIBUTE EJSON_DEBUG
27  #endif
28 
31  namespace internal {
32  class Document;
33  class Array;
34  class Object;
35  class Boolean;
36  class Null;
37  class Number;
38  class String;
42  class Value : public ememory::EnableSharedFromThis<Value> {
43  protected:
45  public:
50  enum ejson::valueType getType() const;
51  protected:
55  Value() :
56  m_type(ejson::valueType::unknow) {
57  m_type = ejson::valueType::value;
58  };
59  public:
63  virtual ~Value();
64  public:
73  virtual bool iParse(const std::string& _data,
74  size_t& _pos,
75  ejson::FilePos& _filePos,
76  ejson::internal::Document& _doc) = 0;
83  virtual bool iGenerate(std::string& _data,
84  size_t _indent) const = 0;
90  virtual void iMachineGenerate(std::string& _data) const = 0;
94  void display() const;
95  protected:
101  void addIndent(std::string& _data, int32_t _indent) const;
107  void drawElementParsed(char32_t _val, const ejson::FilePos& _filePos) const;
114  bool checkString(char32_t _val) const;
121  bool checkNumber(char32_t _val) const;
129  int32_t countWhiteChar(const std::string& _data, size_t _pos, ejson::FilePos& _filePos) const;
130  public:
134  virtual void clear();
147  protected:
153  static bool isWhiteChar(char32_t _val);
154  };
155  }
156 }
157 
158 #include <ejson/internal/Array.hpp>
160 #include <ejson/internal/Null.hpp>
161 #include <ejson/internal/Number.hpp>
162 #include <ejson/internal/Object.hpp>
163 #include <ejson/internal/String.hpp>
165 
static bool isWhiteChar(char32_t _val)
check if the current element is white or not : &#39;\t&#39; &#39;\n&#39; &#39;\r&#39; &#39; &#39;
int32_t countWhiteChar(const std::string &_data, size_t _pos, ejson::FilePos &_filePos) const
count the number of white char in the string from the specify position (stop at the first element tha...
might be an error ...
might be an error ...
enum ejson::valueType getType() const
Get Value type.
virtual void iMachineGenerate(std::string &_data) const =0
generate a string with the tree of the json (not human readable ==> for computer transfer) ...
the element "..."
virtual void clear()
clear the Node
ejson namespace containing all function for JSON interpretor
Definition: Array.hpp:12
virtual bool iParse(const std::string &_data, size_t &_pos, ejson::FilePos &_filePos, ejson::internal::Document &_doc)=0
parse the Current node [pure VIRUAL]
void addIndent(std::string &_data, int32_t _indent) const
add indentation of the string input.
Value()
basic element of a xml structure
Definition: Value.hpp:55
void drawElementParsed(char32_t _val, const ejson::FilePos &_filePos) const
Display the cuurent element that is curently parse.
Position in the file of the original data.
Definition: FilePos.hpp:14
virtual bool iGenerate(std::string &_data, size_t _indent) const =0
generate a string with the tree of the json
valueType
Type of the JSON elements.
Definition: valueType.hpp:14
ejson Document internal data implementation.
Definition: Document.hpp:20
enum ejson::valueType m_type
Type of the element.
Definition: Value.hpp:44
void display() const
Display the Document on console.
const char32_t Null
virtual ememory::SharedPtr< ejson::internal::Value > clone() const
Copy the curent node and all the child in the curent one.
bool checkString(char32_t _val) const
check if an name (for object named) (not : !"#$%&&#39;()*+,/;<=>?@[]^`{|}~ \n\t\r).
virtual ~Value()
Virtualize destructor.
bool checkNumber(char32_t _val) const
check if an number -+.0123456789e).
Basic main object of all json data.
Definition: Value.hpp:42
virtual bool transfertIn(ememory::SharedPtr< ejson::internal::Value > _obj)
Tranfert all element in the element set in parameter.