Ticket #5876: boost.serialization2.patch

File boost.serialization2.patch, 9.4 KB (added by ybungalobill@…, 11 years ago)

I apologize, the previous fix doesn't fix the save correctly.

  • boost/archive/basic_archive.hpp

     
    210210    }
    211211};
    212212
     213struct tracking_level_type {
     214    int t;
     215    explicit tracking_level_type(const int t_ = 0)
     216        : t(t_)
     217    {};
     218    tracking_level_type(const tracking_level_type & t_)
     219        : t(t_.t)
     220    {}
     221    operator int () const {
     222        return t;
     223    };
     224    operator int & () {
     225        return t;
     226    };
     227    tracking_level_type & operator=(const int t_){
     228        t = t_;
     229        return *this;
     230    }
     231    bool operator==(const tracking_level_type & rhs) const {
     232        return t == rhs.t;
     233    }
     234    bool operator==(const int & rhs) const {
     235        return t == rhs;
     236    }
     237    tracking_level_type & operator=(const tracking_level_type & rhs){
     238        t = rhs.t;
     239        return *this;
     240    }
     241};
     242
    213243struct class_name_type :
    214244    private boost::noncopyable
    215245{
  • boost/archive/detail/basic_iserializer.hpp

     
    5757    #endif
    5858    ~basic_iserializer();
    5959public:
    60     bool serialized_as_pointer() const {
     60    bool maybe_serialized_as_pointer() const {
    6161        return m_bpis != NULL;
    6262    }
    6363    void set_bpis(basic_pointer_iserializer *bpis){
     
    7373    ) const = 0;
    7474    // returns true if class_info should be saved
    7575    virtual bool class_info() const = 0 ;
    76     // returns true if objects should be tracked
    77     virtual bool tracking(const unsigned int) const = 0 ;
     76    // returns the tracking level
     77    virtual int tracking() const = 0 ;
    7878    // returns class version
    7979    virtual version_type version() const = 0 ;
    8080    // returns true if this class is polymorphic
  • boost/archive/detail/basic_oserializer.hpp

     
    5858    #endif
    5959    ~basic_oserializer();
    6060public:
    61     bool serialized_as_pointer() const {
     61    bool maybe_serialized_as_pointer() const {
    6262        return m_bpos != NULL;
    6363    }
    6464    void set_bpos(basic_pointer_oserializer *bpos){
     
    7272    ) const = 0;
    7373    // returns true if class_info should be saved
    7474    virtual bool class_info() const = 0;
    75     // returns true if objects should be tracked
    76     virtual bool tracking(const unsigned int flags) const = 0;
     75    // returns the tracking level
     76    virtual int tracking() const = 0;
    7777    // returns class version
    7878    virtual version_type version() const = 0;
    7979    // returns true if this class is polymorphic
  • boost/archive/detail/iserializer.hpp

     
    142142        return boost::serialization::implementation_level< T >::value
    143143            >= boost::serialization::object_class_info;
    144144    }
    145     virtual bool tracking(const unsigned int /* flags */) const {
    146         return boost::serialization::tracking_level< T >::value
    147                 == boost::serialization::track_always
    148             || ( boost::serialization::tracking_level< T >::value
    149                 == boost::serialization::track_selectively
    150                 && serialized_as_pointer());
     145        virtual int tracking() const {
     146        return boost::serialization::tracking_level< T >::value;
    151147    }
    152148    virtual version_type version() const {
    153149        return version_type(::boost::serialization::version< T >::value);
  • boost/archive/detail/oserializer.hpp

     
    119119        return boost::serialization::implementation_level< T >::value
    120120            >= boost::serialization::object_class_info;
    121121    }
    122     virtual bool tracking(const unsigned int /* flags */) const {
    123         return boost::serialization::tracking_level< T >::value == boost::serialization::track_always
    124             || (boost::serialization::tracking_level< T >::value == boost::serialization::track_selectively
    125                 && serialized_as_pointer());
     122    virtual int tracking() const {
     123        return boost::serialization::tracking_level< T >::value;
    126124    }
    127125    virtual version_type version() const {
    128126        return version_type(::boost::serialization::version< T >::value);
  • libs/serialization/src/basic_iarchive.cpp

     
    135135        const basic_iserializer * bis_ptr;
    136136        const basic_pointer_iserializer * bpis_ptr;
    137137        version_type file_version;
    138         tracking_type tracking_level;
     138        tracking_level_type tracking_level;
    139139        bool initialized;
    140140
    141141        cobject_id(const basic_iserializer & bis_) :
     
    318318    if(! co.initialized){
    319319        if(co.bis_ptr->class_info()){
    320320            class_id_optional_type cid(class_id_type(0));
    321             load(ar, cid);    // to be thrown away
    322             load(ar, co.tracking_level);
    323             load(ar, co.file_version);
     321                        load(ar, cid);    // to be thrown away
     322
     323                        tracking_type tracking;
     324            load(ar, tracking);
     325                        co.tracking_level = tracking ? track_always : track_never;
     326
     327                        load(ar, co.file_version);
    324328        }
    325329        else{
    326330            // override tracking with indicator from class information
    327             co.tracking_level = co.bis_ptr->tracking(m_flags);
     331            co.tracking_level = co.bis_ptr->tracking();
    328332            co.file_version = version_type(
    329333                co.bis_ptr->version()
    330334            );
     
    373377    boost::serialization::state_saver<object_id_type> w(moveable_objects_start);
    374378
    375379    // note: extra line used to evade borland issue
    376     const bool tracking = co.tracking_level;
     380    const bool tracking = co.tracking_level == tracking_level_type(track_always);
    377381
    378382    object_id_type this_id;
    379383    moveable_objects_start =
     
    446450    load_preamble(ar, co);
    447451
    448452    // extra line to evade borland issue
    449     const bool tracking = co.tracking_level;
     453    const bool tracking = co.tracking_level != tracking_level_type(track_never);
    450454    // if we're tracking and the pointer has already been read
    451455    if(tracking && ! track(ar, t))
    452456        // we're done
  • libs/serialization/src/basic_oarchive.cpp

     
    181181            BOOST_ASSERT(false);
    182182            return false;
    183183        }
    184         // returns true if objects should be tracked
    185         bool tracking(const unsigned int) const {
     184        // returns the tracking level
     185        int tracking() const {
    186186            BOOST_ASSERT(false);
    187187            return false;
    188188        }
     
    255255        return;
    256256    }
    257257
     258        const bool has_class_info = bos.class_info();
     259        const tracking_type tracking(
     260                has_class_info && bos.tracking() == track_selectively && bos.maybe_serialized_as_pointer()
     261                || bos.tracking() == track_always
     262        );
     263
    258264    // get class information for this object
    259265    const cobject_type & co = register_type(bos);
    260     if(bos.class_info()){
     266    if(has_class_info){
    261267        if( ! co.m_initialized){
    262268            ar.vsave(class_id_optional_type(co.m_class_id));
    263             ar.vsave(tracking_type(bos.tracking(m_flags)));
     269            ar.vsave(tracking);
    264270            ar.vsave(version_type(bos.version()));
    265271            (const_cast<cobject_type &>(co)).m_initialized = true;
    266272        }
    267273    }
    268274
    269275    // we're not tracking this type of object
    270     if(! bos.tracking(m_flags)){
     276    if(!tracking){
    271277        // just windup the preamble - no object id to write
    272278        ar.end_preamble();
    273279        // and save the data
     
    317323    const basic_oserializer & bos = bpos_ptr->get_basic_serializer();
    318324    std::size_t original_count = cobject_info_set.size();
    319325    const cobject_type & co = register_type(bos);
     326
     327        const tracking_type tracking(bos.tracking() != track_never);
     328
    320329    if(! co.m_initialized){
    321330        ar.vsave(co.m_class_id);
    322331        // if its a previously unregistered class
     
    343352            }
    344353        }
    345354        if(bos.class_info()){
    346             ar.vsave(tracking_type(bos.tracking(m_flags)));
     355            ar.vsave(tracking);
    347356            ar.vsave(version_type(bos.version()));
    348357        }
    349358        (const_cast<cobject_type &>(co)).m_initialized = true;
     
    353362    }
    354363
    355364    // if we're not tracking
    356     if(! bos.tracking(m_flags)){
     365    if(!tracking){
    357366        // just save the data itself
    358367        ar.end_preamble();
    359368        serialization::state_saver<const void *> x(pending_object);