Xrtti.h

00001 /*****************************************************************************\
00002  *                                                                           *
00003  * Xrtti.h                                                                   *
00004  *                                                                           *
00005  * ------------------------------------------------------------------------- *
00006  * Copyright (C) 2007 Bryan Ischo <bryan@ischo.com>                          *
00007  *                                                                           *
00008  * This program is free software; you can redistribute it and/or modify it   *
00009  * under the terms of the GNU General Public License Version 2 as published  *
00010  * by the Free Software Foundation.                                          *
00011  *                                                                           *
00012  * This program is distributed in the hope that it will be useful, but       *
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General *
00015  * Public License for more details.                                          *
00016  *                                                                           *
00017  * You should have received a copy of the GNU General Public License         *
00018  * along with this program; if not, write to:                                *
00019  * The Free Software Foundation, Inc.                                        *
00020  * 51 Franklin Street, Fifth Floor                                           *
00021  * Boston, MA 02110-1301, USA.                                               *
00022  * ------------------------------------------------------------------------- *
00023  *                                                                           *
00024 \*****************************************************************************/
00025 
00026 
00027 #ifndef XRTTI_H
00028 #define XRTTI_H
00029 
00030 #include <typeinfo>
00031 
00036 namespace Xrtti {
00037 
00038 #if 0 // This fixes indentation in emacs
00039 }
00040 #endif
00041 
00042 
00047 typedef XRTTI_U32_ARCH     U32;       
00048 typedef XRTTI_S32_ARCH     S32;       
00055 class Argument;
00056 class Array;
00057 class ArrayOrPointer;
00058 class Base;
00059 class Class;
00060 class Constructor;
00061 class ConstructorSignature;
00062 class Context;
00063 class Destructor;
00064 class DestructorSignature;
00065 class Enumeration;
00066 class EnumerationValue;
00067 class Field;
00068 class Method;
00069 class MethodSignature;
00070 class Namespace;
00071 class Pointer;
00072 class Structure;
00073 class Struct;
00074 class Type;
00075 class TypeEnumeration;
00076 class TypeFunction;
00077 class TypeStructure;
00078 class TypeUnion;
00079 class Union;
00080 
00081 
00086 typedef enum AccessType
00087 {
00088     AccessType_Public,
00089     AccessType_Protected,
00090     AccessType_Private
00091 } AccessType;
00092 
00093 
00098 class Context
00099 {
00100 public:
00101 
00105     enum Type
00106     {
00107         Type_Class          = 0,
00108         Type_Namespace      = 1,
00109         Type_Struct         = 2,
00110         Type_Union          = 3
00111     };
00112 
00116     virtual ~Context() { }
00117 
00132     bool operator ==(const Context &other) const;
00133 
00141     bool operator !=(const Context &other) const
00142         { return !(*this == other); }
00143 
00155     virtual Type GetType() const = 0;
00156 
00162     virtual const char *GetName() const = 0;
00163 
00172     virtual const char *GetFullName() const = 0;
00173 
00178     virtual const Context *GetContext() const = 0;
00179 };
00180 
00181 
00186 class Namespace : public Context
00187 {
00188 public:
00189 
00193     virtual ~Namespace() { }
00194 
00200     virtual Type GetType() const
00201     {
00202         return Type_Namespace;
00203     }
00204 };
00205 
00206 
00211 class Structure : public Context
00212 {
00213 public:
00214 
00218     virtual ~Structure() { }
00219 
00234     bool operator ==(const Structure &other) const;
00235 
00243     bool operator !=(const Structure &other) const
00244         { return !(*this == other); }
00245 
00256     virtual bool IsIncomplete() const = 0;
00257 
00258     
00295     virtual bool HasStructureName() const = 0;
00296     
00297 
00305     virtual AccessType GetAccessType() const = 0;
00306 
00321     virtual const std::type_info *GetTypeInfo() const = 0;
00322 
00332     virtual U32 GetBaseCount() const = 0;
00333 
00340     virtual const Base &GetBase(U32 index) const = 0;
00341 
00347     virtual U32 GetFriendCount() const = 0;
00348 
00356     virtual const Structure &GetFriend(U32 index) const = 0;
00357 
00363     virtual U32 GetFieldCount() const = 0;
00364 
00374     virtual const Field &GetField(U32 index) const = 0;
00375 
00384     virtual bool IsAnonymous() const = 0;
00385 
00391     virtual U32 GetConstructorCount() const = 0;
00392 
00399     virtual const Constructor &GetConstructor(U32 index) const = 0;
00400 
00406     virtual bool HasDestructor() const = 0;
00407 
00414     virtual const Destructor &GetDestructor() const = 0;
00415 
00425     virtual bool IsCreatable() const = 0;
00426 
00436     virtual void *Create() const = 0;
00437 
00448     virtual void *CreateArray(U32 count) const = 0;
00449 
00459     virtual bool IsDeletable() const = 0;
00460 
00466     virtual void Delete(void *pInstance) const = 0;
00467 
00473     virtual void DeleteArray(void *pInstanceArray) const = 0;
00474 };
00475 
00476 
00484 class Base
00485 {
00486 public:
00487 
00491     virtual ~Base() { }
00492 
00507     bool operator ==(const Base &other) const;
00508 
00516     bool operator !=(const Base &other) const
00517         { return !(*this == other); }
00518 
00526     virtual AccessType GetAccessType() const = 0;
00527 
00535     virtual bool IsVirtual() const = 0;
00536 
00542     virtual const Structure &GetStructure() const = 0;
00543     
00552     virtual bool IsCastable() const = 0;
00553 
00574     virtual void *CastSubclass(void *pObject) = 0;
00575 };
00576 
00577 
00584 class Union : public Structure
00585 {
00586 public:
00587 
00591     virtual ~Union() { }
00592 
00607     bool operator ==(const Context &other) const
00608     {
00609         if (other.GetType() != Type_Union) {
00610             return false;
00611         }
00612 
00613         return (*this == (const Union &) other);
00614     }
00615 
00623     bool operator !=(const Context &other) const
00624         { return !(*this == other); }
00625 
00640     bool operator ==(const Union &other) const
00641         { return (((const Structure *) this)->Structure::operator == 
00642                   ((const Structure &) other)); }
00643 
00651     bool operator !=(const Union &other) const
00652         { return !(*this == other); }
00653 
00659     virtual Type GetType() const
00660     {
00661         return Type_Union;
00662     }
00663 };
00664 
00665 
00669 class Struct : public Structure
00670 {
00671 public:
00672 
00676     virtual ~Struct() { }
00677 
00692     bool operator ==(const Context &other) const
00693     {
00694         if (other.GetType() != Type_Struct) {
00695             return false;
00696         }
00697 
00698         return (*this == (const Struct &) other);
00699     }
00700 
00708     bool operator !=(const Context &other) const
00709         { return !(*this == other); }
00710 
00725     bool operator ==(const Struct &other) const;
00726 
00734     bool operator !=(const Struct &other) const
00735         { return !(*this == other); }
00736 
00742     virtual Type GetType() const
00743     {
00744         return Type_Struct;
00745     }
00746 
00754     virtual bool IsAbstract() const = 0;
00755 
00761     virtual U32 GetMethodCount() const = 0;
00762 
00769     virtual const Method &GetMethod(U32 index) const = 0;
00770 };
00771 
00772 
00776 class Class : public Struct
00777 {
00778 public:
00779 
00783     virtual ~Class() { }
00784 
00799     bool operator ==(const Context &other) const
00800     {
00801         if (other.GetType() != Type_Class) {
00802             return false;
00803         }
00804 
00805         return (*this == (const Class &) other);
00806     }
00807 
00815     bool operator !=(const Context &other) const
00816         { return !(*this == other); }
00817 
00832     bool operator ==(const Class &other) const
00833         { return (((const Struct *) this)->Struct::operator == 
00834                   ((const Struct &) other)); }
00835 
00843     bool operator !=(const Class &other) const
00844         { return !(*this == other); }
00845 
00851     virtual Type GetType() const
00852     {
00853         return Type_Class;
00854     }
00855 };
00856 
00857 
00862 class Member
00863 {
00864 public:
00865 
00869     virtual ~Member() { }
00870 
00885     bool operator ==(const Member &other) const;
00886 
00894     bool operator !=(const Member &other) const
00895         { return !(*this == other); }
00896 
00902     virtual AccessType GetAccessType() const = 0;
00903 
00910     virtual const Context &GetContext() const = 0;
00911 
00917     virtual const char *GetName() const = 0;
00918 
00924     virtual bool IsStatic() const = 0;
00925 };
00926 
00927 
00931 class Field : public Member
00932 {
00933 public:
00934 
00938     virtual ~Field() { }
00939 
00954     bool operator ==(const Field &other) const;
00955 
00963     bool operator !=(const Field &other) const
00964         { return !(*this == other); }
00965 
00971     virtual const Type &GetType() const = 0;
00972 
00980     virtual U32 GetBitfieldBitCount() const = 0;
00981     
00990     virtual bool HasOffsetof() const = 0;
00991 
01002     virtual U32 GetOffset() const = 0;
01003 
01012     virtual bool IsAccessible() const = 0;
01013 
01024     virtual void *Get(void *pInstance) const = 0;
01025 };
01026 
01027 
01032 class Argument
01033 {
01034 public:
01035 
01039     virtual ~Argument() { }
01040 
01055     bool operator ==(const Argument &other) const;
01056 
01064     bool operator !=(const Argument &other) const
01065         { return !(*this == other); }
01066 
01072     virtual const Type &GetType() const = 0;
01073 
01079     virtual bool HasDefault() const = 0;
01080 
01088     virtual const void *GetDefault() const = 0;
01089 };
01090 
01091 
01095 class DestructorSignature
01096 {
01097 public:
01098 
01102     virtual ~DestructorSignature() { }
01103 
01118     bool operator ==(const DestructorSignature &other) const;
01119 
01127     bool operator !=(const DestructorSignature &other) const
01128         { return !(*this == other); }
01129 
01137     virtual U32 GetThrowCount() const = 0;
01138 
01147     virtual const Type &GetThrow(U32 index) const = 0;
01148 };
01149 
01150 
01154 class ConstructorSignature : public DestructorSignature
01155 {
01156 public:
01157 
01161     virtual ~ConstructorSignature() { }
01162 
01177     bool operator ==(const ConstructorSignature &other) const;
01178 
01186     bool operator !=(const ConstructorSignature &other) const
01187         { return !(*this == other); }
01188 
01194     virtual U32 GetArgumentCount() const = 0;
01195 
01201     virtual const Argument &GetArgument(U32 index) const = 0;
01202 
01210     virtual bool HasEllipsis() const = 0;
01211 };
01212 
01213 
01217 class MethodSignature : public ConstructorSignature
01218 {
01219 public:
01220 
01224     virtual ~MethodSignature() { }
01225 
01240     bool operator ==(const MethodSignature &other) const;
01241 
01249     bool operator !=(const MethodSignature &other) const
01250         { return !(*this == other); }
01251 
01257     virtual const Type &GetReturnType() const = 0;
01258 };
01259 
01260 
01264 class Destructor : public Member
01265 {
01266 public:
01267 
01271     virtual ~Destructor() { }
01272 
01287     bool operator ==(const Destructor &other) const;
01288 
01296     bool operator !=(const Destructor &other) const
01297         { return !(*this == other); }
01298 
01304     virtual bool IsVirtual() const = 0;
01305 
01311     virtual bool IsPureVirtual() const = 0;
01312 
01318     virtual const DestructorSignature &GetSignature() const = 0;
01319 
01327     virtual bool IsInvokeable() const = 0;
01328 
01337     virtual void Invoke(void *pInstance) const = 0;
01338 };
01339 
01340 
01344 class Constructor : public Member
01345 {
01346 public:
01347 
01351     virtual ~Constructor() { }
01352 
01367     bool operator ==(const Constructor &other) const;
01368 
01376     bool operator !=(const Constructor &other) const
01377         { return !(*this == other); }
01378 
01384     virtual const ConstructorSignature &GetSignature() const = 0;
01385 
01392     virtual const char *GetArgumentName(U32 index) const = 0;
01393 
01401     virtual bool IsInvokeable() const = 0;
01402 
01415     virtual void *Invoke(void **pArgumentValues) const = 0;
01416 };
01417 
01418 
01422 class Method : public Member
01423 {
01424 public:
01425 
01429     virtual ~Method() { }
01430 
01445     bool operator ==(const Method &other) const;
01446 
01454     bool operator !=(const Method &other) const
01455         { return !(*this == other); }
01456 
01462     virtual bool IsOperatorMethod() const = 0;
01463 
01469     virtual bool IsConst() const = 0;
01470 
01476     virtual bool IsVirtual() const = 0;
01477 
01483     virtual bool IsPureVirtual() const = 0;
01484 
01490     virtual const MethodSignature &GetSignature() const = 0;
01491 
01498     virtual const char *GetArgumentName(U32 index) const = 0;
01499 
01507     virtual bool IsInvokeable() const = 0;
01508 
01526     virtual void Invoke(void *pInstance, void *pReturnValue, 
01527                         void **pArgumentValues) const = 0;
01528 };
01529 
01530 
01543 class Type
01544 {
01545 public:
01546     
01550     virtual ~Type() { }
01551 
01566     bool operator ==(const Type &other) const;
01567 
01575     bool operator !=(const Type &other) const
01576         { return !(*this == other); }
01577 
01592     enum BaseType
01593     {
01594         BaseType_Void                    = 0,
01595         BaseType_Bool                    = 1,
01596         BaseType_Char                    = 2,
01597         BaseType_Unsigned_Char           = 3,
01598         BaseType_WChar                   = 4,
01599         BaseType_Short                   = 5,
01600         BaseType_Unsigned_Short          = 6,
01601         BaseType_Int                     = 7,
01602         BaseType_Unsigned_Int            = 8,
01603         BaseType_Long                    = 9,
01604         BaseType_Unsigned_Long           = 10,
01605         BaseType_Long_Long               = 11,
01606         BaseType_Unsigned_Long_Long      = 12,
01607         BaseType_Float                   = 13,
01608         BaseType_Double                  = 14,
01609         BaseType_Long_Double             = 15,
01610         BaseType_Enumeration             = 16,
01611         BaseType_Function                = 17,
01612         BaseType_Structure               = 18
01613     };
01614 
01620     virtual BaseType GetBaseType() const = 0;
01621 
01628     virtual bool IsConst() const = 0;
01629 
01636     virtual bool IsVolatile() const = 0;
01637 
01644     virtual bool IsReference() const = 0;
01645 
01652     virtual U32 GetArrayOrPointerCount() const = 0;
01653 
01660     virtual const ArrayOrPointer &GetArrayOrPointer(U32 index) const = 0;
01661 };
01662 
01663 
01667 class ArrayOrPointer
01668 {
01669 public:
01670 
01674     enum Type
01675     {
01676         Type_Array       = 0,
01677         Type_Pointer     = 1
01678     };
01679 
01680     virtual ~ArrayOrPointer() { }
01681 
01691     virtual Type GetType() const = 0;
01692 };
01693 
01694 
01698 class Array : public ArrayOrPointer
01699 {
01700 public:
01701 
01705     virtual ~Array() { }
01706 
01721     bool operator ==(const ArrayOrPointer &other) const
01722     {
01723         if (other.GetType() != Type_Array) {
01724             return false;
01725         }
01726 
01727         return (*this == (const Array &) other);
01728     }
01729 
01737     bool operator !=(const ArrayOrPointer &other) const
01738         { return !(*this == other); }
01739 
01754     bool operator ==(const Array &other) const;
01755 
01763     bool operator !=(const Array &other) const
01764         { return !(*this == other); }
01765 
01771     virtual Type GetType() const
01772     {
01773         return Type_Array;
01774     }
01775 
01783     virtual bool IsUnbounded() const = 0;
01784 
01792     virtual U32 GetElementCount() const  = 0;
01793 };
01794 
01795 
01800 class Pointer : public ArrayOrPointer
01801 {
01802 public:
01803 
01807     virtual ~Pointer() { }
01808 
01823     bool operator ==(const ArrayOrPointer &other) const
01824     {
01825         if (other.GetType() != Type_Pointer) {
01826             return false;
01827         }
01828 
01829         return (*this == (const Pointer &) other);
01830     }
01831 
01839     bool operator !=(const ArrayOrPointer &other) const
01840         { return !(*this == other); }
01841 
01856     bool operator ==(const Pointer &other) const;
01857 
01865     bool operator !=(const Pointer &other) const
01866         { return !(*this == other); }
01867 
01873     virtual Type GetType() const
01874     {
01875         return Type_Pointer;
01876     }
01877 
01884     virtual bool IsConst() const = 0;
01885 
01892     virtual bool IsVolatile() const = 0;
01893 };
01894 
01895 
01899 class Enumeration
01900 {
01901 public:
01902 
01906     virtual ~Enumeration() { }
01907 
01922     bool operator ==(const Enumeration &other) const;
01923 
01931     bool operator !=(const Enumeration &other) const
01932         { return !(*this == other); }
01933 
01941     virtual AccessType GetAccessType() const = 0;
01942 
01948     virtual const Context &GetContext() const = 0;
01949 
01955     virtual const char *GetName() const = 0;
01956     
01962     virtual U32 GetValueCount() const = 0;
01963 
01970     virtual const EnumerationValue &GetValue(U32 index) const = 0;
01971 };
01972 
01973 
01977 class EnumerationValue
01978 {
01979 public:
01980 
01984     virtual ~EnumerationValue() { }
01985 
02000     bool operator ==(const EnumerationValue &other) const;
02001 
02009     bool operator !=(const EnumerationValue &other) const
02010         { return !(*this == other); }
02011 
02017     virtual const char *GetName() const = 0;
02018 
02024     virtual S32 GetValue() const = 0;
02025 };
02026 
02027 
02031 class TypeEnumeration : public Type
02032 {
02033 public:
02034 
02038     virtual ~TypeEnumeration() { }
02039 
02054     bool operator ==(const TypeEnumeration &other) const;
02055 
02063     bool operator !=(const TypeEnumeration &other) const
02064         { return !(*this == other); }
02065 
02073     virtual const Enumeration &GetEnumeration() const = 0;
02074 };
02075 
02076 
02080 class TypeFunction : public Type
02081 {
02082 public:
02083 
02098     bool operator ==(const TypeFunction &other) const;
02099 
02107     bool operator !=(const TypeFunction &other) const
02108         { return !(*this == other); }
02109 
02115     virtual const MethodSignature &GetSignature() const = 0;
02116 };
02117 
02118 
02123 class TypeStructure : public Type
02124 {
02125 public:
02126 
02130     virtual ~TypeStructure() { }
02131 
02146     bool operator ==(const TypeStructure &other) const;
02147 
02155     bool operator !=(const TypeStructure &other) const
02156         { return !(*this == other); }
02157 
02163     virtual const Structure &GetStructure() const = 0;
02164 };
02165 
02166 
02189 bool Equals(const Context &c1, const Context &c2);
02190 
02208 bool Equals(const Type &type1, const Type &type2);
02209 
02210 
02223 U32 GetContextCount();
02224 
02234 const Context *GetContext(U32 index);
02235 
02246 const Context *LookupContext(const char *pFullName);
02247 
02258 const Structure *LookupStructure(const std::type_info &typeinfo);
02259 
02260 }; // namespace Xrtti
02261 
02262 
02263 #endif // XRTTI_H

Generated on Fri Jul 6 22:48:47 2007 by  doxygen 1.4.6