home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 4.9 KB | 180 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWStrmRW.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWSTRMRW_H
- #include "FWStrmRW.h"
- #endif
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- #ifndef FWOBJREG_H
- #include "FWObjReg.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #pragma segment FWStream
-
-
- //========================================================================================
- // Constants having file scope
- //========================================================================================
-
- enum
- {
- kIDOnly, kIDAndValue
- };
-
- //========================================================================================
- // CLASS FW_CReadableStream
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::FW_CReadableStream
- //----------------------------------------------------------------------------------------
-
- FW_CReadableStream::FW_CReadableStream(FW_CSink* sink,
- FW_CReadableStreamFormatter* formatter,
- FW_CObjectRegistry* objectRegistry) :
- fSink(sink),
- fStreamCreatedFormatter(formatter ? FALSE : TRUE),
- fFormatter(formatter),
- fArchiveCreatedObjectRegistry(objectRegistry ? FALSE : TRUE),
- fObjectRegistry(objectRegistry)
- {
- if (fStreamCreatedFormatter)
- fFormatter = FW_NEW(FW_CReadableStreamFormatter, ());
-
- if (fArchiveCreatedObjectRegistry)
- fObjectRegistry = new FW_CBasicObjectRegistry();
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::~FW_CReadableStream
- //----------------------------------------------------------------------------------------
-
- FW_CReadableStream::~FW_CReadableStream()
- {
- FW_START_DESTRUCTOR
-
- if (fArchiveCreatedObjectRegistry)
- delete fObjectRegistry;
-
- if (fStreamCreatedFormatter)
- delete fFormatter;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CReadableStream::InputObject
- //----------------------------------------------------------------------------------------
-
- void* FW_CReadableStream::InputObject(InputFunction inputFunction)
- {
- FW_CObjectRegistry::ID id;
- short byValue;
- void* objectPtr;
-
- *this >> byValue;
- *this >> id;
-
- switch (byValue)
- {
- case kIDAndValue:
- objectPtr = inputFunction(*this);
- fObjectRegistry->Register(objectPtr, id);
- break;
- case kIDOnly:
- objectPtr = (void*)fObjectRegistry->Lookup(id);
- break;
-
- default:
- FW_ASSERT(FALSE);
- break;
- }
-
- return objectPtr;
- }
-
-
- //========================================================================================
- // CLASS FW_CWritableStream
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::FW_CWritableStream
- //----------------------------------------------------------------------------------------
-
- FW_CWritableStream::FW_CWritableStream(FW_CSink* sink,
- FW_CWritableStreamFormatter* formatter,
- FW_CObjectRegistry* objectRegistry) :
- fSink(sink),
- fStreamCreatedFormatter(formatter ? FALSE : TRUE),
- fFormatter(formatter),
- fArchiveCreatedObjectRegistry(objectRegistry ? FALSE : TRUE),
- fObjectRegistry(objectRegistry)
- {
- if (fStreamCreatedFormatter)
- fFormatter = FW_NEW(FW_CWritableStreamFormatter, ());
-
- if (fArchiveCreatedObjectRegistry)
- fObjectRegistry = new FW_CBasicObjectRegistry();
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::~FW_CWritableStream
- //----------------------------------------------------------------------------------------
-
- FW_CWritableStream::~FW_CWritableStream()
- {
- FW_START_DESTRUCTOR
-
- if (fArchiveCreatedObjectRegistry)
- delete fObjectRegistry;
-
- if (fStreamCreatedFormatter)
- delete fFormatter;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWritableStream::OutputObject
- //----------------------------------------------------------------------------------------
-
- void FW_CWritableStream::OutputObject(OutputFunction outputFunction,
- const void* object)
- {
- FW_CObjectRegistry::ID id = fObjectRegistry->Lookup(object);
-
- if (id == FW_CObjectRegistry::kNotInRegistry)
- {
- id = fObjectRegistry->Register(object);
- *this << ((short)kIDAndValue) << id;
- // Explicitly cast the kIDOnly into a short because on the mac
- // an enum can be a char.
-
- outputFunction(*this, object);
- }
- else
- {
- *this << ((short)kIDOnly) << id;
- // Explicitly cast the kIDOnly into a short because on the mac
- // an enum can be a char.
- }
- }
-