Chemical Data Processing Library C++ API - Version 1.1.1
VectorAssignment.hpp
Go to the documentation of this file.
1 /*
2  * VectorAssignment.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_VECTORASSIGNMENT_HPP
28 #define CDPL_MATH_VECTORASSIGNMENT_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 VectorExpression;
45 
46  template <template <typename T1, typename T2> class F, typename V, typename E>
48  {
50 
51  SizeType size = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(v.getSize()), SizeType(e().getSize()), Base::SizeError);
52 
53  typedef F<typename V::Reference, typename E::ValueType> FunctorType;
54 
55  for (SizeType i = 0; i < size; i++)
56  FunctorType::apply(v(i), e()(i));
57  }
58 
59  template <template <typename T1, typename T2> class F, typename V, typename T>
60  void vectorAssignScalar(V& v, const T& t)
61  {
62  typedef F<typename V::Reference, T> FunctorType;
63  typedef typename V::SizeType SizeType;
64 
65  SizeType size = v.getSize();
66 
67  for (SizeType i = 0; i < size; i++)
68  FunctorType::apply(v(i), t);
69  }
70 
71  template <typename V, typename E>
73  {
75 
76  SizeType size = CDPL_MATH_CHECK_SIZE_EQUALITY(SizeType(v.getSize()), SizeType(e().getSize()), Base::SizeError);
77 
78  for (SizeType i = 0; i < size; i++)
79  std::swap(v(i), e()(i));
80  }
81  } // namespace Math
82 } // namespace CDPL
83 
84 #endif // CDPL_MATH_VECTORASSIGNMENT_HPP
CDPL_MATH_CHECK_SIZE_EQUALITY
#define CDPL_MATH_CHECK_SIZE_EQUALITY(size1, size2, e)
Definition: Check.hpp:62
CDPL::Math::vectorSwap
void vectorSwap(V &v, VectorExpression< E > &e)
Definition: VectorAssignment.hpp:72
CDPL::Chem::CIPDescriptor::E
const unsigned int E
Specifies that the stereocenter has E configuration.
Definition: CIPDescriptor.hpp:96
CDPL::Math::CommonType::Type
std::common_type< T1, T2 >::type Type
Definition: CommonType.hpp:43
CommonType.hpp
Common type deduction.
CDPL::Math::VectorExpression
Definition: Expression.hpp:54
CDPL::Math::vectorAssignVector
void vectorAssignVector(V &v, const VectorExpression< E > &e)
Definition: VectorAssignment.hpp:47
CDPL::Base::SizeError
Thrown to indicate that the size of a (multidimensional) array is not correct.
Definition: Base/Exceptions.hpp:133
V
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
Exceptions.hpp
Definition of exception classes.
CDPL::Chem::AtomType::V
const unsigned int V
Specifies Vanadium.
Definition: AtomType.hpp:177
CDPL::Math::vectorAssignScalar
void vectorAssignScalar(V &v, const T &t)
Definition: VectorAssignment.hpp:60
CDPL
The namespace of the Chemical Data Processing Library.
Check.hpp
Definition of various preprocessor macros for error checking.
CDPL::Chem::AtomType::F
const unsigned int F
Specifies Fluorine.
Definition: AtomType.hpp:107