/usr/include/root/Reflex/Object.h is in libroot-core-dev 5.34.19+dfsg-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | // @(#)root/reflex:$Id$
// 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_Object
#define Reflex_Object
// Include files
#include "Reflex/Type.h"
#include <string>
#include <vector>
namespace Reflex {
// forward declarations
/**
* @class Object Object.h Reflex/Object.h
* @author Stefan Roiser
* @date 24/06/2004
* @ingroup Ref
*/
class RFLX_API Object {
public:
/** constructor */
Object(const Type& type = Type(),
void* mem = 0);
/** constructor */
Object(const Object &);
/** destructor */
~Object() {}
template <typename T>
static Object
Create(T& v) {
return Object(Type::ByTypeInfo(typeid(T)), &v);
}
/**
* operator assigment
*/
Object& operator =(const Object& obj);
/**
* operator ==
*/
bool operator ==(const Object& obj);
/**
* inequal operator
*/
bool operator !=(const Object& obj);
/**
* operator bool
*/
operator bool() const;
/**
* Address will return the memory address of the object
* @return memory address of object
*/
void* Address() const;
/**
* CastObject an object from this class type to another one
* @param to is the class type to cast into
* @param obj the memory address of the object to be casted
*/
Object CastObject(const Type& to) const;
/**
* Destruct will call the destructor of a type and remove its memory
* allocation if desired
*/
void Destruct() const;
/**
* DynamicType is used to discover the dynamic type (useful in
* case of polymorphism)
* @return the actual class of the object
*/
Type DynamicType() const;
/**
* Get the data member value
* @param dm name of the data member to get
* @return member value as object
*/
Object Get(const std::string& dm) const;
/**
* Invoke a member function of the object
* @param fm name of the member function
* @param ret Object to put the return value into (can be 0 for function returning void)
* @param args a vector of memory addresses to parameter values
* @return the return value of the function as object
*/
void Invoke(const std::string& fm,
Object* ret = 0,
const std::vector<void*>& args = std::vector<void*>()) const;
/**
* Invoke a member function of the object
* @param fm name of the member function
* @param ret Object to put the return value into (can be 0 for function returning void)
* @param args a vector of memory addresses to parameter values
* @return the return value of the function as object
*/
template <typename T>
void
Invoke(const std::string& fm,
T& ret,
const std::vector<void*>& args = std::vector<void*>()) const {
Object retO(Type::ByTypeInfo(typeid(T)), &ret);
Invoke(fm, &retO, args);
}
/**
* Invoke a member function of the object
* @param fm name of the member function
* @param sign the signature of the member function (for overloads)
* @param ret Object to put the return value into (can be 0 for function returning void)
* @param args a vector of memory addresses to parameter values
* @return the return value of the function as object
*/
void Invoke(const std::string& fm,
const Type& sign,
Object* ret = 0,
const std::vector<void*>& args = std::vector<void*>()) const;
/**
* Invoke a member function of the object
* @param fm name of the member function
* @param sign the signature of the member function (for overloads)
* @param ret Object to put the return value into (can be 0 for function returning void)
* @param args a vector of memory addresses to parameter values
* @return the return value of the function as object
*/
template <typename T>
void
Invoke(const std::string& fm,
const Type& sign,
T& ret,
const std::vector<void*>& args = std::vector<void*>()) const {
Object retO(Type::ByTypeInfo(typeid(T)), &ret);
Invoke(fm, sign, &retO, args);
}
/**
* Set will set a data member value of this object
* @param dm the name of the data member
* @param value the memory address of the value to set
*/
void Set(const std::string& dm,
const void* value) const;
/**
* Set will set a data member value of this object
* @param dm the name of the data member
* @param value the memory address of the value to set
*/
template <class T>
void Set(const std::string& dm,
const T& value) const;
/**
* TypeOf will return the type of the object
* @return type of the object
*/
Type TypeOf() const;
private:
friend class ValueObject;
/** */
void Set2(const std::string& dm,
const void* value) const;
/**
* the type of the object
* @link aggregation
* @clientCardinality 1
* @supplierCardinality 1
* @label object type
**/
Type fType;
/**
* the address of the object
*/
mutable
void* fAddress;
}; // class Object
/**
* Object_Cast can be used to cast an object into a given type
* (no additional checks are performed for the time being)
* @param o the object to be casted
* @return the address of the object casted into type T
*/
template <class T> T Object_Cast(const Object& o);
} // namespace Reflex
#include "Reflex/Tools.h"
//-------------------------------------------------------------------------------
template <class T>
inline T
Reflex::Object_Cast(const Object& o) {
//-------------------------------------------------------------------------------
return *(T*) o.Address();
}
//-------------------------------------------------------------------------------
inline Reflex::Object::Object(const Type& type,
void* mem)
//-------------------------------------------------------------------------------
: fType(type),
fAddress(mem) {
}
//-------------------------------------------------------------------------------
inline Reflex::Object::Object(const Object& obj)
//-------------------------------------------------------------------------------
: fType(obj.fType),
fAddress(obj.fAddress) {
}
//-------------------------------------------------------------------------------
inline Reflex::Object&
Reflex::Object::operator =(const Object& obj) {
//-------------------------------------------------------------------------------
if (&obj != this) {
fType = obj.fType;
fAddress = obj.fAddress;
}
return *this;
}
//-------------------------------------------------------------------------------
inline bool
Reflex::Object::operator ==(const Object& obj) {
//-------------------------------------------------------------------------------
return fType == obj.fType && fAddress == obj.fAddress;
}
//-------------------------------------------------------------------------------
inline bool
Reflex::Object::operator !=(const Object& obj) {
//-------------------------------------------------------------------------------
return fType != obj.fType || fAddress != obj.fAddress;
}
//-------------------------------------------------------------------------------
inline
Reflex::Object::operator bool() const {
//-------------------------------------------------------------------------------
if (fType && fAddress) {
return true;
}
return false;
}
//-------------------------------------------------------------------------------
inline void*
Reflex::Object::Address() const {
//-------------------------------------------------------------------------------
return fAddress;
}
//-------------------------------------------------------------------------------
inline Reflex::Object
Reflex::Object::CastObject(const Type& to) const {
//-------------------------------------------------------------------------------
if (*this) {
return fType.CastObject(to, *this);
}
return Object();
}
//-------------------------------------------------------------------------------
inline void
Reflex::Object::Destruct() const {
//-------------------------------------------------------------------------------
if (*this) {
fType.Destruct(fAddress);
fAddress = 0;
}
}
//-------------------------------------------------------------------------------
inline Reflex::Type
Reflex::Object::DynamicType() const {
//-------------------------------------------------------------------------------
return fType.DynamicType(*this);
}
//-------------------------------------------------------------------------------
inline void
Reflex::Object::Set(const std::string& dm,
const void* value) const {
//-------------------------------------------------------------------------------
Set2(dm, value);
}
//-------------------------------------------------------------------------------
template <class T>
inline void
Reflex::Object::Set(const std::string& dm,
const T& value) const {
//-------------------------------------------------------------------------------
Set2(dm, &value);
}
//-------------------------------------------------------------------------------
inline Reflex::Type
Reflex::Object::TypeOf() const {
//-------------------------------------------------------------------------------
return fType;
}
#endif // Reflex_Object
|