#include <boost/serialization/string.hpp> #include <boost/serialization/map.hpp> #include <boost/serialization/vector.hpp> #include <SF/string.hpp> #include <SF/map.hpp> #include <SF/vector.hpp> struct X { int myInteger; std::string myString; std::map< std::string, std::map<int,std::vector<int>>> myMap; }; // this serialization function // will work as is with both SF and B.S. template<typename Archive> void serialize(Archive &ar, X &x) { ar & x.myInteger & x.myString & x.myMap; } // if you need to distinguish between SF and B.S. serialization, // specialize the SF serialization function: //void serialize(SF::Archive &ar, X &x) //{ // ar & myInteger & myString & myMap; //}
class Base { // some members here // ... }; typedef boost::shared_ptr<Base> BasePtr; class Derived1 : public Base { // some members here // ... }; class Derived2 : public Base { // some members here // ... }; template<typename Archive> void serialize(Archive &ar, Base &base, const unsigned int) { // ... } template<typename Archive> void serialize(Archive &ar, Derived1 &derived1, const unsigned int) { // valid for both SF and B.S. serializeParent<Base>(derived1); // ... } template<typename Archive> void serialize(Archive &ar, Derived2 &derived2, const unsigned int) { // valid for both SF and B.S. serializeParent<Base>(derived1); // ... } // Boost type registration, needed on both server and client BOOST_CLASS_EXPORT_GUID(Derived1, "Derived1") BOOST_CLASS_EXPORT_GUID(Derived2, "Derived2") RCF_BEGIN(I_PolymorphicArgTest, "") RCF_METHOD_R1(std::string, typeOf, BasePtr) RCF_END(I_PolymorphicArgTest) class PolymorphicArgTest { public: std::string typeOf(BasePtr basePtr) { return typeid(*basePtr).name(); } }; { // SF type registration, needed on both server and client SF::registerType<Derived1>("Derived1"); SF::registerType<Derived2>("Derived2"); RcfClient<I_PolymorphicArgTest> client(endpoint); // SF serialization (default) client.getClientStub().setSerializationProtocol(RCF::SfBinary); std::string typeBase = client.typeOf( BasePtr(new Base()) ); std::string typeDerived1 = client.typeOf( BasePtr(new Derived1()) ); std::string typeDerived2 = client.typeOf( BasePtr(new Derived2()) ); // Boost serialization client.getClientStub().setSerializationProtocol(RCF::BsBinary); typeDerived2 = client.typeOf( BasePtr(new Derived2()) ); }