Dynamic serialization of objects with lists or pointers as members
I need to serialize objects of several (or even many)
different classes, all of those derived from a common
ABC (Abstract Base Class). The problem is that some of
those classes have arrays as members.
It goes like this: first comes the Abstract Base Class:
/////////////////////
class CFoo : public CObject
{
public:
CFoo();
DECLARE_SERIAL(CFoo)
virtual ~CFoo();
virtual void DoThis() = 0;
virtual UINT DoThat() = 0;
}
///////////////////////// here come derived classes:
Class CFoo_A : public CFoo // this is the troublesome one
{
public:
CFoo_A();
DECLARE_DYNCREATE(CFoo_A)
~CFoo_A();
void DoThis();
UINT DoThat();
protected:
CArray<CPoint, CPoint> m_pointArray; // ** POINTER HERE! **
}
///////////////////////////
Class CFoo_B : public CFoo // This one should be no problem
{
public:
CFoo_B();
DECLARE_DYNCREATE(CFoo_B)
~CFoo_B();
void DoThis();
UINT DoThat();
protected:
CPoint m_pointCenter // center of a circumference
UINT m_uRadius // radius in pixels
}
////////////////////////////
Class CFoo_C : public CFoo {...} // and so forth
I certainly don't want to have to store an identifier (string?)
for each CFoo_* object when serializing. The deserialization
would then be a long else-if chain, and that would give me some
headaches when adding new CFoo_* classes in future versions.
I have taken a close look at the examples on dynamic serialization
found on MSDN, but I haven't found one that covers dynamic
creation of objects that include arrays, lists, tables, etc, as
members.
Any hints about how I should manage this?