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 
393 
394 private:
395 
400 
405 
410 
415 
420 
425 
426 };
427 
428 }
429 
430 #include "RefVector.tcc"
431 
432 #endif /* ThePEG_RefVector_H */