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
00046 typedef XRTTI_U32_ARCH U32;
00047 typedef XRTTI_S32_ARCH S32;
00054 class Argument;
00055 class AutoRegister;
00056 class Array;
00057 class Base;
00058 class Class;
00059 class Complete;
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 typedef struct Generated Generated;
00069 class Incomplete;
00070 class Method;
00071 class MethodSignature;
00072 class Namespace;
00073 class Pointer;
00074 class Structure;
00075 class Struct;
00076 class Type;
00077 class TypeEnumeration;
00078 class TypeFunction;
00079 class TypeStructure;
00080 class TypeUnion;
00081 class Union;
00082
00083
00088 typedef enum AccessType
00089 {
00090 AccessType_Public,
00091 AccessType_Protected,
00092 AccessType_Private
00093 } AccessType;
00094
00095
00102 typedef union Value
00103 {
00104 bool bool_v;
00105 signed char char_v;
00106 unsigned char unsigned_char_v;
00107 wchar_t wchar_v;
00108 signed short short_v;
00109 unsigned short unsigned_short_v;
00110 signed int int_v;
00111 unsigned int unsigned_int_v;
00112 signed long long_v;
00113 unsigned long unsigned_long_v;
00114 signed long long long_long_v;
00115 unsigned long long unsigned_long_long_v;
00116 float float_v;
00117 double double_v;
00118 long double long_double_v;
00119 void *pointer_v;
00120 }
00121 Value;
00122
00123
00128 class Context
00129 {
00130 public:
00131
00135 enum Type
00136 {
00137 Type_Class = 0,
00138 Type_Incomplete = 1,
00139 Type_Namespace = 2,
00140 Type_Struct = 3,
00141 Type_Union = 4
00142 };
00143
00156 virtual Type GetType() const = 0;
00157
00163 const char *GetName() const
00164 {
00165 return pNameM;
00166 }
00167
00176 const char *GetFullName() const
00177 {
00178 return pFullNameM;
00179 }
00180
00185 const Context *GetParent() const
00186 {
00187 return pParentM;
00188 }
00189
00190 private:
00191
00192 friend class Incomplete;
00193 friend class Namespace;
00194 friend class Structure;
00195
00196
00197 Context() { }
00198 virtual ~Context() { }
00199 Context(const Context &);
00200 Context &operator =(const Context &);
00201
00202 const char *pNameM;
00203
00204 const char *pFullNameM;
00205
00206 Context *pParentM;
00207 };
00208
00209
00217 class Incomplete : public Context
00218 {
00219 public:
00220
00226 virtual Type GetType() const
00227 {
00228 return Type_Incomplete;
00229 }
00230
00231 private:
00232
00233
00234 Incomplete() { }
00235 virtual ~Incomplete() { }
00236 Incomplete(const Incomplete &);
00237 Incomplete &operator =(const Incomplete &);
00238 };
00239
00240
00245 class Namespace : public Context
00246 {
00247 public:
00248
00254 virtual Type GetType() const
00255 {
00256 return Type_Namespace;
00257 }
00258
00259 private:
00260
00261
00262 Namespace() { }
00263 ~Namespace() { }
00264 Namespace(const Namespace &);
00265 Namespace &operator =(const Namespace &);
00266 };
00267
00268
00273 class Structure : public Context
00274 {
00275 public:
00276
00284 AccessType GetAccessType() const
00285 {
00286 return accessTypeM;
00287 }
00288
00303 const std::type_info *GetTypeInfo() const
00304 {
00305 return pTypeInfoM;
00306 }
00307
00317 U32 GetBaseCount() const
00318 {
00319 return baseCountM;
00320 }
00321
00328 const Base &GetBase(U32 index) const;
00329
00335 U32 GetFieldCount() const
00336 {
00337 return fieldCountM;
00338 }
00339
00348 const Field &GetField(U32 index) const;
00349
00358 bool IsAnonymous() const
00359 {
00360 return isAnonymousM;
00361 }
00362
00368 U32 GetConstructorCount() const
00369 {
00370 return constructorCountM;
00371 }
00372
00379 const Constructor &GetConstructor(U32 index) const;
00380
00386 bool HasDestructor() const
00387 {
00388 return pDestructorM ? true : false;
00389 }
00390
00396 const Destructor &GetDestructor() const;
00397
00407 void *Create() const
00408 {
00409 if (pCreateMethodM) {
00410 return (*pCreateMethodM)();
00411 }
00412 else {
00413 return 0;
00414 }
00415 }
00416
00427 void *CreateArray(U32 count) const
00428 {
00429 if (pCreateArrayMethodM) {
00430 return (*pCreateArrayMethodM)(count);
00431 }
00432 else {
00433 return 0;
00434 }
00435 }
00436
00442 void Delete(void *pInstance) const
00443 {
00444 if (pDeleteMethodM) {
00445 (*pDeleteMethodM)(pInstance);
00446 }
00447 }
00448
00454 void DeleteArray(void **pInstanceArray) const
00455 {
00456 if (pDeleteArrayMethodM) {
00457 (*pDeleteArrayMethodM)(pInstanceArray);
00458 }
00459 }
00460
00461 private:
00462
00463 friend class Struct;
00464 friend class Union;
00465
00466
00467 Structure() { }
00468 ~Structure() { }
00469 Structure(const Structure &);
00470 Structure &operator =(const Structure &);
00471
00472 AccessType accessTypeM;
00473
00474 const std::type_info *pTypeInfoM;
00475
00476 U32 baseCountM;
00477
00478 Base *pBasesM;
00479
00480 U32 fieldCountM;
00481
00482 class Field *pFieldsM;
00483
00484 bool isAnonymousM;
00485
00486 U32 constructorCountM;
00487
00488 Constructor *pConstructorsM;
00489
00490 Destructor *pDestructorM;
00491
00492 void *(*pCreateMethodM)();
00493
00494 void *(*pCreateArrayMethodM)(U32);
00495
00496 void (*pDeleteMethodM)(void *);
00497
00498 void (*pDeleteArrayMethodM)(void *);
00499 };
00500
00501
00509 class Base
00510 {
00511 public:
00512
00518 const Structure &GetStructure() const
00519 {
00520 return *pStructureM;
00521 }
00522
00539 U32 GetOffset() const
00540 {
00541 return offsetM;
00542 }
00543
00544 private:
00545
00546
00547 Base() { }
00548 ~Base() { }
00549 Base(const Base &);
00550 Base &operator =(const Base &);
00551
00552 Structure *pStructureM;
00553
00554 U32 offsetM;
00555 };
00556
00557
00564 class Union : public Structure
00565 {
00566 public:
00567
00573 virtual Type GetType() const
00574 {
00575 return Type_Union;
00576 }
00577
00578 private:
00579
00580
00581 Union() { }
00582 ~Union() { }
00583 Union(const Union &);
00584 Union &operator =(const Union &);
00585 };
00586
00587
00591 class Struct : public Structure
00592 {
00593 public:
00594
00600 virtual Type GetType() const
00601 {
00602 return Type_Struct;
00603 }
00604
00612 bool IsAbstract() const
00613 {
00614 return isAbstractM;
00615 }
00616
00622 U32 GetMethodCount() const
00623 {
00624 return methodCountM;
00625 }
00626
00633 const Method &GetMethod(U32 index) const;
00634
00635 private:
00636
00637 friend class Class;
00638
00639
00640 Struct() { }
00641 ~Struct() { }
00642 Struct(const Struct &);
00643 Struct &operator =(const Struct &);
00644
00645 bool isAbstractM;
00646
00647 U32 methodCountM;
00648
00649 Method *pMethodsM;
00650 };
00651
00652
00656 class Class : public Struct
00657 {
00658 public:
00659
00665 virtual Type GetType() const
00666 {
00667 return Type_Class;
00668 }
00669
00670 private:
00671
00672
00673 Class() { }
00674 ~Class() { }
00675 Class(const Class &);
00676 Class &operator =(const Class &);
00677 };
00678
00679
00684 class Member
00685 {
00686 public:
00687
00693 AccessType GetAccessType() const
00694 {
00695 return accessTypeM;
00696 }
00697
00704 const Context &GetContext() const
00705 {
00706 return *pContextM;
00707 }
00708
00714 const char *GetName() const
00715 {
00716 return pNameM;
00717 }
00718
00724 bool IsStatic() const
00725 {
00726 return isStaticM;
00727 }
00728
00729 private:
00730
00731 friend class Constructor;
00732 friend class Destructor;
00733 friend class Field;
00734 friend class Method;
00735
00736
00737 Member() { }
00738 ~Member() { }
00739 Member(const Member &);
00740 Member &operator =(const Member &);
00741
00742 AccessType accessTypeM;
00743
00744 Context *pContextM;
00745
00746 const char *pNameM;
00747
00748 bool isStaticM;
00749 };
00750
00751
00755 class Field : public Member
00756 {
00757 public:
00758
00764 const Type &GetType() const
00765 {
00766 return *pTypeM;
00767 }
00768
00779 U32 GetOffset() const
00780 {
00781 return offsetM;
00782 }
00783
00796 void Get(void *pInstance, Value &returnValue) const
00797 {
00798 (*pGetMethodM)(pInstance, returnValue);
00799 }
00800
00813 void Set(void *pInstance, const Value &value) const
00814 {
00815 (*pSetMethodM)(pInstance, value);
00816 }
00817
00818 private:
00819
00820
00821 Field() { }
00822 ~Field() { }
00823 Field(const Field &);
00824 Field &operator =(const Field &);
00825
00826 Type *pTypeM;
00827
00828 U32 offsetM;
00829
00830 void (*pGetMethodM)(void *, Value &);
00831
00832 void (*pSetMethodM)(void *, const Value &);
00833 };
00834
00835
00840 class Argument
00841 {
00842 public:
00843
00849 const Type &GetType() const
00850 {
00851 return *pTypeM;
00852 }
00853
00859 bool HasDefault() const
00860 {
00861 return hasDefaultM;
00862 }
00863
00871 const Value &GetDefault() const
00872 {
00873 return defaultM;
00874 }
00875
00876 private:
00877
00878
00879 Argument() { }
00880 ~Argument() { }
00881 Argument(const Argument &);
00882 Argument &operator =(const Argument &);
00883
00884 Type *pTypeM;
00885
00886 bool hasDefaultM;
00887
00888 Value defaultM;
00889 };
00890
00891
00895 class DestructorSignature
00896 {
00897 public:
00898
00906 U32 GetThrowCount() const
00907 {
00908 return throwCountM;
00909 }
00910
00919 const Type &GetThrow(U32 index) const
00920 {
00921 return *(pThrowsM[index]);
00922 }
00923
00924 private:
00925
00926 friend class Destructor;
00927 friend class ConstructorSignature;
00928
00929
00930
00931 DestructorSignature() { }
00932 ~DestructorSignature() { }
00933 DestructorSignature(const DestructorSignature &);
00934 DestructorSignature &operator =(const DestructorSignature &);
00935
00936 U32 throwCountM;
00937 Type **pThrowsM;
00938 };
00939
00940
00944 class ConstructorSignature : public DestructorSignature
00945 {
00946 public:
00947
00953 U32 GetArgumentCount() const
00954 {
00955 return argumentCountM;
00956 }
00957
00963 const Argument &GetArgument(U32 index) const
00964 {
00965 return pArgumentsM[index];
00966 }
00967
00975 bool HasEllipsis() const
00976 {
00977 return hasEllipsisM;
00978 }
00979
00980 private:
00981
00982 friend class Constructor;
00983 friend class MethodSignature;
00984
00985
00986
00987 ConstructorSignature() { }
00988 ~ConstructorSignature() { }
00989 ConstructorSignature(const ConstructorSignature &);
00990 ConstructorSignature &operator =(const ConstructorSignature &);
00991
00992 U32 argumentCountM;
00993
00994 Argument *pArgumentsM;
00995
00996 bool hasEllipsisM;
00997 };
00998
00999
01003 class MethodSignature : public ConstructorSignature
01004 {
01005 public:
01006
01012 const Type &GetReturnType() const
01013 {
01014 return *pReturnTypeM;
01015 }
01016
01017 private:
01018
01019 friend class Method;
01020 friend class TypeFunction;
01021
01022
01023
01024 MethodSignature() { }
01025 ~MethodSignature() { }
01026 MethodSignature(const MethodSignature &);
01027 MethodSignature &operator =(const MethodSignature &);
01028
01029 Type *pReturnTypeM;
01030 };
01031
01032
01036 class Destructor : public Member
01037 {
01038 public:
01039
01045 bool IsVirtual() const
01046 {
01047 return isVirtualM;
01048 }
01049
01055 bool IsPureVirtual() const
01056 {
01057 return isPureVirtualM;
01058 }
01059
01065 const DestructorSignature &GetSignature() const
01066 {
01067 return signatureM;
01068 }
01069
01078 void Invoke(void *pInstance) const
01079 {
01080 (*pInvokeDestructorM)(pInstance);
01081 }
01082
01083 private:
01084
01085
01086 Destructor() { }
01087 ~Destructor() { }
01088 Destructor(const Destructor &);
01089 Destructor &operator =(const Destructor &);
01090
01091 bool isVirtualM, isPureVirtualM;
01092
01093 DestructorSignature signatureM;
01094
01095 void (*pInvokeDestructorM)(void *);
01096 };
01097
01098
01102 class Constructor : public Member
01103 {
01104 public:
01105
01111 const ConstructorSignature &GetSignature() const
01112 {
01113 return signatureM;
01114 }
01115
01122 const char *GetArgumentName(U32 index) const
01123 {
01124 return pArgumentNamesM[index];
01125 }
01126
01141 void *Invoke(Value *pArgumentValues) const
01142 {
01143 Value ret;
01144 (*pInvokeConstructorM)(0, ret, pArgumentValues);
01145 return ret.pointer_v;
01146 }
01147
01148 private:
01149
01150
01151 Constructor() { }
01152 ~Constructor() { }
01153 Constructor(const Constructor &);
01154 Constructor &operator =(const Constructor &);
01155
01156 ConstructorSignature signatureM;
01157
01158 const char **pArgumentNamesM;
01159
01160 void (*pInvokeConstructorM)(void *, Value &, Value *);
01161 };
01162
01163
01167 class Method : public Member
01168 {
01169 public:
01170
01176 bool IsConst() const
01177 {
01178 return isConstM;
01179 }
01180
01186 bool IsVirtual() const
01187 {
01188 return isVirtualM;
01189 }
01190
01196 bool IsPureVirtual() const
01197 {
01198 return isPureVirtualM;
01199 }
01200
01206 const MethodSignature &GetSignature() const
01207 {
01208 return signatureM;
01209 }
01210
01217 const char *GetArgumentName(U32 index) const
01218 {
01219 return pArgumentNamesM[index];
01220 }
01221
01242 void Invoke(void *pInstance, Value &returnValue,
01243 Value *pArgumentValues) const
01244 {
01245 (*pInvokeMethodM)(pInstance, returnValue, pArgumentValues);
01246 }
01247
01248 private:
01249
01250
01251 Method() { }
01252 ~Method() { }
01253 Method(const Method &);
01254 Method &operator =(const Method &);
01255
01256 bool isConstM, isVirtualM, isPureVirtualM;
01257
01258 MethodSignature signatureM;
01259
01260 const char **pArgumentNamesM;
01261
01262 void (*pInvokeMethodM)(void *, Value &, Value *);
01263 };
01264
01265
01278 class Type
01279 {
01280 public:
01281
01296 enum BaseType
01297 {
01298 BaseType_Void = 0,
01299 BaseType_Bool = 1,
01300 BaseType_Char = 2,
01301 BaseType_Unsigned_Char = 3,
01302 BaseType_WChar = 4,
01303 BaseType_Short = 5,
01304 BaseType_Unsigned_Short = 6,
01305 BaseType_Int = 7,
01306 BaseType_Unsigned_Int = 8,
01307 BaseType_Long = 9,
01308 BaseType_Unsigned_Long = 10,
01309 BaseType_Long_Long = 11,
01310 BaseType_Unsigned_Long_Long = 12,
01311 BaseType_Float = 13,
01312 BaseType_Double = 14,
01313 BaseType_Long_Double = 15,
01314 BaseType_Bitfield = 16,
01315 BaseType_Enumeration = 17,
01316 BaseType_Function = 18,
01317 BaseType_Structure = 19
01318 };
01319
01325 BaseType GetBaseType() const
01326 {
01327 return baseTypeM;
01328 }
01329
01336 bool IsConst() const
01337 {
01338 return isConstM;
01339 }
01340
01347 bool IsVolatile() const
01348 {
01349 return isVolatileM;
01350 }
01351
01358 bool IsReference() const
01359 {
01360 return isReferenceM;
01361 }
01362
01369 U32 GetBitfieldBitCount() const
01370 {
01371 return bitCountM;
01372 }
01373
01381 U32 GetPointerCount() const
01382 {
01383 return pointerCountM;
01384 }
01385
01395 const Pointer &GetPointer(U32 depth) const;
01396
01402 U32 GetArrayCount() const
01403 {
01404 return arrayCountM;
01405 }
01406
01416 const Array &GetArray(U32 dimension) const;
01417
01418 private:
01419
01420 friend class TypeEnumeration;
01421 friend class TypeFunction;
01422 friend class TypeStructure;
01423
01424
01425 Type() { }
01426 ~Type() { }
01427 Type(const Type &);
01428 Type &operator =(const Type &);
01429
01430 BaseType baseTypeM;
01431
01432 bool isConstM;
01433
01434 bool isVolatileM;
01435
01436 bool isReferenceM;
01437
01438 U32 bitCountM;
01439
01440 U32 pointerCountM;
01441
01442 Pointer *pPointersM;
01443
01444 U32 arrayCountM;
01445
01446 Array *pArraysM;
01447 };
01448
01449
01454 class Pointer
01455 {
01456 public:
01457
01464 bool IsConst() const
01465 {
01466 return isConstM;
01467 }
01468
01475 bool IsVolatile() const
01476 {
01477 return isVolatileM;
01478 }
01479
01480 private:
01481
01482
01483 Pointer() { }
01484 ~Pointer() { }
01485 Pointer(const Pointer &);
01486 Pointer &operator =(const Pointer &);
01487
01488 bool isConstM;
01489
01490 bool isVolatileM;
01491 };
01492
01493
01497 class Array
01498 {
01499 public:
01500
01508 bool IsUnbounded() const
01509 {
01510 return isUnboundedM;
01511 }
01512
01520 U32 GetElementCount() const
01521 {
01522 return elementCountM;
01523 }
01524
01525 private:
01526
01527
01528 Array() { }
01529 ~Array() { }
01530 Array(const Array &);
01531 Array &operator =(const Array &);
01532
01533 bool isUnboundedM;
01534
01535 U32 elementCountM;
01536 };
01537
01538
01542 class Enumeration
01543 {
01544 public:
01545
01553 AccessType GetAccessType() const
01554 {
01555 return accessTypeM;
01556 }
01557
01563 const Context &GetContext() const
01564 {
01565 return *pContextM;
01566 };
01567
01573 const char *GetName() const
01574 {
01575 return pNameM;
01576 }
01577
01583 U32 GetValueCount() const
01584 {
01585 return valueCountM;
01586 }
01587
01594 const EnumerationValue &GetValue(U32 index) const;
01595
01596 private:
01597
01598
01599 Enumeration() { }
01600 ~Enumeration() { }
01601 Enumeration(const Enumeration &);
01602 Enumeration &operator =(const Enumeration &);
01603
01604 AccessType accessTypeM;
01605
01606 Context *pContextM;
01607
01608 const char *pNameM;
01609
01610 U32 valueCountM;
01611
01612 EnumerationValue *pValuesM;
01613 };
01614
01615
01619 class EnumerationValue
01620 {
01621 public:
01622
01628 const char *GetName() const
01629 {
01630 return pNameM;
01631 }
01632
01638 S32 GetValue() const
01639 {
01640 return valueM;
01641 }
01642
01643 private:
01644
01645
01646 EnumerationValue() { }
01647 ~EnumerationValue() { }
01648 EnumerationValue(const EnumerationValue &);
01649 EnumerationValue &operator =(const EnumerationValue &);
01650
01651 const char *pNameM;
01652
01653 S32 valueM;
01654 };
01655
01656
01660 class TypeEnumeration : public Type
01661 {
01662 public:
01663
01671 const Enumeration &GetEnumeration() const
01672 {
01673 return *pEnumerationM;
01674 }
01675
01676 private:
01677
01678
01679 TypeEnumeration() { }
01680 ~TypeEnumeration() { }
01681 TypeEnumeration(const TypeEnumeration &);
01682 TypeEnumeration &operator =(const TypeEnumeration &);
01683
01684 Enumeration *pEnumerationM;
01685 };
01686
01687
01691 class TypeFunction : public Type
01692 {
01693 public:
01694
01700 const MethodSignature &GetSignature() const
01701 {
01702 return signatureM;
01703 }
01704
01705 private:
01706
01707
01708 TypeFunction() { }
01709 ~TypeFunction() { }
01710 TypeFunction(const TypeFunction &);
01711 TypeFunction &operator =(const TypeFunction &);
01712
01713 MethodSignature signatureM;
01714 };
01715
01716
01721 class TypeStructure : public Type
01722 {
01723 public:
01724
01730 const Structure &GetStructure() const
01731 {
01732 return *pStructureM;
01733 }
01734
01735 private:
01736
01737
01738 TypeStructure() { }
01739 ~TypeStructure() { }
01740 TypeStructure(const TypeStructure &);
01741 TypeStructure &operator =(const TypeStructure &);
01742
01743 Structure *pStructureM;
01744 };
01745
01746
01764 void Register(const Generated *pGenerated);
01765
01771 U32 GetContextCount();
01772
01781 const Context *GetContext(U32 index);
01782
01792 const Context *LookupContext(const char *pFullName);
01793
01804 const Structure *LookupStructure(const std::type_info &typeinfo);
01805
01821 const Struct *LookupStruct(const void *pObjectWithVirtualMethod);
01822
01833 void ShutDown();
01834
01835 };
01836
01837 #endif // XRTTI_H