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 <typeinfo>
00031
00036 namespace Xrtti {
00037
00038 #if 0 // This fixes indentation in emacs
00039 }
00040 #endif
00041
00052 typedef XRTTI_U32_ARCH U32;
00053 typedef XRTTI_S32_ARCH S32;
00060 class Argument;
00061 class AutoRegister;
00062 class Array;
00063 class Base;
00064 class Class;
00065 class Complete;
00066 class Constructor;
00067 class ConstructorSignature;
00068 class Context;
00069 class Destructor;
00070 class DestructorSignature;
00071 class Enumeration;
00072 class EnumerationValue;
00073 class Field;
00074 typedef struct Generated Generated;
00075 class Incomplete;
00076 class Method;
00077 class MethodSignature;
00078 class Namespace;
00079 class Pointer;
00080 class Structure;
00081 class Struct;
00082 class Type;
00083 class TypeEnumeration;
00084 class TypeFunction;
00085 class TypeStructure;
00086 class TypeUnion;
00087 class Union;
00088
00089
00094 typedef enum AccessType
00095 {
00096 AccessType_Public,
00097 AccessType_Protected,
00098 AccessType_Private
00099 } AccessType;
00100
00101
00108 typedef union Value
00109 {
00110 bool bool_v;
00111 signed char char_v;
00112 unsigned char unsigned_char_v;
00113 wchar_t wchar_v;
00114 signed short short_v;
00115 unsigned short unsigned_short_v;
00116 signed int int_v;
00117 unsigned int unsigned_int_v;
00118 signed long long_v;
00119 unsigned long unsigned_long_v;
00120 signed long long long_long_v;
00121 unsigned long long unsigned_long_long_v;
00122 float float_v;
00123 double double_v;
00124 long double long_double_v;
00125 void *pointer_v;
00126 }
00127 Value;
00128
00129
00134 class Context
00135 {
00136 public:
00137
00141 enum Type
00142 {
00143 Type_Class = 0,
00144 Type_Incomplete = 1,
00145 Type_Namespace = 2,
00146 Type_Struct = 3,
00147 Type_Union = 4
00148 };
00149
00162 virtual Type GetType() const = 0;
00163
00169 const char *GetName() const
00170 {
00171 return pNameM;
00172 }
00173
00182 const char *GetFullName() const
00183 {
00184 return pFullNameM;
00185 }
00186
00191 const Context *GetParent() const
00192 {
00193 return pParentM;
00194 }
00195
00196 private:
00197
00198 friend class Incomplete;
00199 friend class Namespace;
00200 friend class Structure;
00201
00202
00203 Context() { }
00204 virtual ~Context() { }
00205 Context(const Context &);
00206 Context &operator =(const Context &);
00207
00208 const char *pNameM;
00209
00210 const char *pFullNameM;
00211
00212 Context *pParentM;
00213 };
00214
00215
00223 class Incomplete : public Context
00224 {
00225 public:
00226
00232 virtual Type GetType() const
00233 {
00234 return Type_Incomplete;
00235 }
00236
00237 private:
00238
00239
00240 Incomplete() { }
00241 virtual ~Incomplete() { }
00242 Incomplete(const Incomplete &);
00243 Incomplete &operator =(const Incomplete &);
00244 };
00245
00246
00251 class Namespace : public Context
00252 {
00253 public:
00254
00260 virtual Type GetType() const
00261 {
00262 return Type_Namespace;
00263 }
00264
00265 private:
00266
00267
00268 Namespace() { }
00269 ~Namespace() { }
00270 Namespace(const Namespace &);
00271 Namespace &operator =(const Namespace &);
00272 };
00273
00274
00279 class Structure : public Context
00280 {
00281 public:
00282
00290 AccessType GetAccessType() const
00291 {
00292 return accessTypeM;
00293 }
00294
00309 const std::type_info *GetTypeInfo() const
00310 {
00311 return pTypeInfoM;
00312 }
00313
00323 U32 GetBaseCount() const
00324 {
00325 return baseCountM;
00326 }
00327
00334 const Base &GetBase(U32 index) const;
00335
00341 U32 GetFieldCount() const
00342 {
00343 return fieldCountM;
00344 }
00345
00354 const Field &GetField(U32 index) const;
00355
00364 bool IsAnonymous() const
00365 {
00366 return isAnonymousM;
00367 }
00368
00374 U32 GetConstructorCount() const
00375 {
00376 return constructorCountM;
00377 }
00378
00385 const Constructor &GetConstructor(U32 index) const;
00386
00392 bool HasDestructor() const
00393 {
00394 return pDestructorM ? true : false;
00395 }
00396
00402 const Destructor &GetDestructor() const;
00403
00413 void *Create() const
00414 {
00415 if (pCreateMethodM) {
00416 return (*pCreateMethodM)();
00417 }
00418 else {
00419 return 0;
00420 }
00421 }
00422
00433 void *CreateArray(U32 count) const
00434 {
00435 if (pCreateArrayMethodM) {
00436 return (*pCreateArrayMethodM)(count);
00437 }
00438 else {
00439 return 0;
00440 }
00441 }
00442
00448 void Delete(void *pInstance) const
00449 {
00450 if (pDeleteMethodM) {
00451 (*pDeleteMethodM)(pInstance);
00452 }
00453 }
00454
00460 void DeleteArray(void **pInstanceArray) const
00461 {
00462 if (pDeleteArrayMethodM) {
00463 (*pDeleteArrayMethodM)(pInstanceArray);
00464 }
00465 }
00466
00467 private:
00468
00469 friend class Struct;
00470 friend class Union;
00471
00472
00473 Structure() { }
00474 ~Structure() { }
00475 Structure(const Structure &);
00476 Structure &operator =(const Structure &);
00477
00478 AccessType accessTypeM;
00479
00480 const std::type_info *pTypeInfoM;
00481
00482 U32 baseCountM;
00483
00484 Base *pBasesM;
00485
00486 U32 fieldCountM;
00487
00488 class Field *pFieldsM;
00489
00490 bool isAnonymousM;
00491
00492 U32 constructorCountM;
00493
00494 Constructor *pConstructorsM;
00495
00496 Destructor *pDestructorM;
00497
00498 void *(*pCreateMethodM)();
00499
00500 void *(*pCreateArrayMethodM)(U32);
00501
00502 void (*pDeleteMethodM)(void *);
00503
00504 void (*pDeleteArrayMethodM)(void *);
00505 };
00506
00507
00515 class Base
00516 {
00517 public:
00518
00524 const Structure &GetStructure() const
00525 {
00526 return *pStructureM;
00527 }
00528
00545 U32 GetOffset() const
00546 {
00547 return offsetM;
00548 }
00549
00550 private:
00551
00552
00553 Base() { }
00554 ~Base() { }
00555 Base(const Base &);
00556 Base &operator =(const Base &);
00557
00558 Structure *pStructureM;
00559
00560 U32 offsetM;
00561 };
00562
00563
00570 class Union : public Structure
00571 {
00572 public:
00573
00579 virtual Type GetType() const
00580 {
00581 return Type_Union;
00582 }
00583
00584 private:
00585
00586
00587 Union() { }
00588 ~Union() { }
00589 Union(const Union &);
00590 Union &operator =(const Union &);
00591 };
00592
00593
00597 class Struct : public Structure
00598 {
00599 public:
00600
00606 virtual Type GetType() const
00607 {
00608 return Type_Struct;
00609 }
00610
00618 bool IsAbstract() const
00619 {
00620 return isAbstractM;
00621 }
00622
00628 U32 GetMethodCount() const
00629 {
00630 return methodCountM;
00631 }
00632
00639 const Method &GetMethod(U32 index) const;
00640
00641 private:
00642
00643 friend class Class;
00644
00645
00646 Struct() { }
00647 ~Struct() { }
00648 Struct(const Struct &);
00649 Struct &operator =(const Struct &);
00650
00651 bool isAbstractM;
00652
00653 U32 methodCountM;
00654
00655 Method *pMethodsM;
00656 };
00657
00658
00662 class Class : public Struct
00663 {
00664 public:
00665
00671 virtual Type GetType() const
00672 {
00673 return Type_Class;
00674 }
00675
00676 private:
00677
00678
00679 Class() { }
00680 ~Class() { }
00681 Class(const Class &);
00682 Class &operator =(const Class &);
00683 };
00684
00685
00690 class Member
00691 {
00692 public:
00693
00699 AccessType GetAccessType() const
00700 {
00701 return accessTypeM;
00702 }
00703
00710 const Context &GetContext() const
00711 {
00712 return *pContextM;
00713 }
00714
00720 const char *GetName() const
00721 {
00722 return pNameM;
00723 }
00724
00730 bool IsStatic() const
00731 {
00732 return isStaticM;
00733 }
00734
00735 private:
00736
00737 friend class Constructor;
00738 friend class Destructor;
00739 friend class Field;
00740 friend class Method;
00741
00742
00743 Member() { }
00744 ~Member() { }
00745 Member(const Member &);
00746 Member &operator =(const Member &);
00747
00748 AccessType accessTypeM;
00749
00750 Context *pContextM;
00751
00752 const char *pNameM;
00753
00754 bool isStaticM;
00755 };
00756
00757
00761 class Field : public Member
00762 {
00763 public:
00764
00770 const Type &GetType() const
00771 {
00772 return *pTypeM;
00773 }
00774
00785 U32 GetOffset() const
00786 {
00787 return offsetM;
00788 }
00789
00802 void Get(void *pInstance, Value &returnValue) const
00803 {
00804 (*pGetMethodM)(pInstance, returnValue);
00805 }
00806
00819 void Set(void *pInstance, const Value &value) const
00820 {
00821 (*pSetMethodM)(pInstance, value);
00822 }
00823
00824 private:
00825
00826
00827 Field() { }
00828 ~Field() { }
00829 Field(const Field &);
00830 Field &operator =(const Field &);
00831
00832 Type *pTypeM;
00833
00834 U32 offsetM;
00835
00836 void (*pGetMethodM)(void *, Value &);
00837
00838 void (*pSetMethodM)(void *, const Value &);
00839 };
00840
00841
00846 class Argument
00847 {
00848 public:
00849
00855 const Type &GetType() const
00856 {
00857 return *pTypeM;
00858 }
00859
00865 bool HasDefault() const
00866 {
00867 return hasDefaultM;
00868 }
00869
00877 const Value &GetDefault() const
00878 {
00879 return defaultM;
00880 }
00881
00882 private:
00883
00884
00885 Argument() { }
00886 ~Argument() { }
00887 Argument(const Argument &);
00888 Argument &operator =(const Argument &);
00889
00890 Type *pTypeM;
00891
00892 bool hasDefaultM;
00893
00894 Value defaultM;
00895 };
00896
00897
00901 class DestructorSignature
00902 {
00903 public:
00904
00912 U32 GetThrowCount() const
00913 {
00914 return throwCountM;
00915 }
00916
00925 const Type &GetThrow(U32 index) const
00926 {
00927 return *(pThrowsM[index]);
00928 }
00929
00930 private:
00931
00932 friend class Destructor;
00933 friend class ConstructorSignature;
00934
00935
00936
00937 DestructorSignature() { }
00938 ~DestructorSignature() { }
00939 DestructorSignature(const DestructorSignature &);
00940 DestructorSignature &operator =(const DestructorSignature &);
00941
00942 U32 throwCountM;
00943 Type **pThrowsM;
00944 };
00945
00946
00950 class ConstructorSignature : public DestructorSignature
00951 {
00952 public:
00953
00959 U32 GetArgumentCount() const
00960 {
00961 return argumentCountM;
00962 }
00963
00969 const Argument &GetArgument(U32 index) const
00970 {
00971 return pArgumentsM[index];
00972 }
00973
00981 bool HasEllipsis() const
00982 {
00983 return hasEllipsisM;
00984 }
00985
00986 private:
00987
00988 friend class Constructor;
00989 friend class MethodSignature;
00990
00991
00992
00993 ConstructorSignature() { }
00994 ~ConstructorSignature() { }
00995 ConstructorSignature(const ConstructorSignature &);
00996 ConstructorSignature &operator =(const ConstructorSignature &);
00997
00998 U32 argumentCountM;
00999
01000 Argument *pArgumentsM;
01001
01002 bool hasEllipsisM;
01003 };
01004
01005
01009 class MethodSignature : public ConstructorSignature
01010 {
01011 public:
01012
01018 const Type &GetReturnType() const
01019 {
01020 return *pReturnTypeM;
01021 }
01022
01023 private:
01024
01025 friend class Method;
01026 friend class TypeFunction;
01027
01028
01029
01030 MethodSignature() { }
01031 ~MethodSignature() { }
01032 MethodSignature(const MethodSignature &);
01033 MethodSignature &operator =(const MethodSignature &);
01034
01035 Type *pReturnTypeM;
01036 };
01037
01038
01042 class Destructor : public Member
01043 {
01044 public:
01045
01051 bool IsVirtual() const
01052 {
01053 return isVirtualM;
01054 }
01055
01061 bool IsPureVirtual() const
01062 {
01063 return isPureVirtualM;
01064 }
01065
01071 const DestructorSignature &GetSignature() const
01072 {
01073 return signatureM;
01074 }
01075
01084 void Invoke(void *pInstance) const
01085 {
01086 (*pInvokeDestructorM)(pInstance);
01087 }
01088
01089 private:
01090
01091
01092 Destructor() { }
01093 ~Destructor() { }
01094 Destructor(const Destructor &);
01095 Destructor &operator =(const Destructor &);
01096
01097 bool isVirtualM, isPureVirtualM;
01098
01099 DestructorSignature signatureM;
01100
01101 void (*pInvokeDestructorM)(void *);
01102 };
01103
01104
01108 class Constructor : public Member
01109 {
01110 public:
01111
01117 const ConstructorSignature &GetSignature() const
01118 {
01119 return signatureM;
01120 }
01121
01128 const char *GetArgumentName(U32 index) const
01129 {
01130 return pArgumentNamesM[index];
01131 }
01132
01147 void *Invoke(Value *pArgumentValues) const
01148 {
01149 Value ret;
01150 (*pInvokeConstructorM)(0, ret, pArgumentValues);
01151 return ret.pointer_v;
01152 }
01153
01154 private:
01155
01156
01157 Constructor() { }
01158 ~Constructor() { }
01159 Constructor(const Constructor &);
01160 Constructor &operator =(const Constructor &);
01161
01162 ConstructorSignature signatureM;
01163
01164 const char **pArgumentNamesM;
01165
01166 void (*pInvokeConstructorM)(void *, Value &, Value *);
01167 };
01168
01169
01173 class Method : public Member
01174 {
01175 public:
01176
01182 bool IsConst() const
01183 {
01184 return isConstM;
01185 }
01186
01192 bool IsVirtual() const
01193 {
01194 return isVirtualM;
01195 }
01196
01202 bool IsPureVirtual() const
01203 {
01204 return isPureVirtualM;
01205 }
01206
01212 const MethodSignature &GetSignature() const
01213 {
01214 return signatureM;
01215 }
01216
01223 const char *GetArgumentName(U32 index) const
01224 {
01225 return pArgumentNamesM[index];
01226 }
01227
01248 void Invoke(void *pInstance, Value &returnValue,
01249 Value *pArgumentValues) const
01250 {
01251 (*pInvokeMethodM)(pInstance, returnValue, pArgumentValues);
01252 }
01253
01254 private:
01255
01256
01257 Method() { }
01258 ~Method() { }
01259 Method(const Method &);
01260 Method &operator =(const Method &);
01261
01262 bool isConstM, isVirtualM, isPureVirtualM;
01263
01264 MethodSignature signatureM;
01265
01266 const char **pArgumentNamesM;
01267
01268 void (*pInvokeMethodM)(void *, Value &, Value *);
01269 };
01270
01271
01284 class Type
01285 {
01286 public:
01287
01302 enum BaseType
01303 {
01304 BaseType_Void = 0,
01305 BaseType_Bool = 1,
01306 BaseType_Char = 2,
01307 BaseType_Unsigned_Char = 3,
01308 BaseType_WChar = 4,
01309 BaseType_Short = 5,
01310 BaseType_Unsigned_Short = 6,
01311 BaseType_Int = 7,
01312 BaseType_Unsigned_Int = 8,
01313 BaseType_Long = 9,
01314 BaseType_Unsigned_Long = 10,
01315 BaseType_Long_Long = 11,
01316 BaseType_Unsigned_Long_Long = 12,
01317 BaseType_Float = 13,
01318 BaseType_Double = 14,
01319 BaseType_Long_Double = 15,
01320 BaseType_Bitfield = 16,
01321 BaseType_Enumeration = 17,
01322 BaseType_Function = 18,
01323 BaseType_Structure = 19
01324 };
01325
01331 BaseType GetBaseType() const
01332 {
01333 return baseTypeM;
01334 }
01335
01342 bool IsConst() const
01343 {
01344 return isConstM;
01345 }
01346
01353 bool IsVolatile() const
01354 {
01355 return isVolatileM;
01356 }
01357
01364 bool IsReference() const
01365 {
01366 return isReferenceM;
01367 }
01368
01375 U32 GetBitfieldBitCount() const
01376 {
01377 return bitCountM;
01378 }
01379
01387 U32 GetPointerCount() const
01388 {
01389 return pointerCountM;
01390 }
01391
01401 const Pointer &GetPointer(U32 depth) const;
01402
01408 U32 GetArrayCount() const
01409 {
01410 return arrayCountM;
01411 }
01412
01422 const Array &GetArray(U32 dimension) const;
01423
01424 private:
01425
01426 friend class TypeEnumeration;
01427 friend class TypeFunction;
01428 friend class TypeStructure;
01429
01430
01431 Type() { }
01432 ~Type() { }
01433 Type(const Type &);
01434 Type &operator =(const Type &);
01435
01436 BaseType baseTypeM;
01437
01438 bool isConstM;
01439
01440 bool isVolatileM;
01441
01442 bool isReferenceM;
01443
01444 U32 bitCountM;
01445
01446 U32 pointerCountM;
01447
01448 Pointer *pPointersM;
01449
01450 U32 arrayCountM;
01451
01452 Array *pArraysM;
01453 };
01454
01455
01460 class Pointer
01461 {
01462 public:
01463
01470 bool IsConst() const
01471 {
01472 return isConstM;
01473 }
01474
01481 bool IsVolatile() const
01482 {
01483 return isVolatileM;
01484 }
01485
01486 private:
01487
01488
01489 Pointer() { }
01490 ~Pointer() { }
01491 Pointer(const Pointer &);
01492 Pointer &operator =(const Pointer &);
01493
01494 bool isConstM;
01495
01496 bool isVolatileM;
01497 };
01498
01499
01503 class Array
01504 {
01505 public:
01506
01514 bool IsUnbounded() const
01515 {
01516 return isUnboundedM;
01517 }
01518
01526 U32 GetElementCount() const
01527 {
01528 return elementCountM;
01529 }
01530
01531 private:
01532
01533
01534 Array() { }
01535 ~Array() { }
01536 Array(const Array &);
01537 Array &operator =(const Array &);
01538
01539 bool isUnboundedM;
01540
01541 U32 elementCountM;
01542 };
01543
01544
01548 class Enumeration
01549 {
01550 public:
01551
01559 AccessType GetAccessType() const
01560 {
01561 return accessTypeM;
01562 }
01563
01569 const Context &GetContext() const
01570 {
01571 return *pContextM;
01572 };
01573
01579 const char *GetName() const
01580 {
01581 return pNameM;
01582 }
01583
01589 U32 GetValueCount() const
01590 {
01591 return valueCountM;
01592 }
01593
01600 const EnumerationValue &GetValue(U32 index) const;
01601
01602 private:
01603
01604
01605 Enumeration() { }
01606 ~Enumeration() { }
01607 Enumeration(const Enumeration &);
01608 Enumeration &operator =(const Enumeration &);
01609
01610 AccessType accessTypeM;
01611
01612 Context *pContextM;
01613
01614 const char *pNameM;
01615
01616 U32 valueCountM;
01617
01618 EnumerationValue *pValuesM;
01619 };
01620
01621
01625 class EnumerationValue
01626 {
01627 public:
01628
01634 const char *GetName() const
01635 {
01636 return pNameM;
01637 }
01638
01644 S32 GetValue() const
01645 {
01646 return valueM;
01647 }
01648
01649 private:
01650
01651
01652 EnumerationValue() { }
01653 ~EnumerationValue() { }
01654 EnumerationValue(const EnumerationValue &);
01655 EnumerationValue &operator =(const EnumerationValue &);
01656
01657 const char *pNameM;
01658
01659 S32 valueM;
01660 };
01661
01662
01666 class TypeEnumeration : public Type
01667 {
01668 public:
01669
01677 const Enumeration &GetEnumeration() const
01678 {
01679 return *pEnumerationM;
01680 }
01681
01682 private:
01683
01684
01685 TypeEnumeration() { }
01686 ~TypeEnumeration() { }
01687 TypeEnumeration(const TypeEnumeration &);
01688 TypeEnumeration &operator =(const TypeEnumeration &);
01689
01690 Enumeration *pEnumerationM;
01691 };
01692
01693
01697 class TypeFunction : public Type
01698 {
01699 public:
01700
01706 const MethodSignature &GetSignature() const
01707 {
01708 return signatureM;
01709 }
01710
01711 private:
01712
01713
01714 TypeFunction() { }
01715 ~TypeFunction() { }
01716 TypeFunction(const TypeFunction &);
01717 TypeFunction &operator =(const TypeFunction &);
01718
01719 MethodSignature signatureM;
01720 };
01721
01722
01727 class TypeStructure : public Type
01728 {
01729 public:
01730
01736 const Structure &GetStructure() const
01737 {
01738 return *pStructureM;
01739 }
01740
01741 private:
01742
01743
01744 TypeStructure() { }
01745 ~TypeStructure() { }
01746 TypeStructure(const TypeStructure &);
01747 TypeStructure &operator =(const TypeStructure &);
01748
01749 Structure *pStructureM;
01750 };
01751
01752
01770 void Register(const Generated *pGenerated);
01771
01777 U32 GetContextCount();
01778
01787 const Context *GetContext(U32 index);
01788
01798 const Context *LookupContext(const char *pFullName);
01799
01810 const Structure *LookupStructure(const std::type_info &typeinfo);
01811
01822 void ShutDown();
01823
01824 };
01825
01826 #endif // XRTTI_H