Boost logo

Boost Users :

Subject: [Boost-users] [Serialization - 1.46.1] : Suggestion
From: Mathieu Peyréga (mathieu.peyrega_at_[hidden])
Date: 2011-05-03 02:58:46


Hello,

Here is a small feature suggestion :
I've been modifying the nvp.hpp file and added after line 142 the
following macro definition :

// Added by Mathieu Peyréga
#define
BOOST_SERIALIZATION_BASE_OBJECT_TEMPLATE_NVP(name,templateparameter) \
     boost::serialization::make_nvp( \
         BOOST_PP_STRINGIZE(name)BOOST_PP_STRINGIZE(templateparameter), \
         boost::serialization::base_object<name<templateparameter>
>(*this) \
    )
//

Which enables "easier" serialization for case like the following where
the is multiple heritage and one of the base class is a template.
Do you think this is the good way to go ?

Best regards,

Mathieu Peyréga

/***************************************************************************************************
                    Short example of the
BOOST_SERIALIZATION_BASE_OBJECT_TEMPLATE_NVP macro
***************************************************************************************************/

class C_Battery : public C_PhysicalElement, public
C_GenericDatabaseObject<C_Battery>
{
    public:
    C_Battery(void);
    C_Battery(C_Battery const& obj);
    C_Battery& operator=(C_Battery const& obj);
    virtual ~C_Battery(void);

    Boolean operator==(C_Battery const& other) const;

    Float64 getTensionPerElement(void) const;
    Float64 getCapacityPerElement(void) const;
    Float64 getFaradicEfficiency(void) const;
    Float64 getUnloadDeepness(void) const;
    Float64 getVolumicInstallationCost(void) const;
    Float64 getNumberOfCycles(void) const;
    Float64 getMonthlySelfLosses(void) const;

    void setTensionPerElement(Float64 const& value);
    void setCapacityPerElement(Float64 const& value);
    void setFaradicEfficiency(Float64 const& value);
    void setUnloadDeepness(Float64 const& value);
    void setVolumicInstallationCost(Float64 const& value);
    void setNumberOfCycles(Float64 const& value);
    void setMonthlySelfLosses(Float64 const& value);

    void loadFromCSVDatabase(C_CSVFileParser const& parser, Int32
recordIndex);

protected:
    friend class C_GenericDatabaseObject<C_Battery>;

    Float64 m_TensionPerElement; // Tension par élément en Volts
    Float64 m_CapacityPerElement; // Capacitée par élément en A*h
    Float64 m_FaradicEfficiency; // Rendement faradique
    Float64 m_UnloadDeepness; // Profondeur de décharge
    Float64 m_VolumicInstallationCost; // Cout d'installation en euro/dm3
    Float64 m_NumberOfCycles; // Nombre de cycles à la
profondeur autorisée
    Float64 m_MonthlySelfLosses; // Auto décharge mensuelle

    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(C_PhysicalElement);
        ar &
BOOST_SERIALIZATION_BASE_OBJECT_TEMPLATE_NVP(C_GenericDatabaseObject,C_Battery);
        ar & BOOST_SERIALIZATION_NVP(m_TensionPerElement);
        ar & BOOST_SERIALIZATION_NVP(m_CapacityPerElement);
        ar & BOOST_SERIALIZATION_NVP(m_FaradicEfficiency);
        ar & BOOST_SERIALIZATION_NVP(m_UnloadDeepness);
        ar & BOOST_SERIALIZATION_NVP(m_VolumicInstallationCost);
        ar & BOOST_SERIALIZATION_NVP(m_NumberOfCycles);
        ar & BOOST_SERIALIZATION_NVP(m_MonthlySelfLosses);
    }
};

BOOST_CLASS_VERSION(C_Battery, 1)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net