Link to home
Start Free TrialLog in
Avatar of bhushanvi
bhushanvi

asked on

About Serializing Complex Data

Hi all,
        I want to serialize complex data and save it to a CFile object. I have found a number of examples showing the serialization and storing of the data to the file. Please send me some links/examples showing the serialization of a CObject derived class containing about 4/5 arrays of structures holding various members of CString, int and float datatypes. How do I serialize such a class? And how do I save and retrieve the contents to/from the CFile object I have created?
Thankyou.
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bhushanvi
bhushanvi

ASKER

Hi,
    Your answer was quite a help! But my data array is not a member of CArray or any other array having homogeneous data. So, can you go ahead and tell me, how can I serialize the data and save it to a txt(?) file or whatever? Here is the prototype of what I am trying to achieve:

class MyObject : public CObject
{
    struct ONE
    {
       CString m1;
       int m2;
       float m3;
    }
    ONE First[20];
    int Num_First;   // holds the number of entries for struct ONE

    struct TWO
    {
        members......;
     }
     TWO Second[10];
     int Num_Second;   //holds the number of entries for struct TWO
     
     struct THREE
     {
         members.......;
     }
      THREE Third[15];
     int Num_Third;   // holds the number of entries for struct THREE

// Functions...

     f(1);
     f(2);
     f(3);
     
     Serialize(ar);      // Serialize function for custom class derived from CObject taking CArchive data as it's parameter.

}
// end of class declaration.

        The above details match to my requirements closely. Is there any way that this could be done?

Or do I have to declare each of those structs as classes derived from CObject and then serialize the data and then save it.

Or alternatively declare a CStringArray for each of the struct members separately and then get the values from the struct with a dot operator and then serialize/deserialize those arrays?

Please let me know in short the steps for how should I go abt it....
THANKYOU.
In the serialise just write/read the individual variables, one after the other