Boost logo

Boost-Commit :

From: bdawes_at_[hidden]
Date: 2007-11-25 12:55:04


Author: bemandawes
Date: 2007-11-25 12:55:04 EST (Sun, 25 Nov 2007)
New Revision: 41365
URL: http://svn.boost.org/trac/boost/changeset/41365

Log:
Full merge from trunk at revision 41356 of entire boost-root tree. Do Serialization separately to verify pre-commit check failures have been fixed.
Added:
   branches/release/libs/serialization/example/Jamfile
      - copied unchanged from r41356, /trunk/libs/serialization/example/Jamfile
   branches/release/libs/serialization/example/demo_gps.hpp
      - copied unchanged from r41356, /trunk/libs/serialization/example/demo_gps.hpp
Removed:
   branches/release/libs/serialization/example/demo_xml.hpp
Text files modified:
   branches/release/libs/serialization/example/demo.cpp | 1 +
   branches/release/libs/serialization/example/demo_shared_ptr.cpp | 14 --------------
   branches/release/libs/serialization/example/demo_xml.cpp | 2 +-
   branches/release/libs/serialization/example/demo_xml_load.cpp | 2 +-
   branches/release/libs/serialization/example/demo_xml_save.cpp | 2 +-
   branches/release/libs/serialization/example/portable_binary_iarchive.hpp | 18 +++++++++++++++++-
   branches/release/libs/serialization/example/portable_binary_oarchive.hpp | 30 ++++++++++++++++++++++++------
   7 files changed, 45 insertions(+), 24 deletions(-)

Modified: branches/release/libs/serialization/example/demo.cpp
==============================================================================
--- branches/release/libs/serialization/example/demo.cpp (original)
+++ branches/release/libs/serialization/example/demo.cpp 2007-11-25 12:55:04 EST (Sun, 25 Nov 2007)
@@ -20,6 +20,7 @@
 #include <boost/serialization/base_object.hpp>
 #include <boost/serialization/utility.hpp>
 #include <boost/serialization/list.hpp>
+#include <boost/serialization/is_abstract.hpp>
 
 /////////////////////////////////////////////////////////////
 // The intent of this program is to serve as a tutorial for

Modified: branches/release/libs/serialization/example/demo_shared_ptr.cpp
==============================================================================
--- branches/release/libs/serialization/example/demo_shared_ptr.cpp (original)
+++ branches/release/libs/serialization/example/demo_shared_ptr.cpp 2007-11-25 12:55:04 EST (Sun, 25 Nov 2007)
@@ -133,13 +133,6 @@
         std::ofstream ofs(filename.c_str());
         boost::archive::text_oarchive oa(ofs);
         oa.register_type(static_cast<B *>(NULL));
- oa.register_type(
- static_cast<
- boost::detail::sp_counted_base_impl<
- B *, boost::checked_deleter<B>
- > *
- >(NULL)
- );
         oa << spa;
         oa << spa1;
     }
@@ -157,13 +150,6 @@
 
         // restore the schedule from the archive
         ia.register_type(static_cast<B *>(NULL));
- ia.register_type(
- static_cast<
- boost::detail::sp_counted_base_impl<
- B *, boost::checked_deleter<B>
- > *
- >(NULL)
- );
         ia >> spa;
         ia >> spa1;
     }

Modified: branches/release/libs/serialization/example/demo_xml.cpp
==============================================================================
--- branches/release/libs/serialization/example/demo_xml.cpp (original)
+++ branches/release/libs/serialization/example/demo_xml.cpp 2007-11-25 12:55:04 EST (Sun, 25 Nov 2007)
@@ -24,7 +24,7 @@
 #include <boost/archive/xml_iarchive.hpp>
 #include <boost/archive/xml_oarchive.hpp>
 
