You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(622) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(303) |
Feb
(64) |
Mar
(5) |
Apr
(63) |
May
(82) |
Jun
(53) |
Jul
(50) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: stephan b. <sg...@us...> - 2005-01-06 17:08:06
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18732/src/IO Modified Files: Makefile.toc Log Message: Added ZLibIOFilter when zlib is active. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/Makefile.toc,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.toc 3 Jan 2005 18:27:55 -0000 1.6 +++ Makefile.toc 6 Jan 2005 17:07:56 -0000 1.7 @@ -11,7 +11,7 @@ URL.o ifeq (1,$(PCLASSES_HAVE_ZLIB)) - OBJECTS += ZLib.o + OBJECTS += ZLib.o ZLibIOFilter.o endif # StringDevice.o |
From: stephan b. <sg...@us...> - 2005-01-06 17:06:38
|
Update of /cvsroot/pclasses/pclasses2/src/s11n In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18348/src/s11n Modified Files: data_node_serialize.h Log Message: A traits-related fix. Index: data_node_serialize.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/s11n/data_node_serialize.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- data_node_serialize.h 28 Dec 2004 04:18:01 -0000 1.4 +++ data_node_serialize.h 6 Jan 2005 17:06:30 -0000 1.5 @@ -252,7 +252,7 @@ } else { - target.children().push_back( sub ); + NT::children(target).push_back( sub ); } return sub != 0; } |
From: stephan b. <sg...@us...> - 2005-01-06 17:05:48
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18142/test Modified Files: s11nTest.cpp Log Message: Moved s11n tests into a UnitTest class. Index: s11nTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/s11nTest.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- s11nTest.cpp 31 Dec 2004 17:41:59 -0000 1.11 +++ s11nTest.cpp 6 Jan 2005 17:05:36 -0000 1.12 @@ -21,6 +21,13 @@ #include "FactoryTest.h" +#include "Test.h" +#include "pclasses/IO/IOStream.h" +#include "pclasses/System/File.h" +#include "pclasses/System/Pipe.h" +#include "pclasses/System/Process.h" +#include "pclasses/System/ProcessIO.h" + using namespace ::P::SIO; typedef std::list<std::string> TestListType; @@ -337,164 +344,139 @@ return 0; } -/// i wish i could make this a P::App... -int main( int argc, char ** argv ) -{ - using namespace ::P::SIO; - - CERR << "P::s11n tests...\n"; - - if( 0 ) - { - return parens_parser(); - } - - if( 2 == argc ) +class S11nTest: public UnitTest { +public: + + void run() throw() { - return test_load( argv[1] ) ? 0 : 1; - } + using namespace ::P::SIO; - typedef std::auto_ptr<TheBase> TAP; - TAP b1 = TAP( new BType ); - NODE_TYPE node; - assert( SERIALIZE(node,TheBase, *b1.get() ) ); // weird: i shouldn't have to deref that AP. - CERR << "Serialize Workie!\n"; + typedef std::auto_ptr<TheBase> TAP; + TAP b1 = TAP( new BType ); + NODE_TYPE node; + P_TEST( SERIALIZE(node,TheBase, *b1.get() ) ); // weird: i shouldn't have to deref that AP. + CERR << "Serialize Workie!\n"; - NODETR::class_name( node, "CType" ); // should force load of CType.so on next line... - TAP b2 = TAP( DESERIALIZE(node,TheBase) ); - assert( b2.get() && "Deserialize failed :(" ); - CERR << "Deser workie: " << b2->classname()<<"\n"; + NODETR::class_name( node, "CType" ); // This should force load of CType.so on next line... + TAP b2 = TAP( DESERIALIZE(node,TheBase) ); + P_TEST( b2.get() && "Deserialize failed :(" ); + CERR << "Deser workie: " << b2->classname()<<"\n"; - typedef std::auto_ptr<SerializerInterface> SAP; - std::string serclass = SERIALIZER_CLASS_NAME; - SAP ser = SAP( ::P::Plugin::pluginManager<SerializerInterface>().create( serclass ) ); - assert( ser.get() && "Could not load serializer :(" ); - CERR << "Loaded serializer '"<<serclass<<"'. :)\n"; + typedef std::auto_ptr<SerializerInterface> SAP; + std::string serclass = SERIALIZER_CLASS_NAME; + SAP ser = SAP( createSerializer() ); + P_TEST( ser.get() && "Could not load serializer :(" ); + CERR << "Loaded serializer '"<<serclass<<"'. :)\n"; - NODETR::clear(node); - - using ::P::Util::LexT; - TestListType list; - TestMapType map; - LexT tmpv; - LexT tmpk; - for( int i = 0; i < 10; i++ ) - { - tmpk = "item" + LexT(i).str(); - // ^^^ reminder: we do this to avoid numeric keys - // in map, because that don't work with XML-compliant Serializers. - tmpv = std::string("this is item #") + LexT(i).str(); - CERR << "Adding ["<<tmpv<<"]\n"; - list.push_back( tmpv ); - map[tmpk] = tmpv; - } - CERR << "list/map sizes == " << list.size() << " , " << map.size()<<"\n"; - - CERR << "Containers...\n"; + NODETR::clear(node); - 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() ) + using ::P::Util::LexT; + TestListType list; + TestMapType map; + LexT tmpv; + LexT tmpk; + for( int i = 0; i < 10; i++ ) { - CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; - ++mit; + tmpk = "item" + LexT(i).str(); + // ^^^ reminder: we do this to avoid numeric keys + // in map, because that don't work with XML-compliant Serializers. + tmpv = std::string("this is item #") + LexT(i).str(); + CERR << "Adding ["<<tmpv<<"]\n"; + list.push_back( tmpv ); + map[tmpk] = tmpv; } - } + CERR << "list/map sizes == " << list.size() << " , " << map.size()<<"\n"; + CERR << "Containers...\n"; + TestMapType::const_iterator mit; + TestListType::const_iterator lit = list.begin(); + size_t at = 0; - assert( serialize(node,list) ); - assert( ser->serialize( node, std::cout ) ); - list.clear(); - assert( deserialize( node, list ) && "deser list failed :(" ); + P_TEST( serialize(node,list) ); + P_TEST( ser->serialize( node, std::cout ) ); + list.clear(); + P_TEST( deserialize( node, list ) && "deser list failed :(" ); - NodeTraits::clear(node); - assert( serialize(node,map) ); - assert( ser->serialize( node, std::cout ) ); - map.clear(); - assert( deserialize( node, map ) && "deser map failed :(" ); - NodeTraits::set( node, "i_deserialized_this", "yes" ); - CERR << "Deserialized:\n"; + NodeTraits::clear(node); + P_TEST( serialize(node,map) ); + P_TEST( ser->serialize( node, std::cout ) ); + map.clear(); + P_TEST( deserialize( node, map ) && "deser map failed :(" ); + NodeTraits::set( node, "i_deserialized_this", "yes" ); + CERR << "Deserialized:\n"; - CERR << "deser list.size() == " << list.size()<<"\n"; - CERR << "map.size() == " << map.size()<<"\n"; + CERR << "deser list.size() == " << list.size()<<"\n"; + CERR << "map.size() == " << map.size()<<"\n"; + P_TEST( save( map, std::cout ) ); + // now prove it... - // now prove it... - if( 0 ) - { - lit = list.begin(); - at = 0; - while( lit != list.end() ) + + if( 1 ) { - CERR << "list["<<at++<<"] = " << (*(lit++))<<"\n"; + CERR << "Manually iterating over deserialized data...\n"; + 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; + } } - mit = map.begin(); - while( mit != map.end() ) + + + if( 0 ) { - CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; - ++mit; + CERR << "s11nCast(list,list2)...\n"; + TestListType2 list2; + P_TEST( s11nCast( list, list2 ) && "s11nCast() failed :(" ); + // ^^^ reminder: only works when list and list2 use compatible + // proxies!!! + CERR << "casted-to list (size=="<<list2.size()<<"):\n"; + save( list2, std::cout ); + CERR << "ACHTUNG: ^^^^^ failure here is normal when the list1/list2 proxies don't match.\n"; + } + + if( 1 ) + { + CERR << "Just what we've always wanted to do: save Time...\n"; + using P::Time; + using P::Date; + using P::DateTime; + Time thetime( 12, 13, 14 ); + Date thedate( 2005, 1, 30 ); + DateTime dt( thedate, thetime ); + save( thetime, std::cout ); + save( thedate, std::cout ); + save( dt, std::cout ); } } +}; +/// i wish i could make this a P::App... +int main( int argc, char ** argv ) +{ + + CERR << "P::s11n tests...\n"; if( 0 ) { - 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 ); - CERR << "ACHTUNG: ^^^^^ failure here is normal when the list1/list2 proxies don't match.\n"; + return parens_parser(); } - if( 1 ) + if( 2 == argc ) { - CERR << "Time...\n"; - using P::Time; - using P::Date; - using P::DateTime; - Time thetime( 12, 13, 14 ); - Date thedate( 2005, 1, 30 ); - DateTime dt( thedate, thetime ); - save( thetime, std::cout ); - save( thedate, std::cout ); - save( dt, std::cout ); - -// CERR << "Using S11nNode-specific API...\n"; -// NODE_TYPE tmnode; -// assert( tmnode.serialize( dt ) ); -// assert( save( tmnode, std::cout ) ); - -// DateTime * pdt = tmnode.deserialize<DateTime>(); -// assert( pdt ); -// CERR << "deserialized (DateTime*) == " << *pdt<<"\n"; -// delete pdt; -// DateTime vdt; -// assert( tmnode.deserialize( vdt ) ); -// CERR << "deserialized DateTime == " << vdt<<"\n"; - + return test_load( argv[1] ) ? 0 : 1; } -// size_t S1 = 7; -// ulong S2 = 7; -// int S3 = 7; -// char S4 = '7'; -// save( S1, std::cout ); -// save( S2, std::cout ); -// save( S3, std::cout ); -// save( S4, std::cout ); - + S11nTest t1; + t1.run(); return 0; } |
From: stephan b. <sg...@us...> - 2005-01-06 17:04:43
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17857/test Modified Files: SimplePropertyStoreTest.cpp Log Message: Added an SIO test. Index: SimplePropertyStoreTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/SimplePropertyStoreTest.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SimplePropertyStoreTest.cpp 30 Dec 2004 22:56:03 -0000 1.6 +++ SimplePropertyStoreTest.cpp 6 Jan 2005 17:04:28 -0000 1.7 @@ -3,7 +3,6 @@ #include <pclasses/SIO/SIO.h> #include <pclasses/s11n/pods_streamable.h> #include <pclasses/s11n/map.h> -#include <pclasses/Util/SimplePropertyStore.h> #include <pclasses/SIO/Proxy/SimplePropertyStore_s11n.h> #include <memory> // auto_ptr #include <cassert> @@ -16,6 +15,11 @@ #define PropMap P::Util::SimplePropertyStore +#define PS11N_TYPE std::map<std::string,std::string> +#define PS11N_TYPE_NAME "map" +#define PS11N_SERIALIZE_FUNCTOR ::P::s11n::map::streamable_map_serializable_proxy +#include <pclasses/SIO/RegisterSerializable.h> + // i wish i could make this a P::App... int main( int argc, char ** argv ) { @@ -40,5 +44,14 @@ save( m, std::cout ); + typedef std::map<std::string,std::string> OtherMap; + OtherMap m2; + if( ! s11nCast( m, m2 ) ) + { + CERR << "Map conversion failed!\n"; + return 1; + } + CERR << "s11nCast() to map<string,string>:\n"; + save( m2, std::cout ); return 0; } |
From: stephan b. <sg...@us...> - 2005-01-06 17:03:55
|
Update of /cvsroot/pclasses/pclasses2/src/SIO/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17652/src/SIO/Proxy Modified Files: SimplePropertyStore_s11n.h Log Message: Added a missing header. Index: SimplePropertyStore_s11n.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/SIO/Proxy/SimplePropertyStore_s11n.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SimplePropertyStore_s11n.h 30 Dec 2004 23:11:13 -0000 1.2 +++ SimplePropertyStore_s11n.h 6 Jan 2005 17:03:45 -0000 1.3 @@ -2,6 +2,7 @@ # error "s11n.h or SIO.h must be included before plugging in s11n proxies!" #else +#include <pclasses/Util/SimplePropertyStore.h> #include "LexT_s11n.h" #if !defined(p_UTIL_SIMPLEPRPOPERTYSTORE_REGISTERED_WITH_S11N) |
From: stephan b. <sg...@us...> - 2005-01-06 17:03:29
|
Update of /cvsroot/pclasses/pclasses2/src/SIO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17499/src/SIO Modified Files: SIO.cpp SIO.h Log Message: Split serializeFor() into input/output serializer getters. Index: SIO.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/SIO/SIO.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SIO.h 31 Dec 2004 17:41:59 -0000 1.2 +++ SIO.h 6 Jan 2005 17:03:16 -0000 1.3 @@ -37,7 +37,7 @@ serialization code may need to use the classes in P::s11n or possibly even P::s11n::io as well. - SIO is a fork/port of the s11n project: + SIO is a P::Classes-centric fork/port of the s11n project. http://s11n.net @@ -55,7 +55,18 @@ */ namespace SIO { + /** + S11nNode is the "data node" type used by the underlying + s11n framework. In short: these containers are used to hold + serialized data for arbitrary objects. See the s11n library + manual and sample applications for more information than + you care to know about this type. + Note that the exact concrete node type is not guaranteed by + the SIO interface! What is guaranteed is that it will be a type + suitable for use with s11n::node_traits<NodeType> and, by + extension, for use within the s11n framework. + */ typedef ::P::s11n::s11n_node S11nNode; /** NodeTraits provide the interface for fetching and @@ -162,18 +173,25 @@ return ::P::s11n::io::load_serializable<S11nNode,SerializableType>( src ); } - /** - See ::P::s11n::io::create_serializer(). + /** + SHOULD return a dynamically-determined output handler for + the given url. - In short: it looks at the given file to determine what - Serializer should be able to read it. + CURRENTLY always returns createSerializer(). - Once IOManager support is completed this will also support - URL-based lookups. + Caller owns the returned pointer, which may be 0. + */ + SerializerInterface * getOutputSerializer( const std::string & url ); - The caller owns the returned object, which may be NULL. - */ - SerializerInterface * serializerFor( const std::string & url ); + /** + SHOULD return a dynamically-determined input handler for + the given url. + + CURRENTLY always returns createSerializer(). + + Caller owns the returned pointer, which may be 0. + */ + SerializerInterface * getInputSerializer( const std::string & url ); /** Saves src to dest using the default @@ -198,6 +216,9 @@ Uses SerializerPluginManager to load a Serializer. The caller owns the returned object, which may be NULL. + + This function does not set the SIO default serializer - use + serializerClass(string) for that. */ SerializerInterface * createSerializer( const std::string & ); @@ -238,10 +259,10 @@ std::string serializerClass(); /** - Serializes fromobj and deserializes the data by passing - it to toobj. Returns false if either operation fails. + Serializes fromobj deserializes the data into + toobj. Returns false if either operation fails. - SerializableT1 and SerializableT must of course be + SerializableT1 and SerializableT2 must of course be Serializables for this to work. See ::P::s11n::s11n_cast() for full details, including @@ -249,7 +270,7 @@ to different types. */ template <typename SerializableT1, typename SerializableT2> - bool s11n_cast( const SerializableT1 & fromobj, SerializableT2 & toobj ) + bool s11nCast( const SerializableT1 & fromobj, SerializableT2 & toobj ) { return ::P::s11n::s11n_cast<S11nNode,SerializableT1,SerializableT2>( fromobj, toobj ); } Index: SIO.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/SIO/SIO.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SIO.cpp 29 Dec 2004 19:54:44 -0000 1.1 +++ SIO.cpp 6 Jan 2005 17:03:16 -0000 1.2 @@ -19,12 +19,20 @@ std::string m_serializer_class = SIO_KEY_DEFAULT_SERIALIZER; - SerializerInterface * serializerFor( const std::string & url ) + SerializerInterface * getOutputSerializer( const std::string & url ) { // @fixme: be more dynamic here: - // todo: port in IManager support from "original" ps11n + // todo: port in IOManager support from "original" ps11n // once IOM is re-implemented in P2. - return ::P::s11n::io::create_serializer<S11nNode>( m_serializer_class ); + return createSerializer(); + } + + SerializerInterface * getInputSerializer( const std::string & url ) + { + // @fixme: be more dynamic here: + // todo: port in IOManager support from "original" ps11n + // once IOM is re-implemented in P2. + return createSerializer( m_serializer_class ); } SerializerInterface * createSerializer( const std::string & c ) @@ -65,6 +73,8 @@ S11nNode * loadNode( const std::string & src ) { + // todo: use getOutputSerializer() once we've got more + // than one Serializer. return ::P::s11n::io::load_node<S11nNode>( src ); } |
From: Christian P. <cp...@us...> - 2005-01-06 17:03:12
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17417/include/pclasses Modified Files: Makefile.am Log Message: Added Callback.h, Signal.h Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.am 27 Dec 2004 07:07:19 -0000 1.3 +++ Makefile.am 6 Jan 2005 17:03:02 -0000 1.4 @@ -6,4 +6,4 @@ ByteOrderTraits.h BasicTypes.h Vector.h Algorithm.h TypeTraits.h \ Stack.h LinkedItem.h Pair.h IntTypeLimits.h Queue.h IntrusivePtr.h \ CircularQueue.h List.h NonCopyable.h Phoenix.h Factory.h \ - Time.h Date.h DateTime.h TimeSpan.h + Time.h Date.h DateTime.h TimeSpan.h Callback.h Signal.h |
From: stephan b. <sg...@us...> - 2005-01-06 17:02:47
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17328/include/pclasses/Util Modified Files: LexT.h Log Message: Fix for istream>> op, from Marc. Index: LexT.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/LexT.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- LexT.h 28 Dec 2004 15:56:23 -0000 1.4 +++ LexT.h 6 Jan 2005 17:02:37 -0000 1.5 @@ -435,13 +435,7 @@ */ inline std::istream & operator>>( std::istream & is, LexT & a ) { - char c; - // while( std::getline( is, a.str() ).good() ); - // ^^^ eeek! strips newlines! - while( ! is.get(c).eof() ) { - a.str().append( &c ); - } - return is; + return std::getline( is, a.str(), static_cast<std::istream::char_type>(std::istream::traits_type::eof()) ); } |
From: stephan b. <sg...@us...> - 2005-01-06 17:02:11
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17219/include/pclasses/IO Modified Files: IOManager.h Log Message: Replaced IOPluginManager with IOManager, as the Plugin support can probably be handled transparently. Index: IOManager.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/IOManager.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- IOManager.h 31 Dec 2004 14:38:25 -0000 1.4 +++ IOManager.h 6 Jan 2005 17:02:03 -0000 1.5 @@ -12,15 +12,15 @@ the P::IO layer. */ template <typename InterfaceT> - class IOPluginManager : public ::P::Plugin::PluginManager<InterfaceT> + class IOManager : public ::P::Factory<InterfaceT> { public: - typdef IOPluginManager<InterfaceT> ThisType; + typdef IOManager<InterfaceT> ThisType; typedef ::P::PluginManager<InterfaceT> ParentType; typedef typename ParentType::FactoryFuncType FactoryFuncType; typedef typename ParentType::ResultType ResultType; - IOPluginManager(){} - virtual ~IOPluginManager(){} + IOManager(){} + virtual ~IOManager(){} /** @@ -29,6 +29,10 @@ Clients may transparently replace or modify the default returned object by specializing P::Hook::FactoryInstanceHook<ThisType>. + + InterfaceT's which want to be loadable via DLL's + should install a FactoryInstanceHook to plug in the + DLL awareness. */ static ThisType & instance() { @@ -61,7 +65,7 @@ { return this->provides( _protocol.protocol() ); } - }; // class IOPluginManager + }; // class IOManager } } // namespace P::IO |
From: Christian P. <cp...@us...> - 2005-01-06 17:02:09
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17154 Modified Files: IOTest.cpp Log Message: Also test IOFilters. Index: IOTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/IOTest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- IOTest.cpp 31 Dec 2004 15:01:57 -0000 1.2 +++ IOTest.cpp 6 Jan 2005 17:02:00 -0000 1.3 @@ -20,16 +20,20 @@ #include "Test.h" #include "pclasses/IO/IOStream.h" +#include "pclasses/IO/IOFilter.h" +#include "pclasses/IO/ZLibIOFilter.h" #include "pclasses/System/File.h" #include "pclasses/System/Pipe.h" #include "pclasses/System/Process.h" #include "pclasses/System/ProcessIO.h" #include <string> +#include <zlib.h> namespace P { using IO::IOStream; +using IO::IOFilter; using System::File; using System::Pipe; using System::Process; @@ -38,11 +42,17 @@ class FileTest: public UnitTest { public: + FileTest(IOFilter* filter) + : _filter(filter) + { + } + void run() throw() { char data[] = "test"; File file("pclasses_file_test.tmp", File::ReadWrite); + file.setFilter(_filter); P_TEST(file.valid()); // write data to file @@ -50,7 +60,15 @@ P_TEST(file.size() == 4); // seek to beginning of file - P_TEST(file.seek(0, File::SeekSet) == 0); + if(file.isSeekable()) + { + P_TEST(file.seek(0, File::SeekSet) == 0); + } + else + { + file.close(); + file.open("pclasses_file_test.tmp", File::Read); + } // read data from file char tmp[4]; @@ -67,7 +85,6 @@ // close file file.close(); P_TEST(!file.valid()); - P_TEST_EXCEPTION(file.close(), LogicError); // this must fail cause pclasses_file_test.tmp already exists... P_TEST_EXCEPTION( @@ -75,10 +92,17 @@ IO::IOError ); } + + private: + IOFilter* _filter; }; class PipeTest: public UnitTest { public: + PipeTest(IOFilter* filter1, IOFilter* filter2) + : _filter1(filter1), _filter2(filter2) + { + } void run() throw() { @@ -87,7 +111,10 @@ Pipe::Pair pipes = Pipe::create(); Pipe& readPipe = pipes.first; + readPipe.setFilter(_filter1); + Pipe& writePipe = pipes.second; + writePipe.setFilter(_filter2); P_TEST(writePipe.valid()); P_TEST(writePipe.write(data, 4) == 4); @@ -102,20 +129,25 @@ writePipe.close(); P_TEST(!writePipe.valid()); - P_TEST_EXCEPTION(writePipe.close(), LogicError); P_TEST(readPipe.read(tmp, 1) == 0); P_TEST(readPipe.eof()); readPipe.close(); P_TEST(!readPipe.valid()); - P_TEST_EXCEPTION(readPipe.close(), LogicError); } + + private: + IOFilter* _filter1, *_filter2; }; class ProcessIOTest: public UnitTest { public: - + ProcessIOTest(IOFilter* filter) + : _filter(filter) + { + } + void run() throw() { char data[] = "test"; @@ -129,6 +161,7 @@ char tmp[4]; ProcessIO& io = proc.processIO(); + io.setFilter(_filter); P_TEST(io.read(tmp, 4) == 4); P_TEST(io.readErr(tmp, 4) == 4); @@ -138,8 +171,12 @@ P_TEST(proc.wait() == 0); P_TEST(proc.state() == Process::Stopped); } + + private: + IOFilter* _filter; }; + } int main(int argc, char* argv[]) @@ -156,14 +193,26 @@ return 0; } - P::PipeTest pt; - pt.run(); - - P::FileTest ft; + P::FileTest ft(0); ft.run(); - P::ProcessIOTest piot; + P::PipeTest pt(0, 0); + pt.run(); + + P::ProcessIOTest piot(0); piot.run(); + // re-run with NullFilter + P::FileTest ft2(new P::IO::IOFilter()); + ft2.run(); + + P::PipeTest pt2(new P::IO::IOFilter(), new P::IO::IOFilter()); + pt2.run(); + + P::ProcessIOTest piot2(new P::IO::IOFilter()); + piot2.run(); + + P::FileTest ft3(new P::IO::ZLibIOFilter()); + ft3.run(); return 0; } |
From: Christian P. <cp...@us...> - 2005-01-06 17:01:33
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16899 Modified Files: Makefile.am Log Message: Added SignalTest. Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.am 30 Dec 2004 17:18:26 -0000 1.2 +++ Makefile.am 6 Jan 2005 17:01:15 -0000 1.3 @@ -5,7 +5,7 @@ PtrTest_LDADD = $(top_builddir)/src/System/libpclasses_system.la $(top_builddir)/src/libpclasses.la noinst_HEADERS = Test.h noinst_PROGRAMS = QueueTest StackTest IntTypeTest ListTest ThreadTest \ - StringTest IOTest + StringTest IOTest SignalTest QueueTest_SOURCES = QueueTest.cpp QueueTest_LDADD = $(top_builddir)/src/libpclasses.la StackTest_SOURCES = StackTest.cpp @@ -21,6 +21,6 @@ StringTest_LDADD = $(top_builddir)/src/Unicode/libpclasses_unicode.la\ $(top_builddir)/src/libpclasses.la IOTest_SOURCES = IOTest.cpp -IOTest_LDADD = $(top_builddir)/src/System/libpclasses_system.la\ - $(top_builddir)/src/IO/libpclasses_io.la\ - $(top_builddir)/src/libpclasses.la +IOTest_LDADD = $(top_builddir)/src/System/libpclasses_system.la \ + $(top_builddir)/src/IO/libpclasses_io.la $(top_builddir)/src/libpclasses.la -lz +SignalTest_SOURCES = SignalTest.cpp |
From: stephan b. <sg...@us...> - 2005-01-06 17:01:33
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16997/include/pclasses Modified Files: Factory.h Log Message: Doc corrections/additions. Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- Factory.h 31 Dec 2004 15:09:52 -0000 1.16 +++ Factory.h 6 Jan 2005 17:01:15 -0000 1.17 @@ -169,9 +169,9 @@ Sample usage: <pre> -Factory<MyClass> & fac = Factory<MyClass>::instance(); -fac.registerFactory( "my_key", P::Hook::FactoryCreateHook>MyClass<::create ); -MyClass *foo = fac.create( "some_key" ); // == NULL +Factory<MyInterface> & fac = Factory<MyInterface>::instance(); +fac.registerFactory( "my_key", P::Hook::FactoryCreateHook<MyInterface,MyClass>::create ); +MyInterface *foo = fac.create( "some_key" ); // == NULL foo = fac.create( "my_key" ); // == a new MyClass object </pre> @@ -182,7 +182,7 @@ other Factory<InterfaceT> instantiations. ContextType is only used as a marker type, and is never instantiated by this class. Used cleverly, it can allow you quite a bit - of freedome in what code has access to which factories. + of freedom in what code has access to which factories. */ template < class InterfaceT, class ContextT = Sharing::FactoryContext, @@ -198,7 +198,7 @@ */ typedef KeyType key_type; - /** Same as ContextType */ + /** Same as ContextT parameterized type. */ typedef ContextT ContextType; /** @@ -285,7 +285,7 @@ return _alias; } key_type exp = (*cit).second; - while( cit != cet ) + while( 1 ) { cit = this->aliases().find( exp ); if( cet == cit ) @@ -306,7 +306,7 @@ /** Tries to instantiate an instance of value_type - using the given key. Returns NULL if no object + using the given key. Returns 0 if no object could be loaded for the given key. Subtypes are free to implement, e.g., DLL lookups. @@ -376,15 +376,35 @@ window. That said, it should never be necessary for clients to use this. - It is safe to call this post-main(), but such calls - may return an empty map! - TODO: use a Hook or Traits type to allow the user to replace this object with his own, so that he can control the scope of the map more fully. + + + At the moment this returns the same object for all + instances of ThisType. Providing a private map from + each instance is under consideration. If we do that + we also will have to change aliasing support to + work the same. + + The reasoning behind using static factory maps is + essentially this: we can only have one definition + of each type. We normally want factories to always + return an instance constructed in the same way. If + we allow multiple factories per type we might + introduce hard-to-track inconsistencies in client + code, where different factories than intended are + accidentally used. OTOH, private factory maps + would open up some interesting possibilities. */ - static FactoryMap & factoryMap() + FactoryMap & factoryMap() { + //return this->m_facs; + return Phoenix<FactoryMap,ContextType>::instance(); + } + const FactoryMap & factoryMap() const + { + //return this->m_facs; return Phoenix<FactoryMap,ContextType>::instance(); } @@ -407,7 +427,8 @@ { return Hook::FactoryInstanceHook<ThisType>::instance(); } - +// private: +// FactoryMap m_facs; }; // class Factory |
From: Christian P. <cp...@us...> - 2005-01-06 17:00:47
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16781 Added Files: SignalTest.cpp Log Message: Added SignalTest. --- NEW FILE: SignalTest.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/Callback.h" #include "pclasses/Signal.h" #include "Test.h" namespace P { class Signal0Test: public UnitTest { public: void testFunc() { _testFunc = true; } static void testFuncStatic() { _testFuncStatic = true; } bool testFunc2() { return true; } static bool testFunc2Static() { return false; } void run() throw() { _testFunc = false; _testFuncStatic = false; // bind signals and see if methods did run Signal0<void> sig; sig.bind(function(&testFuncStatic)); sig.bind(method(this, &Signal0Test::testFunc)); sig.fire(); P_TEST(_testFunc == true); P_TEST(_testFuncStatic == true); // unbind signals and test again .. _testFunc = false; _testFuncStatic = false; sig.unbind(function(&testFuncStatic)); sig.unbind(method(this, &Signal0Test::testFunc)); sig.fire(); P_TEST(_testFunc == false); P_TEST(_testFuncStatic == false); // test signal with bool return-type Signal0<bool> sig2; sig2.bind(function(&testFunc2Static)); sig2.bind(method(this, &Signal0Test::testFunc2)); P_TEST(sig2.fire() == true); } private: bool _testFunc; static bool _testFuncStatic; }; bool Signal0Test::_testFuncStatic = false; } int main(int argc, char* argv[]) { P::Signal0Test s0t; s0t.run(); } |
From: Christian P. <cp...@us...> - 2005-01-06 16:59:34
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16476/include/pclasses Modified Files: Callback.h Signal.h Log Message: Added Callback1, Fucntion1, Method1 templates. Added Signal1 template. Index: Callback.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Callback.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Callback.h 31 Dec 2004 18:43:41 -0000 1.1 +++ Callback.h 6 Jan 2005 16:59:23 -0000 1.2 @@ -25,21 +25,23 @@ /* ----------------- Callback0 ------------------ */ +//! Callback base class with no arguments template <typename RetType> class Callback0 { public: virtual ~Callback0() { } - virtual RetType exec() = 0; + virtual RetType exec() const = 0; protected: Callback0() { } }; +//! Callback base class with no arguments (void specialisation) template <> class Callback0<void> { public: virtual ~Callback0() { } - virtual void exec() = 0; + virtual void exec() const = 0; protected: Callback0() { } @@ -48,6 +50,7 @@ /* -------------- Function0 ------------- */ +//! Function callback class with no arguments template <typename RetType> class Function0: public Callback0<RetType> { public: @@ -56,13 +59,17 @@ Function0(FuncPtr ptr) : _funcPtr(ptr) { } - RetType exec() + RetType exec() const { return (*_funcPtr)(); } + bool operator==(const Function0& f) const + { return _funcPtr == f._funcPtr; } + private: FuncPtr _funcPtr; }; +//! Function callback class with no arguments (void specialisation) template <> class Function0<void>: public Callback0<void> { public: @@ -71,19 +78,24 @@ Function0(FuncPtr ptr) : _funcPtr(ptr) { } - void exec() + void exec() const { (*_funcPtr)(); } + bool operator==(const Function0& f) const + { return _funcPtr == f._funcPtr; } + private: FuncPtr _funcPtr; }; +//! Returns a function-callback object template <typename RetType> -Function0<RetType> callback(RetType (*ptr)()) +Function0<RetType> function(RetType (*ptr)()) { return Function0<RetType>(ptr); } /* ---------- Method0 ------------ */ +//! Method callback class with no arguments template <typename RetType, class ObjT> class Method0: public Callback0<RetType> { public: @@ -92,14 +104,18 @@ Method0(ObjT* obj, FuncPtr ptr) : _obj(obj), _funcPtr(ptr) { } - RetType exec() + RetType exec() const { return (_obj->*_funcPtr)(); } + bool operator==(const Method0& f) const + { return _obj == f._obj && _funcPtr == f._funcPtr; } + private: ObjT* _obj; FuncPtr _funcPtr; }; +//! Method callback class with no arguments (void specialisation) template <class ObjT> class Method0<void, ObjT>: public Callback0<void> { public: @@ -108,18 +124,145 @@ Method0(ObjT* obj, FuncPtr ptr) : _obj(obj), _funcPtr(ptr) { } - void exec() + void exec() const { (_obj->*_funcPtr)(); } + bool operator==(const Method0& f) const + { return _obj == f._obj && _funcPtr == f._funcPtr; } + private: ObjT* _obj; FuncPtr _funcPtr; }; +//! Returns a method-callback object template <typename RetType, class ObjT> -Method0<RetType,ObjT> callback(ObjT* obj, RetType (ObjT::*ptr)()) +Method0<RetType,ObjT> method(ObjT* obj, RetType (ObjT::*ptr)()) { return Method0<RetType,ObjT>(obj, ptr); } + + + +/* ----------------- Callback1 ------------------ */ + +//! Callback base class with one argument +template <typename RetType, typename ArgType1> +class Callback1 { + public: + virtual ~Callback1() { } + virtual RetType exec(ArgType1) const = 0; + + protected: + Callback1() { } +}; + +//! Callback base class with one argument (void specialisation) +template <typename ArgType1> +class Callback1<void, ArgType1> { + public: + virtual ~Callback1() { } + virtual void exec(ArgType1) const = 0; + + protected: + Callback1() { } + +}; + +/* -------------- Function1 ------------- */ + +//! Function callback class with one argument +template <typename RetType, typename ArgType1> +class Function1: public Callback1<RetType, ArgType1> { + public: + typedef RetType (*FuncPtr)(ArgType1); + + Function1(FuncPtr ptr) + : _funcPtr(ptr) { } + + RetType exec(ArgType1 arg1) const + { return (*_funcPtr)(arg1); } + + bool operator==(const Function1& f) const + { return _funcPtr == f._funcPtr; } + + private: + FuncPtr _funcPtr; +}; + +//! Function callback class with one argument (void specialisation) +template <typename ArgType1> +class Function1<void, ArgType1>: public Callback1<void, ArgType1> { + public: + typedef void (*FuncPtr)(ArgType1); + + Function1(FuncPtr ptr) + : _funcPtr(ptr) { } + + void exec(ArgType1 arg1) const + { (*_funcPtr)(arg1); } + + bool operator==(const Function1& f) const + { return _funcPtr == f._funcPtr; } + + private: + FuncPtr _funcPtr; +}; + +//! Returns a function-callback object +template <typename RetType, typename ArgType1> +Function1<RetType, ArgType1> function(RetType (*ptr)(ArgType1)) +{ return Function1<RetType, ArgType1>(ptr); } + +/* ---------- Method1 ------------ */ + +//! Method callback class with one arguments +template <typename RetType, class ObjT, typename ArgType1> +class Method1: public Callback1<RetType, ArgType1> { + public: + typedef RetType (ObjT::*FuncPtr)(ArgType1); + + Method1(ObjT* obj, FuncPtr ptr) + : _obj(obj), _funcPtr(ptr) { } + + RetType exec(ArgType1 arg1) const + { return (_obj->*_funcPtr)(arg1); } + + bool operator==(const Method1& f) const + { return _obj == f._obj && _funcPtr == f._funcPtr; } + + private: + ObjT* _obj; + FuncPtr _funcPtr; +}; + +//! Method callback class with no arguments (void specialisation) +template <class ObjT, typename ArgType1> +class Method1<void, ObjT, ArgType1>: public Callback1<void, ArgType1> { + public: + typedef void (ObjT::*FuncPtr)(ArgType1); + + Method1(ObjT* obj, FuncPtr ptr) + : _obj(obj), _funcPtr(ptr) { } + + void exec(ArgType1 arg1) const + { (_obj->*_funcPtr)(arg1); } + + bool operator==(const Method1& f) const + { return _obj == f._obj && _funcPtr == f._funcPtr; } + + private: + ObjT* _obj; + FuncPtr _funcPtr; +}; + +//! Returns a method-callback object +template <typename RetType, class ObjT, typename ArgType1> +Method1<RetType, ObjT, ArgType1> method(ObjT* obj, RetType (ObjT::*ptr)(ArgType1)) +{ return Method1<RetType, ObjT, ArgType1>(obj, ptr); } + + + + } // !namespace P #endif Index: Signal.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Signal.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Signal.h 31 Dec 2004 18:44:03 -0000 1.1 +++ Signal.h 6 Jan 2005 16:59:24 -0000 1.2 @@ -26,19 +26,22 @@ namespace P { +//! Internal helper for binding a callback to a signal template <class ListType, class CallbackType> void bind_slot(ListType& list, CallbackType cb) { list.push_back(new CallbackType(cb)); } +//! Internal helper for unbinding a callback from a signal template <class ListType, class CallbackType> void unbind_slot(ListType& list, CallbackType cb) { typename ListType::iterator i = list.begin(); while(i != list.end()) { - if(*i == cb) + CallbackType* val = static_cast<CallbackType*>(*i); + if(cb == *val) { delete *i; list.erase(i); @@ -48,6 +51,7 @@ } } +//! Internal helper for unbinding all callbacks template <class ListType> void unbind_slots(ListType& list) { @@ -61,7 +65,8 @@ /* -------------------- Signal0 ---------------- */ -template <class RetType> +//! Base class for Signal0 +template <typename RetType> class SignalBase0 { public: typedef std::list< @@ -82,23 +87,24 @@ void unbind(CallbackType slot) { unbind_slot(_slots, slot); } - virtual RetType exec() const = 0; + virtual RetType fire() const = 0; protected: CallbackList _slots; }; -template <class RetType> +//! Signal with no arguments +template <typename RetType> class Signal0: public SignalBase0<RetType> { public: - RetType exec() const + RetType fire() const { RetType ret = RetType(); typename CallbackList::const_iterator i = _slots.begin(); while(i != _slots.end()) { ret = (*i)->exec(); - if(!ret) + if(ret) break; ++i; } @@ -107,10 +113,11 @@ } }; +//! Signal with no arguments (void specialisation) template <> class Signal0<void>: public SignalBase0<void> { public: - void exec() const + void fire() const { CallbackList::const_iterator i = _slots.begin(); while(i != _slots.end()) @@ -121,6 +128,71 @@ } }; +/* -------------------- Signal1 ---------------- */ + +//! Base class for Signal1 +template <typename RetType, typename ArgType1> +class SignalBase1 { + public: + typedef std::list< + Callback1<RetType, ArgType1>* + > CallbackList; + + SignalBase1() + { } + + virtual ~SignalBase1() + { unbind_slots(_slots); } + + template <class CallbackType> + void bind(CallbackType slot) + { bind_slot(_slots, slot); } + + template <class CallbackType> + void unbind(CallbackType slot) + { unbind_slot(_slots, slot); } + + virtual RetType fire() const = 0; + + protected: + CallbackList _slots; +}; + +//! Signal with one argument +template <typename RetType, typename ArgType1> +class Signal1: public SignalBase1<RetType, ArgType1> { + public: + RetType fire(ArgType1 arg1) const + { + RetType ret = RetType(); + typename CallbackList::const_iterator i = _slots.begin(); + while(i != _slots.end()) + { + ret = (*i)->exec(arg1); + if(ret) + break; + ++i; + } + + return ret; + } +}; + +//! Signal with one arguments (void specialisation) +template <typename ArgType1> +class Signal1<void, ArgType1>: public SignalBase1<void, ArgType1> { + public: + void fire(ArgType1 arg1) const + { + typename CallbackList::const_iterator i = _slots.begin(); + while(i != _slots.end()) + { + (*i)->exec(arg1); + ++i; + } + } +}; + } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-06 16:53:54
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14991/src/IO Modified Files: Makefile.am Log Message: Added ZLibIOFilter.[h|cpp] Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.am 3 Jan 2005 13:56:23 -0000 1.3 +++ Makefile.am 6 Jan 2005 16:53:44 -0000 1.4 @@ -2,5 +2,5 @@ METASOURCES = AUTO lib_LTLIBRARIES = libpclasses_io.la -libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp IOFilter.cpp URL.cpp ZLib.cpp +libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp libpclasses_io_la_LIBADD = $(top_builddir)/src/libpclasses.la -lz |
From: Christian P. <cp...@us...> - 2005-01-06 16:53:53
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14991/include/pclasses/IO Modified Files: Makefile.am Log Message: Added ZLibIOFilter.[h|cpp] Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Makefile.am 3 Jan 2005 13:56:23 -0000 1.3 +++ Makefile.am 6 Jan 2005 16:53:44 -0000 1.4 @@ -1,3 +1,3 @@ INCLUDES = METASOURCES = AUTO -pkginclude_HEADERS = IOError.h IODevice.h IOStream.h IOFilter.h URL.h ZLib.h +pkginclude_HEADERS = IOError.h IODevice.h IOStream.h IOFilter.h URL.h ZLib.h ZLibIOFilter.h |
From: Christian P. <cp...@us...> - 2005-01-06 16:47:59
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11889/src/IO Added Files: ZLibIOFilter.cpp Log Message: Added ZLibIOFilter as promised to Stephan ;-) --- NEW FILE: ZLibIOFilter.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include <pclasses/IO/ZLibIOFilter.h> namespace P { namespace IO { ZLibIOFilter::ZLibIOFilter() : _strmOut(0), _strmIn(0) { } ZLibIOFilter::~ZLibIOFilter() { if(_strmOut) delete _strmOut; if(_strmIn) delete _strmIn; } IOFilter* ZLibIOFilter::create() { return new ZLibIOFilter(); } void ZLibIOFilter::sync(bool close) { // sync output stream ... if(_strmOut) { if(close) { while(!_strmOut->finish()) flushAvailBytes(); flushAvailBytes(); _strmOut->reset(); } else { _strmOut->sync(); flushAvailBytes(); } } if(_strmIn) { if(close) _strmIn->reset(); } IOFilter::sync(close); } bool ZLibIOFilter::isSeekable() { // seeking is too complex (for now ;-) return false; } size_t ZLibIOFilter::read(char* buffer, size_t count) throw(IO::IOError) { if(!_strmIn) _strmIn = new P::IO::ZLibInputStream(); if(_strmIn->bytesAvail() < count) { // refill output buffer ... char tmp[1024]; size_t got = IOFilter::read(tmp, sizeof(tmp)); size_t consumed = _strmIn->inflate(tmp, got); if(consumed < sizeof(tmp)) { //@fixme: we need to buffer rememaining bytes we could not inflate } count = _strmIn->bytesAvail(); } // dequeue bytes available in output buffer ... memcpy(buffer, _strmIn->buffer(), count); _strmIn->dequeue(count); return count; } size_t ZLibIOFilter::write(const char* buffer, size_t count) throw(IO::IOError) { if(!_strmOut) _strmOut = new P::IO::ZLibOutputStream(9); size_t consumed = _strmOut->deflate(buffer, count); flushAvailBytes(); return consumed; } size_t ZLibIOFilter::peek(char* buffer, size_t count) throw(IO::IOError) { return 0; } offset_t ZLibIOFilter::seek(offset_t offset, IO::IODevice::SeekMode mode) throw(IO::IOError) { throw IO::IOError(0, "Could not seek on device", P_SOURCEINFO); return -1; } offset_t ZLibIOFilter::size() const throw(IO::IOError) { //@fixme!!! return IOFilter::size(); } void ZLibIOFilter::flushAvailBytes() { size_t avail = _strmOut->bytesAvail(); if(avail) _strmOut->dequeue(IOFilter::write(_strmOut->buffer(), avail)); } } } |
From: Christian P. <cp...@us...> - 2005-01-06 16:47:59
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11889/include/pclasses/IO Added Files: ZLibIOFilter.h Log Message: Added ZLibIOFilter as promised to Stephan ;-) --- NEW FILE: ZLibIOFilter.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_ZLibIOFilter_h #define P_IO_ZLibIOFilter_h #include <pclasses/IO/IOFilter.h> #include <pclasses/IO/ZLib.h> namespace P { namespace IO { //! ZLib I/O Filter /*! ZLib stream based I/O Filter. This is not a gzip filter! */ class ZLibIOFilter: public IOFilter { public: ZLibIOFilter(); ~ZLibIOFilter(); IOFilter* create(); void sync(bool close); bool isSeekable(); size_t read(char* buffer, size_t count) throw(IOError); size_t write(const char* buffer, size_t count) throw(IO::IOError); size_t peek(char* buffer, size_t count) throw(IOError); offset_t seek(offset_t offset, IO::IODevice::SeekMode mode) throw(IOError); offset_t size() const throw(IOError); private: void flushAvailBytes(); ZLibOutputStream* _strmOut; ZLibInputStream* _strmIn; }; } // !namespace IO } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-01-06 16:41:47
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11357/src/IO Modified Files: ZLib.cpp Log Message: Rework of ZLibStream and ZLibOutputStream. Added ZLibInputStream. Index: ZLib.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/ZLib.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ZLib.cpp 3 Jan 2005 13:43:49 -0000 1.1 +++ ZLib.cpp 6 Jan 2005 16:41:38 -0000 1.2 @@ -20,6 +20,7 @@ #include "pclasses/IO/ZLib.h" #include <zlib.h> +#include <iostream> namespace P { @@ -44,12 +45,15 @@ return _msg; } -ZLibStream::ZLibStream() +ZLibStream::ZLibStream(size_t bufferSize) { + if(bufferSize < 1) + bufferSize = 64; + _strm = new z_stream; - _buffer = new char[1024]; - _bufferSize = 1024; - + _buffer = new char[bufferSize]; + _bufferSize = bufferSize; + _strm->zalloc = Z_NULL; _strm->zfree = Z_NULL; _strm->opaque = Z_NULL; @@ -57,8 +61,6 @@ _strm->next_out = (Bytef*)_buffer; _strm->avail_in = 0; _strm->avail_out = _bufferSize; - - _crc32 = ::crc32(0L, Z_NULL, 0); } ZLibStream::~ZLibStream() @@ -72,28 +74,31 @@ return _bufferSize - _strm->avail_out; } -size_t ZLibStream::read(char* buffer, size_t count) throw(ZLibError) +const char* ZLibStream::buffer() const throw() +{ + return (const char*)_strm->next_out - (_bufferSize - _strm->avail_out); +} + +size_t ZLibStream::dequeue(size_t count) throw(ZLibError) { size_t avail = bytesAvail(); if(count > avail) count = avail; - memcpy(buffer, _strm->next_out - avail, count); - // move remaining bytes to top of buffer ... if(count < avail) memmove(_buffer, _strm->next_out - avail + count, avail - count); - _strm->next_out = (Bytef*)_buffer; - _strm->avail_out = _bufferSize; + _strm->next_out -= count; + _strm->avail_out += count; return count; } -UInt32 ZLibStream::crc32() const throw() +UInt32 ZLibStream::adler32() const throw() { - return _crc32; + return _strm->adler; } void ZLibStream::put(const char* buffer, size_t count) throw(ZLibError) @@ -106,97 +111,108 @@ _strm->avail_out -= count; } - -ZLibOutputStream::ZLibOutputStream(int level) throw(ZLibError) -: ZLibStream(), _state(Ready) +ZLibOutputStream::ZLibOutputStream(int level, size_t bufferSize) throw(ZLibError) +: ZLibStream(bufferSize) { int ret; - if((ret = deflateInit(_strm, level)) != Z_OK) + if((ret = ::deflateInit(_strm, level)) != Z_OK) throw ZLibError(ret, _strm->msg, "Could not init zlib deflate", P_SOURCEINFO); - - putFooter(); } ZLibOutputStream::~ZLibOutputStream() throw() { + ::deflateEnd(_strm); } -void ZLibOutputStream::putHeader() +size_t ZLibOutputStream::deflate(const char* buffer, size_t count) throw(ZLibError) { - char header[] = { 0x1f /*magic1*/, 0x8b /*magic2*/, Z_DEFLATED, 0 /*flags*/, - 0, 0, 0, 0 /*time*/, 0 /*xflags*/, 0x03 /* OS code*/ }; + if(!count) + return 0; - put(header, sizeof(header)); + _strm->next_in = (Bytef*)buffer; + _strm->avail_in = count; + + int ret = ::deflate(_strm, Z_NO_FLUSH); + if(ret != Z_OK) + throw ZLibError(ret, _strm->msg, "Could not deflate", P_SOURCEINFO); + + // return with number of bytes consumed ... + size_t deflated = count - _strm->avail_in; + return deflated; } -void ZLibOutputStream::putFooter() +void ZLibOutputStream::sync() throw(ZLibError) { - UInt32 footer[2]; - footer[0] = UInt32(_crc32).littleEndian(); - footer[1] = UInt32(_strm->total_in).littleEndian(); - - put((const char*)footer, sizeof(footer)); + int ret = ::deflate(_strm, Z_SYNC_FLUSH); + if(ret != Z_OK) + throw ZLibError(ret, _strm->msg, "Could not sync stream", P_SOURCEINFO); } -size_t ZLibOutputStream::deflate(const char* buffer, size_t count) throw(ZLibError) +bool ZLibOutputStream::finish() throw(ZLibError) { - if(!count) - return 0; + int ret = ::deflate(_strm, Z_FINISH); + // not enough buffer was avail... should call finish() again + if(ret == Z_OK) + return false; - size_t deflated = 0; + if(ret != Z_STREAM_END) + throw ZLibError(Z_BUF_ERROR, 0, "Could not finish stream", P_SOURCEINFO); - if(_state == Ready) - { - _strm->next_in = (Bytef*)buffer; - _strm->avail_in = count; - - int ret = ::deflate(_strm, Z_NO_FLUSH); - if(ret != Z_OK) - throw ZLibError(ret, _strm->msg, "Could not deflate", P_SOURCEINFO); + return true; +} - // update crc32 and return with number of bytes consumed ... - deflated = count - _strm->avail_in; - _crc32 = ::crc32(_crc32, (const Bytef*)buffer, deflated); - } +void ZLibOutputStream::reset() throw(ZLibError) +{ + _strm->next_out = (Bytef*)_buffer; + _strm->avail_out = _bufferSize; - return deflated; + int ret = ::deflateReset(_strm); + if(ret != Z_OK) + throw ZLibError(ret, _strm->msg, "Could not reset stream", P_SOURCEINFO); } -bool ZLibOutputStream::finish() throw(ZLibError) +ZLibInputStream::ZLibInputStream(size_t bufferSize) throw(ZLibError) +: ZLibStream(bufferSize) { - if(_state < AboutToFinish) - { - int ret = ::deflate(_strm, Z_FINISH); - // not enough buffer was avail... should call finish() again - if(ret == Z_OK) - return false; - - if(ret != Z_STREAM_END) - throw ZLibError(Z_BUF_ERROR, 0, "Could not finish zlib stream", P_SOURCEINFO); - - _state = AboutToFinish; - } + int ret; + if((ret = ::inflateInit(_strm)) != Z_OK) + throw ZLibError(ret, _strm->msg, "Could not init zlib inflate", P_SOURCEINFO); +} - if(_state == AboutToFinish) - { - if(_strm->avail_out < 8) - return false; +ZLibInputStream::~ZLibInputStream() throw() +{ + ::inflateEnd(_strm); +} - putHeader(); - _state = Finished; +size_t ZLibInputStream::inflate(const char* buffer, size_t count) throw(ZLibError) +{ + if(!count) + return 0; + + _strm->next_in = (Bytef*)buffer; + _strm->avail_in = count; + + int ret = ::inflate(_strm, Z_NO_FLUSH); + if(ret == Z_STREAM_END) + { + // we do nothing, so this or next call to inflate() returns 0 } + else if(ret != Z_OK) + throw ZLibError(ret, _strm->msg, "Could not inflate", P_SOURCEINFO); - return true; + // return with number of bytes consumed ... + size_t inflated = count - _strm->avail_in; + return inflated; } -void ZLibOutputStream::reset() throw(ZLibError) +void ZLibInputStream::reset() throw(ZLibError) { _strm->next_out = (Bytef*)_buffer; _strm->avail_out = _bufferSize; - _crc32 = ::crc32(0L, Z_NULL, 0); - _state = Ready; - deflateReset(_strm); + int ret = ::inflateReset(_strm); + if(ret != Z_OK) + throw ZLibError(ret, _strm->msg, "Could not reset stream", P_SOURCEINFO); } |
From: Christian P. <cp...@us...> - 2005-01-06 16:41:47
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11357/include/pclasses/IO Modified Files: ZLib.h Log Message: Rework of ZLibStream and ZLibOutputStream. Added ZLibInputStream. Index: ZLib.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/ZLib.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ZLib.h 3 Jan 2005 13:43:50 -0000 1.1 +++ ZLib.h 6 Jan 2005 16:41:38 -0000 1.2 @@ -49,56 +49,68 @@ //! ZLib stream base class ZLibStream { public: - ZLibStream(); + ZLibStream(size_t bufferSize); virtual ~ZLibStream(); //! Number of bytes available to consume size_t bytesAvail() const throw(); - //! Consume compressed data - size_t read(char* buffer, size_t count) throw(ZLibError); + //! Returns the Adler32 checksum of consumed data + UInt32 adler32() const throw(); - //! Returns the crc32 - UInt32 crc32() const throw(); + //! Returns a pointer to the produced data + const char* buffer() const throw(); - protected: + //! Dequeue produced data + size_t dequeue(size_t count) throw(ZLibError); + + //! Put data into producer buffer void put(const char* buffer, size_t count) throw(ZLibError); + protected: z_stream* _strm; char* _buffer; size_t _bufferSize; - UInt32 _crc32; }; //! ZLib output (deflate) stream class ZLibOutputStream: public ZLibStream { public: - ZLibOutputStream(int level = 6) throw(ZLibError); + ZLibOutputStream(int level = 6, size_t bufferSize = 1024) throw(ZLibError); ~ZLibOutputStream() throw(); //! Deflate (compress) buffer into output buffer + /*! + Returns the number of bytes actually deflated. + */ size_t deflate(const char* buffer, size_t count) throw(ZLibError); + void sync() throw(ZLibError); + //! Finish compression and reset state bool finish() throw(ZLibError); //! Reset stream void reset() throw(ZLibError); +}; - private: - void putHeader(); - void putFooter(); +//! ZLib input (inflate) stream +class ZLibInputStream: public ZLibStream { + public: + ZLibInputStream(size_t bufferSize = 1024) throw(ZLibError); + ~ZLibInputStream() throw(); - enum State { - Ready, - AboutToFinish, - Finished - }; + //! Inflate (decompress) buffer into output buffer + /*! + Returns the number of bytes actually inflated, which may be NULL + when <count> is NULL or the end of the stream has been reached. + */ + size_t inflate(const char* buffer, size_t count) throw(ZLibError); - State _state; + //! Reset stream + void reset() throw(ZLibError); }; - } // !namespace IO } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-06 16:40:27
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11059/src/IO Modified Files: IODevice.cpp IOFilter.cpp Log Message: Added bool parameter to IOFilter::sync() Index: IODevice.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IODevice.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- IODevice.cpp 3 Jan 2005 13:50:44 -0000 1.4 +++ IODevice.cpp 6 Jan 2005 16:40:14 -0000 1.5 @@ -53,7 +53,7 @@ if(valid()) { if(_filter) - _filter->sync(); + _filter->sync(true); _close(); } @@ -87,7 +87,7 @@ void IODevice::sync() const throw(IOError) { if(_filter) - _filter->sync(); + _filter->sync(false); _sync(); } Index: IOFilter.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IOFilter.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IOFilter.cpp 3 Jan 2005 13:50:44 -0000 1.1 +++ IOFilter.cpp 6 Jan 2005 16:40:14 -0000 1.2 @@ -32,18 +32,18 @@ IOFilter::~IOFilter() { if(_dev) - sync(); + sync(true); } void IOFilter::setDevice(IODevice* dev) { if(_dev) - sync(); + sync(true); _dev = dev; } -void IOFilter::sync() +void IOFilter::sync(bool close) { _dev->_sync(); } |
From: Christian P. <cp...@us...> - 2005-01-06 16:40:23
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11059/include/pclasses/IO Modified Files: IOFilter.h Log Message: Added bool parameter to IOFilter::sync() Index: IOFilter.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/IOFilter.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IOFilter.h 3 Jan 2005 13:50:44 -0000 1.1 +++ IOFilter.h 6 Jan 2005 16:40:14 -0000 1.2 @@ -37,7 +37,7 @@ virtual IOFilter* create(); - virtual void sync(); + virtual void sync(bool close); virtual bool isSeekable(); |
From: stephan b. <sg...@us...> - 2005-01-03 18:28:37
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17191/src/IO Modified Files: Makefile.toc Log Message: Added ZLib.o if zlib is found by configure. Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/Makefile.toc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Makefile.toc 30 Dec 2004 19:29:39 -0000 1.5 +++ Makefile.toc 3 Jan 2005 18:27:55 -0000 1.6 @@ -7,8 +7,15 @@ OBJECTS = IODevice.o \ IOError.o \ + IOFilter.o \ URL.o +ifeq (1,$(PCLASSES_HAVE_ZLIB)) + OBJECTS += ZLib.o +endif + +# StringDevice.o + CLEAN_FILES += $(OBJECTS) build_libs = 1 |
From: stephan b. <sg...@us...> - 2005-01-03 18:28:11
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17191 Modified Files: configure.pclasses2 Log Message: Added ZLib.o if zlib is found by configure. Index: configure.pclasses2 =================================================================== RCS file: /cvsroot/pclasses/pclasses2/configure.pclasses2,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- configure.pclasses2 30 Dec 2004 20:14:10 -0000 1.23 +++ configure.pclasses2 3 Jan 2005 18:27:55 -0000 1.24 @@ -19,7 +19,7 @@ ####### compilers: toc_test_require gnu_cpp_tools toc_test_require gcc_try_compile ${TOC_HOME}/tests/cpp/check_stl_newstyle.cpp -test x1 = x${configure_enable_ccdv} && toc_test use_ccdv +test x1 = "x${configure_enable_ccdv-0}" && toc_test use_ccdv ############################################################ # accumulate -I and -L/-l entries here: # Reminder: these are the flags for linking @@ -27,10 +27,18 @@ ldadd="${LDADD}" ############################################################ +#################################################### +# prefer ltdl, else allow dl. +toc_test libltdl || toc_test_require libdl +#################################################### + +######################################################## +# compression support... +toc_test bzlib && toc_export PCLASSES_HAVE_BZ2LIB=1 +toc_test zlib && toc_export PCLASSES_HAVE_ZLIB=1 +compression_ldadd="${LDADD_ZLIB} ${LDADD_BZLIB}" +######################################################### -toc_test libltdl || toc_test_require libdl # prefer ltdl, else allow dl. -toc_test bzlib -toc_test zlib UCD=./src/Unicode/UnicodeData.txt test -e $UCD || { @@ -189,7 +197,7 @@ toc_export LIBPNET_CFLAGS="" toc_export LIBPIO_BASENAME=pclasses_io -toc_export LIBPIO_LDADD="${LIBPCORE_CLIENT_LDADD}" +toc_export LIBPIO_LDADD="${LIBPCORE_CLIENT_LDADD} ${compression_ldadd}" toc_export LIBPIO_CLIENT_LDADD="-l${LIBPIO_BASENAME}" toc_export LIBPIO_CFLAGS="${inc}" |
From: Christian P. <cp...@us...> - 2005-01-03 13:56:33
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20346/src/IO Modified Files: Makefile.am Log Message: Added Zlib.[h|cpp], IOFilter.[h|cpp] Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.am 30 Dec 2004 17:17:41 -0000 1.2 +++ Makefile.am 3 Jan 2005 13:56:23 -0000 1.3 @@ -2,5 +2,5 @@ METASOURCES = AUTO lib_LTLIBRARIES = libpclasses_io.la -libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp URL.cpp -libpclasses_io_la_LIBADD = $(top_builddir)/src/libpclasses.la $(top_builddir)/src/Unicode/libpclasses_unicode.la +libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp IOFilter.cpp URL.cpp ZLib.cpp +libpclasses_io_la_LIBADD = $(top_builddir)/src/libpclasses.la -lz |