/usr/include/ThePEG/Utilities/ClassDescription.h is in libthepeg-dev 1.8.0-3build1.
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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | // -*- C++ -*-
//
// ClassDescription.h is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#ifndef ThePEG_ClassDescription_H
#define ThePEG_ClassDescription_H
#include "ThePEG/Config/ThePEG.h"
#include "ClassDescription.fh"
#include "ThePEG/Utilities/Named.h"
#include "ThePEG/Persistency/PersistentOStream.fh"
#include "ThePEG/Persistency/PersistentIStream.fh"
#include "ClassTraits.h"
#include "DescriptionList.h"
namespace ThePEG {
/**
* ClassDescriptionBase is the base class for all class description
* classes. ClassDescriptionBase is the non-templated base class for
* the templated ClassDescriptionTBase, ClassDescription,
* AbstractClassDescription, NoPIOClassDescription and
* AbstractNoPIOClassDescription classes. An instantiation of one of
* these classes represents a meta class encapsulating information
* about the template argument class. This information is obtained
* from the templated ClassTraits class which can be specialized for
* any given class should the default information not be
* satisfactory. Information is also obtained from the templated
* BaseClassTraits class which must be specialized for each class
* declaring a typedef for each of its base classes.
*
* The information about a class stored in a
* <code>ClassDescriptionBase</code> objects is the following:<BR> a
* platform-independent class name,<BR> a reference to the
* <code>type_info</code><BR> an integer version number,<BR> a vector
* of <code>ClassDescriptionBase*</code> corresponding to the base
* classes,<BR> methods for reading/writing members of a class from/to
* a PersistentIStream/PersistentOStream and<BR> a method for creating
* an object of a class.
*
* The ClassDescriptionBase objects should be created before main() is
* executed, and shouold therfore be instantiated as static member
* variables. Only one ClassDescriptionBase object shall be
* instantiated for each class to be described. The
* ClassDescriptionBase objects are automatically stored in a purely
* static DescriptionList class.
*
* AbstractClassDescription and AbstractNoPIOClassDescription should
* be used for abstract base classes, while NoPIOClassDescription and
* AbstractNoPIOClassDescription should be used for classes which do
* not have any members which need to be read and written
* persistently.
*
* @see ClassTraits
* @see PersistentIStream
* @see PersistentOStream
* @see DescriptionList
*/
class ClassDescriptionBase: public Named {
public:
/** A vector of class descriptions. */
typedef vector<const ClassDescriptionBase *> DescriptionVector;
protected:
/**
* The constructor used by sub-classes.
* @param newName the platform independent name of the class.
* @param newInfo the type_info object corresponding to the class.
* @param newVersion the implementation version of the class.
* @param newLibrary the name of a file containing the dynamic
* @param abst true if the class is abstract.
* library where the class is implemented.
*/
ClassDescriptionBase(string newName,
const type_info & newInfo,
int newVersion,
string newLibrary,
bool abst)
: Named(newName), theVersion(newVersion), theLibrary(newLibrary),
theInfo(newInfo), isAbstract(abst), done(false) {}
public:
/**
* Empty destructor.
*/
virtual ~ClassDescriptionBase();
/**
* The standart RTTI type_info object for the described class.
*/
const type_info & info() const { return theInfo; }
/**
* The version of the described class.
*/
int version() const { return theVersion; }
/**
* The name of a file containing the dynamic
* library where the class is implemented.
*/
string library() const { return theLibrary; }
/**
* Return true if this object was set up properly.
*/
bool check() const { return done; }
/**
* Return the descriptions of the base classes of the described
* class.
*/
const DescriptionVector & descriptions() const { return theBaseClasses; }
/**
* Set up the base class information for this object.
*/
virtual void setup() = 0;
/**
* Create an object of the described class.
*/
virtual BPtr create() const = 0;
/**
* Output the members of an object of the described class to a
* persistent stream.
* @param b the object to be written.
* @param os the persistent stream.
*/
virtual void output(tcBPtr b, PersistentOStream & os) const = 0;
/**
* Read the members of an object of the described class from a
* persistent stream.
* @param b the object to be read.
* @param is the persistent stream.
* @param oldVersion the version number of the object when it was written.
*/
virtual void input(tBPtr b, PersistentIStream & is, int oldVersion) const = 0;
/**
* Return true if the class described by the argument is a base
* class of the class described by this.
*/
bool isA(const ClassDescriptionBase & base) const;
/**
* Return true if the corresponding class is abstract.
*/
bool abstract() const { return isAbstract; }
protected:
/**
* Set the base classes.
* @param first an iterator refering to the first base class
* @param last an iterator giving the end of the range of base class
* descriptions.
*/
void baseClasses(DescriptionVector::iterator first,
DescriptionVector::iterator last)
{
theBaseClasses = DescriptionVector(first, last);
done = true;
}
private:
/**
* The version of the described class.
*/
int theVersion;
/**
* The library file where this class may be found.
*/
string theLibrary;
/**
* The type_info object for the described class
*/
const type_info & theInfo;
/**
* The vector of base classes.
*/
DescriptionVector theBaseClasses;
/**
* True if this class is abstract.
*/
bool isAbstract;
/**
* True if this object was set up properly.
*/
bool done;
};
/**
* A helper class for tracing the base classes of a class to be
* described
*/
template <typename T, int IBase,
typename B = typename BaseClassTrait<T,IBase>::NthBase>
struct ClassDescriptionHelper {
/** Add base classes */
static void addBases(vector<const ClassDescriptionBase *> & c){
const ClassDescriptionBase * b = DescriptionList::find(typeid(B));
if ( !b ) return;
c.push_back(b);
ClassDescriptionHelper<T,IBase+1>::addBases(c);
}
};
/** @cond TRAITSPECIALIZATIONS */
/**
* A helper class for tracing the base classes of a class to be
* described
*/
template <typename T, int IBase>
struct ClassDescriptionHelper<T, IBase, int> {
/** Add base classes */
static void addBases(vector<const ClassDescriptionBase *> & ) {}
};
/** @endcond */
/**
* An intermediate templated base class derived from
* ClassDescriptionBase.
*/
template <typename T>
class ClassDescriptionTBase: public ClassDescriptionBase {
public:
/** The traits class for the template argument class. */
typedef ClassTraits<T> Traits;
public:
/**
* Default constructor. If \a abst is true then the corresponding
* class is abstract.
*/
ClassDescriptionTBase(bool abst)
: ClassDescriptionBase(Traits::className(), typeid(T), Traits::version(),
Traits::library(), abst)
{
DescriptionList::Register(*this);
T::Init();
}
/**
* The descructor.
*/
virtual ~ClassDescriptionTBase() {}
/**
* Set up the base class information for this object.
*/
virtual void setup() {
DescriptionVector bases;
ClassDescriptionHelper<T,1>::addBases(bases);
baseClasses(bases.begin(), bases.end());
}
};
/**
* A concreate implementation of ClassDescriptionBase describing an
* abstract class with persistent data.
*/
template <typename T>
class AbstractClassDescription: public ClassDescriptionTBase<T> {
public:
/** The traits class for the template argument class. */
typedef ClassTraits<T> Traits;
public:
/**
* Default constructor.
*/
AbstractClassDescription() : ClassDescriptionTBase<T>(true) {}
/**
* Do not create an object of the described class (which is
* abstract). Just return the null pointer.
*/
virtual BPtr create() const {
throw std::logic_error("Tried to instantiate virtual class " + Named::name());
}
/**
* Output the members of an object of the described class to a
* persistent stream.
* @param b the object to be written.
* @param os the persistent stream.
*/
virtual void output(tcBPtr b, PersistentOStream & os) const {
Traits::output(Traits::cast(b), os);
}
/**
* Read the members of an object of the described class from a
* persistent stream.
* @param b the object to be read.
* @param is the persistent stream.
* @param oldVersion the version number of the object when it was written.
*/
virtual void input(tBPtr b, PersistentIStream & is,
int oldVersion) const {
Traits::input(Traits::cast(b), is, oldVersion);
}
};
/**
* A concreate implementation of ClassDescriptionBase describing a
* concrete class with persistent data.
*/
template <typename T>
class ClassDescription: public ClassDescriptionTBase<T> {
public:
/** The traits class for the template argument class. */
typedef ClassTraits<T> Traits;
public:
/**
* Default constructor.
*/
ClassDescription() : ClassDescriptionTBase<T>(false) {}
/**
* Create an object of the described class.
*/
virtual BPtr create() const { return Traits::create(); }
/**
* Output the members of an object of the described class to a
* persistent stream.
* @param b the object to be written.
* @param os the persistent stream.
*/
virtual void output(tcBPtr b, PersistentOStream & os) const {
Traits::output(Traits::cast(b), os);
}
/**
* Read the members of an object of the described class from a
* persistent stream.
* @param b the object to be read.
* @param is the persistent stream.
* @param oldVersion the version number of the object when it was written.
*/
virtual void input(tBPtr b, PersistentIStream & is,
int oldVersion) const {
Traits::input(Traits::cast(b), is, oldVersion);
}
};
/**
* A concreate implementation of ClassDescriptionBase describing a
* concrete class without persistent data.
*/
template <typename T>
class NoPIOClassDescription: public ClassDescriptionTBase<T> {
public:
/** The traits class for the template argument class. */
typedef ClassTraits<T> Traits;
public:
/**
* Default constructor.
*/
NoPIOClassDescription() : ClassDescriptionTBase<T>(false) {}
/**
* Create an object of the described class.
*/
virtual BPtr create() const { return Traits::create(); }
/**
* Do nothing since the described class has no persistent data.
*/
virtual void output(tcBPtr, PersistentOStream &) const {}
/**
* Do nothing since the described class has no persistent data.
*/
virtual void input(tBPtr, PersistentIStream &, int) const {}
};
/**
* A concreate implementation of ClassDescriptionBase describing an
* abstract class without persistent data.
*/
template <typename T>
class AbstractNoPIOClassDescription: public ClassDescriptionTBase<T> {
public:
/** The traits class for the template argument class. */
typedef ClassTraits<T> Traits;
public:
/**
* Default constructor.
*/
AbstractNoPIOClassDescription() : ClassDescriptionTBase<T>(true) {}
/**
* Do not create an object of the described class (which is
* abstract). Just return the null pointer.
*/
virtual BPtr create() const {
throw std::logic_error("Tried to instantiate virtual class " + Named::name());
}
/**
* Do nothing since the described class has no persistent data.
*/
virtual void output(tcBPtr, PersistentOStream & ) const {}
/**
* Do nothing since the described class has no persistent data.
*/
virtual void input(tBPtr, PersistentIStream &, int) const {}
};
}
#define ThePEG_DECLARE_CLASS_DESCRIPTION(Class) \
/** Describe a concrete class with persistent data. */ \
static ClassDescription<Class> init ## Class \
#define ThePEG_DECLARE_ABSTRACT_CLASS_DESCRIPTION(Class) \
/** Describe an abstract class with persistent data. */ \
static AbstractClassDescription<Class> init ## Class \
#define ThePEG_DECLARE_NOPIO_CLASS_DESCRIPTION(Class) \
/** Describe a concrete class without persistent data. */ \
static NoPIOClassDescription<Class> init ## Class \
#define ThePEG_DECLARE_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
/** Describe an abstract class without persistent data. */ \
static AbstractNoPIOClassDescription<Class> init ## Class \
#define ThePEG_IMPLEMENT_CLASS_DESCRIPTION(Class) \
ClassDescription<Class> Class::init ## Class \
#define ThePEG_IMPLEMENT_ABSTRACT_CLASS_DESCRIPTION(Class) \
AbstractClassDescription<Class> Class::init ## Class \
#define ThePEG_IMPLEMENT_NOPIO_CLASS_DESCRIPTION(Class) \
NoPIOClassDescription<Class> Class::init ## Class \
#define ThePEG_IMPLEMENT_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
AbstractNoPIOClassDescription<Class> Class::init ## Class \
#endif /* ThePEG_ClassDescription_H */
|