-#include "demo_xml.hpp"
+#include "demo_gps.hpp"
 
 void save_schedule(const bus_schedule &s, const char * filename){
     // make an archive

Deleted: branches/release/libs/serialization/example/demo_xml.hpp
==============================================================================
--- branches/release/libs/serialization/example/demo_xml.hpp 2007-11-25 12:55:04 EST (Sun, 25 Nov 2007)
+++ (empty file)
@@ -1,284 +0,0 @@
-#ifndef BOOST_SERIALIZATION_EXAMPLE_DEMO_XML_HPP
-#define BOOST_SERIALIZATION_EXAMPLE_DEMO_XML_HPP
-
-/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-//
-// demo_xml.hpp
-//
-// (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
-// Use, modification and distribution is 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)
-
-
-#include <string>
-#include <iomanip>
-#include <iostream>
-#include <fstream>
-
-#include <boost/serialization/nvp.hpp>
-#include <boost/serialization/utility.hpp>
-#include <boost/serialization/list.hpp>
-#include <boost/serialization/version.hpp>
-
-// This illustration models the bus system of a small city.
-// This includes, multiple bus stops, bus routes and schedules.
-// There are different kinds of stops. Bus stops in general will
-// will appear on multiple routes. A schedule will include
-// muliple trips on the same route.
-
-/////////////////////////////////////////////////////////////
-// gps coordinate
-//
-// llustrates serialization for a simple type
-//
-class gps_position
-{
- friend class boost::serialization::access;
- friend std::ostream & operator<<(std::ostream &os, const gps_position &gp);
-
- int degrees;
- int minutes;
- float seconds;
-
- template<class Archive>
- void serialize(Archive & ar, const unsigned int /* file_version */){
- ar & BOOST_SERIALIZATION_NVP(degrees)
- & BOOST_SERIALIZATION_NVP(minutes)
- & BOOST_SERIALIZATION_NVP(seconds);
- }
-
-public:
- // every serializable class needs a constructor
- gps_position(){};
- gps_position(int _d, int _m, float _s) :
- degrees(_d), minutes(_m), seconds(_s)
- {}
-};
-
-std::ostream & operator<<(std::ostream &os, const gps_position &gp)
-{
- return os << ' ' << gp.degrees << (unsigned char)186 << gp.minutes << '\'' << gp.seconds << '"';
-}
-
-/////////////////////////////////////////////////////////////
-// One bus stop
-//
-// illustrates serialization of serializable members
-//
-
-class bus_stop
-{
- friend class boost::serialization::access;
- virtual std::string description() const = 0;
- gps_position latitude;
- gps_position longitude;
-
- template<class Archive>
- void serialize(Archive &ar, const unsigned int version)
- {
- ar & BOOST_SERIALIZATION_NVP(latitude);
- ar & BOOST_SERIALIZATION_NVP(longitude);
- }
-
-protected:
- bus_stop(const gps_position & _lat, const gps_position & _long) :
- latitude(_lat), longitude(_long)
- {}
-public:
- bus_stop(){}
- friend std::ostream & operator<<(std::ostream &os, const bus_stop &gp);
- virtual ~bus_stop(){}
-};
-
-BOOST_IS_ABSTRACT(bus_stop)
-
-std::ostream & operator<<(std::ostream &os, const bus_stop &bs)
-{
- return os << bs.latitude << bs.longitude << ' ' << bs.description();
-}
-
-/////////////////////////////////////////////////////////////
-// Several kinds of bus stops
-//
-// illustrates serialization of derived types
-//
-class bus_stop_corner : public bus_stop
-{
- friend class boost::serialization::access;
- std::string street1;
- std::string street2;
- virtual std::string description() const
- {
- return street1 + " and " + street2;
- }
- template<class Archive>
- void serialize(Archive &ar, const unsigned int version)
- {
- // save/load base class information
- ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(bus_stop);
- ar & BOOST_SERIALIZATION_NVP(street1);
- ar & BOOST_SERIALIZATION_NVP(street2);
- }
-public:
- bus_stop_corner(){}
- bus_stop_corner(const gps_position & _lat, const gps_position & _long,
- const std::string & _s1, const std::string & _s2
- ) :
- bus_stop(_lat, _long), street1(_s1), street2(_s2)
- {
- }
-};
-
-class bus_stop_destination : public bus_stop
-{
- friend class boost::serialization::access;
- std::string name;
- virtual std::string description() const
- {
- return name;
- }
- template<class Archive>
- void serialize(Archive &ar, const unsigned int version)
- {
- ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(bus_stop)
- & BOOST_SERIALIZATION_NVP(name);
- }
-public:
- bus_stop_destination(){}
- bus_stop_destination(
- const gps_position & _lat, const gps_position & _long, const std::string & _name
- ) :
- bus_stop(_lat, _long), name(_name)
- {
- }
-};
-
-/////////////////////////////////////////////////////////////
-// a bus route is a collection of bus stops
-//
-// illustrates serialization of STL collection templates.
-//
-// illustrates serialzation of polymorphic pointer (bus stop *);
-//
-// illustrates storage and recovery of shared pointers is correct
-// and efficient. That is objects pointed to by more than one
-// pointer are stored only once. In such cases only one such
-// object is restored and pointers are restored to point to it
-//
-class bus_route
-{
- friend class boost::serialization::access;
- friend std::ostream & operator<<(std::ostream &os, const bus_route &br);
- typedef bus_stop * bus_stop_pointer;
- std::list<bus_stop_pointer> stops;
- template<class Archive>
- void serialize(Archive &ar, const unsigned int version)
- {
- // in this program, these classes are never serialized directly but rather
- // through a pointer to the base class bus_stop. So we need a way to be
- // sure that the archive contains information about these derived classes.
- //ar.template register_type<bus_stop_corner>();
- ar.register_type(static_cast<bus_stop_corner *>(NULL));
- //ar.template register_type<bus_stop_destination>();
- ar.register_type(static_cast<bus_stop_destination *>(NULL));
- // serialization of stl collections is already defined
- // in the header
- ar & BOOST_SERIALIZATION_NVP(stops);
- }
-public:
- bus_route(){}
- void append(bus_stop *_bs)
- {
- stops.insert(stops.end(), _bs);
- }
-};
-std::ostream & operator<<(std::ostream &os, const bus_route &br)
-{
- std::list<bus_stop *>::const_iterator it;
- // note: we're displaying the pointer to permit verification
- // that duplicated pointers are properly restored.
- for(it = br.stops.begin(); it != br.stops.end(); it++){
- os << '\n' << std::hex << "0x" << *it << std::dec << ' ' << **it;
- }
- return os;
-}
-
-/////////////////////////////////////////////////////////////
-// a bus schedule is a collection of routes each with a starting time
-//
-// Illustrates serialization of STL objects(pair) in a non-intrusive way.
-// See definition of operator<< <pair<F, S> >(ar, pair)
-//
-// illustrates nesting of serializable classes
-//
-// illustrates use of version number to automatically grandfather older
-// versions of the same class.
-
-class bus_schedule
-{
- friend class boost::serialization::access;
- friend std::ostream & operator<<(std::ostream &os, const bus_schedule &bs);
- template<class Archive>
- void serialize(Archive &ar, const unsigned int version)
- {
- ar & BOOST_SERIALIZATION_NVP(schedule);
- }
- // note: this structure was made public. because the friend declarations
- // didn't seem to work as expected.
-public:
- struct trip_info
- {
- template<class Archive>
- void serialize(Archive &ar, const unsigned int file_version)
- {
- // in versions 2 or later
- if(file_version >= 2)
- // read the drivers name
- ar & BOOST_SERIALIZATION_NVP(driver);
- // all versions have the follwing info
- ar & BOOST_SERIALIZATION_NVP(hour)
- & BOOST_SERIALIZATION_NVP(minute);
- }
-
- // starting time
- int hour;
- int minute;
- // only after system shipped was the driver's name added to the class
- std::string driver;
-
- trip_info(){}
- trip_info(int _h, int _m, const std::string &_d) :
- hour(_h), minute(_m), driver(_d)
- {}
- ~trip_info(){
- }
- };
-// friend std::ostream & operator<<(std::ostream &os, const trip_info &ti);
-private:
- std::list<std::pair<trip_info, bus_route *> > schedule;
-public:
- void append(const std::string &_d, int _h, int _m, bus_route *_br)
- {
- schedule.insert(schedule.end(), std::make_pair(trip_info(_h, _m, _d), _br));
- }
- bus_schedule(){}
-};
-
-BOOST_CLASS_VERSION(bus_schedule::trip_info, 3)
-BOOST_CLASS_VERSION(bus_schedule, 2)
-
-std::ostream & operator<<(std::ostream &os, const bus_schedule::trip_info &ti)
-{
- return os << '\n' << ti.hour << ':' << ti.minute << ' ' << ti.driver << ' ';
-}
-std::ostream & operator<<(std::ostream &os, const bus_schedule &bs)
-{
- std::list<std::pair<bus_schedule::trip_info, bus_route *> >::const_iterator it;
- for(it = bs.schedule.begin(); it != bs.schedule.end(); it++){
- os << it->first << *(it->second);
- }
- return os;
-}
-
-#endif // BOOST_SERIALIZATION_EXAMPLE_DEMO_XML_HPP

Modified: branches/release/libs/serialization/example/demo_xml_load.cpp
==============================================================================
--- branches/release/libs/serialization/example/demo_xml_load.cpp (original)
+++ branches/release/libs/serialization/example/demo_xml_load.cpp 2007-11-25 12:55:04 EST (Sun, 25 Nov 2007)
@@ -13,7 +13,7 @@
 
 #include <boost/archive/xml_iarchive.hpp>
 
-#include "demo_xml.hpp"
+#include "demo_gps.hpp"
 
 void
 restore_schedule(bus_schedule &s, const char * filename)

Modified: branches/release/libs/serialization/example/demo_xml_save.cpp
==============================================================================
--- branches/release/libs/serialization/example/demo_xml_save.cpp (original)
+++ branches/release/libs/serialization/example/demo_xml_save.cpp 2007-11-25 12:55:04 EST (Sun, 25 Nov 2007)
@@ -13,7 +13,7 @@
 
 #include <boost/archive/xml_oarchive.hpp>
 
-#include "demo_xml.hpp"
+#include "demo_gps.hpp"
 
 void save_schedule(const bus_schedule &s, const char * filename){
     // make an archive

Modified: branches/release/libs/serialization/example/portable_binary_iarchive.hpp
==============================================================================
--- branches/release/libs/serialization/example/portable_binary_iarchive.hpp (original)
+++ branches/release/libs/serialization/example/portable_binary_iarchive.hpp 2007-11-25 12:55:04 EST (Sun, 25 Nov 2007)
@@ -55,7 +55,8 @@
         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 @@
                 *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<class T>
     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));

Modified: branches/release/libs/serialization/example/portable_binary_oarchive.hpp
==============================================================================
--- branches/release/libs/serialization/example/portable_binary_oarchive.hpp (original)
+++ branches/release/libs/serialization/example/portable_binary_oarchive.hpp 2007-11-25 12:55:04 EST (Sun, 25 Nov 2007)
@@ -52,13 +52,25 @@
     friend class boost::archive::basic_binary_oarchive<portable_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 @@
     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);
     }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk