ROOT logo
// @(#)root/reflex:$Id: Base.h 29288 2009-07-01 13:03:35Z axel $
// Author: Stefan Roiser 2004

// Copyright CERN, CH-1211 Geneva 23, 2004-2006, All rights reserved.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose is hereby granted without fee, provided that this copyright and
// permissions notice appear in all copies and derivatives.
//
// This software is provided "as is" without express or implied warranty.

#ifndef REFLEX_BASE_H
#define REFLEX_BASE_H 1

// Include files
#include "Reflex/Kernel.h"
#include "Reflex/Type.h"

namespace Reflex {
// forward declarations

/**
 * @class Base Base.h Reflex/Base.h
 * @author Stefan Roiser
 * @date   2004-01-28
 * @ingroup Ref
 */
class RFLX_API Base {
   friend class Class;

public:
   /** default constructor */
   Base();


   /** constructor */
   Base(const Type &baseType,
        OffsetFunction offsetFP,
        unsigned int modifiers = 0);


   /** destructor */
   virtual ~Base() {}


   /**
    * the bool operator returns true if the type of the base is resolved (implemented)
    * @return true if base type is implemented
    */
   operator bool() const;


   /**
    * Name will return the string represenation of the base class
    * @param  typedefexp expand typedefs or not
    * @return string represenation of base class
    */
   std::string Name(unsigned int mod = 0) const;


   /**
    * IsPrivate will return true if the inheritance is private
    * @return true if inheritance is private
    */
   bool IsPrivate() const;


   /**
    * IsProtected will return true if the inheritance is protected
    * @return true if inheritance is protected
    */
   bool IsProtected() const;


   /**
    * IsPublic will return true if the inheritance is public
    * @return true if inheritance is public
    */
   bool IsPublic() const;


   /**
    * IsVirtual will return true if the inheritance is virtual
    * @return true if inheritance is virtual
    */
   bool IsVirtual() const;


   /**
    * Offset will return the Offset to the base class as int
    * @return Offset to base class
    */
   size_t Offset(void* mem = 0) const;


   /**
    * OffsetFP will return a pointer to the function which calculates the Offset
    * between the two classes
    * @return pointer to Offset calculating function
    */
   OffsetFunction OffsetFP() const;


   /**
    * ToType will return this base classes type
    * @param mod accepts FINAL to go to the final type for a typedef
    * @return type of base class
    */
   Type ToType() const;


   /**
    * ToScope will return this base classes scope
    * @return this base class as scope
    */
   Scope ToScope() const;

private:
   const Class* BaseClass() const;

private:
   /** function pointer to Stubfunction for Offset calculation */
   OffsetFunction fOffsetFP;


   /** modifiers of inheritance relation */
   unsigned int fModifiers;


   /**
    * pointer to base class
    * @label base bype
    * @link aggregation
    * @supplierCardinality 1
    * @clientCardinality 1
    */
   Type fBaseType;


   /**
    * back link to the class corresponding to the base
    * @label base class
    * @link aggregation
    * @clientCardinality 1
    * @supplierCardinality 0..1
    **/
   mutable
   const Class * fBaseClass;

};    // class Base
} // namespace Reflex


//-------------------------------------------------------------------------------
inline Reflex::Base::Base()
//-------------------------------------------------------------------------------
   : fOffsetFP(0),
   fModifiers(0),
   fBaseType(0, 0),
   fBaseClass(0) {
}


//-------------------------------------------------------------------------------
inline
Reflex::Base::operator bool() const {
//-------------------------------------------------------------------------------
   if (fBaseType) {
      return true;
   }
   return false;
}


//-------------------------------------------------------------------------------
inline bool
Reflex::Base::IsPrivate() const {
//-------------------------------------------------------------------------------
   return 0 != (fModifiers & PRIVATE);
}


//-------------------------------------------------------------------------------
inline bool
Reflex::Base::IsProtected() const {
//-------------------------------------------------------------------------------
   return 0 != (fModifiers & PROTECTED);
}


//-------------------------------------------------------------------------------
inline bool
Reflex::Base::IsPublic() const {
//-------------------------------------------------------------------------------
   return 0 != (fModifiers & PUBLIC);
}


//-------------------------------------------------------------------------------
inline bool
Reflex::Base::IsVirtual() const {
//-------------------------------------------------------------------------------
   return 0 != (fModifiers & VIRTUAL);
}


//-------------------------------------------------------------------------------
inline size_t
Reflex::Base::Offset(void* mem) const {
//-------------------------------------------------------------------------------
   return fOffsetFP(mem);
}


//-------------------------------------------------------------------------------
inline Reflex::OffsetFunction
Reflex::Base::OffsetFP() const {
//-------------------------------------------------------------------------------
   return fOffsetFP;
}


//-------------------------------------------------------------------------------
inline Reflex::Type
Reflex::Base::ToType() const {
//-------------------------------------------------------------------------------
   return fBaseType;
}


//-------------------------------------------------------------------------------
inline Reflex::Scope
Reflex::Base::ToScope() const {
//-------------------------------------------------------------------------------
// We are invoking "Type::operator Scope() const" here,
// be very careful with the cast (do not cast to a reference).
   return static_cast<const Scope>(fBaseType);
}


#endif // Reflex_Base
 Base.h:1
 Base.h:2
 Base.h:3
 Base.h:4
 Base.h:5
 Base.h:6
 Base.h:7
 Base.h:8
 Base.h:9
 Base.h:10
 Base.h:11
 Base.h:12
 Base.h:13
 Base.h:14
 Base.h:15
 Base.h:16
 Base.h:17
 Base.h:18
 Base.h:19
 Base.h:20
 Base.h:21
 Base.h:22
 Base.h:23
 Base.h:24
 Base.h:25
 Base.h:26
 Base.h:27
 Base.h:28
 Base.h:29
 Base.h:30
 Base.h:31
 Base.h:32
 Base.h:33
 Base.h:34
 Base.h:35
 Base.h:36
 Base.h:37
 Base.h:38
 Base.h:39
 Base.h:40
 Base.h:41
 Base.h:42
 Base.h:43
 Base.h:44
 Base.h:45
 Base.h:46
 Base.h:47
 Base.h:48
 Base.h:49
 Base.h:50
 Base.h:51
 Base.h:52
 Base.h:53
 Base.h:54
 Base.h:55
 Base.h:56
 Base.h:57
 Base.h:58
 Base.h:59
 Base.h:60
 Base.h:61
 Base.h:62
 Base.h:63
 Base.h:64
 Base.h:65
 Base.h:66
 Base.h:67
 Base.h:68
 Base.h:69
 Base.h:70
 Base.h:71
 Base.h:72
 Base.h:73
 Base.h:74
 Base.h:75
 Base.h:76
 Base.h:77
 Base.h:78
 Base.h:79
 Base.h:80
 Base.h:81
 Base.h:82
 Base.h:83
 Base.h:84
 Base.h:85
 Base.h:86
 Base.h:87
 Base.h:88
 Base.h:89
 Base.h:90
 Base.h:91
 Base.h:92
 Base.h:93
 Base.h:94
 Base.h:95
 Base.h:96
 Base.h:97
 Base.h:98
 Base.h:99
 Base.h:100
 Base.h:101
 Base.h:102
 Base.h:103
 Base.h:104
 Base.h:105
 Base.h:106
 Base.h:107
 Base.h:108
 Base.h:109
 Base.h:110
 Base.h:111
 Base.h:112
 Base.h:113
 Base.h:114
 Base.h:115
 Base.h:116
 Base.h:117
 Base.h:118
 Base.h:119
 Base.h:120
 Base.h:121
 Base.h:122
 Base.h:123
 Base.h:124
 Base.h:125
 Base.h:126
 Base.h:127
 Base.h:128
 Base.h:129
 Base.h:130
 Base.h:131
 Base.h:132
 Base.h:133
 Base.h:134
 Base.h:135
 Base.h:136
 Base.h:137
 Base.h:138
 Base.h:139
 Base.h:140
 Base.h:141
 Base.h:142
 Base.h:143
 Base.h:144
 Base.h:145
 Base.h:146
 Base.h:147
 Base.h:148
 Base.h:149
 Base.h:150
 Base.h:151
 Base.h:152
 Base.h:153
 Base.h:154
 Base.h:155
 Base.h:156
 Base.h:157
 Base.h:158
 Base.h:159
 Base.h:160
 Base.h:161
 Base.h:162
 Base.h:163
 Base.h:164
 Base.h:165
 Base.h:166
 Base.h:167
 Base.h:168
 Base.h:169
 Base.h:170
 Base.h:171
 Base.h:172
 Base.h:173
 Base.h:174
 Base.h:175
 Base.h:176
 Base.h:177
 Base.h:178
 Base.h:179
 Base.h:180
 Base.h:181
 Base.h:182
 Base.h:183
 Base.h:184
 Base.h:185
 Base.h:186
 Base.h:187
 Base.h:188
 Base.h:189
 Base.h:190
 Base.h:191
 Base.h:192
 Base.h:193
 Base.h:194
 Base.h:195
 Base.h:196
 Base.h:197
 Base.h:198
 Base.h:199
 Base.h:200
 Base.h:201
 Base.h:202
 Base.h:203
 Base.h:204
 Base.h:205
 Base.h:206
 Base.h:207
 Base.h:208
 Base.h:209
 Base.h:210
 Base.h:211
 Base.h:212
 Base.h:213
 Base.h:214
 Base.h:215
 Base.h:216
 Base.h:217
 Base.h:218
 Base.h:219
 Base.h:220
 Base.h:221
 Base.h:222
 Base.h:223
 Base.h:224
 Base.h:225
 Base.h:226
 Base.h:227
 Base.h:228
 Base.h:229
 Base.h:230
 Base.h:231
 Base.h:232
 Base.h:233
 Base.h:234
 Base.h:235
 Base.h:236
 Base.h:237
 Base.h:238
 Base.h:239
 Base.h:240
 Base.h:241