thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
Reference.h
1 // -*- C++ -*-
2 //
3 // Reference.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_Reference_H
10 #define ThePEG_Reference_H
11 // This is the declaration of the Reference and ReferenceBase classes.
12 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "InterfaceBase.h"
15 #include "Reference.xh"
16 #include "Reference.fh"
17 
18 namespace ThePEG {
19 
38 
39 public:
40 
76  ReferenceBase(string newName, string newDescription,
77  string newClassName,
78  const type_info & newTypeInfo,
79  string newRefClassName,
80  const type_info & newRefTypeInfo, bool depSafe,
81  bool readonly, bool norebind, bool nullable, bool defnull);
82 
89  virtual string exec(InterfacedBase & ib, string action,
90  string arguments) const;
91 
95  virtual string fullDescription(const InterfacedBase & ib) const;
96 
100  virtual string type() const;
101 
106  virtual string doxygenType() const;
107 
111  virtual void set(InterfacedBase & ib, IBPtr ip, bool chk = true)
112  const = 0;
113 
117  virtual IBPtr get(const InterfacedBase & ib)
118  const = 0;
119 
124  virtual bool check(const InterfacedBase & ib, cIBPtr ip) const
125  = 0;
126 
133  virtual void rebind(InterfacedBase & ib, const TranslationMap & trans,
134  const IVector & defs) const;
135 
139  virtual IVector getReferences(const InterfacedBase & ib) const;
140 
141 };
142 
143 
161 template <class T, class R>
162 class Reference: public ReferenceBase {
163 
164 public:
165 
167  typedef typename Ptr<R>::pointer RefPtr;
169  typedef typename Ptr<R>::const_pointer cRefPtr;
171  typedef void (T::*SetFn)(RefPtr);
173  typedef bool (T::*CheckFn)(cRefPtr) const;
175  typedef RefPtr (T::*GetFn)() const;
177  typedef RefPtr T::* Member;
178 
179 public:
180 
215  Reference(string newName, string newDescription,
216  Member newMember, bool depSafe = false,
217  bool readonly = false, bool rebind = true, bool nullable = true,
218  SetFn newSetFn = 0, GetFn newGetFn = 0,
219  CheckFn newCheckFn = 0)
220  : ReferenceBase(newName, newDescription,
221  ClassTraits<T>::className(), typeid(T),
222  ClassTraits<R>::className(), typeid(R),
223  depSafe, readonly, !rebind, nullable, false),
224  theMember(newMember), theSetFn(newSetFn), theGetFn(newGetFn),
225  theCheckFn(newCheckFn) {}
226 
265  Reference(string newName, string newDescription,
266  Member newMember, bool depSafe, bool readonly, bool rebind,
267  bool nullable, bool defnull, SetFn newSetFn = 0, GetFn newGetFn = 0,
268  CheckFn newCheckFn = 0)
269  : ReferenceBase(newName, newDescription,
270  ClassTraits<T>::className(), typeid(T),
271  ClassTraits<R>::className(), typeid(R),
272  depSafe, readonly, !rebind, nullable, defnull),
273  theMember(newMember), theSetFn(newSetFn), theGetFn(newGetFn),
274  theCheckFn(newCheckFn) {}
275 
276 
280  virtual void set(InterfacedBase & ib, IBPtr ip, bool chk = true) const
281  ;
282 
286  virtual IBPtr get(const InterfacedBase & ib) const
287  ;
288 
293  virtual bool check(const InterfacedBase & ib, cIBPtr newRef) const
294  ;
295 
299  void setSetFunction(SetFn sf) { theSetFn = sf; }
300 
304  void setGetFunction(GetFn gf) { theGetFn = gf; }
305 
309  void setCheckFunction(CheckFn cf) { theCheckFn = cf; }
310 
311 private:
312 
317 
321  SetFn theSetFn;
322 
326  GetFn theGetFn;
327 
331  CheckFn theCheckFn;
332 
333 
334 };
335 
336 }
337 
338 #include "Reference.tcc"
339 
340 #endif /* ThePEG_Reference_H */
virtual string exec(InterfacedBase &ib, string action, string arguments) const
The general interface method overriding the one in InterfaceBase.
Ptr< R >::const_pointer cRefPtr
A const pointer to the class of objects referred to.
Definition: Reference.h:169
virtual string fullDescription(const InterfacedBase &ib) const
Return a complete description of this reference.
ConstRCPtr is a reference counted (smart) const pointer.
Definition: RCPtr.h:320
Rebinder is a class associating pairs of pointers to objects.
Definition: Rebinder.h:27
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Ptr< R >::pointer RefPtr
A pointer to the class of objects referred to.
Definition: Reference.h:167
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by &#39;get()&#39;.
Definition: Reference.h:304
This is the main config header file for ThePEG.
virtual bool check(const InterfacedBase &ib, cIBPtr ip) const =0
Check if set(ib, ip) will be successfull but do not do anything.
SetFn theSetFn
A pointer to a member function to be used by &#39;set()&#39;.
Definition: Reference.h:321
RefPtr T::* Member
Declaration of a direct pointer to the member variable.
Definition: Reference.h:177
CheckFn theCheckFn
Give a pointer to a member function to be used by &#39;check()&#39;.
Definition: Reference.h:331
InterfacedBase is the base class of all Interfaced objects to be handled by the BaseRepository class...
RefInterfaceBase is an abstract base class inheriting from InterfaceBase used for subclasses dealing ...
virtual string doxygenType() const
Return a string describing the type of interface to be included in the Doxygen documentation.
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
virtual void rebind(InterfacedBase &ib, const TranslationMap &trans, const IVector &defs) const
In the object ib, replace the pointer in this interface with one of the translated ones provided by t...
Reference(string newName, string newDescription, Member newMember, bool depSafe, bool readonly, bool rebind, bool nullable, bool defnull, SetFn newSetFn=0, GetFn newGetFn=0, CheckFn newCheckFn=0)
Standard constructor.
Definition: Reference.h:265
GetFn theGetFn
Give a pointer to a member function to be used by &#39;get()&#39;.
Definition: Reference.h:326
string className() const
Return the class name for the class this interface is defined for.
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
Member theMember
The pointer to the member variable.
Definition: Reference.h:316
void setCheckFunction(CheckFn cf)
Give a pointer to a member function to be used by &#39;check()&#39;.
Definition: Reference.h:309
The Reference class and its base class ReferenceBase defines an interface to a class derived from the...
Definition: Reference.h:37
vector< IBPtr > IVector
A vector of pointers to InterfacedBase objects.
Definition: Containers.h:67
ReferenceBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, string newRefClassName, const type_info &newRefTypeInfo, bool depSafe, bool readonly, bool norebind, bool nullable, bool defnull)
Standard constructor.
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by &#39;set()&#39;.
Definition: Reference.h:299
Reference(string newName, string newDescription, Member newMember, bool depSafe=false, bool readonly=false, bool rebind=true, bool nullable=true, SetFn newSetFn=0, GetFn newGetFn=0, CheckFn newCheckFn=0)
Standard constructor.
Definition: Reference.h:215
virtual string type() const
Return a code for the type of this reference.
The Reference and its base class ReferenceBase defines an interface to a class derived from the Inter...
Definition: Reference.h:162
virtual IVector getReferences(const InterfacedBase &ib) const
Return the pointer to another object in ib (in a vector).