ThePEG  1.8.0
Reference.h
1 // -*- C++ -*-
2 //
3 // Reference.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_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 
310 
311 private:
312 
317 
322 
327 
332 
333 
334 };
335 
336 }
337 
338 #include "Reference.tcc"
339 
340 #endif /* ThePEG_Reference_H */