# Include "commonstreamstore. H"
# Include <s32file. h>
// Constructs objects of Type ccassa, ccassb and ccassc,
// Externalizes them to a direct file store and then destroys
// Cclassa, cclassb and cclassc objects.
Local_c void domakeandstorel (const tdesc & aname );
// Constructs "empty" cclassa, classb and cclassc objects and
// Restores them from the direct file store.
Local_c void dorestorel (const tdesc & aname );
// Displays the contents of a cclassa object
Class cclassa;
Local_c void doshow (const tdesc & aheading, const cclassa & Ana );
// Displays the contents of a cclassb object
Class cclassb;
Local_c void doshow (const tdesc & aheading, const cclassb & AB );
// Displays the contents of a cclassb object
Class cclassc;
Local_c void doshow (const tdesc & aheading, const cclassc & AC );
// Definition of cclassa
Class cclassa: Public cbase
{
Public:
Static cclassa * newlc ();
~ Cclassa ();
Void settextl (const tdesc & aData );
Void externalizel (rwritestream & astream) const;
Void internalizel (rreadstream & astream );
Public:
Hbufc * ivarbuffer;
Tint iintvalue;
Tuint iuintvalue;
};
// Definition of cclassb
Class cclassb: Public cbase
{
Public:
Static cclassb * newlc ();
Void externalizel (rwritestream & astream) const;
Void internalizel (rreadstream & astream );
Public:
Tbuf <32> ifixbuffer;
Tuint iuintvalue;
Tint iintvalue;
Treal irealvalue;
};
// Definition of cclassc
# Define kstdirectclasscgranularity 4
Class cclassc: Public cbase
{
Public:
Static cclassc * newlc ();
~ Cclassc ();
Void constructl ();
Void addnumbertoarrayl (tint avalue );
Void externalizel (rwritestream & astream) const;
Void internalizel (rreadstream & astream );
Public:
Tbuf <32> ifixbuffer;
Carrayfixflat <tint> * iarray;
};
// The file name, extension and path for the file store
_ Metadata (kfullnameoffilestore, "C: // epoc32ex // data // writedirectfs. dat ");
// Do the example
Local_c void doexamplel ()
{
// Make sure directory exists
Fssession. mkdirall (kfullnameoffilestore );
Domakeandstorel (kfullnameoffilestore );
Dorestorel (kfullnameoffilestore );
}
Local_c void domakeandstorel (const tdesc & aname)
{
// Construct an object of Type cclassa and put some
// Data into it
_ Partition (ktxtforclassa, "text for cclassa ");
Cclassa * Thea = cclassa: newlc ();
Thea-> settextl (ktxtforclassa );
Thea-> iintvalue =-1;
Thea-> iuintvalue = 2;
// Construct an object of Type cclassb and put some
// Data into it
_ Partition (ktxtforclassb, "text for cclassb ");
Cclassb * theb = cclassb: newlc ();
Theb-> ifixbuffer = ktxtforclassb;
Theb-> iintvalue =-3;
Theb-> iuintvalue = 4;
Theb-> irealvalue = 5.6;
// Construct an object of Type cclassc and put some
// Data into it
_ Construct (ktxtforclassc, "text for cclassc ");
Cclassc * theC = cclassc: newlc ();
TheC-> ifixbuffer = ktxtforclassc;
TheC-> addnumbertoarrayl (21 );
TheC-> addnumbertoarrayl (42 );
TheC-> addnumbertoarrayl (101 );
// Show contents of the cclassa object
_ Contents (ktxtclassacontent, "cclassa content ...");
Doshow (ktxtclassacontent, * Thea );
// Show contents of the cclassb object
_ Construct (ktxtclassbcontent, "cclassb content ...");
Doshow (ktxtclassbcontent, * theb );
// Show contents of the cclassc object
_ Contents (ktxtclassccontent, "cclassc content ...");
Doshow (ktxtclassccontent, * theC );
// Create (replace) the direct file store
Tparse filestorename;
Fssession. parse (aname, filestorename );
Cfilestore * store = cdirectfilestore: replacelc (fssession, filestorename. fullname (), efilewrite );
// Must say what kind of file store.
Store-> settypel (kdirectfilestorelayoutuid );
// Construct the output stream.
Rstorewritestream outstream;
Tstreamid id = outstream. createlc (* store );
// Stream out the cclassa object,
// Cclassb object and the cclassc object
Outstream <* Thea <* theb <* theC;
// Equally we cocould have done:
// Outstream <* Thea;
// Outstream <* theb;
// Outstream <* theC;
// To the same effect
// The order in which the objects are written out is
// Arbitrary, but it is important to note that
// The order in which they are written out is the same
// As the order in which they will be read in later!
// Commit Changes to the stream
Outstream. commitl ();
// Cleanup the Stream Object
Cleanupstack: popanddestroy ();
// Set this stream ID as the root
Store-> setrootl (ID );
// Commit Changes to the store
Store-> commitl ();
// Destroy the direct file store object (closes the file ),
// Destroy the cclassc object,
// Destroy the cclassb object,
// Destroy the cclassa object.
Cleanupstack: popanddestroy (4 );
}
Local_c void dorestorel (const tdesc & aname)
{
// Construct "empty" cclassa, cclassb and cclassc objects
Cclassa * Thea = cclassa: newlc ();
Cclassb * theb = cclassb: newlc ();
Cclassc * theC = cclassc: newlc ();
// Open the direct file store
Tparse filestorename;
Fssession. parse (aname, filestorename );
Cfilestore * store = cdirectfilestore: openlc (fssession, filestorename. fullname (), efileread );
// Construct and open the root stream which
// Contains the representation of our objects.
Rstorereadstream instream;
Instream. openlc (* store, store-> root ());
// Stream in the cclassa object,
// Cclassb object and the cclassc object
Instream> * Thea> * theb> * theC;
// Equally we cocould have done:
// Instream> * Thea;
// Instream> * theb;
// Instream> * theC;
// To the same effect
// Cleanup the Stream Object
Cleanupstack: popanddestroy ();
// Show restored contents of the cclassa object
_ Restore (ktxtrestoredcclassa, "restored cclassa content ...");
Doshow (ktxtrestoredcclassa, * Thea );
// Show restored contents of the cclassb object
_ Partition (ktxtrestoredcclassb, "restored cclassb content ...");
Doshow (ktxtrestoredcclassb, * theb );
// Show restored contents of the cclassc object
_ Restore (ktxtrestoredcclassc, "restored cclassc content ...");
Doshow (ktxtrestoredcclassc, * theC );
// Destroy the direct file store object (closes the file)
// Destroy the cclassc object,
// Destroy the cclassb object,
// Destroy the cclassa object,
Cleanupstack: popanddestroy (4 );
}
_ Aggregate (ktxtnewline, "/N ");
_ Partition (kformattype1, "/n % s ,");
_ Partition (kformattype2, "% d ,");
_ Partition (kformattype3, "% u ");
_ Partition (kformattype4, "% u ,");
_ Partition (kformattype5, "% F ");
Local_c void doshow (const tdesc & aheading, const cclassa & Ana)
{
Console-> printf (ktxtnewline );
Console-> printf (aheading );
Console-> printf (kformattype1, Ana. ivarbuffer );
Console-> printf (kformattype2, Ana. iintvalue );
Console-> printf (kformattype3, Ana. iuintvalue );
Console-> printf (ktxtnewline );
}
Local_c void doshow (const tdesc & aheading, const cclassb & AB)
{
Console-> printf (ktxtnewline );
Console-> printf (aheading );
Console-> printf (kformattype1, & AB. ifixbuffer );
Console-> printf (kformattype2, AB. iintvalue );
Console-> printf (kformattype4, AB. iuintvalue );
Console-> printf (kformattype5, AB. irealvalue );
Console-> printf (ktxtnewline );
}
_ Trim (ktxtnoarrayitems, "<no array items> ");
_ Forward (ktxtcolonsep ,":");
_ Commit (ktxtcommasep ,",");
_ Partition (kformattype6, "% d array item (s )");
_ Partition (kformattype7, "% S % d ");
Local_c void doshow (const tdesc & aheading, const cclassc & AC)
{
Console-> printf (ktxtnewline );
Console-> printf (aheading );
Console-> printf (kformattype1, & ac. ifixbuffer );
Tint COUNT = ac. iarray-> count ();
If (! Count)
Console-> printf (ktxtnoarrayitems );
Else
{
Tptrc PTR;
PTR. Set (ktxtcolonsep );
Console-> printf (kformattype6, count );
For (tint Index = 0; index <count; index ++)
{
Console-> printf (kformattype7, & PTR, (* AC. iarray) [Index]);
PTR. Set (ktxtcommasep );
}
}
Console-> printf (ktxtnewline );
}
//************************************** *************************
//************************************** *************************
Cclassa * cclassa: newlc ()
{
Cclassa * Self = new (eleave) cclassa;
Cleanupstack: pushl (Self );
Return self;
}
Cclassa ::~ Cclassa ()
{
Delete ivarbuffer;
}
Void cclassa: settextl (const tdesc & aData)
{
Ivarbuffer = aData. allocl ();
}
Void cclassa: externalizel (rwritestream & astream) const
{
Astream. writeint32l (ivarbuffer-> des (). maxlength ());
Astream <* ivarbuffer;
Astream. writeint32l (iintvalue );
Astream. writeuint32l (iuintvalue );
}
Void cclassa: internalizel (rreadstream & astream)
{
Tint maxlen;
Maxlen = astream. readint32l ();
Ivarbuffer = hbufc: newl (astream, maxlen );
Iintvalue = astream. readint32l ();
Iuintvalue = astream. readuint32l ();
}
//************************************** *************************
//************************************** *************************
Cclassb * cclassb: newlc ()
{
Cclassb * Self = new (eleave) cclassb;
Cleanupstack: pushl (Self );
Return self;
}
Void cclassb: externalizel (rwritestream & astream) const
{
Astream <ifixbuffer;
Astream. writeint32l (iintvalue );
Astream. writeuint32l (iuintvalue );
Astream. writereal64l (irealvalue );
}
Void cclassb: internalizel (rreadstream & astream)
{
Astream> ifixbuffer;
Iintvalue = astream. readint32l ();
Iuintvalue = astream. readuint32l ();
Irealvalue = astream. readreal64l ();
}
//************************************** *************************
//************************************** *************************
Cclassc * cclassc: newlc ()
{
Cclassc * Self = new (eleave) cclassc;
Cleanupstack: pushl (Self );
Self-> constructl ();
Return self;
}
Void cclassc: constructl ()
{
Iarray = new (eleave) carrayfixflat <tint> (kstdirectclasscgranularity );
}
Void cclassc: addnumbertoarrayl (tint avalue)
{
Iarray-> appendl (avalue );
}
Cclassc ::~ Cclassc ()
{
Delete iarray;
}
Void cclassc: externalizel (rwritestream & astream) const
{
Astream <ifixbuffer;
Tint count;
Count = iarray-> count ();
Astream. writeint32l (count );
For (tint Index = 0; index <count; index ++)
Astream. writeint32l (* iarray) [Index]);
}
Void cclassc: internalizel (rreadstream & astream)
{
Astream> ifixbuffer;
Tint count;
Count = astream. readint32l ();
For (tint Index = 0; index <count; index ++)
Iarray-> appendl (astream. readint32l ());
}