thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
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
269
virtual
void
setup
() {
270
DescriptionVector
bases;
271
ClassDescriptionHelper<T,1>::addBases
(bases);
272
baseClasses
(bases.begin(), bases.end());
273
}
274
275
};
276
281
template
<
typename
T>
282
class
AbstractClassDescription
:
public
ClassDescriptionTBase
<T> {
283
284
public
:
285
287
typedef
ClassTraits<T>
Traits
;
288
289
public
:
290
294
AbstractClassDescription
() :
ClassDescriptionTBase
<T>(true) {}
295
300
virtual
BPtr
create
()
const
{
301
throw
std::logic_error(
"Tried to instantiate virtual class "
+
Named::name
());
302
}
303
310
virtual
void
output
(
tcBPtr
b,
PersistentOStream
& os)
const
{
311
Traits::output
(
Traits::cast
(b), os);
312
}
313
321
virtual
void
input
(
tBPtr
b,
PersistentIStream
& is,
322
int
oldVersion)
const
{
323
Traits::input
(
Traits::cast
(b), is, oldVersion);
324
}
325
326
};
327
332
template
<
typename
T>
333
class
ClassDescription
:
public
ClassDescriptionTBase
<T> {
334
335
public
:
336
338
typedef
ClassTraits<T>
Traits
;
339
340
public
:
341
345
ClassDescription
() :
ClassDescriptionTBase
<T>(false) {}
346
350
virtual
BPtr
create
()
const
{
return
Traits::create
(); }
351
358
virtual
void
output
(
tcBPtr
b,
PersistentOStream
& os)
const
{
359
Traits::output
(
Traits::cast
(b), os);
360
}
361
369
virtual
void
input
(
tBPtr
b,
PersistentIStream
& is,
370
int
oldVersion)
const
{
371
Traits::input
(
Traits::cast
(b), is, oldVersion);
372
}
373
374
};
375
380
template
<
typename
T>
381
class
NoPIOClassDescription
:
public
ClassDescriptionTBase
<T> {
382
383
public
:
384
386
typedef
ClassTraits<T>
Traits
;
387
388
public
:
389
393
NoPIOClassDescription
() :
ClassDescriptionTBase
<T>(false) {}
394
398
virtual
BPtr
create
()
const
{
return
Traits::create
(); }
399
403
virtual
void
output
(
tcBPtr
,
PersistentOStream
&)
const
{}
404
408
virtual
void
input
(
tBPtr
,
PersistentIStream
&,
int
)
const
{}
409
410
};
411
416
template
<
typename
T>
417
class
AbstractNoPIOClassDescription
:
public
ClassDescriptionTBase
<T> {
418
419
public
:
420
422
typedef
ClassTraits<T>
Traits
;
423
424
public
:
425
429
AbstractNoPIOClassDescription
() :
ClassDescriptionTBase
<T>(true) {}
430
435
virtual
BPtr
create
()
const
{
436
throw
std::logic_error(
"Tried to instantiate virtual class "
+
Named::name
());
437
}
438
442
virtual
void
output
(
tcBPtr
,
PersistentOStream
& )
const
{}
443
447
virtual
void
input
(
tBPtr
,
PersistentIStream
&,
int
)
const
{}
448
449
};
450
451
}
452
453
#define ThePEG_DECLARE_CLASS_DESCRIPTION(Class) \
454
\
455
static ClassDescription<Class> init ## Class \
456
457
#define ThePEG_DECLARE_ABSTRACT_CLASS_DESCRIPTION(Class) \
458
\
459
static AbstractClassDescription<Class> init ## Class \
460
461
#define ThePEG_DECLARE_NOPIO_CLASS_DESCRIPTION(Class) \
462
\
463
static NoPIOClassDescription<Class> init ## Class \
464
465
#define ThePEG_DECLARE_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
466
\
467
static AbstractNoPIOClassDescription<Class> init ## Class \
468
469
#define ThePEG_IMPLEMENT_CLASS_DESCRIPTION(Class) \
470
ClassDescription<Class> Class::init ## Class \
471
472
#define ThePEG_IMPLEMENT_ABSTRACT_CLASS_DESCRIPTION(Class) \
473
AbstractClassDescription<Class> Class::init ## Class \
474
475
#define ThePEG_IMPLEMENT_NOPIO_CLASS_DESCRIPTION(Class) \
476
NoPIOClassDescription<Class> Class::init ## Class \
477
478
#define ThePEG_IMPLEMENT_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
479
AbstractNoPIOClassDescription<Class> Class::init ## Class \
480
481
#endif
/* ThePEG_ClassDescription_H */
ThePEG.h
This is the main config header file for ThePEG.
ThePEG::AbstractClassDescription
A concreate implementation of ClassDescriptionBase describing an abstract class with persistent data.
Definition:
ClassDescription.h:282
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:310
ThePEG::AbstractClassDescription::create
virtual BPtr create() const
Do not create an object of the described class (which is abstract).
Definition:
ClassDescription.h:300
ThePEG::AbstractClassDescription::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:287
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:321
ThePEG::AbstractClassDescription::AbstractClassDescription
AbstractClassDescription()
Default constructor.
Definition:
ClassDescription.h:294
ThePEG::AbstractNoPIOClassDescription
A concreate implementation of ClassDescriptionBase describing an abstract class without persistent da...
Definition:
ClassDescription.h:417
ThePEG::AbstractNoPIOClassDescription::output
virtual void output(tcBPtr, PersistentOStream &) const
Do nothing since the described class has no persistent data.
Definition:
ClassDescription.h:442
ThePEG::AbstractNoPIOClassDescription::create
virtual BPtr create() const
Do not create an object of the described class (which is abstract).
Definition:
ClassDescription.h:435
ThePEG::AbstractNoPIOClassDescription::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:422
ThePEG::AbstractNoPIOClassDescription::input
virtual void input(tBPtr, PersistentIStream &, int) const
Do nothing since the described class has no persistent data.
Definition:
ClassDescription.h:447
ThePEG::AbstractNoPIOClassDescription::AbstractNoPIOClassDescription
AbstractNoPIOClassDescription()
Default constructor.
Definition:
ClassDescription.h:429
ThePEG::ClassDescriptionBase
ClassDescriptionBase is the base class for all class description classes.
Definition:
ClassDescription.h:63
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::theInfo
const type_info & theInfo
The type_info object for the described class.
Definition:
ClassDescription.h:191
ThePEG::ClassDescriptionBase::theLibrary
string theLibrary
The library file where this class may be found.
Definition:
ClassDescription.h:186
ThePEG::ClassDescriptionBase::done
bool done
True if this object was set up properly.
Definition:
ClassDescription.h:206
ThePEG::ClassDescriptionBase::abstract
bool abstract() const
Return true if the corresponding class is abstract.
Definition:
ClassDescription.h:159
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::ClassDescriptionBase::setup
virtual void setup()=0
Set up the base class information for this object.
ThePEG::ClassDescriptionBase::theBaseClasses
DescriptionVector theBaseClasses
The vector of base classes.
Definition:
ClassDescription.h:196
ThePEG::ClassDescriptionBase::theVersion
int theVersion
The version of the described class.
Definition:
ClassDescription.h:181
ThePEG::ClassDescriptionBase::DescriptionVector
vector< const ClassDescriptionBase * > DescriptionVector
A vector of class descriptions.
Definition:
ClassDescription.h:68
ThePEG::ClassDescriptionBase::descriptions
const DescriptionVector & descriptions() const
Return the descriptions of the base classes of the described class.
Definition:
ClassDescription.h:121
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::ClassDescriptionBase::isAbstract
bool isAbstract
True if this class is abstract.
Definition:
ClassDescription.h:201
ThePEG::ClassDescriptionBase::version
int version() const
The version of the described class.
Definition:
ClassDescription.h:104
ThePEG::ClassDescriptionBase::baseClasses
void baseClasses(DescriptionVector::iterator first, DescriptionVector::iterator last)
Set the base classes.
Definition:
ClassDescription.h:169
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::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::ClassDescriptionBase::info
const type_info & info() const
The standart RTTI type_info object for the described class.
Definition:
ClassDescription.h:99
ThePEG::ClassDescriptionBase::check
bool check() const
Return true if this object was set up properly.
Definition:
ClassDescription.h:115
ThePEG::ClassDescriptionBase::~ClassDescriptionBase
virtual ~ClassDescriptionBase()
Empty destructor.
ThePEG::ClassDescriptionBase::create
virtual BPtr create() const =0
Create an object of the described class.
ThePEG::ClassDescriptionTBase
An intermediate templated base class derived from ClassDescriptionBase.
Definition:
ClassDescription.h:245
ThePEG::ClassDescriptionTBase::setup
virtual void setup()
Set up the base class information for this object.
Definition:
ClassDescription.h:269
ThePEG::ClassDescriptionTBase::ClassDescriptionTBase
ClassDescriptionTBase(bool abst)
Default constructor.
Definition:
ClassDescription.h:258
ThePEG::ClassDescriptionTBase::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:250
ThePEG::ClassDescription
A concreate implementation of ClassDescriptionBase describing a concrete class with persistent data.
Definition:
ClassDescription.h:333
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:358
ThePEG::ClassDescription::create
virtual BPtr create() const
Create an object of the described class.
Definition:
ClassDescription.h:350
ThePEG::ClassDescription::ClassDescription
ClassDescription()
Default constructor.
Definition:
ClassDescription.h:345
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:369
ThePEG::ClassDescription::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:338
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::DescriptionList::Register
static void Register(ClassDescriptionBase &)
Insert a description in the list.
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::Named::name
const string & name() const
Return name.
Definition:
Named.h:42
ThePEG::NoPIOClassDescription
A concreate implementation of ClassDescriptionBase describing a concrete class without persistent dat...
Definition:
ClassDescription.h:381
ThePEG::NoPIOClassDescription::Traits
ClassTraits< T > Traits
The traits class for the template argument class.
Definition:
ClassDescription.h:386
ThePEG::NoPIOClassDescription::NoPIOClassDescription
NoPIOClassDescription()
Default constructor.
Definition:
ClassDescription.h:393
ThePEG::NoPIOClassDescription::input
virtual void input(tBPtr, PersistentIStream &, int) const
Do nothing since the described class has no persistent data.
Definition:
ClassDescription.h:408
ThePEG::NoPIOClassDescription::create
virtual BPtr create() const
Create an object of the described class.
Definition:
ClassDescription.h:398
ThePEG::NoPIOClassDescription::output
virtual void output(tcBPtr, PersistentOStream &) const
Do nothing since the described class has no persistent data.
Definition:
ClassDescription.h:403
ThePEG::PersistentIStream
PersistentIStream is used to read persistent objects from a stream where they were previously written...
Definition:
PersistentIStream.h:48
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::Pointer::RCPtr
RCPtr is a reference counted (smart) pointer.
Definition:
RCPtr.h:60
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::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
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
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::ClassDescriptionHelper
A helper class for tracing the base classes of a class to be described.
Definition:
ClassDescription.h:216
ThePEG::ClassDescriptionHelper::addBases
static void addBases(vector< const ClassDescriptionBase * > &c)
Add base classes.
Definition:
ClassDescription.h:218
ThePEG::ClassTraitsBase::cast
static TPtr cast(BPtr b)
Perform a dynamic cast from the given pointer to a pointer to T.
Definition:
ClassTraits.h:106
ThePEG::ClassTraitsBase::create
static TPtr create()
Create a T object and return a smart pointer to it.
Definition:
ClassTraits.h:60
ThePEG::ClassTraitsBase::input
static void input(tTPtr t, PersistentIStream &is, int oldVersion)
Read the T part of an object from a persistent stream.
Definition:
ClassTraits.h:99
ThePEG::ClassTraitsBase::output
static void output(tcTPtr t, PersistentOStream &os)
Write the T part of an object to a persistent stream.
Definition:
ClassTraits.h:92
ThePEG::ClassTraits
The default concrete implementation of ClassTraitsBase.
Definition:
ClassTraits.h:134
Generated on Thu Jun 20 2024 14:47:02 for ThePEG by
1.9.6