thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.2.1
Utilities
ClassDescription.h
1
// -*- C++ -*-
2
//
3
// ClassDescription.h is a part of ThePEG - Toolkit for HEP Event Generation
4
// Copyright (C) 1999-2019 Leif Lonnblad
5
//
6
// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8
//
9
#ifndef ThePEG_ClassDescription_H
10
#define ThePEG_ClassDescription_H
11
12
#include "
ThePEG/Config/ThePEG.h
"
13
#include "ClassDescription.fh"
14
#include "ThePEG/Utilities/Named.h"
15
#include "ThePEG/Persistency/PersistentOStream.fh"
16
#include "ThePEG/Persistency/PersistentIStream.fh"
17
#include "ClassTraits.h"
18
#include "DescriptionList.h"
19
20
namespace
ThePEG
{
21
63
class
ClassDescriptionBase
:
public
Named
{
64
65
public
:
66
68
typedef
vector<const ClassDescriptionBase *>
DescriptionVector
;
69
70
protected
:
71
81
ClassDescriptionBase
(
string
newName,
82
const
type_info & newInfo,
83
int
newVersion,
84
string
newLibrary,
85
bool
abst)
86
:
Named
(newName),
theVersion
(newVersion),
theLibrary
(newLibrary),
87
theInfo
(newInfo),
isAbstract
(abst),
done
(false) {}
88
89
public
:
90
94
virtual
~ClassDescriptionBase
();
95
99
const
type_info &
info
()
const
{
return
theInfo
; }
100
104
int
version
()
const
{
return
theVersion
; }
105
110
string
library
()
const
{
return
theLibrary
; }
111
115
bool
check
()
const
{
return
done
; }
116
121
const
DescriptionVector &
descriptions
()
const
{
return
theBaseClasses
; }
122
126
virtual
void
setup
() = 0;
127
131
virtual
BPtr
create
()
const
= 0;
132
139
virtual
void
output
(
tcBPtr
b,
PersistentOStream
& os)
const
= 0;
140
148
virtual
void
input
(
tBPtr
b,
PersistentIStream
& is,
int
oldVersion)
const
= 0;
149
154
bool
isA
(
const
ClassDescriptionBase
& base)
const
;
155
159
bool
abstract
()
const
{
return
isAbstract
; }
160
161
protected
:
162
169
void
baseClasses
(DescriptionVector::iterator first,
170
DescriptionVector::iterator last)
171
{
172
theBaseClasses
=
DescriptionVector
(first, last);
173
done
=
true
;
174
}
175
176
private
:
177
181
int
theVersion
;
182
186
string
theLibrary
;
187
191
const
type_info &
theInfo
;
192
196
DescriptionVector
theBaseClasses
;
197
201
bool
isAbstract
;
202
206
bool
done
;
207
208
};
209
214
template
<
typename
T,
int
IBase,
215
typename
B =
typename
BaseClassTrait<T,IBase>::NthBase
>
216
struct
ClassDescriptionHelper
{
218
static
void
addBases
(vector<const ClassDescriptionBase *> & c){
219
const
ClassDescriptionBase
* b =
DescriptionList::find
(
typeid
(B));
220
if
( !b )
return
;
221
c.push_back(b);
222
ClassDescriptionHelper<T,IBase+1>::addBases
(c);
223
}
224
};
225
232
template
<
typename
T,
int
IBase>
233
struct
ClassDescriptionHelper
<T, IBase, int> {
235
static
void
addBases(vector<const ClassDescriptionBase *> & ) {}
236
};
237
244
template
<
typename
T>
245
class
ClassDescriptionTBase
:
public
ClassDescriptionBase
{
246
247
public
:
248
250
typedef
ClassTraits<T>
Traits
;
251
252
public
:
253
258
ClassDescriptionTBase
(
bool
abst)
259
:
ClassDescriptionBase
(Traits::className(), typeid(T), Traits::
version
(),
260
Traits::
library
(), abst)
261
{
262
DescriptionList::Register
(*
this
);
263
T::Init();
264
}
265
266
270
virtual
~ClassDescriptionTBase
() {}
271
275
virtual
void
setup
() {
276
DescriptionVector
bases;
277
ClassDescriptionHelper<T,1>::addBases
(bases);
278
baseClasses
(bases.begin(), bases.end());
279
}
280
281
};
282
287
template
<
typename
T>
288
class
AbstractClassDescription
:
public
ClassDescriptionTBase
<T> {
289
290
public
:
291
293
typedef
ClassTraits<T>
Traits
;
294
295
public
:
296
300
AbstractClassDescription
() :
ClassDescriptionTBase
<T>(true) {}
301
306
virtual
BPtr
create
()
const
{
307
throw
std::logic_error(
"Tried to instantiate virtual class "
+
Named::name
());
308
}
309
316
virtual
void
output
(
tcBPtr
b,
PersistentOStream
& os)
const
{
317
Traits::output(Traits::cast(b), os);
318
}
319
327
virtual
void
input
(
tBPtr
b,
PersistentIStream
& is,
328
int
oldVersion)
const
{
329
Traits::input(Traits::cast(b), is, oldVersion);
330
}
331
332
};
333
338
template
<
typename
T>
339
class
ClassDescription
:
public
ClassDescriptionTBase
<T> {
340
341
public
:
342
344
typedef
ClassTraits<T>
Traits
;
345
346
public
:
347
351
ClassDescription
() :
ClassDescriptionTBase
<T>(false) {}
352
356
virtual
BPtr
create
()
const
{
return
Traits::create(); }
357
364
virtual
void
output
(
tcBPtr
b,
PersistentOStream
& os)
const
{
365
Traits::output(Traits::cast(b), os);
366
}
367
375
virtual
void
input
(
tBPtr
b,
PersistentIStream
& is,
376
int
oldVersion)
const
{
377
Traits::input(Traits::cast(b), is, oldVersion);
378
}
379
380
};
381
386
template
<
typename
T>
387
class
NoPIOClassDescription
:
public
ClassDescriptionTBase
<T> {
388
389
public
:
390
392
typedef
ClassTraits<T>
Traits
;
393
394
public
:
395
399
NoPIOClassDescription
() :
ClassDescriptionTBase
<T>(false) {}
400
404
virtual
BPtr
create
()
const
{
return
Traits::create(); }
405
409
virtual
void
output
(
tcBPtr
,
PersistentOStream
&)
const
{}
410
414
virtual
void
input
(
tBPtr
,
PersistentIStream
&,
int
)
const
{}
415
416
};
417
422
template
<
typename
T>
423
class
AbstractNoPIOClassDescription
:
public
ClassDescriptionTBase
<T> {
424
425
public
:
426
428
typedef
ClassTraits<T>
Traits
;
429
430
public
:
431
435
AbstractNoPIOClassDescription
() :
ClassDescriptionTBase
<T>(true) {}
436
441
virtual
BPtr
create
()
const
{
442
throw
std::logic_error(
"Tried to instantiate virtual class "
+
Named::name
());
443
}
444
448
virtual
void
output
(
tcBPtr
,
PersistentOStream
& )
const
{}
449
453
virtual
void
input
(
tBPtr
,
PersistentIStream
&,
int
)
const
{}
454
455
};
456
457
}
458
459
#define ThePEG_DECLARE_CLASS_DESCRIPTION(Class) \
460
\
461
static ClassDescription<Class> init ## Class \
462
463
#define ThePEG_DECLARE_ABSTRACT_CLASS_DESCRIPTION(Class) \
464
\
465
static AbstractClassDescription<Class> init ## Class \
466
467
#define ThePEG_DECLARE_NOPIO_CLASS_DESCRIPTION(Class) \
468
\
469
static NoPIOClassDescription<Class> init ## Class \
470
471
#define ThePEG_DECLARE_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
472
\
473
static AbstractNoPIOClassDescription<Class> init ## Class \
474
475
#define ThePEG_IMPLEMENT_CLASS_DESCRIPTION(Class) \
476
ClassDescription<Class> Class::init ## Class \
477
478
#define ThePEG_IMPLEMENT_ABSTRACT_CLASS_DESCRIPTION(Class) \
479
AbstractClassDescription<Class> Class::init ## Class \
480
481
#define ThePEG_IMPLEMENT_NOPIO_CLASS_DESCRIPTION(Class) \
482
NoPIOClassDescription<Class> Class::init ## Class \
483
484
#define ThePEG_IMPLEMENT_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
485
AbstractNoPIOClassDescription<Class> Class::init ## Class \
486
487
#endif
/* ThePEG_ClassDescription_H */
ThePEG::NoPIOClassDescription::NoPIOClassDescription
NoPIOClassDescription()
Default constructor.
Definition:
ClassDescription.h:399
ThePEG::AbstractClassDescription::create
virtual BPtr create() const
Do not create an object of the described class (which is abstract).
Definition:
ClassDescription.h:306
ThePEG::PersistentIStream
PersistentIStream is used to read persistent objects from a stream where they were previously written...
Definition:
PersistentIStream.h:48
ThePEG::AbstractClassDescription::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:293
ThePEG::ClassDescriptionBase::create
virtual BPtr create() const =0
Create an object of the described class.
ThePEG::NoPIOClassDescription::output
virtual void output(tcBPtr, PersistentOStream &) const
Do nothing since the described class has no persistent data.
Definition:
ClassDescription.h:409
ThePEG::ClassDescriptionBase
ClassDescriptionBase is the base class for all class description classes.
Definition:
ClassDescription.h:63
ThePEG::ClassDescription::create
virtual BPtr create() const
Create an object of the described class.
Definition:
ClassDescription.h:356
ThePEG::DescriptionList::find
static const ClassDescriptionBase * find(const type_info &ti)
Get the description of a class giving its type_info object.
Definition:
DescriptionList.h:48
ThePEG::ClassDescription
A concreate implementation of ClassDescriptionBase describing a concrete class with persistent data...
Definition:
ClassDescription.h:339
ThePEG::DescriptionList::Register
static void Register(ClassDescriptionBase &)
Insert a description in the list.
ThePEG::ClassDescriptionBase::theInfo
const type_info & theInfo
The type_info object for the described class.
Definition:
ClassDescription.h:191
ThePEG::PersistentOStream
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
Definition:
PersistentOStream.h:51
ThePEG::AbstractClassDescription
A concreate implementation of ClassDescriptionBase describing an abstract class with persistent data...
Definition:
ClassDescription.h:288
ThePEG::ClassDescription::ClassDescription
ClassDescription()
Default constructor.
Definition:
ClassDescription.h:351
ThePEG::Pointer::TransientConstRCPtr
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition:
RCPtr.h:696
ThePEG::AbstractClassDescription::input
virtual void input(tBPtr b, PersistentIStream &is, int oldVersion) const
Read the members of an object of the described class from a persistent stream.
Definition:
ClassDescription.h:327
ThePEG::Pointer::TransientRCPtr
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition:
RCPtr.h:519
ThePEG::ClassDescriptionHelper::addBases
static void addBases(vector< const ClassDescriptionBase *> &c)
Add base classes.
Definition:
ClassDescription.h:218
ThePEG::AbstractNoPIOClassDescription::create
virtual BPtr create() const
Do not create an object of the described class (which is abstract).
Definition:
ClassDescription.h:441
ThePEG::ClassDescriptionTBase
An intermediate templated base class derived from ClassDescriptionBase.
Definition:
ClassDescription.h:245
ThePEG::ClassDescriptionBase::baseClasses
void baseClasses(DescriptionVector::iterator first, DescriptionVector::iterator last)
Set the base classes.
Definition:
ClassDescription.h:169
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
ThePEG::Named
The Named class is a simple concrete base class to used by classes of objects with a name...
Definition:
Named.h:24
ThePEG::NoPIOClassDescription::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:392
ThePEG::ClassDescriptionTBase::ClassDescriptionTBase
ClassDescriptionTBase(bool abst)
Default constructor.
Definition:
ClassDescription.h:258
ThePEG.h
This is the main config header file for ThePEG.
ThePEG::ClassDescriptionBase::theBaseClasses
DescriptionVector theBaseClasses
The vector of base classes.
Definition:
ClassDescription.h:196
ThePEG::NoPIOClassDescription
A concreate implementation of ClassDescriptionBase describing a concrete class without persistent dat...
Definition:
ClassDescription.h:387
ThePEG::ClassDescriptionTBase::setup
virtual void setup()
Set up the base class information for this object.
Definition:
ClassDescription.h:275
ThePEG::ClassDescriptionBase::theVersion
int theVersion
The version of the described class.
Definition:
ClassDescription.h:181
ThePEG::ClassDescriptionBase::setup
virtual void setup()=0
Set up the base class information for this object.
ThePEG::ClassDescriptionBase::theLibrary
string theLibrary
The library file where this class may be found.
Definition:
ClassDescription.h:186
ThePEG::AbstractNoPIOClassDescription::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:428
ThePEG::ClassDescriptionBase::info
const type_info & info() const
The standart RTTI type_info object for the described class.
Definition:
ClassDescription.h:99
ThePEG::ClassDescription::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:344
ThePEG::NoPIOClassDescription::create
virtual BPtr create() const
Create an object of the described class.
Definition:
ClassDescription.h:404
ThePEG::AbstractNoPIOClassDescription
A concreate implementation of ClassDescriptionBase describing an abstract class without persistent da...
Definition:
ClassDescription.h:423
ThePEG::ClassDescriptionBase::ClassDescriptionBase
ClassDescriptionBase(string newName, const type_info &newInfo, int newVersion, string newLibrary, bool abst)
The constructor used by sub-classes.
Definition:
ClassDescription.h:81
ThePEG::ClassDescriptionBase::isAbstract
bool isAbstract
True if this class is abstract.
Definition:
ClassDescription.h:201
ThePEG::ClassDescription::input
virtual void input(tBPtr b, PersistentIStream &is, int oldVersion) const
Read the members of an object of the described class from a persistent stream.
Definition:
ClassDescription.h:375
ThePEG::AbstractNoPIOClassDescription::AbstractNoPIOClassDescription
AbstractNoPIOClassDescription()
Default constructor.
Definition:
ClassDescription.h:435
ThePEG::ClassDescriptionBase::version
int version() const
The version of the described class.
Definition:
ClassDescription.h:104
ThePEG::AbstractClassDescription::AbstractClassDescription
AbstractClassDescription()
Default constructor.
Definition:
ClassDescription.h:300
ThePEG::Pointer::RCPtr
RCPtr is a reference counted (smart) pointer.
Definition:
RCPtr.h:60
ThePEG::Named::name
const string & name() const
Return name.
Definition:
Named.h:42
ThePEG::ClassDescriptionBase::isA
bool isA(const ClassDescriptionBase &base) const
Return true if the class described by the argument is a base class of the class described by this...
ThePEG::NoPIOClassDescription::input
virtual void input(tBPtr, PersistentIStream &, int) const
Do nothing since the described class has no persistent data.
Definition:
ClassDescription.h:414
ThePEG::ClassDescription::output
virtual void output(tcBPtr b, PersistentOStream &os) const
Output the members of an object of the described class to a persistent stream.
Definition:
ClassDescription.h:364
ThePEG::ClassDescriptionBase::library
string library() const
The name of a file containing the dynamic library where the class is implemented. ...
Definition:
ClassDescription.h:110
ThePEG::AbstractClassDescription::output
virtual void output(tcBPtr b, PersistentOStream &os) const
Output the members of an object of the described class to a persistent stream.
Definition:
ClassDescription.h:316
ThePEG::ClassDescriptionBase::output
virtual void output(tcBPtr b, PersistentOStream &os) const =0
Output the members of an object of the described class to a persistent stream.
ThePEG::ClassTraits
The default concrete implementation of ClassTraitsBase.
Definition:
ClassTraits.h:134
ThePEG::ClassDescriptionBase::DescriptionVector
vector< const ClassDescriptionBase * > DescriptionVector
A vector of class descriptions.
Definition:
ClassDescription.h:68
ThePEG::BaseClassTrait::NthBase
int NthBase
The type of the BaseN'th base class (int means there are no further base classes).
Definition:
ClassTraits.h:161
ThePEG::ClassDescriptionTBase::~ClassDescriptionTBase
virtual ~ClassDescriptionTBase()
The descructor.
Definition:
ClassDescription.h:270
ThePEG::ClassDescriptionBase::descriptions
const DescriptionVector & descriptions() const
Return the descriptions of the base classes of the described class.
Definition:
ClassDescription.h:121
ThePEG::ClassDescriptionBase::check
bool check() const
Return true if this object was set up properly.
Definition:
ClassDescription.h:115
ThePEG::ClassDescriptionBase::done
bool done
True if this object was set up properly.
Definition:
ClassDescription.h:206
ThePEG::AbstractNoPIOClassDescription::input
virtual void input(tBPtr, PersistentIStream &, int) const
Do nothing since the described class has no persistent data.
Definition:
ClassDescription.h:453
ThePEG::ClassDescriptionBase::input
virtual void input(tBPtr b, PersistentIStream &is, int oldVersion) const =0
Read the members of an object of the described class from a persistent stream.
ThePEG::ClassDescriptionHelper
A helper class for tracing the base classes of a class to be described.
Definition:
ClassDescription.h:216
ThePEG::AbstractNoPIOClassDescription::output
virtual void output(tcBPtr, PersistentOStream &) const
Do nothing since the described class has no persistent data.
Definition:
ClassDescription.h:448
ThePEG::ClassDescriptionTBase::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:250
ThePEG::ClassDescriptionBase::~ClassDescriptionBase
virtual ~ClassDescriptionBase()
Empty destructor.
Generated on Sat Apr 11 2020 14:31:16 for ThePEG by
1.8.13