I'm trying to (de)serialize a polymorphic vector, but have different issues with different attempts. The entire order of events are:
- Serialize a Polymorphic Vector on Server Side
- Send the serialized string over the network
- De-serialize to a new Polymorphic Vector on Client Side
- Edit Data in Vector (includes adding, editing and deleting) on Client Side
- Serialize the edited Polymorphic Vector on Client Side
- Send the new serialized string over the network
- De-serialize the new Polymorphic Vector on Server Side <--- This is where my problem lies
I have Class Derived (and DerivedB, DerivedC etc) which derives from Class Base & a Class LotsOfBases which holds a Vector of Virtual Base.
Although, I don't see how this could be causing the issue - I believe my issue is because the objects in the Vector coming from the Server are in a particular order (AAABBCCCCD) and when they come back they are in a random order and may have different quantities of derived classes (ABABCDDDA).
Below are my failed attempts. Using method 2 below, if I am lucky I can send information back and forth (if class order remains the same), but when the class types change order, the problems begin to occur.
Code Used & Compile/Runtime Error:
Compiles with no additions of course, but I get RunTime issues as Boost doesn't know which class is which... So I tried:
ar.template register_type<Derived>() ;
- Registering Class in "LotsOfBases.h"'s Serialize Function and got the following when called at RunTime:Error @ RunTime: what(): Input Stream Error
- This is where I've had most success and what is mainly mentioned above.ar.register_type<static...
But I get compile errors stating its a function (saw this else where on StackOverflowBOOST_CLASS_EXPORT(Derived) ;
At the end of the ".h" file which gives n warnings for each different sub-class of Base and fails to compile. Error:multiple definition of ``boost::archive::detail::extra_detail::init_guid<Derived>::g'
I tried to register the classes with the archiver in the main where LotsOfBases gets Deserialised. Compiler warnings
BOOST_CLASS_EXPORT_IMPLEMENT(TextQuestion)
from Exporting Class Serialization - Same errors as 6 iirc.The examples above without links are from my trolling through ~30 pages on StackOverflow which are similar but their solutions offered don't seem to work for me or are to do with Boost Serialization but somewhat irrelevant.
The following is a shortened version of my code (without edits used from elsewhere):
Classes' Code
LotsOfBases:
#include "s11n.h" //Import All Serialization Headers In Correct Order
namespace boost { namespace serialization { class access ; } }
class LotsOfBases
{
public:
std::vector<Base *> getAllBases() ;
protected:
std::vector<Base *> allBases() ;
friend class boost::serialization::access ;
template <typename Archive>
void serialize(Archive& ar, const unsigned int /*version*/)
{
ar & allBases ;
}
} ;
Base:
#include "s11n.h" //Import All Serialization Headers In Correct Order
namespace boost { namespace serialization { class access ; } }
class Base
{
public:
Base() ;
~Base() ;
virtual std::string getBaseLocation() ;
protected:
std::string baseLocation ;
friend class boost::serialization::access ;
template <typename Archive>
void serialize(Archive& ar, const unsigned int /*version*/)
{
ar & baseLocation ;
}
} ;
Derived
#include "s11n.h" //Import All Serialization Headers In Correct Order
namespace boost { namespace serialization { class access ; } }
class Derived
{
public:
Derived() ;
bool getIsAttackableBase() ;
private:
bool isAttackableBase ;
typedef Base _super;
friend class boost::serialization::access ;
template <typename Archive>
void serialize(Archive& ar, const unsigned int /*version*/)
{
ar & boost::serialization::base_object<_super>(*this) ;
ar & isAttackableBase ;
}
I'm sure it shouldn't be so difficult. So, I guess my question is... What am I doing wrong? Where should I start reading/researching now?