[Cppunit-cvs] cppunit2/src/cpput properties.cpp,1.1,1.2
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2004-11-19 22:58:07
|
Update of /cvsroot/cppunit/cppunit2/src/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31257/src/cpput Modified Files: properties.cpp Log Message: * added toString() to Value & Properties. Index: properties.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/properties.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** properties.cpp 19 Nov 2004 19:32:18 -0000 1.1 --- properties.cpp 19 Nov 2004 22:57:57 -0000 1.2 *************** *** 1,3 **** --- 1,4 ---- #include <opentest/properties.h> + #include <cpptl/stringtools.h> #include <string.h> *************** *** 438,441 **** --- 439,468 ---- + std::string + Value::toString() const + { + switch ( type() ) + { + case vtNone: + return "<:none:>"; + case vtBoolean: + return CppTL::toString( asBool() ); + case vtSignedInteger: + return CppTL::toString( guts_.intValue_ ); + case vtUnsignedInteger: + return CppTL::toString( guts_.uintValue_ ); + case vtReal: + return CppTL::toString( guts_.realValue_ ); + case vtString: + return "'" + asString() + "'"; /// @todo string should be escaped... + case vtProperties: + return asProperties().toString(); + default: // unreachable + CPPTL_DEBUG_ASSERT_UNREACHABLE; + return false; + } + } + + // Inline implementation of Property *************** *** 1050,1052 **** --- 1077,1118 ---- + std::string + Properties::toString() const + { + return toString( "" ); + } + + + std::string + Properties::toString( const std::string &prefix ) const + { + std::string str; + PropertyList::const_iterator it = properties_.begin(); + PropertyList::const_iterator itEnd = properties_.end(); + for ( ;it != itEnd; ++it ) + { + const Value &value = it->value(); + if ( value.isProperties() ) + str += value.asProperties().toString( prefix + "/" + it->name() ); + else + { + str += prefix; + str += " = "; + str += value.toString(); + str += "\n"; + } + } + + for ( unsigned int index = 0; index < indexedProperties_.size(); ++index ) + { + str += prefix; + str += "["; + str += CppTL::toString( index ); + str += "] = "; + str += indexedProperties_[index].toString(); + str += "\n"; + } + return str; + } + } // namespace OpenTest |