home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 5.0 KB | 137 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWArOper.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWAROPER_H
- #define FWAROPER_H
-
- #ifndef FWARDYNA_H
- #include "FWArDyna.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_SomCast
- //----------------------------------------------------------------------------------------
-
- SOMObject* FW_SomCast(SOMObject *object, SOMClass *className);
-
- //----------------------------------------------------------------------------------------
- // FW_READ_DYNAMIC_OBJECT
- //
- // Global function for reading from a readableStream. The type 'className'
- // must be a dynamic class or a compile-time error will occur.
- //----------------------------------------------------------------------------------------
-
- // JEL:
- // I would like to be able to pass FW_TYPEID_FROM_TYPE(tType) into
- // FW_CPrivArchiver::CreateObject, and then use RTTI to enforce the requirement
- // that the object contained in the stream is a valid subtype of tType.
- // Unfortunately, native C++ RTTI doesn't give me a built-in way to do it
- // (I need a function that takes two typeids and returns true if one is a subtype
- // of the other, and dynamic_cast can't be used for this).
- // The ODF RTTI emulation has this capability, but we expect native RTTI will be used
- // by most developers.
-
- template <class tType>
- inline void FW_ReadObject(FW_CReadableStream& stream, tType*& object)
- {
- FW_CPrivArchiver::CreateObject(stream, (void *&)(object));
-
- #ifndef FW_COMPILER_SUPPORTS_RTTI
- // This is really a compile/link time check, it's not much help as a runtime check.
- // All it does is verify that the class tType has both the FW_DECARE_CLASS
- // and W_DEFINE_CLASS_Mx macros. If FW_DECLARE_CLASS is missing, the line should
- // result in a compile-time error. If FW_DEFINE_CLASS_Mx is missing, it will result
- // in a link-time error. (Because of a compiler bug, the MPW based compilers can not
- // handle this particular check -- so we disable it for them. [SFU] )
- #if !defined __SC__ && !defined __MRC__
- FW_ASSERT(FW_PrivStaticGetClassInfo(object) != 0);
- #endif
- #endif
- }
-
- #if 1
- // The template function is a
- #define FW_READ_DYNAMIC_OBJECT(stream, object, className) \
- FW_ReadObject(stream, *object)
- #else
- #define FW_READ_DYNAMIC_OBJECT(stream, object, className) \
- { \
- className** _temp_ = object; \
- FW_CPrivArchiver::CreateObject(stream, (void *&)(*_temp_)); \
- *(object) = FW_DYNAMIC_CAST(className, *_temp_); \
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_WRITE_DYNAMIC_OBJECT
- //
- // Global function for writing to a writableStream. The type 'className' must
- // must be a dynamic class or a compile-time error will occur.
- //----------------------------------------------------------------------------------------
-
- template <class tType>
- inline void FW_WriteObject(FW_CWritableStream& stream, const tType* object)
- {
- const char* classString = object != NULL
- ? FW_CLASSNAME_FROM_POINTER(object)
- : FW_CLASSNAME_FROM_TYPE(tType);
- FW_CPrivArchiver::OutputObject(stream, object, classString);
- }
-
- #if 1
- #define FW_WRITE_DYNAMIC_OBJECT(stream, object, className) \
- FW_WriteObject(stream, object)
- #else
- #define FW_WRITE_DYNAMIC_OBJECT(stream, object, className) \
- { \
- const className* _temp_ = object; \
- const char* classString = _temp_ != NULL \
- ? FW_CLASSNAME_FROM_POINTER(_temp_) \
- : FW_CLASSNAME_FROM_TYPE(className); \
- FW_CPrivArchiver::OutputObject(stream, _temp_, classString); \
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_READ_DYNAMIC_SOM_OBJECT
- //
- // Global function for reading from a readableStream. The type 'className'
- // must be a dynamic class or a compile-time error will occur.
- //----------------------------------------------------------------------------------------
-
- #define FW_READ_DYNAMIC_SOM_OBJECT(stream, object, className) \
- { \
- className** _temp_ = object; \
- FW_CPrivArchiver::CreateObject(stream, (void *&)(*_temp_)); \
- *(object) = (className*)FW_SomCast(*_temp_,className##ClassData.classObject); \
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_WRITE_DYNAMIC_SOM_OBJECT
- //
- // Global template function for writing to a writableStream. The type 'className' must
- // must be a dynamic class or a compile-time error will occur.
- //----------------------------------------------------------------------------------------
-
- #define FW_WRITE_DYNAMIC_SOM_OBJECT(stream, object, className) \
- { \
- className* _temp_ = object; \
- if (_temp_ != NULL) \
- FW_CPrivArchiver::OutputObject(stream, _temp_, _temp_->somGetClassName()); \
- else \
- FW_CPrivArchiver::OutputObject(stream, 0, #className); \
- }
-
- #endif
-