antioch-0.4.0
metaprogramming.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 
27 #ifndef ANTIOCH_METAPROGRAMMING_H
28 #define ANTIOCH_METAPROGRAMMING_H
29 
30 // Antioch
32 
33 // C++
34 #include <cstddef> // For size_t
35 
36 namespace Antioch
37 {
38 #define ANTIOCH_PLAIN_SCALAR(Type) \
39  \
40 inline \
41 Type \
42 max (const Type& in) { return in; } \
43  \
44 inline \
45 Type \
46 min (const Type& in) { return in; } \
47  \
48 template <> \
49 inline \
50 Type if_else(bool condition, \
51  Type if_true, \
52  Type if_false) \
53 { \
54  if (condition) \
55  return if_true; \
56  else \
57  return if_false; \
58 } \
59  \
60 template <> \
61 struct has_size<Type> \
62 { \
63  const static bool value = false; \
64 }; \
65  \
66 template <> \
67 struct return_auto<Type> \
68 { \
69  const static bool value = false; \
70 }; \
71  \
72 template <> \
73 struct value_type<Type> \
74 { \
75  typedef Type type; \
76 }; \
77  \
78 template <> \
79 struct raw_value_type<Type> \
80 { \
81  typedef Type type; \
82 }; \
83  \
84 template <typename NewScalar> \
85 struct rebind<Type, NewScalar> \
86 { \
87  typedef NewScalar type; \
88 }
89 
90 
92 ANTIOCH_PLAIN_SCALAR(double);
93 ANTIOCH_PLAIN_SCALAR(long double);
97 ANTIOCH_PLAIN_SCALAR(unsigned short);
98 ANTIOCH_PLAIN_SCALAR(unsigned int);
99 ANTIOCH_PLAIN_SCALAR(unsigned long);
100 
101 template <typename T>
102 inline
103 void set_zero(T& output) { output = 0; }
104 
105 template <typename T>
106 inline
107 T zero_clone(const T& /* example */) { return 0; }
108 
109 template <typename T, typename T2>
110 inline
111 void zero_clone(T& output, const T2& /* example */) { output = 0; }
112 
113 template <typename T>
114 inline
115 void init_clone(T& output, const T& example) { output = example; }
116 
117 template <typename Vector, typename Scalar>
118 inline
119 void init_constant(Vector& output, const Scalar& example)
120 {
121  for (typename Antioch::size_type<Vector>::type i=0;
122  i != output.size(); ++i)
123  init_clone(output[i], example);
124 }
125 
126 template <typename T, typename Scalar>
127 inline
128 T constant_clone(const T& /* example */, const Scalar& value) { return value; }
129 
130 template <typename T, typename Scalar>
131 inline
132 void constant_fill(T& output, const Scalar& value) { output = value; }
133 
134 template <typename T, typename VectorScalar>
135 inline
136 T custom_clone(const T& /*example*/, const VectorScalar& values, unsigned int indexes) {return values[indexes];}
137 
138 template <typename T, typename VectorScalar>
139 inline
140 T custom_clone(const T& /*example*/, const VectorScalar& values, const typename Antioch::rebind<T,unsigned int>::type & indexes)
141 {
142  T returnval(indexes.size()); //bof bof - metaphysicl has size within type, this suppose that size_type<indexes>::type can be changed in value_type<T>::type
143 
144  for(unsigned int i = 0; i < indexes.size(); i++)
145  {
146  returnval[i] = values[indexes[i]];
147  }
148  return returnval;
149 }
150 
151 
152 template <typename VectorT>
153 inline
154 typename value_type<VectorT>::type
155 eval_index(const VectorT& vec, unsigned int index)
156 {
157  return vec[index];
158 }
159 
160 inline
161 bool conjunction(const bool & vec)
162 {
163  return vec;
164 }
165 
166 template <typename T>
167 inline
168 bool conjunction(const T & vec)
169 {
170  typedef typename tag_type<T>::type tag;
171  return conjunction_root(vec,tag());
172 }
173 
174 template <typename T>
175 inline
177 {
178  for(unsigned int i = 0; i < vec.size(); i++)
179  {
180  if(!vec[i])return false;
181  }
182  return true;
183 }
184 
185 inline
186 bool disjunction(const bool & vec)
187 {
188  return vec;
189 }
190 
191 template <typename T>
192 inline
193 bool disjunction(const T & vec)
194 {
195  typedef typename tag_type<T>::type tag;
196  return disjunction_root(vec,tag());
197 }
198 
199 template <typename T>
200 inline
202 {
203  for(unsigned int i = 0; i < vec.size(); i++)
204  {
205  if(vec[i])return true;
206  }
207  return false;
208 }
209 
210 } // end namespace Antioch
211 
212 #endif //ANTIOCH_METAPROGRAMMING_H
bool conjunction_root(const T &vec, eigen_library_tag)
Definition: eigen_utils.h:278
bool conjunction(const bool &vec)
T custom_clone(const T &, const VectorScalar &values, unsigned int indexes)
bool disjunction_root(const T &vec, eigen_library_tag)
Definition: eigen_utils.h:285
void init_clone(T &output, const T &example)
enable_if_c< is_eigen< typename value_type< VectorT >::type >::value, typename value_type< VectorT >::type >::type eval_index(const VectorT &vec, const _Matrix< _UIntT, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &index)
Definition: eigen_utils.h:268
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > constant_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex, const Scalar &value)
Definition: eigen_utils.h:181
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Definition: eigen_utils.h:217
void constant_fill(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &output, const Scalar &value)
Definition: eigen_utils.h:204
ANTIOCH_PLAIN_SCALAR(float)
void init_constant(Vector &output, const Scalar &example)
The parameters are reduced parameters.
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > zero_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex)
Definition: eigen_utils.h:145
bool disjunction(const bool &vec)

Generated on Thu Jul 7 2016 11:09:46 for antioch-0.4.0 by  doxygen 1.8.8