[964] | 1 | /*
|
---|
| 2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
| 3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
| 4 | */
|
---|
| 5 | /*
|
---|
| 6 | We use references to static objects so that the order of initialization shouldn't matter.
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | /**
|
---|
| 10 | @file FUObjectType.h
|
---|
| 11 | This file contains the FUObjectType class.
|
---|
| 12 | */
|
---|
| 13 |
|
---|
| 14 | #ifndef _FU_OBJECT_TYPE_H_
|
---|
| 15 | #define _FU_OBJECT_TYPE_H_
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | An object type.
|
---|
| 19 | Used for RTTI-purpose and to easily allow up-classing of objects.
|
---|
| 20 | Every object class should have one object type has a static member
|
---|
| 21 | and available through the virtual FUObject::GetObjectType function.
|
---|
| 22 | All FUObject up-classes should use the DeclareObjectType macro.
|
---|
| 23 | @ingroup FUtils
|
---|
| 24 | */
|
---|
| 25 | class FCOLLADA_EXPORT FUObjectType
|
---|
| 26 | {
|
---|
| 27 | private:
|
---|
| 28 | const FUObjectType* parent;
|
---|
| 29 | #ifdef _DEBUG
|
---|
| 30 | const char* typeName;
|
---|
| 31 | #endif
|
---|
| 32 |
|
---|
| 33 | public:
|
---|
| 34 | /** [INTERNAL] Constructor: do not use directly.
|
---|
| 35 | Only the FUObject class should use this constructor.
|
---|
| 36 | All other class object types should use the constructor below.
|
---|
| 37 | Use neither constructor directly: use the ImplementObjectType macro.
|
---|
| 38 | @param typeName The name of type.
|
---|
| 39 | Used only in debug builds for debugging purposes. */
|
---|
| 40 | FUObjectType(const char* typeName);
|
---|
| 41 |
|
---|
| 42 | /** [INTERNAL] Constructor: do not use directly.
|
---|
| 43 | Use the ImplementObjectType macro.
|
---|
| 44 | @param parent The parent class object type.
|
---|
| 45 | @param typeName The name of type.
|
---|
| 46 | Used only in debug builds for debugging purposes. */
|
---|
| 47 | FUObjectType(const FUObjectType& parent, const char* typeName);
|
---|
| 48 |
|
---|
| 49 | /** Retrieves the type of the down-class.
|
---|
| 50 | @return The type of the down-class. The FUObject class
|
---|
| 51 | will return itself as the parent, so be careful when looping down.*/
|
---|
| 52 | const FUObjectType& GetParent() const { return (parent != NULL) ? *parent : *this; }
|
---|
| 53 |
|
---|
| 54 | /** Retrieves whether this object type includes a given object type.
|
---|
| 55 | This function allows you to verify if this object type is
|
---|
| 56 | of a given object type or some up-class of the given object type.
|
---|
| 57 | You should use this comparison function before up-casting an object.
|
---|
| 58 | @param otherType A second object type.
|
---|
| 59 | @return Whether this object type includes the given object type. */
|
---|
| 60 | bool Includes(const FUObjectType& otherType) const;
|
---|
| 61 |
|
---|
| 62 | /** Retrieves whether a given object type is equivalent to this object type.
|
---|
| 63 | @param otherType A second object type.
|
---|
| 64 | @return Whether the two object types are equivalent. */
|
---|
| 65 | inline bool operator==(const FUObjectType& otherType) const { return &otherType == this; }
|
---|
| 66 |
|
---|
| 67 | /** Retrieves whether a given object type is different from this object type.
|
---|
| 68 | @param otherType A second object type.
|
---|
| 69 | @return Whether the two object type are different. */
|
---|
| 70 | inline bool operator!=(const FUObjectType& otherType) const { return &otherType != this; }
|
---|
| 71 | };
|
---|
| 72 |
|
---|
| 73 | /**
|
---|
| 74 | Declares the object type for an object class.
|
---|
| 75 | Use this macro inside the class declarations of up-classes of the FUObject class
|
---|
| 76 | to easily implement RTTI.
|
---|
| 77 | */
|
---|
| 78 | #define DeclareObjectType \
|
---|
| 79 | private: \
|
---|
| 80 | static class FUObjectType __classType; \
|
---|
| 81 | public: \
|
---|
| 82 | static const FUObjectType& GetClassType() { return __classType; } \
|
---|
| 83 | virtual const FUObjectType& GetObjectType() const { return __classType; } \
|
---|
| 84 | private:
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | Implements the object type for an object class.
|
---|
| 88 | Use this macro inside your code files only to create the objects
|
---|
| 89 | necessary to support RTTI in your up-classes of the FUObject class.
|
---|
| 90 | @param ClassName The name of the class.
|
---|
| 91 | @param ParentClassName The name of the down-class of the given class.
|
---|
| 92 | */
|
---|
| 93 | #define ImplementObjectType(ClassName, ParentClassName) \
|
---|
| 94 | FUObjectType ClassName::__classType(ParentClassName::GetClassType(), #ClassName) \
|
---|
| 95 |
|
---|
| 96 | #endif // _FU_OBJECT_TYPE_H_
|
---|