// $Revision: 1.1 $ // Copyright © 1995 Taligent, Inc. All rights reserved. // Taligent Confidential #ifndef Taligent_STREAMTOMEMIMP #define Taligent_STREAMTOMEMIMP #ifndef HIDE_TEMPLATE_DEFINITIONS #define MAKE_TStreamToMem_DEFINITIONS_VISIBLE #define MAKE_TStreamTest_DEFINITIONS_VISIBLE #else #define inline #endif #ifdef MAKE_TStreamToMem_DEFINITIONS_VISIBLE template TStreamToMem::TStreamToMem(aClass *theObject, const TStandardText& className) : fObjectToBeStreamed(theObject), fClassName(className) { } template TStreamToMem::~TStreamToMem() { } template void TStreamToMem::WriteToMem() { TContext aContext; fMemStream.SetContext(&aContext); ::Flatten(fObjectToBeStreamed, fMemStream); fMemStream.Seek(0); fMemStream.SetContext(NIL); } template aClass* TStreamToMem::ReadFromMem() { aClass *theStreamedInObject; TContext aContext; fMemStream.SetContext(&aContext); ::Resurrect(theStreamedInObject, fMemStream); return theStreamedInObject; } template aClass* TStreamToMem::Test() { int failed = 0; try { WriteToMem(); } catch ( ... ) { PrintError("Flattening failed"); failed = 1; } aClass *aResurrectedObject = NIL; if (!failed) { try { aResurrectedObject = ReadFromMem(); } catch ( ... ) { // PrintError("Resurrecting failed"); aResurrectedObject = new aClass(*fObjectToBeStreamed); failed = 2; } } if (failed == 2) { // PrintError("Testing streaming"); TGrowingChunkyStream mem; TContext aContext; mem.SetContext(&aContext); try { *fObjectToBeStreamed >>= mem; } catch ( ... ) { PrintError("\t StreamOut ( >>= ) failed"); failed = 1; } if (failed != 1) { aClass *clone = NIL; try { clone = new aClass(*fObjectToBeStreamed); *clone <<= mem; } catch ( ... ) { PrintError("\t StreamIn ( <<= ) failed"); } delete clone; } } return aResurrectedObject; } template void TStreamToMem::PrintError(const char *errorMessage) { // TTypeInfo aTypeInfo = ::DynamicTypeInfo(*fObjectToBeStreamed); // qprintf("%s for class: %s\n",errorMessage,aTypeInfo.name()); qprintf("%s for class: ",errorMessage); QPrintText(fClassName, FALSE); qprintf("\n"); } #endif // MAKE_TStreamToMem_DEFINITIONS_VISIBLE #ifdef MAKE_TStreamCopyAssignmentTest_DEFINITIONS_VISIBLE template TStreamCopyAssignmentTest::TStreamCopyAssignmentTest(aClass *theObject, TStandardText className) { TStreamToMem aStreamToMem(theObject, className); delete aStreamToMem.Test(); // empty ctor try { aClass anObject; } catch ( ... ) { PrintError("\t empty ctor failed", className); } // copy ctor try { aClass copyObject(*theObject); } catch ( ... ) { PrintError("\t copy ctor failed", className); } // assignment operator try { aClass assignmentObject; assignmentObject.operator=(*theObject); } catch ( ... ) { PrintError("\t assignment operator failed", className); } } template void TStreamCopyAssignmentTest::PrintError(const char *errorMessage, TStandardText className) { qprintf("%s for class: ",errorMessage); QPrintText(className, FALSE); qprintf("\n"); } #endif // MAKE_TStreamCopyAssignmentTest_DEFINITIONS_VISIBLE #ifdef HIDE_TEMPLATE_DEFINITIONS #undef inline #endif #endif