0

How can I serialize a map with type electric_potential and double ?? In my code I have put these headers:

#include <boost/serialization/complex.hpp>
#include <boost/serialization/map.hpp>
#include <boost/units/physical_dimensions/electric_potential.hpp>

template<class Archive, class T> 
static void serialize( Archive & ar, T & t, const unsigned int file_version ){ 
  t.serialize(ar, file_version); 
}
extern "C++" class Data_substation_AC2 : public Data_OG
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
    ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Data_OG);
    ar & BOOST_SERIALIZATION_NVP(_primary_voltage);
    ar & BOOST_SERIALIZATION_NVP(_secondary_voltage);
    ar & BOOST_SERIALIZATION_NVP(_impedance1);
    ar & BOOST_SERIALIZATION_NVP(_impedance2);
    ar & BOOST_SERIALIZATION_NVP(_location);
}
std::string                                                   _name;        
bu::quantity<si::electric_potential>                          _primary_voltage;
bu::quantity<si::electric_potential>                          _secondary_voltage;
bu::quantity<si::resistance, std::complex<double>>            _impedance1;
bu::quantity<si::resistance, std::complex<double>>            _impedance2;
Data_location                                                 _location;     

I tried all the headers but still I have this error:

error C2039: 'serialize' : is not a member of 'boost::units::
quantity<boost::units::si::electric_potential,double>'

I am looking for the most simple way to solve this. Thanks in this picture the code when i use the type electrical_potential

Saad
  • 1
  • 1
  • Show the code that causes the compilation error. – Dennis Apr 15 '16 at 11:32
  • in the class access.hpp: in this function template static void serialize( Archive & ar, T & t, const unsigned int file_version ){ t.serialize(ar, file_version); } – Saad Apr 15 '16 at 11:53
  • Edit your original post to include your code – Dennis Apr 15 '16 at 12:31
  • see reference to function template instantiation 'void boost::serialization::access::serialize(Archive &,T &,const unsigned int)' being compiled with [ Archive=boost::archive::xml_oarchive , T=boost::units::quantity ] – Saad Apr 15 '16 at 12:33
  • You need to give a complete, self-contained and concise example that reproduces the issue. To me it looks like you are passing a `boost::units:: quantity` type into your `serialize` function and that this type does not have the method `serialise`. I suspect that you are new to templates, and that what you have is not what you wanted to do. Describe what you are trying to achieve. – Dennis Apr 15 '16 at 12:33
  • where i can put the method serialize to this type ?? – Saad Apr 15 '16 at 12:46
  • in my original post link of picture of my code – Saad Apr 15 '16 at 15:29
  • here is my code: extern "C++" class Data_substation_AC2 : public Data_OG {private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Data_OG); ar & BOOST_SERIALIZATION_NVP(_primary_voltage); ar & BOOST_SERIALIZATION_NVP(_impedance1); } bu::quantity _primary_voltage; bu::quantity> _impedance1; – Saad Apr 15 '16 at 15:38

1 Answers1

0

I fail to see what the problem could be. The fact that you don't show a complete, self-contained sample means I can't help you realize the problem, except by showing what I did to make it work:

Live On Coliru

#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/complex.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/string.hpp>
#include <boost/units/base_unit.hpp>
#include <boost/units/io.hpp>
#include <boost/units/physical_dimensions/electric_potential.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si.hpp>
#include <boost/units/unit.hpp>

namespace bu = boost::units;
namespace si = bu::si;

//template<class Archive, class T> 
//static void serialize( Archive & ar, T & t, const unsigned int file_version ){ 
    //t.serialize(ar, file_version); 
//}

struct Data_OG{
        template<class Archive> void serialize(Archive &, const unsigned int) { } 
};
struct Data_location {
        template<class Archive> void serialize(Archive &, const unsigned int) { }
};

class Data_substation_AC2 : public Data_OG
{
    private:
        friend class boost::serialization::access;
        template<class Archive>
            void serialize(Archive & ar, const unsigned int) {
                ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Data_OG);
                ar & BOOST_SERIALIZATION_NVP(_primary_voltage);
                ar & BOOST_SERIALIZATION_NVP(_secondary_voltage);
                ar & BOOST_SERIALIZATION_NVP(_impedance1);
                ar & BOOST_SERIALIZATION_NVP(_impedance2);
                ar & BOOST_SERIALIZATION_NVP(_location);
            }
        std::string                                                   _name;        
        bu::quantity<si::electric_potential>                          _primary_voltage;
        bu::quantity<si::electric_potential>                          _secondary_voltage;
        bu::quantity<si::resistance, std::complex<double>>            _impedance1;
        bu::quantity<si::resistance, std::complex<double>>            _impedance2;
        Data_location _location;
};

int main() {
    Data_substation_AC2 dsac2;

    boost::archive::xml_oarchive oa(std::cout);
    oa << BOOST_SERIALIZATION_NVP(dsac2);
}

Prints

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <!DOCTYPE boost_serialization>
    <boost_serialization signature="serialization::archive" version="14">
    <dsac2 class_id="0" tracking_level="0" version="0">
        <Data_OG class_id="1" tracking_level="0" version="0"></Data_OG>
        <_primary_voltage class_id="2" tracking_level="0" version="0">
            <value>0.00000000000000000e+00</value>
        </_primary_voltage>
        <_secondary_voltage>
            <value>0.00000000000000000e+00</value>
        </_secondary_voltage>
        <_impedance1 class_id="3" tracking_level="0" version="0">
            <value>
                <real>0.00000000000000000e+00</real>
                <imag>0.00000000000000000e+00</imag>
            </value>
        </_impedance1>
        <_impedance2>
            <value>
                <real>0.00000000000000000e+00</real>
                <imag>0.00000000000000000e+00</imag>
            </value>
        </_impedance2>
        <_location class_id="4" tracking_level="0" version="0"></_location>
    </dsac2>
    </boost_serialization>
sehe
  • 374,641
  • 47
  • 450
  • 633