ThePEG  1.8.0
RefVector.h
1 // -*- C++ -*-
2 //
3 // RefVector.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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 
138  virtual IVector get(const InterfacedBase & ib) const
139  = 0;
140 
145  virtual bool check(const InterfacedBase & ib, cIBPtr ip, int i) const
146  = 0;
147 
154  virtual void rebind(InterfacedBase & ib, const TranslationMap & trans,
155  const IVector & defs) const;
156 
160  virtual IVector getReferences(const InterfacedBase & ib) const;
161 
166  int size() const { return theSize; }
167 
172  void setSize(int sz) { theSize = sz; }
173 
178  void setVariableSize() { theSize = 0; }
179 
180 private:
181 
185  int theSize;
186 
187 };
188 
189 
208 template <class T, class R>
209 class RefVector: public RefVectorBase {
210 
211 public:
212 
214  typedef typename Ptr<R>::pointer RefPtr;
216  typedef typename Ptr<R>::const_pointer cRefPtr;
218  typedef void (T::*SetFn)(RefPtr, int);
220  typedef void (T::*InsFn)(RefPtr, int);
222  typedef void (T::*DelFn)(int);
224  typedef bool (T::*CheckFn)(cRefPtr, int) const;
226  typedef vector<RefPtr> (T::*GetFn)() const;
231  typedef vector<RefPtr> T::* Member;
232 
233 public:
234 
277  RefVector(string newName, string newDescription,
278  Member newMember, int newSize, bool depSafe = false,
279  bool readonly = false, bool rebind = true, bool nullable = true,
280  SetFn newSetFn = 0, InsFn newInsFn = 0, DelFn newDelFn = 0,
281  GetFn newGetFn = 0, CheckFn newCheckFn = 0);
282 
329  RefVector(string newName, string newDescription,
330  Member newMember, int newSize, bool depSafe,
331  bool readonly, bool rebind, bool nullable, bool defnull,
332  SetFn newSetFn = 0, InsFn newInsFn = 0, DelFn newDelFn = 0,
333  GetFn newGetFn = 0, CheckFn newCheckFn = 0);
334 
339  virtual void set(InterfacedBase & ib, IBPtr ip, int i, bool chk = true)
340  const;
341 
346  virtual void insert(InterfacedBase & ib, IBPtr ip, int i, bool chk = true)
347  const;
348 
352  virtual void erase(InterfacedBase & ib, int i)
353  const;
354 
359  virtual IVector get(const InterfacedBase & ib) const
360  ;
361 
366  virtual bool check(const InterfacedBase & ib, cIBPtr, int i) const
367  ;
368 
372  void setSetFunction(SetFn sf) { theSetFn = sf; }
373 
377  void setInsertFunction(InsFn ifn) { theInsFn = ifn; }
378 
382  void setGetFunction(GetFn gf) { theGetFn = gf; }
383 
387  void setEraseFunction(DelFn df) { theDelFn = df; }
388 
392  void setCheckFunction(CheckFn cf) { theCheckFn = cf; }
393 
394 private:
395 
400 
404  SetFn theSetFn;
405 
409  InsFn theInsFn;
410 
414  DelFn theDelFn;
415 
419  GetFn theGetFn;
420 
424  CheckFn theCheckFn;
425 
426 };
427 
428 }
429 
430 #include "RefVector.tcc"
431 
432 #endif /* ThePEG_RefVector_H */
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by &#39;set()&#39;.
Definition: RefVector.h:372
InsFn theInsFn
Give a pointer to a member function to be used by &#39;insert()&#39;.
Definition: RefVector.h:409
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:214
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:172
vector< RefPtr > T::* Member
Declaration of a direct pointer to the member variable in case it is a vector.
Definition: RefVector.h:231
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by &#39;get()&#39;.
Definition: RefVector.h:382
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:209
ConstRCPtr is a reference counted (smart) const pointer.
Definition: RCPtr.h:315
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
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:178
Ptr< R >::const_pointer cRefPtr
A const pointer to the class of objects referred to.
Definition: RefVector.h:216
int theSize
The size of the container being interfaced.
Definition: RefVector.h:185
SetFn theSetFn
A pointer to a member function to be used by &#39;set()&#39;.
Definition: RefVector.h:404
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:392
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:387
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:419
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:377
vector< RefPtr >(T::* GetFn)() const
A pointer to a menberfunction to be used for the &#39;get&#39; action.
Definition: RefVector.h:226
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:399
int size() const
Get the size of the container being interfaced.
Definition: RefVector.h:166
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:414
CheckFn theCheckFn
Give a pointer to a member function to be used by &#39;check()&#39;.
Definition: RefVector.h:424