home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 6.2 KB | 177 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWClaInf.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWCLAINF_H
- #define FWCLAINF_H
-
- #ifndef FWCLAIMP_H
- #include "FWClaImp.h"
- #endif
-
- #ifdef FW_COMPILER_SUPPORTS_RTTI
- #include <typeinfo.h>
- #endif
-
- #ifndef FW_COMPILER_SUPPORTS_RTTI
- inline int operator==(const FW_SClassInfo& first, const FW_SClassInfo& second)
- { return &first == &second; }
- #endif
-
- #ifndef FW_COMPILER_SUPPORTS_RTTI
- inline int operator!=(const FW_SClassInfo& first, const FW_SClassInfo& second)
- { return &first != &second; }
- #endif
-
- //========================================================================================
- // FW_PrivStaticGetClassInfo
- //========================================================================================
-
- #ifndef FW_COMPILER_SUPPORTS_RTTI
- template <class T>
- inline FW_SClassInfoPtr FW_PrivStaticGetClassInfo(T*)
- {
- return &T::fgClassInfo;
- }
- #endif
-
- //========================================================================================
- // FW_PrivVirtualGetClassInfo
- //========================================================================================
-
- #ifndef FW_COMPILER_SUPPORTS_RTTI
- template <class T>
- inline FW_SClassInfoPtr FW_PrivVirtualGetClassInfo(const T* p)
- {
- return p ? p->PrivVirtualGetClassInfo() : 0;
- }
- #endif
-
- //
- // [JEL] Reminder by KVV:
- //
- // Probably need to change DYNAMIC_CAST so its syntax is like in the ANSI C++ draft, i.e.:
- //
- // A* a = ...
- // const B* b = dynamic_cast<const B*>(a);
- //
- // JEL, 12/14/95: KVV is referring to the problem with const. I've tweaked
- // things a bit and it's now possible to write:
- //
- // const B* b = FW_DYNAMIC_CAST(const B, a);
-
- #ifndef FW_COMPILER_SUPPORTS_RTTI
- template <class tTo, class tFrom>
- inline void* FW_DynamicCast(tTo* to, tFrom* from)
- {
- return FW_PrivDynamicCast(from,
- FW_PrivVirtualGetClassInfo(from),
- FW_PrivStaticGetClassInfo(from),
- FW_PrivStaticGetClassInfo(to));
- }
- #endif
-
- //========================================================================================
- // Macros for generating and accessing class information
- //========================================================================================
-
- // ----- The public macros for declaring and defining RTTI scaffolding
-
- #ifdef FW_COMPILER_SUPPORTS_RTTI
- #define FW_DECLARE_CLASS
- #define FW_DEFINE_CLASS_M0(name)
- #define FW_DEFINE_CLASS_M1(name, ancestor)
- #define FW_DEFINE_CLASS_M2(name, ancestor1, ancestor2)
- #define FW_DEFINE_CLASS_M3(name, ancestor1, ancestor2, ancestor3)
- #define FW_DEFINE_CLASS_M4(name, ancestor1, ancestor2, ancestor3, ancestor4)
- #else
- #ifndef FWCLAPRV_H
- #include "FWClaPrv.h"
- #endif
- #define FW_DECLARE_CLASS \
- virtual FW_SClassInfoPtr PrivVirtualGetClassInfo(void) const; \
- FW_SClassInfoPtr PrivNonVirtualGetClassInfo(void) const \
- { return &fgClassInfo; } \
- static FW_SClassInfo fgClassInfo; \
- static const FW_SClassInfoPtr fgAncestors[]; \
- static const size_t fgAncestorOffsets[];
-
- #define FW_DEFINE_CLASS_M0(name) \
- _FW_CLASS_ANCESTORS_IMPLEMENT_M0(name) \
- _FW_DEFINE_CLASSINFO_OBJECT(name) \
- _FW_CLASSINFO_ACCESSOR_MEMBERS(name)
-
- #define FW_DEFINE_CLASS_M1(name, ancestor) \
- _FW_CLASS_ANCESTORS_IMPLEMENT_M1(name, ancestor) \
- _FW_DEFINE_CLASSINFO_OBJECT(name) \
- _FW_CLASSINFO_ACCESSOR_MEMBERS(name)
-
- #define FW_DEFINE_CLASS_M2(name, ancestor1, ancestor2) \
- _FW_CLASS_ANCESTORS_IMPLEMENT_M2(name, ancestor1, ancestor2) \
- _FW_DEFINE_CLASSINFO_OBJECT(name) \
- _FW_CLASSINFO_ACCESSOR_MEMBERS(name)
-
- #define FW_DEFINE_CLASS_M3(name, ancestor1, ancestor2, ancestor3) \
- _FW_CLASS_ANCESTORS_IMPLEMENT_M3(name, ancestor1, ancestor2, ancestor3) \
- _FW_DEFINE_CLASSINFO_OBJECT(name) \
- _FW_CLASSINFO_ACCESSOR_MEMBERS(name)
-
- #define FW_DEFINE_CLASS_M4(name, ancestor1, ancestor2, ancestor3, ancestor4) \
- _FW_CLASS_ANCESTORS_IMPLEMENT_M4(name, ancestor1, ancestor2, ancestor3, ancestor4) \
- _FW_DEFINE_CLASSINFO_OBJECT(name) \
- _FW_CLASSINFO_ACCESSOR_MEMBERS(name)
- #endif
-
- //========================================================================================
- // RTTI Portability Macros
- //
- // These macros provide a transition path until all compilers support RTTI.
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // Dynamic Cast Macro
- //----------------------------------------------------------------------------------------
-
- #ifdef FW_COMPILER_SUPPORTS_RTTI
- #define FW_DYNAMIC_CAST(T, p) dynamic_cast<T*>(p)
- #else
- #define FW_DYNAMIC_CAST(T, p) (T*) FW_DynamicCast((T*)0, p)
- #endif
-
- //----------------------------------------------------------------------------------------
- // typeid macros
- //----------------------------------------------------------------------------------------
-
- // Note, C++ typeid's are TypeInfo *references*.
- // ODF TYPEIDs are FW_ClassInfo *references*
- // Internally, ODF usually uses FW_SClassInfoPtrs, which are are FW_ClassInfo *pointers*.
-
- #ifdef FW_COMPILER_SUPPORTS_RTTI
- typedef type_info FW_TypeInfo;
- #define FW_TYPEID_FROM_TYPE(type) (typeid(type))
- #define FW_TYPEID_FROM_POINTER(p) (typeid(*(p)))
- #else
- typedef FW_SClassInfo FW_TypeInfo;
- #define FW_TYPEID_FROM_TYPE(type) (*FW_CLASS_INFO_PTR(type))
- #define FW_TYPEID_FROM_POINTER(p) (*(p)->PrivVirtualGetClassInfo())
- #endif
-
- //----------------------------------------------------------------------------------------
- // Class name macros
- //----------------------------------------------------------------------------------------
-
- #ifdef FW_COMPILER_SUPPORTS_RTTI
- #define FW_CLASSNAME_FROM_TYPE(type) (typeid(type).name())
- #define FW_CLASSNAME_FROM_POINTER(p) (typeid(*(p)).name())
- #else
- #define FW_CLASSNAME_FROM_TYPE(type) (FW_TYPEID_FROM_TYPE(type).fClassName)
- #define FW_CLASSNAME_FROM_POINTER(p) (FW_TYPEID_FROM_POINTER(p).fClassName)
- #endif
-
- #endif
-