From: stephan b. <sg...@us...> - 2004-12-26 07:53:29
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2805/src/s11n Modified Files: Makefile.toc data_node_algo.h data_node_functor.h list.h map.h s11n_node.h Log Message: Mass commit: fixes vis-a-vis node traits. Made s11n_node's API mostly private, which turned up lots of long-standing code which was not using traits. Index: s11n_node.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/s11n_node.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- s11n_node.h 26 Dec 2004 00:55:20 -0000 1.2 +++ s11n_node.h 26 Dec 2004 07:53:19 -0000 1.3 @@ -12,7 +12,7 @@ #include <vector> #include "str.h" // to/from() string - +#include "traits.h" // node_traits namespace P { namespace s11n { /** @@ -22,7 +22,7 @@ class s11n_node { public: - + friend class node_traits<s11n_node>; /** The map type this object uses to store properties. */ @@ -117,6 +117,18 @@ */ s11n_node( const s11n_node & rhs ); + + /** + Returns this node's name, as set via name(string). + + Only in the public API because name() is used by + some algos which don't know about node_traits. + */ + std::string name() const; + + + private: + /** Returns a list of the s11n_node children of this object. The caller should not delete any pointers @@ -190,10 +202,6 @@ */ void name( const std::string & n ); - /** - Returns this node's name, as set via name(string). - */ - std::string name() const; /** Index: map.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/map.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- map.h 26 Dec 2004 01:26:15 -0000 1.3 +++ map.h 26 Dec 2004 07:53:19 -0000 1.4 @@ -435,15 +435,14 @@ NodeType * ch = 0; for( ; e != b; ++b ) { - ch = new NodeType; - ch->name( "pair" ); + ch = TR::create( "pair" ); if( ! serialize_pair( *ch, *b ) ) { delete( ch ); CERR << "serialize_map: child failed serialize.\n"; return false; } - dest.children().push_back( ch ); + TR::children(dest).push_back( ch ); } return true; } @@ -457,14 +456,14 @@ const std::string & subnodename, const MapType & src ) { - NodeType * ch = new NodeType; - ch->name( subnodename ); + typedef node_traits<NodeType> TR; + NodeType * ch = TR::create( subnodename ); if( ! serialize_map<NodeType,MapType>( *ch, src ) ) { delete( ch ); return false; } - dest.children().push_back( ch ); + TR::children(dest).push_back( ch ); return true; } @@ -492,6 +491,7 @@ template <typename NodeType, typename MapType> bool deserialize_map( const NodeType & src, MapType & dest ) { + typedef node_traits<NodeType> TR; typedef typename NodeType::child_list_type::const_iterator CIT; //typedef typename SerializableType::value_type VT; // ^^^ no, because VT::first_type is const! @@ -500,7 +500,7 @@ typedef typename MapType::mapped_type VType; typedef std::pair< KType, VType > PairType; PairType pair; - CIT b = src.children().begin(), e = src.children().end(); + CIT b = TR::children(src).begin(), e = TR::children(src).end(); const NodeType *ch = 0; for( ; e != b ; ++b ) { Index: data_node_algo.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/data_node_algo.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- data_node_algo.h 26 Dec 2004 00:55:20 -0000 1.2 +++ data_node_algo.h 26 Dec 2004 07:53:19 -0000 1.3 @@ -108,12 +108,13 @@ const NodeT * find_child_by_name( const NodeT & parent, const std::string & name ) { + typedef node_traits<NodeT> TR; typedef typename NodeT::child_list_type::const_iterator CIT; - CIT it = std::find_if( parent.children().begin(), - parent.children().end(), - s11n::same_name<NodeT>( name ) + CIT it = std::find_if( TR::children(parent).begin(), + TR::children(parent).end(), + same_name<NodeT>( name ) ); - return (parent.children().end() == it) ? 0 : *it; + return (TR::children(parent).end() == it) ? 0 : *it; } /** @@ -131,12 +132,13 @@ NodeT * find_child_by_name( NodeT & parent, const std::string & name ) { + typedef node_traits<NodeT> TR; typedef typename NodeT::child_list_type::iterator IT; - IT it = std::find_if( parent.children().begin(), - parent.children().end(), - s11n::same_name<NodeT>( name ) + IT it = std::find_if( TR::children(parent).begin(), + TR::children(parent).end(), + same_name<NodeT>( name ) ); - return (parent.children().end() == it) ? 0 : *it; + return (TR::children(parent).end() == it) ? 0 : *it; } Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/Makefile.toc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Makefile.toc 26 Dec 2004 04:09:28 -0000 1.5 +++ Makefile.toc 26 Dec 2004 07:53:19 -0000 1.6 @@ -4,10 +4,12 @@ SUBDIRS = io + SOURCES = \ data_node.cpp \ s11n.cpp \ s11n_node.cpp \ + SIO.cpp \ string_util.cpp HEADERS = $(wildcard *.h) @@ -17,6 +19,7 @@ data_node \ s11n \ s11n_node \ + SIO \ string_util \ ) Index: list.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/list.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- list.h 26 Dec 2004 01:26:15 -0000 1.3 +++ list.h 26 Dec 2004 07:53:19 -0000 1.4 @@ -82,7 +82,7 @@ NodeType * ch = new NodeType; if( ! serialize( *ch, *it ) ) { - CERR << "serialize_list: a child failed to serialize: " << ch->name() << " @ " << std::hex << ch << "\n"; + CERR << "serialize_list: a child failed to serialize: " << TR::name(*ch) << " @ " << std::hex << ch << "\n"; s11n::dump_node_debug( *ch, std::cerr ); delete( ch ); return false; @@ -102,6 +102,7 @@ const std::string & subnodename, const SerType & src ) { + typedef node_traits<NodeType> TR; NodeType * ch = new NodeType; ch->name( subnodename ); if( ! serialize_list<NodeType,SerType>( *ch, src ) ) @@ -109,7 +110,7 @@ delete( ch ); return false; } - dest.children().push_back( ch ); + TRchildren(dest).push_back( ch ); return true; } @@ -153,7 +154,7 @@ std::string implclass; static const char * errprefix = "deserialize_list(node,list) "; #define ERRPRE if(0) CERR << errprefix << "srcnode="<<std::dec<<&src << ": " - ERRPRE <<"starting... dest list size="<<dest.size()<<". src child count="<<src.children().size()<<"\n"; + ERRPRE <<"starting... dest list size="<<dest.size()<<". src child count="<<TR::children(src).size()<<"\n"; int bogocount = 0; for( ; et != it; ++it ) { @@ -179,7 +180,7 @@ if( ! deserialize( *nch, ser ) ) { CERR << "deserialize_list(): deser of a child failed!\n"; - CERR << "name="<< nch->name()<< ". implclass="<< implclass<<" @ " << std::hex<<nch <<"\n"; + CERR << "name="<< TR::name(*nch)<< ". implclass="<< implclass<<" @ " << std::hex<<nch <<"\n"; s11n::dump_node_debug( *nch, std::cerr ); ACVT::release( ser ); return false; Index: data_node_functor.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/data_node_functor.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- data_node_functor.h 26 Dec 2004 00:55:20 -0000 1.2 +++ data_node_functor.h 26 Dec 2004 07:53:19 -0000 1.3 @@ -44,7 +44,7 @@ void dump_node_debug( const NodeType & n, std::ostream & os ) { typedef node_traits<NodeType> NTR; - os << "node dump: ["<<n.name()<<"]["<<NTR::class_name(n)<<"]@"<<std::hex<<&n<<"\n"; + os << "node dump: ["<<NTR::name(n)<<"]["<<NTR::class_name(n)<<"]@"<<std::hex<<&n<<"\n"; typedef typename NTR::const_iterator PT; PT b = NTR::begin(n), e = NTR::end(n); os << "==================== properties:\n"; |