mikymod 12 лет назад
Родитель
Сommit
fa08fc9278
3 измененных файлов с 17 добавлено и 31 удалено
  1. 0 1
      src/Device.cpp
  2. 0 6
      src/JSONParser.cpp
  3. 17 24
      src/JSONParser.h

+ 0 - 1
src/Device.cpp

@@ -538,7 +538,6 @@ void Device::read_engine_settings()
 	json.get_root().get_number("width").to_int(width);
 	os::printf("value = %s\n", value);
 	os::printf("width = %d\n", width);
-
 }
 
 

+ 0 - 6
src/JSONParser.cpp

@@ -401,7 +401,6 @@ JSONParser&	JSONParser::get_object(const char* key)
 			// Store token's id in a json node
 			m_nodes[m_nodes_count].m_id = m_tokens[i+1].m_id;	
 			m_nodes[m_nodes_count].m_type = JSON_OBJECT;
-			m_nodes[m_nodes_count].print();
 
 			// If token stored has parent
 			if (m_tokens[i+1].has_parent())
@@ -445,7 +444,6 @@ JSONParser& JSONParser::get_array(const char* key, uint32_t element)
 			// Store array-token's id in a json node
 			m_nodes[m_nodes_count].m_id = m_tokens[i + 1].m_id;	
 			m_nodes[m_nodes_count].m_type = JSON_ARRAY;
-			m_nodes[m_nodes_count].print();
 
 			// If token stored has parent
 			if (m_tokens[i + 1].has_parent())
@@ -460,7 +458,6 @@ JSONParser& JSONParser::get_array(const char* key, uint32_t element)
 			// Store element-token's id in a json node
 			m_nodes[m_nodes_count].m_id = m_tokens[i + 1 + element].m_id;	
 			m_nodes[m_nodes_count].m_type = JSON_ARRAY;
-			m_nodes[m_nodes_count].print();
 
 			if (m_tokens[i + 1 + element].has_parent())
 			{
@@ -497,7 +494,6 @@ JSONParser&	JSONParser::get_string(const char* key)
 
 			m_nodes[m_nodes_count].m_id = m_tokens[i+1].m_id;	
 			m_nodes[m_nodes_count].m_type = JSON_STRING;
-			m_nodes[m_nodes_count].print();
 
 			if (m_tokens[i+1].has_parent())
 			{
@@ -533,7 +529,6 @@ JSONParser& JSONParser::get_number(const char* key)
 
 			m_nodes[m_nodes_count].m_id = m_tokens[i+1].m_id;	
 			m_nodes[m_nodes_count].m_type = JSON_NUMBER;
-			m_nodes[m_nodes_count].print();
 
 			if (m_tokens[i+1].has_parent())
 			{
@@ -569,7 +564,6 @@ JSONParser& JSONParser::get_bool(const char* key)
 
 			m_nodes[m_nodes_count].m_id = m_tokens[i+1].m_id;	
 			m_nodes[m_nodes_count].m_type = JSON_BOOL;
-			m_nodes[m_nodes_count].print();
 
 			if (m_tokens[i+1].has_parent())
 			{

+ 17 - 24
src/JSONParser.h

@@ -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;
 
 };