00001 // @(#)root/reflex:$Id: Base.h 29288 2009-07-01 13:03:35Z axel $ 00002 // Author: Stefan Roiser 2004 00003 00004 // Copyright CERN, CH-1211 Geneva 23, 2004-2006, All rights reserved. 00005 // 00006 // Permission to use, copy, modify, and distribute this software for any 00007 // purpose is hereby granted without fee, provided that this copyright and 00008 // permissions notice appear in all copies and derivatives. 00009 // 00010 // This software is provided "as is" without express or implied warranty. 00011 00012 #ifndef REFLEX_BASE_H 00013 #define REFLEX_BASE_H 1 00014 00015 // Include files 00016 #include "Reflex/Kernel.h" 00017 #include "Reflex/Type.h" 00018 00019 namespace Reflex { 00020 // forward declarations 00021 00022 /** 00023 * @class Base Base.h Reflex/Base.h 00024 * @author Stefan Roiser 00025 * @date 2004-01-28 00026 * @ingroup Ref 00027 */ 00028 class RFLX_API Base { 00029 friend class Class; 00030 00031 public: 00032 /** default constructor */ 00033 Base(); 00034 00035 00036 /** constructor */ 00037 Base(const Type &baseType, 00038 OffsetFunction offsetFP, 00039 unsigned int modifiers = 0); 00040 00041 00042 /** destructor */ 00043 virtual ~Base() {} 00044 00045 00046 /** 00047 * the bool operator returns true if the type of the base is resolved (implemented) 00048 * @return true if base type is implemented 00049 */ 00050 operator bool() const; 00051 00052 00053 /** 00054 * Name will return the string represenation of the base class 00055 * @param typedefexp expand typedefs or not 00056 * @return string represenation of base class 00057 */ 00058 std::string Name(unsigned int mod = 0) const; 00059 00060 00061 /** 00062 * IsPrivate will return true if the inheritance is private 00063 * @return true if inheritance is private 00064 */ 00065 bool IsPrivate() const; 00066 00067 00068 /** 00069 * IsProtected will return true if the inheritance is protected 00070 * @return true if inheritance is protected 00071 */ 00072 bool IsProtected() const; 00073 00074 00075 /** 00076 * IsPublic will return true if the inheritance is public 00077 * @return true if inheritance is public 00078 */ 00079 bool IsPublic() const; 00080 00081 00082 /** 00083 * IsVirtual will return true if the inheritance is virtual 00084 * @return true if inheritance is virtual 00085 */ 00086 bool IsVirtual() const; 00087 00088 00089 /** 00090 * Offset will return the Offset to the base class as int 00091 * @return Offset to base class 00092 */ 00093 size_t Offset(void* mem = 0) const; 00094 00095 00096 /** 00097 * OffsetFP will return a pointer to the function which calculates the Offset 00098 * between the two classes 00099 * @return pointer to Offset calculating function 00100 */ 00101 OffsetFunction OffsetFP() const; 00102 00103 00104 /** 00105 * ToType will return this base classes type 00106 * @param mod accepts FINAL to go to the final type for a typedef 00107 * @return type of base class 00108 */ 00109 Type ToType() const; 00110 00111 00112 /** 00113 * ToScope will return this base classes scope 00114 * @return this base class as scope 00115 */ 00116 Scope ToScope() const; 00117 00118 private: 00119 const Class* BaseClass() const; 00120 00121 private: 00122 /** function pointer to Stubfunction for Offset calculation */ 00123 OffsetFunction fOffsetFP; 00124 00125 00126 /** modifiers of inheritance relation */ 00127 unsigned int fModifiers; 00128 00129 00130 /** 00131 * pointer to base class 00132 * @label base bype 00133 * @link aggregation 00134 * @supplierCardinality 1 00135 * @clientCardinality 1 00136 */ 00137 Type fBaseType; 00138 00139 00140 /** 00141 * back link to the class corresponding to the base 00142 * @label base class 00143 * @link aggregation 00144 * @clientCardinality 1 00145 * @supplierCardinality 0..1 00146 **/ 00147 mutable 00148 const Class * fBaseClass; 00149 00150 }; // class Base 00151 } // namespace Reflex 00152 00153 00154 //------------------------------------------------------------------------------- 00155 inline Reflex::Base::Base() 00156 //------------------------------------------------------------------------------- 00157 : fOffsetFP(0), 00158 fModifiers(0), 00159 fBaseType(0, 0), 00160 fBaseClass(0) { 00161 } 00162 00163 00164 //------------------------------------------------------------------------------- 00165 inline 00166 Reflex::Base::operator bool() const { 00167 //------------------------------------------------------------------------------- 00168 if (fBaseType) { 00169 return true; 00170 } 00171 return false; 00172 } 00173 00174 00175 //------------------------------------------------------------------------------- 00176 inline bool 00177 Reflex::Base::IsPrivate() const { 00178 //------------------------------------------------------------------------------- 00179 return 0 != (fModifiers & PRIVATE); 00180 } 00181 00182 00183 //------------------------------------------------------------------------------- 00184 inline bool 00185 Reflex::Base::IsProtected() const { 00186 //------------------------------------------------------------------------------- 00187 return 0 != (fModifiers & PROTECTED); 00188 } 00189 00190 00191 //------------------------------------------------------------------------------- 00192 inline bool 00193 Reflex::Base::IsPublic() const { 00194 //------------------------------------------------------------------------------- 00195 return 0 != (fModifiers & PUBLIC); 00196 } 00197 00198 00199 //------------------------------------------------------------------------------- 00200 inline bool 00201 Reflex::Base::IsVirtual() const { 00202 //------------------------------------------------------------------------------- 00203 return 0 != (fModifiers & VIRTUAL); 00204 } 00205 00206 00207 //------------------------------------------------------------------------------- 00208 inline size_t 00209 Reflex::Base::Offset(void* mem) const { 00210 //------------------------------------------------------------------------------- 00211 return fOffsetFP(mem); 00212 } 00213 00214 00215 //------------------------------------------------------------------------------- 00216 inline Reflex::OffsetFunction 00217 Reflex::Base::OffsetFP() const { 00218 //------------------------------------------------------------------------------- 00219 return fOffsetFP; 00220 } 00221 00222 00223 //------------------------------------------------------------------------------- 00224 inline Reflex::Type 00225 Reflex::Base::ToType() const { 00226 //------------------------------------------------------------------------------- 00227 return fBaseType; 00228 } 00229 00230 00231 //------------------------------------------------------------------------------- 00232 inline Reflex::Scope 00233 Reflex::Base::ToScope() const { 00234 //------------------------------------------------------------------------------- 00235 // We are invoking "Type::operator Scope() const" here, 00236 // be very careful with the cast (do not cast to a reference). 00237 return static_cast<const Scope>(fBaseType); 00238 } 00239 00240 00241 #endif // Reflex_Base