From: stephan b. <sg...@us...> - 2004-12-26 14:44:55
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9868/test Modified Files: s11nTest.cpp Log Message: Worked around compiler bug :(. Added s11n_cast() demo. Index: s11nTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/s11nTest.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- s11nTest.cpp 26 Dec 2004 08:09:07 -0000 1.4 +++ s11nTest.cpp 26 Dec 2004 14:44:46 -0000 1.5 @@ -14,20 +14,34 @@ using namespace ::P::SIO; +typedef std::list<std::string> TestListType2; +typedef std::list<P::Util::LexT> TestListType; +// compiler bug, gcc 3.3.5 20040809 +// When adding :: before P in the above decl it fails +// with a 'parse error before :', but it allows +// me to do :: on the map here: typedef std::map<std::string,::P::Util::LexT> TestMapType; +#define USE_FAT_PROXIES 1 +#if ! USE_FAT_PROXIES // install a custom proxy, which doesn't produce as fat // output as the default one for maps: -#define PS11N_TYPE TestMapType -#define PS11N_TYPE_NAME "TestMapType" -#define PS11N_SERIALIZE_FUNCTOR ::P::s11n::map::streamable_map_serializable_proxy -#include <pclasses/s11n/reg_serializable_traits.h> +# define PS11N_TYPE TestMapType +# define PS11N_TYPE_NAME "TestMapType" +# define PS11N_SERIALIZE_FUNCTOR ::P::s11n::map::streamable_map_serializable_proxy +# include <pclasses/s11n/reg_serializable_traits.h> +// ditto for our list... +# define PS11N_TYPE TestListType +# define PS11N_TYPE_NAME "TestListType" +# define PS11N_SERIALIZE_FUNCTOR ::P::s11n::list::streamable_list_serializable_proxy +# include <pclasses/s11n/reg_serializable_traits.h> +#endif // ! USE_FAT_PROXIES #define SERIALIZE(Node,SType,SObj) serialize< SType >( Node, SObj ) #define DESERIALIZE(Node,SType) deserialize< SType >( Node ) -#define SERIALIZER_CLASS_NAME "<!DOCTYPE P::s11n::io::expat_serializer>" +#define SERIALIZER_CLASS_NAME "expat" // #define SERIALIZER_CLASS_NAME "expat" bool test_load( const std::string & fn ) @@ -80,8 +94,7 @@ NODETR::clear(node); using ::P::Util::LexT; - typedef std::list<LexT> ListT; - ListT list; + TestListType list; TestMapType map; LexT tmpv; LexT tmpk; @@ -99,6 +112,25 @@ CERR << "Containers...\n"; + TestMapType::const_iterator mit; + TestListType::const_iterator lit = list.begin(); + size_t at = 0; + if( 0 ) + { + while( lit != list.end() ) + { + CERR << "list["<<at++<<"] = " << (*(lit++))<<"\n"; + } + mit = map.begin(); + while( mit != map.end() ) + { + CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; + ++mit; + } + } + + + assert( serialize(node,list) ); assert( ser->serialize( node, std::cout ) ); list.clear(); @@ -117,18 +149,29 @@ // now prove it... - ListT::const_iterator lit = list.begin(); - size_t at = 0; - while( lit != list.end() ) - { - CERR << "list["<<at++<<"] = " << (*(lit++))<<"\n"; - } - TestMapType::const_iterator mit = map.begin(); - while( mit != map.end() ) + if( 0 ) { - CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; - ++mit; + lit = list.begin(); + at = 0; + while( lit != list.end() ) + { + CERR << "list["<<at++<<"] = " << (*(lit++))<<"\n"; + } + mit = map.begin(); + while( mit != map.end() ) + { + CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; + ++mit; + } } + + CERR << "s11n_cast(list,list2)...\n"; + TestListType2 list2; + assert( s11n_cast( list, list2 ) && "s11n_cast() failed :(" ); + // ^^^ reminder: only works when list and list2 use compatible + // proxies!!! + CERR << "casted-to list (size=="<<list2.size()<<"):\n"; + save( list2, std::cout ); return 0; } |