elementFormulaRCP_std.hh

Go to the documentation of this file.
1 
8 #ifndef elementformulaRCP_std_hh
9 #define elementformulaRCP_std_hh
10 
11 #include "toolbox/sharedPointer.hh"
12 #include "elementFormula.hh"
13 #include "formula.hh"
14 #include "constFormula.hh"
15 
16 #define ElemFormRCPClone_D 0
17 #define ElemFormRCPValue_D 0
18 #define FormRCPClone_D 0
19 #define FormRCPValue_D 0
20 
21 namespace concepts {
22 
23 
24  // ***************************************** RCP<const ElementFormula<F,G> > **
25 
26  template<class F, typename G>
27  class RCP<const ElementFormula<F,G> >
28  : public std::shared_ptr<const ElementFormula<F,G> >
29  {
30  public:
38  explicit RCP(const F x)
39  : std::shared_ptr<const ElementFormula<F,G> >
40  (new const ConstFormula<F>(x)) {}
41 
43  RCP() : std::shared_ptr<const ElementFormula<F,G> >() {}
44 
45  // this conversion operator is already implemented for shared_ptr
46  #if 0
47  // implicit conversion ops.
48  template<class OldF, class OldG>
49  RCP(RCP< const ElementFormula<OldF,OldG> > old)
50  : std::shared_ptr<const ElementFormula<F,G> >( old )
51  {
52  }
53  #endif
54 
67  explicit RCP(const ElementFormula<F,G>* x)
68  : std::shared_ptr<const ElementFormula<F,G> >(x) {}
69 
71  RCP(std::shared_ptr<const ElementFormula<F,G> >& x)
72  : std::shared_ptr<const ElementFormula<F,G> >(x) {}
73 
76  template<class H>
77  RCP(const std::shared_ptr<H>& x)
78  : std::shared_ptr<const ElementFormula<F,G> >(x) {}
79 
81  template<class H, class I>
82  RCP(H x, I y) : std::shared_ptr<const ElementFormula<F,G> >(x, y) {}
83 
88  // but more importantly it is severely prone to errors.
90  // this functions tells C++ to convert any const
91  // reference to ElementFormulas AUTOMATICALLY into
92  // RCP<ElementFormula>. In particular this strip of code
93  // equates EF-References with EF-SmartPointer, so it equates
94  // references with pointers. I do not know which side effects
95  // this strip of code can create, but expect severe ones!
96  //explicit RCP(const ElementFormula<F,G>& x)
98  : std::shared_ptr<const ElementFormula<F,G> >(x.clone())
99  {
100  DEBUGL(ElemFormRCPClone_D, "Cloned " << **this << " = *" << *this);
101  }
102 
105  {
106  RCP<const ElementFormula<F,G> >(x).swap(*this);
107  return *this;
108  }
109 
110  template<class H>
112  operator=(const RCP<H>& x)
113  {
114  RCP<const ElementFormula<F,G> >(x).swap(*this);
115  return *this;
116  }
117 
118 #if ElemFormRCPValue_D
119  // for debugging in case of zero pointers: output of pointer
120  const ElementFormula<F,G>& operator* () const // never throws
121  {
122  DEBUGL(1, *this);
123  return std::shared_ptr<const ElementFormula<F,G> >(*this).operator*();
124  }
125 #endif
126  };
127 
128 
129  // ************************************************ RCP<const Formula<F,G> > **
130 
131  template<class F>
132  class RCP<const Formula<F> > : public std::shared_ptr<const Formula<F> >
133  {
134  public:
142  explicit RCP(const F x)
143  : std::shared_ptr<const Formula<F> >(new const ConstFormula<F>(x)) {}
144 
146  RCP() : std::shared_ptr<const Formula<F> >() {}
147 
160  explicit RCP(const Formula<F>* x)
161  : std::shared_ptr<const Formula<F> >(x) {}
162 
163  RCP(std::shared_ptr<const Formula<F> >& x)
164  : std::shared_ptr<const Formula<F> >(x) {}
165 
166  template<class H>
167  RCP(const std::shared_ptr<H>& x)
168  : std::shared_ptr<const Formula<F> >(x) {}
169 
171  template<class H, class I>
172  RCP(H x, I y) : std::shared_ptr<const Formula<F> >(x, y) {}
173 
178  // but more importantly it is severely prone to errors.
180  // this functions tells C++ to convert any const
181  // reference to ElementFormulas AUTOMATICALLY into
182  // RCP<ElementFormula>. In particular this strip of code
183  // equates EF-References with EF-SmartPointer, so it equates
184  // references with pointers. I do not know which side effects
185  // this strip of code can create, but expect severe ones!
186  explicit RCP(const Formula<F>& x) : std::shared_ptr<const Formula<F> >(x.clone())
187  {
188  DEBUGL(FormRCPClone_D, "Cloned " << **this << " = *" << *this);
189  }
190 
192  operator=(const RCP<const Formula<F> >& x)
193  {
194  RCP<const Formula<F> >(x).swap(*this);
195  return *this;
196  }
197 
198  template<class H>
200  operator=(const RCP<H>& x)
201  {
202  RCP<const Formula<F> >(x).swap(*this);
203  return *this;
204  }
205 
206 #if FormRCPValue_D
207  // for debugging in case of zero pointers: output of pointer
208  const Formula<F>& operator* () const // never throws
209  {
210  DEBUGL(1, *this);
211  return std::shared_ptr<const Formula<F> >(*this).operator*();
212  }
213 #endif
214 
215  };
216 
217 
218 } // namespace concepts
219 
220 
221 #endif // elementformulaRCP_std_hh
RCP< const Formula< F > > & operator=(const RCP< const Formula< F > > &x)
Class for a constant formula.
Definition: constFormula.hh:26
RCP(const F x)
Special constructor for a constant.
Point< typename Combtype< F, Real >::type, dim > operator*(const Real x, const Point< F, dim > &y)
Interface for a formula.
Definition: lform.hh:18
RCP(H x, I y)
Constructor with any two parameters, I is a deleter function.
RCP(const std::shared_ptr< H > &x)
RCP(std::shared_ptr< const ElementFormula< F, G > > &x)
conversion constructor from std::shared_ptr
#define DEBUGL(doit, msg)
RCP(const Formula< F > &x)
Constructor with a given reference, ElementFormula will be cloned.
RCP< const Formula< F > > & operator=(const RCP< H > &x)
RCP(const ElementFormula< F, G > *x)
Constructor for a simple pointer to ElementFormula, which will be deleted by the RCP.
RCP()
Default constructor.
Interface for a formula defined element by element.
RCP< const ElementFormula< F, G > > & operator=(const RCP< const ElementFormula< F, G > > &x)
RCP< const ElementFormula< F, G > > & operator=(const RCP< H > &x)
RCP(H x, I y)
Constructor with any two parameters.
Reference-counting pointer.
Definition: bf_iddiv.hh:15
#define ElemFormRCPClone_D
RCP(const F x)
Special constructor for a constant.
RCP()
Default constructor, creates an RCP to a NULL-pointer.
RCP(const std::shared_ptr< H > &x)
conversion constructor from std::shared_ptr<H>, where H can be converted into ElementFormula<F,...
RCP(std::shared_ptr< const Formula< F > > &x)
#define FormRCPClone_D
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
RCP(const Formula< F > *x)
Constructor for a simple pointer to ElementFormula, which will be deleted by the RCP.
RCP(const ElementFormula< F, G > &x)
Constructor with a given reference, ElementFormula will be cloned.
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich