فهرست منبع

m_begin is not necessary anymore. Yeah.

Daniele Bartolini 12 سال پیش
والد
کامیت
c9daa26628
2فایلهای تغییر یافته به همراه23 افزوده شده و 48 حذف شده
  1. 13 37
      engine/core/json/JSONParser.cpp
  2. 10 11
      engine/core/json/JSONParser.h

+ 13 - 37
engine/core/json/JSONParser.cpp

@@ -194,19 +194,19 @@ static bool is_escapee(char c)
 
 //--------------------------------------------------------------------------
 JSONElement::JSONElement()
-	: m_begin(NULL), m_at(NULL)
+	: m_at(NULL)
 {
 }
 
 //--------------------------------------------------------------------------
 JSONElement::JSONElement(const char* at)
-	: m_begin(at), m_at(at)
+	: m_at(at)
 {
 }
 
 //--------------------------------------------------------------------------
 JSONElement::JSONElement(const JSONElement& other)
-	: m_begin(other.m_at), m_at(other.m_at)
+	: m_at(other.m_at)
 {
 }
 
@@ -214,7 +214,6 @@ JSONElement::JSONElement(const JSONElement& other)
 JSONElement& JSONElement::operator=(const JSONElement& other)
 {
 	// Our begin is the other's at
-	m_begin = other.m_at;
 	m_at = other.m_at;
 
 	return *this;
@@ -382,37 +381,28 @@ bool JSONElement::is_key_unique(const char* k) const
 }
 
 //--------------------------------------------------------------------------
-bool JSONElement::bool_value()
+bool JSONElement::bool_value() const
 {
 	const bool value = JSONParser::parse_bool(m_at);
-
-	m_at = m_begin;
-
 	return value;
 }
 
 //--------------------------------------------------------------------------
-int32_t JSONElement::int_value()
+int32_t JSONElement::int_value() const
 {
 	const int32_t value = JSONParser::parse_int(m_at);
-
-	m_at = m_begin;
-
 	return value;
 }
 
 //--------------------------------------------------------------------------
-float JSONElement::float_value()
+float JSONElement::float_value() const
 {
 	const float value = JSONParser::parse_float(m_at);
-
-	m_at = m_begin;
-
 	return value;
 }
 
 //--------------------------------------------------------------------------
-const char* JSONElement::string_value()
+const char* JSONElement::string_value() const
 {
 	static TempAllocator1024 alloc;
 	static List<char> string(alloc);
@@ -421,13 +411,11 @@ const char* JSONElement::string_value()
 
 	JSONParser::parse_string(m_at, string);
 
-	m_at = m_begin;
-
 	return string.begin();
 }
 
 //--------------------------------------------------------------------------
-void JSONElement::array_value(List<bool>& array)
+void JSONElement::array_value(List<bool>& array) const
 {
 	TempAllocator1024 alloc;
 	List<const char*> temp(alloc);
@@ -438,12 +426,10 @@ void JSONElement::array_value(List<bool>& array)
 	{
 		array.push_back(JSONParser::parse_bool(temp[i]));
 	}
-
-	m_at = m_begin;
 }
 
 //--------------------------------------------------------------------------
-void JSONElement::array_value(List<int16_t>& array)
+void JSONElement::array_value(List<int16_t>& array) const
 {
 	TempAllocator1024 alloc;
 	List<const char*> temp(alloc);
@@ -454,12 +440,10 @@ void JSONElement::array_value(List<int16_t>& array)
 	{
 		array.push_back((int16_t)JSONParser::parse_int(temp[i]));
 	}
-
-	m_at = m_begin;
 }
 
 //--------------------------------------------------------------------------
-void JSONElement::array_value(List<uint16_t>& array)
+void JSONElement::array_value(List<uint16_t>& array) const
 {
 	TempAllocator1024 alloc;
 	List<const char*> temp(alloc);
@@ -470,12 +454,10 @@ void JSONElement::array_value(List<uint16_t>& array)
 	{
 		array.push_back((uint16_t)JSONParser::parse_int(temp[i]));
 	}
-
-	m_at = m_begin;
 }
 
 //--------------------------------------------------------------------------
-void JSONElement::array_value(List<int32_t>& array)
+void JSONElement::array_value(List<int32_t>& array) const
 {
 	TempAllocator1024 alloc;
 	List<const char*> temp(alloc);
@@ -486,12 +468,10 @@ void JSONElement::array_value(List<int32_t>& array)
 	{
 		array.push_back((int32_t)JSONParser::parse_int(temp[i]));
 	}
-
-	m_at = m_begin;
 }
 
 //--------------------------------------------------------------------------
-void JSONElement::array_value(List<uint32_t>& array)
+void JSONElement::array_value(List<uint32_t>& array) const
 {
 	TempAllocator1024 alloc;
 	List<const char*> temp(alloc);
@@ -502,12 +482,10 @@ void JSONElement::array_value(List<uint32_t>& array)
 	{
 		array.push_back((uint32_t)JSONParser::parse_int(temp[i]));
 	}
-
-	m_at = m_begin;
 }
 
 //--------------------------------------------------------------------------
-void JSONElement::array_value(List<float>& array)
+void JSONElement::array_value(List<float>& array) const
 {
 	TempAllocator1024 alloc;
 	List<const char*> temp(alloc);
@@ -518,8 +496,6 @@ void JSONElement::array_value(List<float>& array)
 	{
 		array.push_back(JSONParser::parse_float(temp[i]));
 	}
-
-	m_at = m_begin;
 }
 
 //--------------------------------------------------------------------------

+ 10 - 11
engine/core/json/JSONParser.h

@@ -122,20 +122,20 @@ public:
 	uint32_t			size() const;
 
 	/// Returns the boolean value of the element.
-	bool				bool_value();
+	bool				bool_value() const;
 
 	/// Returns the integer value of the element.
-	int32_t				int_value();
+	int32_t				int_value() const;
 
 	/// Returns the float value of the element.
-	float				float_value();
+	float				float_value() const;
 
 	/// Returns the string value of the element.
 	/// @warning
 	/// The returned string is kept internally until the next call to
 	/// this function, so it is highly unsafe to just keep the pointer
 	/// instead of copying its content somewhere else.
-	const char*			string_value();
+	const char*			string_value() const;
 
 	/// Returns the array value of the element.
 	/// @note
@@ -143,26 +143,25 @@ public:
 	/// array elements by JSONElement::operator[] and it is the very preferred way
 	/// for retrieving array elemets. However, you have to be sure that the array
 	/// contains only items of the given @array type.
-	void				array_value(List<bool>& array);
+	void				array_value(List<bool>& array) const;
 
 	/// @copydoc JSONElement::array_value(List<bool>&)
-	void				array_value(List<int16_t>& array);
+	void				array_value(List<int16_t>& array) const;
 
 	/// @copydoc JSONElement::array_value(List<bool>&)
-	void				array_value(List<uint16_t>& array);
+	void				array_value(List<uint16_t>& array) const;
 
 	/// @copydoc JSONElement::array_value(List<bool>&)
-	void				array_value(List<int32_t>& array);
+	void				array_value(List<int32_t>& array) const;
 
 	/// @copydoc JSONElement::array_value(List<bool>&)
-	void				array_value(List<uint32_t>& array);
+	void				array_value(List<uint32_t>& array) const;
 
 	/// @copydoc JSONElement::array_value(List<bool>&)
-	void				array_value(List<float>& array);
+	void				array_value(List<float>& array) const;
 
 private:
 
-	const char*			m_begin;
 	const char*			m_at;
 
 	friend class 		JSONParser;