|
|
@@ -22,15 +22,6 @@ enum JSONType
|
|
|
|
|
|
};
|
|
|
|
|
|
-/// JSON error typology
|
|
|
-enum JSONError
|
|
|
-{
|
|
|
- JSON_NO_MEMORY = 0, // Not enough token provided
|
|
|
- JSON_INV_CHAR = 1, // Invalid character inside JSON string
|
|
|
- JSON_INV_PART = 2, // JSON string is incompleted
|
|
|
- JSON_SUCCESS = 3 // Everything OK!
|
|
|
-};
|
|
|
-
|
|
|
/// JSONToken is a container which have pointer to a single json entity
|
|
|
/// (primitive, object, array or string) of a json file.
|
|
|
struct JSONToken
|
|
|
@@ -63,6 +54,7 @@ struct JSONToken
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+///
|
|
|
struct JSONNode
|
|
|
{
|
|
|
int32_t m_id;
|
|
|
@@ -86,25 +78,25 @@ public:
|
|
|
JSONParser(Allocator& allocator, File* file, size_t size = 1024);
|
|
|
/// Destructor
|
|
|
~JSONParser();
|
|
|
-
|
|
|
+ /// Get root element
|
|
|
JSONParser& get_root();
|
|
|
-
|
|
|
+ /// Get object @a key
|
|
|
JSONParser& get_object(const char* key);
|
|
|
-
|
|
|
- JSONParser& get_array(const char* key, uint32_t element);
|
|
|
-
|
|
|
+ /// Get array @a key and element @a index
|
|
|
+ JSONParser& get_array(const char* key, uint32_t index);
|
|
|
+ /// Get string @a key
|
|
|
JSONParser& get_string(const char* key);
|
|
|
-
|
|
|
+ /// Get number @a key
|
|
|
JSONParser& get_number(const char* key);
|
|
|
-
|
|
|
+ /// Get boolean @a key
|
|
|
JSONParser& get_bool(const char* key);
|
|
|
-
|
|
|
+ /// Convert element taken from @a get_string to string
|
|
|
void to_string(char* value);
|
|
|
-
|
|
|
+ /// Convert element taken from @a get_number to float
|
|
|
void to_float(float& value);
|
|
|
-
|
|
|
+ /// Convert element taken from @a get_number to int
|
|
|
void to_int(int& value);
|
|
|
-
|
|
|
+ /// Convert element taken from @a get_bool to boolean
|
|
|
void to_bool(bool& value);
|
|
|
|
|
|
private:
|
|
|
@@ -118,15 +110,16 @@ private:
|
|
|
void parse_number();
|
|
|
/// Allocate token node
|
|
|
JSONToken* allocate_token();
|
|
|
- /// Fill token and set boundaries
|
|
|
+ /// Fill @a token with @a type and boundaries (@a start and @a stop)
|
|
|
void fill_token(JSONToken* token, JSONType type, int32_t start, int32_t end);
|
|
|
/// Reset all JSON nodes
|
|
|
void reset_nodes();
|
|
|
|
|
|
-
|
|
|
+ /// JSONParser allocator
|
|
|
Allocator& m_allocator;
|
|
|
/// JSON data
|
|
|
File* m_file;
|
|
|
+
|
|
|
/// Next token to allocate
|
|
|
int32_t m_next_token;
|
|
|
/// Previous token e.g parent or array
|
|
|
@@ -138,9 +131,9 @@ private:
|
|
|
/// m_tokens default size, default 1024
|
|
|
size_t m_tokens_number;
|
|
|
|
|
|
- ///
|
|
|
+ /// DOM-like abstraction
|
|
|
JSONNode* m_nodes;
|
|
|
- ///
|
|
|
+ /// Number of nodes in DOM-like abtraction
|
|
|
uint32_t m_nodes_count;
|
|
|
|
|
|
};
|