Chemical Data Processing Library C++ API - Version 1.4.0
Expression.hpp
Go to the documentation of this file.
1 /*
2  * Expression.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_EXPRESSION_HPP
28 #define CDPL_MATH_EXPRESSION_HPP
29 
30 
31 namespace CDPL
32 {
33 
34  namespace Math
35  {
36 
41  template <typename E>
42  class Expression
43  {
44 
45  public:
47  typedef E ExpressionType;
48 
49  protected:
52 
53  private:
54  const Expression& operator=(const Expression&);
55  };
56 
64  template <typename E>
65  class VectorExpression : public Expression<E>
66  {
67 
68  public:
70  typedef E ExpressionType;
71 
76  const ExpressionType& operator()() const
77  {
78  return *static_cast<const ExpressionType*>(this);
79  }
80 
86  {
87  return *static_cast<ExpressionType*>(this);
88  }
89 
90  protected:
93  };
94 
102  template <typename E>
103  class MatrixExpression : public Expression<E>
104  {
105 
106  public:
108  typedef E ExpressionType;
109 
114  const ExpressionType& operator()() const
115  {
116  return *static_cast<const ExpressionType*>(this);
117  }
118 
124  {
125  return *static_cast<ExpressionType*>(this);
126  }
127 
128  protected:
131  };
132 
140  template <typename E>
142  {
143 
144  public:
146  typedef E ExpressionType;
147 
152  const ExpressionType& operator()() const
153  {
154  return *static_cast<const ExpressionType*>(this);
155  }
156 
162  {
163  return *static_cast<ExpressionType*>(this);
164  }
165 
166  protected:
169  };
170 
178  template <typename E>
179  class GridExpression : public Expression<E>
180  {
181 
182  public:
184  typedef E ExpressionType;
185 
190  const ExpressionType& operator()() const
191  {
192  return *static_cast<const ExpressionType*>(this);
193  }
194 
200  {
201  return *static_cast<ExpressionType*>(this);
202  }
203 
204  protected:
207  };
208 
213  template <typename C>
215  {
216 
217  public:
219  typedef C ContainerType;
220 
225  const ContainerType& operator()() const
226  {
227  return *static_cast<const ContainerType*>(this);
228  }
229 
235  {
236  return *static_cast<ContainerType*>(this);
237  }
238 
239  protected:
242  };
243 
248  template <typename C>
250  {
251 
252  public:
254  typedef C ContainerType;
255 
260  const ContainerType& operator()() const
261  {
262  return *static_cast<const ContainerType*>(this);
263  }
264 
270  {
271  return *static_cast<ContainerType*>(this);
272  }
273 
274  protected:
277  };
278 
283  template <typename C>
285  {
286 
287  public:
289  typedef C ContainerType;
290 
295  const ContainerType& operator()() const
296  {
297  return *static_cast<const ContainerType*>(this);
298  }
299 
305  {
306  return *static_cast<ContainerType*>(this);
307  }
308 
309  protected:
312  };
313 
318  template <typename C>
319  class GridContainer : public GridExpression<C>
320  {
321 
322  public:
324  typedef C ContainerType;
325 
330  const ContainerType& operator()() const
331  {
332  return *static_cast<const ContainerType*>(this);
333  }
334 
340  {
341  return *static_cast<ContainerType*>(this);
342  }
343 
344  protected:
347  };
348  } // namespace Math
349 } // namespace CDPL
350 
351 #endif // CDPL_MATH_EXPRESSION_HPP
CRTP base class for all numeric expression types in the Math namespace (Barton-Nackman idiom).
Definition: Expression.hpp:43
E ExpressionType
The derived expression type (made available to expression-template machinery).
Definition: Expression.hpp:47
~Expression()
Definition: Expression.hpp:51
Expression()
Definition: Expression.hpp:50
Refinement of Math::GridExpression marking the derived type as a concrete (writable) grid container.
Definition: Expression.hpp:320
ContainerType & operator()()
Returns a reference to the derived grid container.
Definition: Expression.hpp:339
~GridContainer()
Definition: Expression.hpp:346
const ContainerType & operator()() const
Returns a const reference to the derived grid container.
Definition: Expression.hpp:330
C ContainerType
The derived grid container type.
Definition: Expression.hpp:324
GridContainer()
Definition: Expression.hpp:345
CRTP base class for all grid expression types.
Definition: Expression.hpp:180
E ExpressionType
The derived grid expression type.
Definition: Expression.hpp:184
ExpressionType & operator()()
Returns a reference to the derived grid expression.
Definition: Expression.hpp:199
GridExpression()
Definition: Expression.hpp:205
~GridExpression()
Definition: Expression.hpp:206
const ExpressionType & operator()() const
Returns a const reference to the derived grid expression.
Definition: Expression.hpp:190
Refinement of Math::MatrixExpression marking the derived type as a concrete (writable) matrix contain...
Definition: Expression.hpp:250
const ContainerType & operator()() const
Returns a const reference to the derived matrix container.
Definition: Expression.hpp:260
MatrixContainer()
Definition: Expression.hpp:275
C ContainerType
The derived matrix container type.
Definition: Expression.hpp:254
~MatrixContainer()
Definition: Expression.hpp:276
ContainerType & operator()()
Returns a reference to the derived matrix container.
Definition: Expression.hpp:269
CRTP base class for all matrix expression types.
Definition: Expression.hpp:104
E ExpressionType
The derived matrix expression type.
Definition: Expression.hpp:108
const ExpressionType & operator()() const
Returns a const reference to the derived matrix expression.
Definition: Expression.hpp:114
MatrixExpression()
Definition: Expression.hpp:129
ExpressionType & operator()()
Returns a reference to the derived matrix expression.
Definition: Expression.hpp:123
~MatrixExpression()
Definition: Expression.hpp:130
Refinement of Math::QuaternionExpression marking the derived type as a concrete (writable) quaternion...
Definition: Expression.hpp:285
ContainerType & operator()()
Returns a reference to the derived quaternion container.
Definition: Expression.hpp:304
const ContainerType & operator()() const
Returns a const reference to the derived quaternion container.
Definition: Expression.hpp:295
QuaternionContainer()
Definition: Expression.hpp:310
C ContainerType
The derived quaternion container type.
Definition: Expression.hpp:289
~QuaternionContainer()
Definition: Expression.hpp:311
CRTP base class for all quaternion expression types.
Definition: Expression.hpp:142
QuaternionExpression()
Definition: Expression.hpp:167
ExpressionType & operator()()
Returns a reference to the derived quaternion expression.
Definition: Expression.hpp:161
~QuaternionExpression()
Definition: Expression.hpp:168
const ExpressionType & operator()() const
Returns a const reference to the derived quaternion expression.
Definition: Expression.hpp:152
E ExpressionType
The derived quaternion expression type.
Definition: Expression.hpp:146
Refinement of Math::VectorExpression marking the derived type as a concrete (writable) vector contain...
Definition: Expression.hpp:215
~VectorContainer()
Definition: Expression.hpp:241
C ContainerType
The derived vector container type.
Definition: Expression.hpp:219
ContainerType & operator()()
Returns a reference to the derived vector container.
Definition: Expression.hpp:234
const ContainerType & operator()() const
Returns a const reference to the derived vector container.
Definition: Expression.hpp:225
VectorContainer()
Definition: Expression.hpp:240
CRTP base class for all vector expression types.
Definition: Expression.hpp:66
const ExpressionType & operator()() const
Returns a const reference to the derived vector expression.
Definition: Expression.hpp:76
~VectorExpression()
Definition: Expression.hpp:92
ExpressionType & operator()()
Returns a reference to the derived vector expression.
Definition: Expression.hpp:85
E ExpressionType
The derived vector expression type.
Definition: Expression.hpp:70
VectorExpression()
Definition: Expression.hpp:91
constexpr unsigned int C
Specifies Carbon.
Definition: AtomType.hpp:92
constexpr unsigned int E
Specifies that the stereocenter has E configuration.
Definition: CIPDescriptor.hpp:96
The namespace of the Chemical Data Processing Library.