From: stephan b. <sg...@us...> - 2004-12-26 14:35:22
|
Update of /cvsroot/pclasses/pclasses2/src/s11n/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8125/src/s11n/io Modified Files: data_node_io.h Log Message: Fixed a broken if(os.good() ) return false. Removed a bunch of commented-out code. Index: data_node_io.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/io/data_node_io.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- data_node_io.h 26 Dec 2004 12:30:06 -0000 1.3 +++ data_node_io.h 26 Dec 2004 14:35:13 -0000 1.4 @@ -163,7 +163,7 @@ { std::ofstream os( destfile.c_str() ); // @fixme: zfstream support was removed for P! - if( os.good() ) return false; + if( ! os.good() ) return false; bool b = this->serialize( src, os ); return b; } @@ -267,12 +267,14 @@ Special feature: - If the first line of the stream is "#s11n::io::load_serializer" - then the next token on that line is expected to be a Serializer - class name. This function will try to classload that object. - If successful it will use that type to deserialize the input - string. If unsuccessful it will read the next line for a cookie - and try to use that Serializer. If that fails, it will return 0. + If the first line of the stream is + "#s11n::io::serializer CLASSNAME" then the CLASSNAME + token is expected to be a Serializer class name. This + function will try to classload that object. If + successful it will use that type to deserialize the + input stream. NOT YET IMPLEMENTED: if unsuccessful it + will read the next line for a cookie and try to use + that Serializer. If that fails, it will return 0. */ template <typename NodeType> NodeType * @@ -370,14 +372,15 @@ if( AsFile ) { is = AP( new std::ifstream( src.c_str() ) ); + if( ! is->good() ) return 0; } else { is = AP( new std::istringstream(src) ); } // AP is = AP( zfstream::get_istream( src, AsFile ) ); - // ^^^^ @fixme: zfstream removed because P doesn't have this support (yet) - if( ! is.get() ) return 0; +// if( ! is.get() ) return 0; +// ^^^^ @fixme: zfstream removed because P doesn't have this support (yet) return load_node<NodeType>( *is ); } @@ -432,61 +435,6 @@ } - /** - Saves src to the given ostream using the given - Serializer type. - - ONLY use this for saving root nodes! - */ - template <typename SerializerT> - bool save_node( const typename SerializerT::node_type & src, std::ostream & dest ) - { - return SerializerT().serialize( src, dest ); - } - - - /** - Saves src, a Serializable type, to the given - ostream using a SerializerT serializer. - - SerializerT must be compatible with - s11n::io::data_node_serializer<> - conventions and must provide a <code>typedef XXX - node_type</code>, where XXX is a data type - conforming to s11n::data_node - conventions. - - Returns true on success, false on error. - - ONLY use this for saving root nodes! - */ - template <typename SerializerT,typename SerializableT> - bool save_serializable( const SerializableT & src, - std::ostream & dest ) - { - typedef typename SerializerT::node_type node_type; - node_type node( "serializable" ); - if( ! ::P::s11n::serialize<node_type,SerializableT>( node, src ) ) return false; - return SerializerT().serialize( node, dest ); - } - - /** - An overloaded form which takes a filename. - - ONLY use this for saving root nodes! - */ - template <typename SerializerT,typename SerializableT> - bool save_serializable( const SerializableT & src, - const std::string & filename ) - { -// typedef std::auto_ptr<std::ostream> AP; -// AP os = AP( zfstream::get_ostream( filename ) ); -// if( ! os.get() ) return false; -// @fixme: ^^^ zfstream removed for P - std::ofstream os( filename.c_str() ); - if( ! os.good() ) return false; - return save_serializable<SerializerT,SerializableT>( src, os ); - } } // namespace io |