thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.1.5
RefVector.h
1 // -*- C++ -*-
2 //
3 // RefVector.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2017 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_RefVector_H
10 #define ThePEG_RefVector_H
11 // This is the declaration of the RefVector and RefVectorBase classes.
12 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "InterfaceBase.h"
15 #include "RefVector.xh"
16 #include "RefVector.fh"
17 
18 namespace ThePEG {
19 
39 
40 public:
41 
79  RefVectorBase(string newName, string newDescription,
80  string newClassName,
81  const type_info & newTypeInfo,
82  string newRefClassName,
83  const type_info & newRefTypeInfo,
84  int newSize, bool depSafe,
85  bool readonly, bool norebind, bool nullable, bool defnull);
86 
95  virtual string exec(InterfacedBase & ib, string action,
96  string arguments) const;
97 
101  virtual string fullDescription(const InterfacedBase & ib) const;
102 
106  virtual string type() const;
107 
112  virtual string doxygenType() const;
113 
118  virtual void set(InterfacedBase & ib, IBPtr ip, int i, bool chk = true)
119  const = 0;
120 
125  virtual void insert(InterfacedBase & ib, IBPtr ip, int i, bool chk = true)
126  const = 0;
127 
131  virtual void erase(InterfacedBase & ib, int i)
132  const = 0;
133 
137  virtual void clear(InterfacedBase & ib)
138  const = 0;
139 
144  virtual IVector get(const InterfacedBase & ib) const
145  = 0;
146 
151  virtual bool check(const InterfacedBase & ib, cIBPtr ip, int i) const
152  = 0;
153 
160  virtual void rebind(InterfacedBase & ib, const TranslationMap & trans,
161  const IVector & defs) const;
162 
166  virtual IVector getReferences(const InterfacedBase & ib) const;
167 
172  int size() const { return theSize; }
173 
178  void setSize(int sz) { theSize = sz; }
179 
184  void setVariableSize() { theSize = 0; }
185 
186 private:
187 
191  int theSize;
192 
193 };
194 
195 
214 template <class T, class R>
215 class RefVector: public RefVectorBase {
216 
217 public:
218 
220  typedef typename Ptr<R>::pointer RefPtr;
222  typedef typename Ptr<R>::const_pointer cRefPtr;
224  typedef void (T::*SetFn)(RefPtr, int);
226  typedef void (T::*InsFn)(RefPtr, int);
228  typedef void (T::*DelFn)(int);
230  typedef bool (T::*CheckFn)(cRefPtr, int) const;
232  typedef vector<RefPtr> (T::*GetFn)() const;
237  typedef vector<RefPtr> T::* Member;
238 
239 public:
240 
283  RefVector(string newName, string newDescription,
284  Member newMember, int newSize, bool depSafe = false,
285  bool readonly = false, bool rebind = true, bool nullable = true,
286  SetFn newSetFn = 0, InsFn newInsFn = 0, DelFn newDelFn = 0,
287  GetFn newGetFn = 0, CheckFn newCheckFn = 0);
288 
335  RefVector(string newName, string newDescription,
336  Member newMember, int newSize, bool depSafe,
337  bool readonly, bool rebind, bool nullable, bool defnull,
338  SetFn newSetFn = 0, InsFn newInsFn = 0, DelFn newDelFn = 0,
339  GetFn newGetFn = 0, CheckFn newCheckFn = 0);
340 
345  virtual void set(InterfacedBase & ib, IBPtr ip, int i, bool chk = true)
346  const;
347 
352  virtual void insert(InterfacedBase & ib, IBPtr ip, int i, bool chk = true)
353  const;
354 
358  virtual void erase(InterfacedBase & ib, int i)
359  const;
360 
364  virtual void clear(InterfacedBase & ib)
365  const;
366 
371  virtual IVector get(const InterfacedBase & ib) const
372  ;
373 
378  virtual bool check(const InterfacedBase & ib, cIBPtr, int i) const
379  ;
380 
384  void setSetFunction(SetFn sf) { theSetFn = sf; }
385 
389  void setInsertFunction(InsFn ifn) { theInsFn = ifn; }
390 
394  void setGetFunction(GetFn gf) { theGetFn = gf; }
395 
399  void setEraseFunction(DelFn df) { theDelFn = df; }
400 
404  void setCheckFunction(CheckFn cf) { theCheckFn = cf; }
405 
406 private:
407 
412 
416  SetFn theSetFn;
417 
421  InsFn theInsFn;
422 
426  DelFn theDelFn;
427 
431  GetFn theGetFn;
432 
436  CheckFn theCheckFn;
437 
438 };
439 
440 }
441 
442 #include "RefVector.tcc"
443 
444 #endif /* ThePEG_RefVector_H */
virtual void clear(InterfacedBase &ib) const =0
Clear the container of pointers of ib.
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by &#39;set()&#39;.
Definition: RefVector.h:384
InsFn theInsFn
Give a pointer to a member function to be used by &#39;insert()&#39;.
Definition: RefVector.h:421
virtual void insert(InterfacedBase &ib, IBPtr ip, int i, bool chk=true) const =0
Insert a new pointer before the i&#39;th element of a container of pointers of ib and set it to ip...
Ptr< R >::pointer RefPtr
A pointer to the class of objects referred to.
Definition: RefVector.h:220
virtual IVector getReferences(const InterfacedBase &ib) const
Return pointers to other objects in ib.
virtual string fullDescription(const InterfacedBase &ib) const
Return a complete description of this reference vector.
void setSize(int sz)
Set the size of the container being interfaced.
Definition: RefVector.h:178
vector< RefPtr > T::* Member
Declaration of a direct pointer to the member variable in case it is a vector.
Definition: RefVector.h:237
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by &#39;get()&#39;.
Definition: RefVector.h:394
virtual bool check(const InterfacedBase &ib, cIBPtr ip, int i) const =0
Check if set(ib, ip, i) will be successfull but do not do anything.
The RefVector and its base class RefVectorBase defines an interface to a class derived from the Inter...
Definition: RefVector.h:215
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
This is the main config header file for ThePEG.
virtual void erase(InterfacedBase &ib, int i) const =0
Remove the i&#39;th element of a container of pointers of ib.
void setVariableSize()
Set the size of the container being interfaced to -1, i.e.
Definition: RefVector.h:184
Ptr< R >::const_pointer cRefPtr
A const pointer to the class of objects referred to.
Definition: RefVector.h:222
int theSize
The size of the container being interfaced.
Definition: RefVector.h:191
SetFn theSetFn
A pointer to a member function to be used by &#39;set()&#39;.
Definition: RefVector.h:416
virtual string doxygenType() const
Return a string describing the type of interface to be included in the Doxygen documentation.
The RefVector and its base class RefVectorBase defines an interface to a class derived from the Inter...
Definition: RefVector.h:38
void setCheckFunction(CheckFn cf)
Give a pointer to a member function to be used by &#39;check()&#39;.
Definition: RefVector.h:404
virtual string exec(InterfacedBase &ib, string action, string arguments) const
The general interface method overriding the one in InterfaceBase.
void setEraseFunction(DelFn df)
Give a pointer to a member function to be used by &#39;erase()&#39;.
Definition: RefVector.h:399
RefVectorBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, string newRefClassName, const type_info &newRefTypeInfo, int newSize, bool depSafe, bool readonly, bool norebind, bool nullable, bool defnull)
Standard constructor.
GetFn theGetFn
Give a pointer to a member function to be used by &#39;get()&#39;.
Definition: RefVector.h:431
virtual void rebind(InterfacedBase &ib, const TranslationMap &trans, const IVector &defs) const
In the object ib, replace all pointers to objects in this interface with the translated ones provided...
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 ...
void setInsertFunction(InsFn ifn)
Give a pointer to a member function to be used by &#39;insert()&#39;.
Definition: RefVector.h:389
vector< RefPtr >(T::* GetFn)() const
A pointer to a menberfunction to be used for the &#39;get&#39; action.
Definition: RefVector.h:232
virtual string type() const
Return a code for the type of this reference.
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
Member theMember
The pointer to the member variable.
Definition: RefVector.h:411
int size() const
Get the size of the container being interfaced.
Definition: RefVector.h:172
vector< IBPtr > IVector
A vector of pointers to InterfacedBase objects.
Definition: Containers.h:67
DelFn theDelFn
Give a pointer to a member function to be used by &#39;erase()&#39;.
Definition: RefVector.h:426
CheckFn theCheckFn
Give a pointer to a member function to be used by &#39;check()&#39;.
Definition: RefVector.h:436