Chemical Data Processing Library C++ API - Version 1.2.0
GridAssignment.hpp
Go to the documentation of this file.
1 /*
2  * GridAssignment.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_GRIDASSIGNMENT_HPP
28 #define CDPL_MATH_GRIDASSIGNMENT_HPP
29 
30 #include <utility>
31 
32 #include "CDPL/Math/Check.hpp"
33 #include "CDPL/Math/CommonType.hpp"
34 #include "CDPL/Base/Exceptions.hpp"
35 
36 
37 namespace CDPL
38 {
39 
40  namespace Math
41  {
42 
43  template <typename E>
44  class GridExpression;
45  template <template <typename T1, typename T2> class F, typename G, typename E>
46  void gridAssignGrid(G& g, const GridExpression<E>& e)
47  {
49 
50  SizeType size1 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize1()), SizeType(e().getSize1()), Base::SizeError);
51  SizeType size2 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize2()), SizeType(e().getSize2()), Base::SizeError);
52  SizeType size3 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize3()), SizeType(e().getSize3()), Base::SizeError);
53 
54  typedef F<typename G::Reference, typename E::ValueType> FunctorType;
55 
56  for (SizeType i = 0; i < size1; i++)
57  for (SizeType j = 0; j < size2; j++)
58  for (SizeType k = 0; k < size3; k++)
59  FunctorType::apply(g(i, j, k), e()(i, j, k));
60  }
61 
62  template <template <typename T1, typename T2> class F, typename G, typename T>
63  void gridAssignScalar(G& g, const T& t)
64  {
65  typedef F<typename G::Reference, T> FunctorType;
66  typedef typename G::SizeType SizeType;
67 
68  SizeType size1 = g.getSize1();
69  SizeType size2 = g.getSize2();
70  SizeType size3 = g.getSize3();
71 
72  for (SizeType i = 0; i < size1; i++)
73  for (SizeType j = 0; j < size2; j++)
74  for (SizeType k = 0; k < size3; k++)
75  FunctorType::apply(g(i, j, k), t);
76  }
77 
78  template <typename G, typename E>
79  void gridSwap(G& g, GridExpression<E>& e)
80  {
82 
83  SizeType size1 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize1()), SizeType(e().getSize1()), Base::SizeError);
84  SizeType size2 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize2()), SizeType(e().getSize2()), Base::SizeError);
85  SizeType size3 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize3()), SizeType(e().getSize3()), Base::SizeError);
86 
87  for (SizeType i = 0; i < size1; i++)
88  for (SizeType j = 0; j < size2; j++)
89  for (SizeType k = 0; k < size3; k++)
90  std::swap(g(i, j, k), e()(i, j, k));
91  }
92  } // namespace Math
93 } // namespace CDPL
94 
95 #endif // CDPL_MATH_GRIDASSIGNMENT_HPP
Definition of exception classes.
Definition of various preprocessor macros for error checking.
#define CDPL_MATH_CHECK_SIZE_EQUALITY(size1, size2, e)
Definition: Check.hpp:62
Common type deduction.
Thrown to indicate that the size of a (multidimensional) array is not correct.
Definition: Base/Exceptions.hpp:133
Definition: Expression.hpp:120
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int F
Specifies Fluorine.
Definition: AtomType.hpp:107
constexpr unsigned int E
Specifies that the stereocenter has E configuration.
Definition: CIPDescriptor.hpp:96
void gridAssignScalar(G &g, const T &t)
Definition: GridAssignment.hpp:63
void gridAssignGrid(G &g, const GridExpression< E > &e)
Definition: GridAssignment.hpp:46
void gridSwap(G &g, GridExpression< E > &e)
Definition: GridAssignment.hpp:79
The namespace of the Chemical Data Processing Library.
std::common_type< T1, T2 >::type Type
Definition: CommonType.hpp:43