[Cppunit-cvs] cppunit2/src/opentest SConscript,1.6,1.7 serializer.cpp,1.9,1.10
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-11-07 22:43:25
|
Update of /cvsroot/cppunit/cppunit2/src/opentest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30871/src/opentest Modified Files: SConscript serializer.cpp Log Message: - replaced usage of OpenTest::Properties with Json::Value. Json::Value provides a simpler interface and a standard *simple* serialization format. - jsoncpp has been inlined in CppTL to make deploy easier and remove an external dependency. Index: SConscript =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/opentest/SConscript,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SConscript 8 Aug 2005 22:10:21 -0000 1.6 --- SConscript 7 Nov 2005 22:43:08 -0000 1.7 *************** *** 4,11 **** interfaces.cpp serializer.cpp - texttestdriver.cpp """ ), 'opentest' ) # remoteinterfaces.cpp # sharedmemorytransport.cpp --- 4,11 ---- interfaces.cpp serializer.cpp """ ), 'opentest' ) + # texttestdriver.cpp # remoteinterfaces.cpp # sharedmemorytransport.cpp Index: serializer.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/opentest/serializer.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** serializer.cpp 6 Sep 2005 07:31:42 -0000 1.9 --- serializer.cpp 7 Nov 2005 22:43:08 -0000 1.10 *************** *** 33,41 **** ccNoneValue = 0x26, // '&' ccNewDictionnaryEntry = 0x27, // "'" ! ccPropertyList = 0x28, // '(' ! ccNamedPropertiesEnd = 0x29, // ')' ccPositiveReal = 0x2a, // '*' ccPositiveInteger = 0x2b, // '+' ! ccEmptyProperties = 0x2c, // ',' ccNegativeInteger = 0x2d, // '-' ccRealDot = 0x2e, // '.' --- 33,41 ---- ccNoneValue = 0x26, // '&' ccNewDictionnaryEntry = 0x27, // "'" ! ccArrayValue = 0x28, // '(' ! ccObjectValueEnd = 0x29, // ')' ccPositiveReal = 0x2a, // '*' ccPositiveInteger = 0x2b, // '+' ! ccEmptyObjectValue = 0x2c, // ',' ccNegativeInteger = 0x2d, // '-' ccRealDot = 0x2e, // '.' *************** *** 667,700 **** - Stream & - Stream::operator <<( const Properties &properties ) - { - Properties::PropertyEnum enumProperties = properties.properties(); - if ( properties.hasList() ) - { - doSerializeInteger( ccPropertyList, properties.listSize() ); - for ( unsigned int valueIndex =0; valueIndex < properties.listSize(); ++valueIndex ) - *this << properties.at( valueIndex ); - } - else if ( !enumProperties.hasNext() ) - { - write( ccEmptyProperties ); - } - - if ( enumProperties.hasNext() ) - { - do - { - const Property &property = enumProperties.next(); - saveDictionnaryEntry( property.name() ); - *this << property.value(); - } - while ( enumProperties.hasNext() ); - write( ccNamedPropertiesEnd ); - } - return *this; - } - - bool Stream::isNamedPropertyControl( Byte control ) --- 667,670 ---- *************** *** 705,749 **** ! Stream & ! Stream::operator >>( Properties &properties ) { ! Byte control = readNextByte(); ! if ( control == ccEmptyProperties ) ! return *this; ! if ( control == ccPropertyList ) { ! LargestUnsignedInt length; ! doUnserializeInteger( length ); ! while ( length-- ) { ! Value value; ! *this >> value; ! properties.append( value ); } ! control = readNextByte(); } - if ( !isNamedPropertyControl(control) ) - { - if ( !properties.hasList() ) - setError( "Expected Properties." ); - else - ungetLastByte(); - return *this; - } do { String name; readDictionnaryEntry( control, name ); ! Value value; ! *this >> value; ! properties.set( name, value ); control = readNextByte(); } while ( isNamedPropertyControl(control) ); ! if ( control != ccNamedPropertiesEnd ) setError( "Unexpected end of named property list." ); - return *this; } --- 675,735 ---- ! void ! Stream::serializeArrayValue( const Value &value ) { ! LargestUnsignedInt length = value.size(); ! doSerializeInteger( ccArrayValue, length ); ! for ( LargestUnsignedInt index = 0; index < length; ++index ) ! *this << value[index]; ! } ! ! void ! Stream::serializeObjectValue( const Value &value ) ! { ! Value::Members names = value.getMemberNames(); // @todo implements a more efficient iteration over members ! if ( names.empty() ) { ! write( ccEmptyObjectValue ); ! } ! else ! { ! Value::Members::const_iterator it = names.begin(); ! Value::Members::const_iterator itEnd = names.end(); ! for ( ; it != itEnd; ++it ) { ! saveDictionnaryEntry( *it ); ! *this << value[*it]; } ! write( ccObjectValueEnd ); } + } + + + void + Stream::unserializeArrayValue( Value &value ) + { + value = Value( Json::arrayValue ); + LargestUnsignedInt length; + doUnserializeInteger( length ); + for ( LargestUnsignedInt index = 0; index < length; ++index ) + *this >> value[index]; + } + void + Stream::unserializeObjectValue( Byte control, + Value &value ) + { + value = Value( Json::objectValue ); do { String name; readDictionnaryEntry( control, name ); ! *this >> value[ name.c_str() ]; control = readNextByte(); } while ( isNamedPropertyControl(control) ); ! if ( control != ccObjectValueEnd ) setError( "Unexpected end of named property list." ); } *************** *** 754,786 **** switch ( value.type() ) { ! case Value::vtNone: write( ccNoneValue ); break; ! case Value::vtBoolean: *this << value.asBool(); break; #ifndef CPPTL_NO_INT64 ! case Value::vtSignedInteger: ! *this << value.asInt64(); break; ! case Value::vtUnsignedInteger: ! *this << value.asUInt64(); break; #else ! case Value::vtSignedInteger: *this << value.asInt(); break; ! case Value::vtUnsignedInteger: *this << value.asUInt(); break; #endif ! case Value::vtReal: ! *this << value.asReal(); break; ! case Value::vtString: ! *this << value.asString(); break; ! case Value::vtProperties: ! *this << value.asProperties(); break; default: --- 740,775 ---- switch ( value.type() ) { ! case Json::nullValue: write( ccNoneValue ); break; ! case Json::booleanValue: *this << value.asBool(); break; #ifndef CPPTL_NO_INT64 ! case Json::intValue: ! *this << value.asInt(); break; ! case Json::uintValue: ! *this << value.asUInt(); break; #else ! case Json::intValue: *this << value.asInt(); break; ! case Json::uintValue: *this << value.asUInt(); break; #endif ! case Json::realValue: ! *this << value.asDouble(); break; ! case Json::stringValue: ! *this << String( value.asString().c_str() ); break; ! case Json::arrayValue: ! serializeArrayValue( value ); ! break; ! case Json::objectValue: ! serializeObjectValue( value ); break; default: *************** *** 807,821 **** String str; readString( str ); ! value = Value( str ); } break; case ccLookUpDictionnaryEntry: case ccNewDictionnaryEntry: ! case ccPropertyList: ! { ! ungetLastByte(); ! value = Value( Properties() ); ! *this >> value.asProperties(); ! } break; case ccNoneValue: --- 796,811 ---- String str; readString( str ); ! value = Value( str.c_str() ); } break; case ccLookUpDictionnaryEntry: case ccNewDictionnaryEntry: ! unserializeObjectValue( control, value ); ! break; ! case ccEmptyObjectValue: ! value = Value( Json::objectValue ); ! break; ! case ccArrayValue: ! unserializeArrayValue( value ); break; case ccNoneValue: *************** *** 836,840 **** ungetLastByte(); *this >> integer; ! value = Value( integer ); } break; --- 826,830 ---- ungetLastByte(); *this >> integer; ! value = Value( Value::UInt(integer) ); } break; *************** *** 844,848 **** ungetLastByte(); *this >> integer; ! value = Value( integer ); } break; --- 834,838 ---- ungetLastByte(); *this >> integer; ! value = Value( Value::Int(integer) ); } break; |