home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 10.7 KB | 294 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWStrgAr.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWSTRGAR_H
- #include "FWStrgAr.h"
- #endif
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWBNDSTR_H
- #include "FWBndStr.h"
- #endif
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #pragma segment Strings
-
- //========================================================================================
- // Define string RTTI information
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_CByteString)
- FW_DEFINE_CLASS_M1(FW_CString, FW_CByteString)
-
- FW_DEFINE_CLASS_M1(FW_CBoundedString, FW_CString)
- FW_DEFINE_CLASS_M1(FW_CString32, FW_CBoundedString)
- FW_DEFINE_CLASS_M1(FW_CString255, FW_CBoundedString)
-
- FW_DEFINE_CLASS_M1(FW_CDynamicString, FW_CString)
-
- //========================================================================================
- // Register archiver read/write methods for string classes
- //========================================================================================
-
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LString32, FW_CString32, (FW_CString32Archiver::Read), (FW_CString32Archiver::Write))
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LString255, FW_CString255, (FW_CString255Archiver::Read), (FW_CString255Archiver::Write))
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LDynamicString, FW_CDynamicString, (FW_CDynamicStringArchiver::Read), (FW_CDynamicStringArchiver::Write))
-
- //========================================================================================
- // FW_InitializeStrings
- //========================================================================================
-
- void FW_InitializeStrings(void)
- {
- //???JEL: This function is now obsolete (as of 11/4/94).
- // The strings component no longer needs to be initialized.
- // FW_CDynamicArchiver::MergeArchiverMaps();
- }
-
- //========================================================================================
- // FW_CStringArchiver
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CStringArchiver::Read
- //----------------------------------------------------------------------------------------
-
- void FW_CStringArchiver::Read(FW_CReadableStream & archive, FW_CString& string)
- {
- FW_ByteCount byteCount;
- FW_ByteCount charWidth;
- FW_CharacterCount charCount;
-
- archive >> byteCount;
- archive >> charWidth;
- string.GrowCapacity(byteCount);
- FW_ASSERT(byteCount <= string.GetCapacity());
- archive.Read(string.fRepresentation, byteCount);
-
- if (charWidth > 0)
- charCount = byteCount/charWidth;
- else
- {
- charCount = FW_CharactersInBlock(string.fRepresentation, byteCount);
- charWidth = sizeof(FW_Char);
- }
- string.PrivSetLength(charCount, byteCount, charWidth);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CStringArchiver::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CStringArchiver::Write(FW_CWritableStream & archive,
- const FW_CString &string)
- {
- FW_ByteCount byteCount = string.GetByteLength();
- FW_ByteCount charWidth = string.GetCharWidth();
-
- archive << byteCount;
- archive << charWidth;
- archive.Write(string.fRepresentation, byteCount);
- }
-
- //========================================================================================
- // FW_CDynamicStringArchiver
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicStringArchiver::Read
- //----------------------------------------------------------------------------------------
-
- void * FW_CDynamicStringArchiver::Read(FW_CReadableStream & archive)
- {
- FW_CDynamicString * string = FW_NEW(FW_CDynamicString, ());
- FW_CStringArchiver::Read(archive, *string);
- return string;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDynamicStringArchiver::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CDynamicStringArchiver::Write(FW_CWritableStream & archive,
- const void *object)
- {
- const FW_CString* objectString = (const FW_CString*)object;
- const FW_CDynamicString* string = FW_DYNAMIC_CAST(FW_CDynamicString, objectString);
- FW_ASSERT(string != 0);
- FW_CStringArchiver::Write(archive, *string);
- }
-
- //========================================================================================
- // FW_CString32Archiver
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CString32Archiver::Read
- //----------------------------------------------------------------------------------------
-
- void * FW_CString32Archiver::Read(FW_CReadableStream & archive)
- {
- FW_CString32 * string = FW_NEW(FW_CString32, ());
- FW_CStringArchiver::Read(archive, *string);
- return string;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString32Archiver::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CString32Archiver::Write(FW_CWritableStream & archive,
- const void *object)
- {
- const FW_CString* objectString = (const FW_CString*)object;
- const FW_CString32* string = FW_DYNAMIC_CAST(FW_CString32, objectString);
- FW_ASSERT(string != 0);
- FW_CStringArchiver::Write(archive, *string);
- }
-
- //========================================================================================
- // FW_CString255Archiver
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CString255Archiver::Read
- //----------------------------------------------------------------------------------------
-
- void * FW_CString255Archiver::Read(FW_CReadableStream & archive)
- {
- FW_CString255 * string = FW_NEW(FW_CString255, ());
- FW_CStringArchiver::Read(archive, *string);
- return string;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CString255Archiver::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CString255Archiver::Write(FW_CWritableStream & archive, const void *object)
- {
- const FW_CString* objectString = (const FW_CString*)object;
- const FW_CString255* string = FW_DYNAMIC_CAST(FW_CString255, objectString);
- FW_ASSERT(string != 0);
- FW_CStringArchiver::Write(archive, *string);
- }
-
- //########################################################################################
- // Work around SCpp 8.0.3 bug - importing overloaded functions doesn't work.
- // Replace overloaded functions with normal functions with different names.
- // Use inline overloaded functions which turn around and call the renamed
- // functions so client code isn't affected.
- //########################################################################################
-
- //----------------------------------------------------------------------------------------
- // operator>>(FW_CReadableStream& stream, FW_CDynamicString& string)
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CReadableStream& _FW_StreamInDynamic (FW_CReadableStream& stream, FW_CDynamicString& string)
- {
- FW_ByteCount numberBytes;
- stream >> numberBytes;
- FW_Char* storage = new FW_Char[numberBytes];
- FW_TRY
- {
- stream.Read(storage, numberBytes);
- string.ReplaceAll(storage, numberBytes);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete storage;
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- delete storage;
- return stream;
- }
-
- //----------------------------------------------------------------------------------------
- // operator<<(FW_CWritableStream& stream, const FW_CDynamicString& string)
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CWritableStream& _FW_StreamOutDynamic (FW_CWritableStream& stream, const FW_CDynamicString& string)
- {
- FW_ByteCount numberBytes = string.GetByteLength();
- const FW_Char* storage = (const FW_Char*) string;
- stream << numberBytes;
- stream.Write(storage, numberBytes);
- return stream;
- }
-
- //----------------------------------------------------------------------------------------
- // operator>>(FW_CReadableStream& stream, FW_CString32& string)
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CReadableStream& _FW_StreamInStr32 (FW_CReadableStream& stream, FW_CString32& string)
- {
- FW_ByteCount numberBytes;
- stream >> numberBytes;
- FW_Char storage[64];
- stream.Read(storage, numberBytes);
- string.ReplaceAll(storage, numberBytes);
- return stream;
- }
-
- //----------------------------------------------------------------------------------------
- // operator<<(FW_CWritableStream& stream, const FW_CString32& string)
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CWritableStream& _FW_StreamOutStr32 (FW_CWritableStream& stream, const FW_CString32& string)
- {
- FW_ByteCount numberBytes = string.GetByteLength();
- const FW_Char* storage = (const FW_Char*) string;
- stream << numberBytes;
- stream.Write(storage, numberBytes);
- return stream;
- }
-
- //----------------------------------------------------------------------------------------
- // operator>>(FW_CReadableStream& stream, FW_CString255& string)
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CReadableStream& _FW_StreamInStr255 (FW_CReadableStream& stream, FW_CString255& string)
- {
- FW_ByteCount numberBytes;
- stream >> numberBytes;
- FW_Char storage[512];
- stream.Read(storage, numberBytes);
- string.ReplaceAll(storage, numberBytes);
- return stream;
- }
-
- //----------------------------------------------------------------------------------------
- // operator<<(FW_CWritableStream& stream, const FW_CString255& string)
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CWritableStream& _FW_StreamOutStr255 (FW_CWritableStream& stream, const FW_CString255& string)
- {
- FW_ByteCount numberBytes = string.GetByteLength();
- const FW_Char* storage = (const FW_Char*) string;
- stream << numberBytes;
- stream.Write(storage, numberBytes);
- return stream;
- }
-
-