Daniele Bartolini преди 12 години
родител
ревизия
b41801d13f
променени са 2 файла, в които са добавени 52 реда и са изтрити 3 реда
  1. 2 2
      engine/core/json/JSONParser.cpp
  2. 50 1
      engine/core/json/JSONParser.h

+ 2 - 2
engine/core/json/JSONParser.cpp

@@ -577,7 +577,7 @@ void JSONParser::parse_array(const char* s, List<const char*>& array)
 }
 
 //-----------------------------------------------------------------------------
-void JSONParser::parse_object(const char* s, List<JSONPair>& map)
+void JSONParser::parse_object(const char* s, List<JSONPair>& object)
 {
 	CE_ASSERT_NOT_NULL(s);
 
@@ -613,7 +613,7 @@ void JSONParser::parse_object(const char* s, List<JSONPair>& map)
 			ch = skip_whites(ch);
 
 			pair.val = ch;
-			map.push_back(pair);
+			object.push_back(pair);
 
 			// Skip any value
 			ch = skip_array(ch);

+ 50 - 1
engine/core/json/JSONParser.h

@@ -48,43 +48,92 @@ struct JSONPair
 	const char* val;
 };
 
+/// Parses JSON documents.
 class JSONParser
 {
 public:
 
+	/// Read the JSON document contained in the non-null @a s string.
+	/// @note
+	/// The @a s string has to remain valid for the whole parser's
+	/// existence scope.
 						JSONParser(const char* s);
 
+	/// Returns the root element of the JSON document.
 	JSONParser&			root();
 
+	/// Returns the @a i -th item of the current array.
 	JSONParser&			operator[](uint32_t i);
+
+	/// Returns the element corresponding to key @a k of the
+	/// current object.
+	/// @note
+	/// If the key is not unique in the object scope, the last
+	/// key in order of appearance will be selected.
 	JSONParser&			key(const char* k);
 
+	/// Returns true wheter the current element is the JSON nil special value.
 	bool				is_nil() const;
+
+	/// Returns true wheter the current element is a JSON boolean (true or false).
 	bool				is_bool() const;
+
+	/// Returns true wheter the current element is a JSON number.
 	bool				is_number() const;
+
+	/// Returns true whether the current element is a JSON string.
 	bool				is_string() const;
+
+	/// Returns true whether the current element is a JSON array.
 	bool				is_array() const;
+
+	/// Returns true whether the current element is a JSON object.
 	bool				is_object() const;
 
+	/// Returns the size of the current element based on the
+	/// element's type:
+	/// * nil, bool, number: 1
+	/// * string: length of the string
+	/// * array: number of elements in the array
+	/// * object: number of keys in the object
 	uint32_t			size();
 
+	/// Returns the boolean value of the current element.
 	bool				bool_value() const;
+
+	/// Returns the integer value of the current element.
 	int32_t				int_value() const;
+
+	/// Returns the float value of the current element.
 	float				float_value() const;
 
 public:
 
+	/// Returns the type of the @a s JSON text. 
 	static JSONType		type(const char* s);
 
+	/// Parses the @a s JSON string a puts its C representation into @a str.
 	static void			parse_string(const char* s, List<char>& str);
+
+	/// Returns the value of the @a s JSON number as double.
 	static double		parse_number(const char* s);
 
+	/// Returns the value of the @a s JSON boolean.
 	static bool			parse_bool(const char* s);
+
+	/// Returns the value of the @a s JSON number as signed integer.
 	static int32_t 		parse_int(const char* s);
+
+	/// Returns the value of the @a s JSON number as float.
 	static float		parse_float(const char* s);
 
+	/// Parses the @a s JSON array and puts it into @a array as pointers to
+	/// the corresponding items into the original @a s string.
 	static void			parse_array(const char* s, List<const char*>& array);
-	static void			parse_object(const char* s, List<JSONPair>& map);
+
+	/// Parses the @a s JSON object and puts it into @a object as pointers to
+	/// the corresponding key/value pairs into the original @a s string.
+	static void			parse_object(const char* s, List<JSONPair>& object);
 
 private: