Chemical Data Processing Library C++ API - Version 1.4.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;
54  template <template <typename T1, typename T2> class F, typename G, typename E>
55  void gridAssignGrid(G& g, const GridExpression<E>& e)
56  {
58 
59  SizeType size1 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize1()), SizeType(e().getSize1()), Base::SizeError);
60  SizeType size2 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize2()), SizeType(e().getSize2()), Base::SizeError);
61  SizeType size3 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize3()), SizeType(e().getSize3()), Base::SizeError);
62 
63  typedef F<typename G::Reference, typename E::ValueType> FunctorType;
64 
65  for (SizeType i = 0; i < size1; i++)
66  for (SizeType j = 0; j < size2; j++)
67  for (SizeType k = 0; k < size3; k++)
68  FunctorType::apply(g(i, j, k), e()(i, j, k));
69  }
70 
79  template <template <typename T1, typename T2> class F, typename G, typename T>
80  void gridAssignScalar(G& g, const T& t)
81  {
82  typedef F<typename G::Reference, T> FunctorType;
83  typedef typename G::SizeType SizeType;
84 
85  SizeType size1 = g.getSize1();
86  SizeType size2 = g.getSize2();
87  SizeType size3 = g.getSize3();
88 
89  for (SizeType i = 0; i < size1; i++)
90  for (SizeType j = 0; j < size2; j++)
91  for (SizeType k = 0; k < size3; k++)
92  FunctorType::apply(g(i, j, k), t);
93  }
94 
103  template <typename G, typename E>
105  {
107 
108  SizeType size1 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize1()), SizeType(e().getSize1()), Base::SizeError);
109  SizeType size2 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize2()), SizeType(e().getSize2()), Base::SizeError);
110  SizeType size3 = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(g.getSize3()), SizeType(e().getSize3()), Base::SizeError);
111 
112  for (SizeType i = 0; i < size1; i++)
113  for (SizeType j = 0; j < size2; j++)
114  for (SizeType k = 0; k < size3; k++)
115  std::swap(g(i, j, k), e()(i, j, k));
116  }
117  } // namespace Math
118 } // namespace CDPL
119 
120 #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)
Throws the exception e if size1 differs from size2, otherwise returns std::min(size1,...
Definition: Check.hpp:84
Common type deduction.
Thrown to indicate that the size of a (multidimensional) array is not correct.
Definition: Base/Exceptions.hpp:133
CRTP base class for all grid expression types.
Definition: Expression.hpp:180
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)
Applies the element-wise functor F to every (grid cell, scalar) pair, i.e. F::apply(g(i,...
Definition: GridAssignment.hpp:80
void gridAssignGrid(G &g, const GridExpression< E > &e)
Applies the element-wise functor F to every (grid cell, source cell) pair, i.e. F::apply(g(i,...
Definition: GridAssignment.hpp:55
void gridSwap(G &g, GridExpression< E > &e)
Swaps the cells of two equally sized grid expressions cell by cell.
Definition: GridAssignment.hpp:104
The namespace of the Chemical Data Processing Library.
std::common_type< T1, T2 >::type Type
The common type.
Definition: CommonType.hpp:49