00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef XRTTI_H
00028 #define XRTTI_H
00029
00030 #include <inttypes.h>
00031 #include <typeinfo>
00032
00037 namespace Xrtti {
00038
00039 #if 0 // This fixes indentation in emacs
00040 }
00041 #endif
00042
00043
00048 typedef uint32_t u32;
00049 typedef int32_t s32;
00056 class Argument;
00057 class Array;
00058 class ArrayOrPointer;
00059 class Base;
00060 class Class;
00061 class Constructor;
00062 class ConstructorSignature;
00063 class Context;
00064 class Destructor;
00065 class DestructorSignature;
00066 class Enumeration;
00067 class EnumerationValue;
00068 class Field;
00069 class Method;
00070 class MethodSignature;
00071 class Namespace;
00072 class Pointer;
00073 class Structure;
00074 class Struct;
00075 class Type;
00076 class TypeEnumeration;
00077 class TypeFunction;
00078 class TypeStructure;
00079 class TypeUnion;
00080 class Union;
00081
00082
00087 typedef enum AccessType
00088 {
00089 AccessType_Public,
00090 AccessType_Protected,
00091 AccessType_Private
00092 } AccessType;
00093
00094
00099 class Context
00100 {
00101 public:
00102
00106 enum Type
00107 {
00108 Type_Class = 0,
00109 Type_Namespace = 1,
00110 Type_Struct = 2,
00111 Type_Union = 3
00112 };
00113
00117 virtual ~Context() { }
00118
00133 bool operator ==(const Context &other) const;
00134
00142 bool operator !=(const Context &other) const
00143 { return !(*this == other); }
00144
00156 virtual Type GetType() const = 0;
00157
00163 virtual const char *GetName() const = 0;
00164
00173 virtual const char *GetFullName() const = 0;
00174
00179 virtual const Context *GetContext() const = 0;
00180 };
00181
00182
00187 class Namespace : public Context
00188 {
00189 public:
00190
00194 virtual ~Namespace() { }
00195
00201 virtual Type GetType() const
00202 {
00203 return Type_Namespace;
00204 }
00205 };
00206
00207
00212 class Structure : public Context
00213 {
00214 public:
00215
00219 virtual ~Structure() { }
00220
00235 bool operator ==(const Structure &other) const;
00236
00244 bool operator !=(const Structure &other) const
00245 { return !(*this == other); }
00246
00257 virtual bool IsIncomplete() const = 0;
00258
00266 virtual bool HasSizeof() const = 0;
00267
00277 virtual u32 GetSizeof() const = 0;
00278
00315 virtual bool HasStructureName() const = 0;
00316
00324 virtual AccessType GetAccessType() const = 0;
00325
00340 virtual const std::type_info *GetTypeInfo() const = 0;
00341
00351 virtual u32 GetBaseCount() const = 0;
00352
00359 virtual const Base &GetBase(u32 index) const = 0;
00360
00366 virtual u32 GetFriendCount() const = 0;
00367
00375 virtual const Structure &GetFriend(u32 index) const = 0;
00376
00382 virtual u32 GetFieldCount() const = 0;
00383
00393 virtual const Field &GetField(u32 index) const = 0;
00394
00404 virtual bool IsAnonymous() const = 0;
00405
00411 virtual u32 GetConstructorCount() const = 0;
00412
00419 virtual const Constructor &GetConstructor(u32 index) const = 0;
00420
00426 virtual bool HasDestructor() const = 0;
00427
00434 virtual const Destructor &GetDestructor() const = 0;
00435
00445 virtual bool IsCreatable() const = 0;
00446
00456 virtual void *Create() const = 0;
00457
00468 virtual void *CreateArray(u32 count) const = 0;
00469
00479 virtual bool IsDeletable() const = 0;
00480
00486 virtual void Delete(void *pInstance) const = 0;
00487
00493 virtual void DeleteArray(void *pInstanceArray) const = 0;
00494 };
00495
00496
00504 class Base
00505 {
00506 public:
00507
00511 virtual ~Base() { }
00512
00527 bool operator ==(const Base &other) const;
00528
00536 bool operator !=(const Base &other) const
00537 { return !(*this == other); }
00538
00546 virtual AccessType GetAccessType() const = 0;
00547
00555 virtual bool IsVirtual() const = 0;
00556
00562 virtual const Structure &GetStructure() const = 0;
00563
00572 virtual bool IsCastable() const = 0;
00573
00594 virtual void *CastSubclass(void *pObject) const = 0;
00595 };
00596
00597
00604 class Union : public Structure
00605 {
00606 public:
00607
00611 virtual ~Union() { }
00612
00627 bool operator ==(const Context &other) const
00628 {
00629 if (other.GetType() != Type_Union) {
00630 return false;
00631 }
00632
00633 return (*this == (const Union &) other);
00634 }
00635
00643 bool operator !=(const Context &other) const
00644 { return !(*this == other); }
00645
00660 bool operator ==(const Union &other) const
00661 { return (((const Structure *) this)->Structure::operator ==
00662 ((const Structure &) other)); }
00663
00671 bool operator !=(const Union &other) const
00672 { return !(*this == other); }
00673
00679 virtual Type GetType() const
00680 {
00681 return Type_Union;
00682 }
00683 };
00684
00685
00689 class Struct : public Structure
00690 {
00691 public:
00692
00696 virtual ~Struct() { }
00697
00712 bool operator ==(const Context &other) const
00713 {
00714 if (other.GetType() != Type_Struct) {
00715 return false;
00716 }
00717
00718 return (*this == (const Struct &) other);
00719 }
00720
00728 bool operator !=(const Context &other) const
00729 { return !(*this == other); }
00730
00745 bool operator ==(const Struct &other) const;
00746
00754 bool operator !=(const Struct &other) const
00755 { return !(*this == other); }
00756
00762 virtual Type GetType() const
00763 {
00764 return Type_Struct;
00765 }
00766
00774 virtual bool IsAbstract() const = 0;
00775
00781 virtual u32 GetMethodCount() const = 0;
00782
00789 virtual const Method &GetMethod(u32 index) const = 0;
00790 };
00791
00792
00796 class Class : public Struct
00797 {
00798 public:
00799
00803 virtual ~Class() { }
00804
00819 bool operator ==(const Context &other) const
00820 {
00821 if (other.GetType() != Type_Class) {
00822 return false;
00823 }
00824
00825 return (*this == (const Class &) other);
00826 }
00827
00835 bool operator !=(const Context &other) const
00836 { return !(*this == other); }
00837
00852 bool operator ==(const Class &other) const
00853 { return (((const Struct *) this)->Struct::operator ==
00854 ((const Struct &) other)); }
00855
00863 bool operator !=(const Class &other) const
00864 { return !(*this == other); }
00865
00871 virtual Type GetType() const
00872 {
00873 return Type_Class;
00874 }
00875 };
00876
00877
00882 class Member
00883 {
00884 public:
00885
00889 virtual ~Member() { }
00890
00905 bool operator ==(const Member &other) const;
00906
00914 bool operator !=(const Member &other) const
00915 { return !(*this == other); }
00916
00922 virtual AccessType GetAccessType() const = 0;
00923
00930 virtual const Context &GetContext() const = 0;
00931
00937 virtual const char *GetName() const = 0;
00938
00944 virtual bool IsStatic() const = 0;
00945 };
00946
00947
00951 class Field : public Member
00952 {
00953 public:
00954
00958 virtual ~Field() { }
00959
00974 bool operator ==(const Field &other) const;
00975
00983 bool operator !=(const Field &other) const
00984 { return !(*this == other); }
00985
00991 virtual const Type &GetType() const = 0;
00992
01000 virtual u32 GetBitfieldBitCount() const = 0;
01001
01010 virtual bool HasOffset() const = 0;
01011
01022 virtual u32 GetOffset() const = 0;
01023
01032 virtual bool IsAccessible() const = 0;
01033
01048 virtual void *Get(void *pInstance) const = 0;
01049 };
01050
01051
01056 class Argument
01057 {
01058 public:
01059
01063 virtual ~Argument() { }
01064
01079 bool operator ==(const Argument &other) const;
01080
01088 bool operator !=(const Argument &other) const
01089 { return !(*this == other); }
01090
01096 virtual const Type &GetType() const = 0;
01097
01103 virtual bool HasDefault() const = 0;
01104
01113 virtual const char *GetDefault() const = 0;
01114 };
01115
01116
01120 class DestructorSignature
01121 {
01122 public:
01123
01127 virtual ~DestructorSignature() { }
01128
01143 bool operator ==(const DestructorSignature &other) const;
01144
01152 bool operator !=(const DestructorSignature &other) const
01153 { return !(*this == other); }
01154
01162 virtual u32 GetThrowCount() const = 0;
01163
01172 virtual const Type &GetThrow(u32 index) const = 0;
01173 };
01174
01175
01179 class ConstructorSignature : public DestructorSignature
01180 {
01181 public:
01182
01186 virtual ~ConstructorSignature() { }
01187
01202 bool operator ==(const ConstructorSignature &other) const;
01203
01211 bool operator !=(const ConstructorSignature &other) const
01212 { return !(*this == other); }
01213
01219 virtual u32 GetArgumentCount() const = 0;
01220
01226 virtual const Argument &GetArgument(u32 index) const = 0;
01227
01235 virtual bool HasEllipsis() const = 0;
01236 };
01237
01238
01242 class MethodSignature : public ConstructorSignature
01243 {
01244 public:
01245
01249 virtual ~MethodSignature() { }
01250
01265 bool operator ==(const MethodSignature &other) const;
01266
01274 bool operator !=(const MethodSignature &other) const
01275 { return !(*this == other); }
01276
01282 virtual const Type &GetReturnType() const = 0;
01283 };
01284
01285
01289 class Destructor : public Member
01290 {
01291 public:
01292
01296 virtual ~Destructor() { }
01297
01312 bool operator ==(const Destructor &other) const;
01313
01321 bool operator !=(const Destructor &other) const
01322 { return !(*this == other); }
01323
01329 virtual bool IsVirtual() const = 0;
01330
01336 virtual bool IsPureVirtual() const = 0;
01337
01343 virtual const DestructorSignature &GetSignature() const = 0;
01344
01352 virtual bool IsInvokeable() const = 0;
01353
01362 virtual void Invoke(void *pInstance) const = 0;
01363 };
01364
01365
01369 class Constructor : public Member
01370 {
01371 public:
01372
01376 virtual ~Constructor() { }
01377
01392 bool operator ==(const Constructor &other) const;
01393
01401 bool operator !=(const Constructor &other) const
01402 { return !(*this == other); }
01403
01409 virtual const ConstructorSignature &GetSignature() const = 0;
01410
01417 virtual const char *GetArgumentName(u32 index) const = 0;
01418
01426 virtual bool IsInvokeable() const = 0;
01427
01440 virtual void *Invoke(void **pArgumentValues) const = 0;
01441 };
01442
01443
01447 class Method : public Member
01448 {
01449 public:
01450
01454 virtual ~Method() { }
01455
01470 bool operator ==(const Method &other) const;
01471
01479 bool operator !=(const Method &other) const
01480 { return !(*this == other); }
01481
01487 virtual bool IsOperatorMethod() const = 0;
01488
01494 virtual bool IsConst() const = 0;
01495
01501 virtual bool IsVirtual() const = 0;
01502
01508 virtual bool IsPureVirtual() const = 0;
01509
01515 virtual const MethodSignature &GetSignature() const = 0;
01516
01523 virtual const char *GetArgumentName(u32 index) const = 0;
01524
01532 virtual bool IsInvokeable() const = 0;
01533
01551 virtual void Invoke(void *pInstance, void *pReturnValue,
01552 void **pArgumentValues) const = 0;
01553 };
01554
01555
01568 class Type
01569 {
01570 public:
01571
01575 virtual ~Type() { }
01576
01591 bool operator ==(const Type &other) const;
01592
01600 bool operator !=(const Type &other) const
01601 { return !(*this == other); }
01602
01617 enum BaseType
01618 {
01619 BaseType_Void = 0,
01620 BaseType_Bool = 1,
01621 BaseType_Char = 2,
01622 BaseType_Unsigned_Char = 3,
01623 BaseType_WChar = 4,
01624 BaseType_Short = 5,
01625 BaseType_Unsigned_Short = 6,
01626 BaseType_Int = 7,
01627 BaseType_Unsigned_Int = 8,
01628 BaseType_Long = 9,
01629 BaseType_Unsigned_Long = 10,
01630 BaseType_Long_Long = 11,
01631 BaseType_Unsigned_Long_Long = 12,
01632 BaseType_Float = 13,
01633 BaseType_Double = 14,
01634 BaseType_Long_Double = 15,
01635 BaseType_Enumeration = 16,
01636 BaseType_Function = 17,
01637 BaseType_Structure = 18
01638 };
01639
01645 virtual BaseType GetBaseType() const = 0;
01646
01653 virtual bool IsConst() const = 0;
01654
01661 virtual bool IsVolatile() const = 0;
01662
01669 virtual bool IsReference() const = 0;
01670
01677 virtual u32 GetArrayOrPointerCount() const = 0;
01678
01685 virtual const ArrayOrPointer &GetArrayOrPointer(u32 index) const = 0;
01686 };
01687
01688
01692 class ArrayOrPointer
01693 {
01694 public:
01695
01699 enum Type
01700 {
01701 Type_Array = 0,
01702 Type_Pointer = 1
01703 };
01704
01705 virtual ~ArrayOrPointer() { }
01706
01716 virtual Type GetType() const = 0;
01717 };
01718
01719
01723 class Array : public ArrayOrPointer
01724 {
01725 public:
01726
01730 virtual ~Array() { }
01731
01746 bool operator ==(const ArrayOrPointer &other) const
01747 {
01748 if (other.GetType() != Type_Array) {
01749 return false;
01750 }
01751
01752 return (*this == (const Array &) other);
01753 }
01754
01762 bool operator !=(const ArrayOrPointer &other) const
01763 { return !(*this == other); }
01764
01779 bool operator ==(const Array &other) const;
01780
01788 bool operator !=(const Array &other) const
01789 { return !(*this == other); }
01790
01796 virtual Type GetType() const
01797 {
01798 return Type_Array;
01799 }
01800
01808 virtual bool IsUnbounded() const = 0;
01809
01817 virtual u32 GetElementCount() const = 0;
01818 };
01819
01820
01825 class Pointer : public ArrayOrPointer
01826 {
01827 public:
01828
01832 virtual ~Pointer() { }
01833
01848 bool operator ==(const ArrayOrPointer &other) const
01849 {
01850 if (other.GetType() != Type_Pointer) {
01851 return false;
01852 }
01853
01854 return (*this == (const Pointer &) other);
01855 }
01856
01864 bool operator !=(const ArrayOrPointer &other) const
01865 { return !(*this == other); }
01866
01881 bool operator ==(const Pointer &other) const;
01882
01890 bool operator !=(const Pointer &other) const
01891 { return !(*this == other); }
01892
01898 virtual Type GetType() const
01899 {
01900 return Type_Pointer;
01901 }
01902
01909 virtual bool IsConst() const = 0;
01910
01917 virtual bool IsVolatile() const = 0;
01918 };
01919
01920
01924 class Enumeration
01925 {
01926 public:
01927
01931 virtual ~Enumeration() { }
01932
01947 bool operator ==(const Enumeration &other) const;
01948
01956 bool operator !=(const Enumeration &other) const
01957 { return !(*this == other); }
01958
01966 virtual AccessType GetAccessType() const = 0;
01967
01973 virtual const Context &GetContext() const = 0;
01974
01980 virtual const char *GetName() const = 0;
01981
01987 virtual u32 GetValueCount() const = 0;
01988
01995 virtual const EnumerationValue &GetValue(u32 index) const = 0;
01996 };
01997
01998
02002 class EnumerationValue
02003 {
02004 public:
02005
02009 virtual ~EnumerationValue() { }
02010
02025 bool operator ==(const EnumerationValue &other) const;
02026
02034 bool operator !=(const EnumerationValue &other) const
02035 { return !(*this == other); }
02036
02042 virtual const char *GetName() const = 0;
02043
02049 virtual s32 GetValue() const = 0;
02050 };
02051
02052
02056 class TypeEnumeration : public Type
02057 {
02058 public:
02059
02063 virtual ~TypeEnumeration() { }
02064
02079 bool operator ==(const TypeEnumeration &other) const;
02080
02088 bool operator !=(const TypeEnumeration &other) const
02089 { return !(*this == other); }
02090
02098 virtual const Enumeration &GetEnumeration() const = 0;
02099 };
02100
02101
02105 class TypeFunction : public Type
02106 {
02107 public:
02108
02123 bool operator ==(const TypeFunction &other) const;
02124
02132 bool operator !=(const TypeFunction &other) const
02133 { return !(*this == other); }
02134
02140 virtual const MethodSignature &GetSignature() const = 0;
02141 };
02142
02143
02148 class TypeStructure : public Type
02149 {
02150 public:
02151
02155 virtual ~TypeStructure() { }
02156
02171 bool operator ==(const TypeStructure &other) const;
02172
02180 bool operator !=(const TypeStructure &other) const
02181 { return !(*this == other); }
02182
02188 virtual const Structure &GetStructure() const = 0;
02189 };
02190
02191
02214 bool Equals(const Context &c1, const Context &c2);
02215
02233 bool Equals(const Type &type1, const Type &type2);
02234
02235
02248 u32 GetContextCount();
02249
02259 const Context *GetContext(u32 index);
02260
02271 const Context *LookupContext(const char *pFullName);
02272
02283 const Structure *LookupStructure(const std::type_info &typeinfo);
02284
02285 };
02286
02287
02288 #endif // XRTTI_H