diff --git a/example/Jamfile b/example/Jamfile new file mode 100644 index 00000000..5695e376 --- /dev/null +++ b/example/Jamfile @@ -0,0 +1,41 @@ +# Boost serialization Library Build Jamfile +# (C) Copyright Robert Ramey 2002-2004. +# Use, modification, and distribution are subject to the +# Boost Software License, Version 1.0. (See accompanying file +# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +# +# See http://www.boost.org/libs/serialization for the library home page. + +subproject libs/serialization/example ; + +rule demo-bsl-build ( demo-name ) +{ + exe $(demo-name) + : # sources + $(demo-name).cpp + ../build/boost_serialization + : # requirements + # copy to a path rooted at BOOST_ROOT: + $(BOOST_ROOT) + $(BOOST_ROOT) + $(BOOST_ROOT) + <*>-w-8080 + -Gy + -Gy + -Gy + -Gy + : # default build + debug + ; +} + +demo-bsl-build demo ; +demo-bsl-build demo_auto_ptr ; +demo-bsl-build demo_exception ; +demo-bsl-build demo_fast_archive ; +demo-bsl-build demo_pimpl ; +demo-bsl-build demo_portable_archive ; +demo-bsl-build demo_shared_ptr ; +demo-bsl-build demo_xml ; +demo-bsl-build demo_xml_save ; +demo-bsl-build demo_xml_load ; diff --git a/example/demo.cpp b/example/demo.cpp index 279d8245..2ee4e7fd 100644 --- a/example/demo.cpp +++ b/example/demo.cpp @@ -20,6 +20,7 @@ #include #include #include +#include ///////////////////////////////////////////////////////////// // The intent of this program is to serve as a tutorial for diff --git a/example/demo_xml.hpp b/example/demo_gps.hpp similarity index 98% rename from example/demo_xml.hpp rename to example/demo_gps.hpp index 408412a1..5749eff1 100644 --- a/example/demo_xml.hpp +++ b/example/demo_gps.hpp @@ -1,9 +1,9 @@ -#ifndef BOOST_SERIALIZATION_EXAMPLE_DEMO_XML_HPP -#define BOOST_SERIALIZATION_EXAMPLE_DEMO_XML_HPP +#ifndef BOOST_SERIALIZATION_EXAMPLE_DEMO_GPS_HPP +#define BOOST_SERIALIZATION_EXAMPLE_DEMO_GPS_HPP /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // -// demo_xml.hpp +// demo_gps.hpp // // (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com . // Use, modification and distribution is subject to the Boost Software @@ -281,4 +281,4 @@ std::ostream & operator<<(std::ostream &os, const bus_schedule &bs) return os; } -#endif // BOOST_SERIALIZATION_EXAMPLE_DEMO_XML_HPP +#endif // BOOST_SERIALIZATION_EXAMPLE_DEMO_GPS_HPP diff --git a/example/demo_shared_ptr.cpp b/example/demo_shared_ptr.cpp index cbc66add..2fda6e02 100644 --- a/example/demo_shared_ptr.cpp +++ b/example/demo_shared_ptr.cpp @@ -133,13 +133,6 @@ int main(int argc, char *argv[]) std::ofstream ofs(filename.c_str()); boost::archive::text_oarchive oa(ofs); oa.register_type(static_cast(NULL)); - oa.register_type( - static_cast< - boost::detail::sp_counted_base_impl< - B *, boost::checked_deleter - > * - >(NULL) - ); oa << spa; oa << spa1; } @@ -157,13 +150,6 @@ int main(int argc, char *argv[]) // restore the schedule from the archive ia.register_type(static_cast(NULL)); - ia.register_type( - static_cast< - boost::detail::sp_counted_base_impl< - B *, boost::checked_deleter - > * - >(NULL) - ); ia >> spa; ia >> spa1; } diff --git a/example/demo_xml.cpp b/example/demo_xml.cpp index 4459d0e2..c9524aef 100644 --- a/example/demo_xml.cpp +++ b/example/demo_xml.cpp @@ -24,7 +24,7 @@ namespace std{ #include #include -#include "demo_xml.hpp" +#include "demo_gps.hpp" void save_schedule(const bus_schedule &s, const char * filename){ // make an archive diff --git a/example/demo_xml_load.cpp b/example/demo_xml_load.cpp index ae95be03..cd8e03c1 100644 --- a/example/demo_xml_load.cpp +++ b/example/demo_xml_load.cpp @@ -13,7 +13,7 @@ #include -#include "demo_xml.hpp" +#include "demo_gps.hpp" void restore_schedule(bus_schedule &s, const char * filename) diff --git a/example/demo_xml_save.cpp b/example/demo_xml_save.cpp index 695011ca..ff03d54a 100644 --- a/example/demo_xml_save.cpp +++ b/example/demo_xml_save.cpp @@ -13,7 +13,7 @@ #include -#include "demo_xml.hpp" +#include "demo_gps.hpp" void save_schedule(const bus_schedule &s, const char * filename){ // make an archive diff --git a/example/portable_binary_iarchive.hpp b/example/portable_binary_iarchive.hpp index 375faee9..e5e93151 100644 --- a/example/portable_binary_iarchive.hpp +++ b/example/portable_binary_iarchive.hpp @@ -55,7 +55,8 @@ class portable_binary_iarchive : portable_binary_iarchive, std::istream::char_type, std::istream::traits_type - > + >, + public boost::archive::detail::shared_ptr_helper { typedef boost::archive::binary_iarchive_impl< portable_binary_iarchive, @@ -92,12 +93,27 @@ public: *first = x; } #endif + + // extend sign if necessary + if((l >> (size - 1) * 8) & 0x80){ + l |= (-1 << (size * 8)); + } } // default fall through for any types not specified here template void load(T & t){ this->primitive_base_t::load(t); } + void load(unsigned short & t){ + long l; + load_impl(l, sizeof(unsigned short)); + t = l; + } + void load(short & t){ + long l; + load_impl(l, sizeof(short)); + t = l; + } void load(unsigned int & t){ long l; load_impl(l, sizeof(unsigned int)); diff --git a/example/portable_binary_oarchive.hpp b/example/portable_binary_oarchive.hpp index 549ebc4c..e14668ac 100644 --- a/example/portable_binary_oarchive.hpp +++ b/example/portable_binary_oarchive.hpp @@ -52,13 +52,25 @@ public: friend class boost::archive::basic_binary_oarchive; friend class boost::archive::save_access; #endif - void save_impl(long l){ + void save_impl(const long l){ long ll = l; - char size = 0;; - do{ - ll >>= 8; - ++size; - }while(ll != -1 && ll != 0); + char size = 0; + if(l < 0){ + // make sure that enough of data is output + // to include a high order bit indicating the sign + char x; + do{ + x = ll; + ll >>= 8; + ++size; + }while(ll != -1 && x < 0); + } + else{ + do{ + ll >>= 8; + ++size; + }while(ll != 0); + } this->archive_base_t::save(size); @@ -84,6 +96,12 @@ public: void save(const T & t){ this->primitive_base_t::save(t); } + void save(const short t){ + save_impl(t); + } + void save(const unsigned short t){ + save_impl(t); + } void save(const unsigned int t){ save_impl(t); }