|
@@ -6,11 +6,16 @@ using namespace JSON;
|
|
JSONValue::JSONValue()
|
|
JSONValue::JSONValue()
|
|
{
|
|
{
|
|
this->type = NULL_;
|
|
this->type = NULL_;
|
|
|
|
+ ref = 1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+JSONValue::~JSONValue()
|
|
|
|
+{}
|
|
|
|
+
|
|
JSONValue::JSONValue( JSONType type )
|
|
JSONValue::JSONValue( JSONType type )
|
|
{
|
|
{
|
|
this->type = type;
|
|
this->type = type;
|
|
|
|
+ ref = 1;
|
|
}
|
|
}
|
|
|
|
|
|
JSONType JSONValue::getType() const
|
|
JSONType JSONValue::getType() const
|
|
@@ -23,6 +28,19 @@ Text JSONValue::toString() const
|
|
return Text( "null" );
|
|
return Text( "null" );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+JSONValue *JSONValue::getThis()
|
|
|
|
+{
|
|
|
|
+ ref++;
|
|
|
|
+ return this;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+JSONValue *JSONValue::release()
|
|
|
|
+{
|
|
|
|
+ if( !--ref )
|
|
|
|
+ delete this;
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
JSONBool::JSONBool( bool b )
|
|
JSONBool::JSONBool( bool b )
|
|
: JSONValue( BOOLEAN )
|
|
: JSONValue( BOOLEAN )
|
|
@@ -81,13 +99,13 @@ Text JSONString::toString() const
|
|
JSONArray::JSONArray()
|
|
JSONArray::JSONArray()
|
|
: JSONValue( ARRAY )
|
|
: JSONValue( ARRAY )
|
|
{
|
|
{
|
|
- array = new Array< JSONValue >();
|
|
+ array = new RCArray< JSONValue >();
|
|
}
|
|
}
|
|
|
|
|
|
JSONArray::JSONArray( Text string )
|
|
JSONArray::JSONArray( Text string )
|
|
: JSONValue( ARRAY )
|
|
: JSONValue( ARRAY )
|
|
{
|
|
{
|
|
- array = new Array< JSONValue >();
|
|
+ array = new RCArray< JSONValue >();
|
|
string = Parser::removeWhitespace( string );
|
|
string = Parser::removeWhitespace( string );
|
|
if( string.getText()[ 0 ] == '[' && string.getText()[ string.getLength() - 1 ] == ']' )
|
|
if( string.getText()[ 0 ] == '[' && string.getText()[ string.getLength() - 1 ] == ']' )
|
|
{
|
|
{
|
|
@@ -122,12 +140,12 @@ JSONArray &JSONArray::operator=( const JSONArray &arr )
|
|
return *this;
|
|
return *this;
|
|
}
|
|
}
|
|
|
|
|
|
-void JSONArray::addValue( JSONValue value )
|
|
+void JSONArray::addValue( JSONValue *value )
|
|
{
|
|
{
|
|
array->add( value );
|
|
array->add( value );
|
|
}
|
|
}
|
|
|
|
|
|
-JSONValue JSONArray::getValue( int i ) const
|
|
+JSONValue *JSONArray::getValue( int i ) const
|
|
{
|
|
{
|
|
return array->get( i );
|
|
return array->get( i );
|
|
}
|
|
}
|
|
@@ -142,7 +160,7 @@ Text JSONArray::toString() const
|
|
Text str = "[";
|
|
Text str = "[";
|
|
for( auto i = array->getIterator(); i; i++ )
|
|
for( auto i = array->getIterator(); i; i++ )
|
|
{
|
|
{
|
|
- str += i._.toString();
|
|
+ str += i->toString();
|
|
if( i.hasNext() )
|
|
if( i.hasNext() )
|
|
str += ",";
|
|
str += ",";
|
|
}
|
|
}
|
|
@@ -155,14 +173,14 @@ JSONObject::JSONObject()
|
|
: JSONValue( OBJECT )
|
|
: JSONValue( OBJECT )
|
|
{
|
|
{
|
|
fields = new Array< Text >();
|
|
fields = new Array< Text >();
|
|
- values = new Array< JSONValue >();
|
|
+ values = new RCArray< JSONValue >();
|
|
}
|
|
}
|
|
|
|
|
|
JSONObject::JSONObject( Text string )
|
|
JSONObject::JSONObject( Text string )
|
|
: JSONValue( OBJECT )
|
|
: JSONValue( OBJECT )
|
|
{
|
|
{
|
|
fields = new Array< Text >();
|
|
fields = new Array< Text >();
|
|
- values = new Array< JSONValue >();
|
|
+ values = new RCArray< JSONValue >();
|
|
string = Parser::removeWhitespace( string );
|
|
string = Parser::removeWhitespace( string );
|
|
if( string.getText()[ 0 ] == '{' && string.getText()[ string.getLength() - 1 ] == '}' )
|
|
if( string.getText()[ 0 ] == '{' && string.getText()[ string.getLength() - 1 ] == '}' )
|
|
{
|
|
{
|
|
@@ -210,7 +228,7 @@ JSONObject &JSONObject::operator=( const JSONObject &obj )
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-bool JSONObject::addValue( Text field, JSONValue value )
|
|
+bool JSONObject::addValue( Text field, JSONValue *value )
|
|
{
|
|
{
|
|
if( hasValue( field ) )
|
|
if( hasValue( field ) )
|
|
return 0;
|
|
return 0;
|
|
@@ -243,14 +261,14 @@ bool JSONObject::hasValue( Text field )
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-JSONValue JSONObject::getValue( Text field )
|
|
+JSONValue *JSONObject::getValue( Text field )
|
|
{
|
|
{
|
|
for( int i = 0; i < fields->getEintragAnzahl(); i++ )
|
|
for( int i = 0; i < fields->getEintragAnzahl(); i++ )
|
|
{
|
|
{
|
|
if( fields->get( i ).istGleich( field ) )
|
|
if( fields->get( i ).istGleich( field ) )
|
|
return values->get( i );
|
|
return values->get( i );
|
|
}
|
|
}
|
|
- return JSONValue();
|
|
+ return new JSONValue();
|
|
}
|
|
}
|
|
|
|
|
|
Iterator< Text > JSONObject::getFields()
|
|
Iterator< Text > JSONObject::getFields()
|
|
@@ -258,7 +276,7 @@ Iterator< Text > JSONObject::getFields()
|
|
return fields->getIterator();
|
|
return fields->getIterator();
|
|
}
|
|
}
|
|
|
|
|
|
-Iterator< JSONValue > JSONObject::getValues()
|
|
+Iterator< JSONValue* > JSONObject::getValues()
|
|
{
|
|
{
|
|
return values->getIterator();
|
|
return values->getIterator();
|
|
}
|
|
}
|
|
@@ -272,7 +290,7 @@ Text JSONObject::toString() const
|
|
str += "\"";
|
|
str += "\"";
|
|
str += k._.getText();
|
|
str += k._.getText();
|
|
str += "\":";
|
|
str += "\":";
|
|
- str += v._.toString().getText();
|
|
+ str += v->toString().getText();
|
|
if( v.hasNext() )
|
|
if( v.hasNext() )
|
|
str += ",";
|
|
str += ",";
|
|
}
|
|
}
|
|
@@ -357,26 +375,26 @@ Text Parser::removeWhitespace( const char *str )
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-JSONValue Parser::getValue( const char *str )
|
|
+JSONValue *Parser::getValue( const char *str )
|
|
{
|
|
{
|
|
Text string = Parser::removeWhitespace( str );
|
|
Text string = Parser::removeWhitespace( str );
|
|
if( string.istGleich( "true" ) )
|
|
if( string.istGleich( "true" ) )
|
|
- return JSONBool( 1 );
|
|
+ return new JSONBool( 1 );
|
|
if( string.istGleich( "false" ) )
|
|
if( string.istGleich( "false" ) )
|
|
- return JSONBool( 0 );
|
|
+ return new JSONBool( 0 );
|
|
if( string.getText()[ 0 ] == '"' )
|
|
if( string.getText()[ 0 ] == '"' )
|
|
{
|
|
{
|
|
string.remove( 0, 1 );
|
|
string.remove( 0, 1 );
|
|
string.remove( string.getLength() - 1, string.getLength() );
|
|
string.remove( string.getLength() - 1, string.getLength() );
|
|
- return JSONString( string );
|
|
+ return new JSONString( string );
|
|
}
|
|
}
|
|
if( string.getText()[ 0 ] == '[' )
|
|
if( string.getText()[ 0 ] == '[' )
|
|
- return JSONArray( string );
|
|
+ return new JSONArray( string );
|
|
if( string.getText()[ 0 ] == '{' )
|
|
if( string.getText()[ 0 ] == '{' )
|
|
- return JSONObject( string );
|
|
+ return new JSONObject( string );
|
|
if( Text( (double)string ).istGleich( string.getText() ) )
|
|
if( Text( (double)string ).istGleich( string.getText() ) )
|
|
- return JSONNumber( string );
|
|
+ return new JSONNumber( string );
|
|
- return JSONValue();
|
|
+ return new JSONValue();
|
|
}
|
|
}
|
|
|
|
|
|
int Parser::findFieldEndInObject( const char *str )
|
|
int Parser::findFieldEndInObject( const char *str )
|