antioch-0.4.0
metaprogramming_decl.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_DECL_H
28 #define ANTIOCH_METAPROGRAMMING_DECL_H
29 
30 namespace Antioch
31 {
32  // A workaround for trying to use commas in arguments to macros
33 #define ANTIOCH_COMMA ,
34 
35  // Allow us to use auto when sufficiently complete C++11 support is
36  // available, while falling back on preselected types when C++11
37  // is not available.
38 #ifdef ANTIOCH_HAVE_AUTO_THIS
39 #define ANTIOCH_AUTO(Type) auto
40 #define ANTIOCH_RETURNEXPR(Type, Expr) \
41  -> typename Antioch::if_else_type<Antioch::return_auto<Type>::value, \
42  decltype(Expr), \
43  Type>::type
44 #define ANTIOCH_AUTOFUNC(Type, Expr) \
45  -> typename Antioch::if_else_type<Antioch::return_auto<Type>::value, \
46  decltype(Expr), \
47  Type>::type \
48  { return Expr; }
49 #else
50 #define ANTIOCH_AUTO(Type) Type
51 #define ANTIOCH_RETURNEXPR(Type, Expr)
52 #define ANTIOCH_AUTOFUNC(Type, Expr) { return Expr; }
53 #endif
54 
55  // Helper metafunctions
56  template <bool B, class T = void>
57  struct enable_if_c {
58  typedef T type;
59  };
60 
61  template <class T>
62  struct enable_if_c<false, T> {};
63 
64  template <bool B, class T1, class T2>
65  struct if_else_type {
66  typedef T1 type;
67  };
68 
69  template <class T1, class T2>
70  struct if_else_type<false, T1, T2> {
71  typedef T2 type;
72  };
73 
74  // Base class to allow tag dispatching
75  // http://www.generic-programming.org/languages/cpp/techniques.php
77 
78  // ::value == true for vector classes with size() methods
79  template <typename T, typename Enable=void>
80  struct has_size;
81 
82  // ::value == true for classes with expression templates that can be
83  // safely returned via auto user functions
84  template <typename T, typename Enable=void>
85  struct return_auto;
86 
87  // size_type<T>::size is defined to be the result type of the size()
88  // method for vector classes
89  template <typename T, typename Enable=void>
90  struct size_type;
91 
92  // A class to identify the underlying value type value_type<T>::type
93  // of a numeric container type T.
94  template <typename T, typename Enable=void>
95  struct value_type;
96 
97  // A class to identify the concrete state type state_type<T>::type
98  // of a (possibly template expression) type T.
99  template <typename T, typename Enable=void>
100  struct state_type;
101 
102  // A class to identify the underlying value type
103  // raw_value_type<T>::type of
104  // container-of-container types.
105  template <typename T, typename Enable=void>
107 
108  // A class for generating "int" from "float" or "valarray<int>" from
109  // "valarray<float>" etc.
110  template <typename Vector, typename NewScalar, typename Enable=void>
111  struct rebind;
112 
113  /*
114  template <typename T>
115  inline
116  typename value_type<T>::type
117  max (const T& in);
118 
119  template <typename T>
120  inline
121  typename value_type<T>::type
122  min (const T& in);
123  */
124 
125  template <typename T, typename Enable=void>
126  struct tag_type
127  {
128  typedef const numeric_library_tag type;
129  };
130 
131  template <typename T>
132  struct value_type<const T>
133  {
134  typedef const typename value_type<T>::type type;
135  };
136 
137  template <typename T>
138  struct raw_value_type<const T>
139  {
140  typedef const typename raw_value_type<T>::type type;
141  };
142 
143  template <typename T1, typename T2>
145  {
146  typedef T1 type;
147  };
148 
149  template <typename T>
151  {
152  typedef T & type;
153  };
154 
155 
156  // A function for zero-initializing vectorized numeric types
157  // while resizing them to match the example input
158  template <typename T>
159  inline
160  T zero_clone(const T& example);
161 
162  // A function for zero-initializing vectorized numeric types
163  // while resizing them to match the example input
164  template <typename T1, typename T2>
165  inline
166  void zero_clone(T1& output, const T2& example);
167 
168  // A function for initializing vectorized numeric types to a
169  // constant while resizing them to match the example input
170  template <typename T, typename Scalar>
171  inline
172  T constant_clone(const T& example, const Scalar& value);
173 
174  // A function for initializing non vectorized numeric types to
175  // custom constants stored in vector
176  template <typename T, typename VectorScalar>
177  inline
178  T custom_clone(const T& example, const VectorScalar& values, unsigned int indexes);
179 
180  // A function for initializing vectorized numeric types to
181  // custom constants stored in vector
182  template <typename T, typename VectorScalar>
183  inline
184  T custom_clone(const T& example, const VectorScalar& values, const typename Antioch::rebind<T,unsigned int>::type & indexes);
185 
186  // A function for filling already-initialized vectorized numeric
187  // types with a constant.
188  template <typename T, typename Scalar>
189  inline
190  void constant_fill(T& output, const Scalar& value);
191 
192  // A function for initializing vectorized numeric types
193  // while resizing them to match the example input
194  template <typename T>
195  inline
196  void init_clone(T& output, const T& example);
197 
198  // A function for zero-setting vectorized numeric types
199  template <typename T>
200  inline
201  void set_zero(T& output);
202 
203  // A function for initializing numeric vector types. Resizes the
204  // contents of vector-of-vector types but does not resize the outer
205  // vector.
206  template <typename Vector, typename Scalar>
207  inline
208  void init_constant(Vector& output, const Scalar& example);
209 
210  // A function for replicating the effect of the ternary operator on
211  // numeric types.
212  //
213  // The first argument should be a boolean for a scalar type, or a
214  // vector of booleans or an expression type for vector types.
215  //
216  // The second and third arguments should be expression types or
217  // vector types.
218  template <typename T>
219  inline
220  T if_else(bool condition,
221  T if_true,
222  T if_false);
223 
224  // A function for indexing a vector type with an (integral) numeric
225  // type.
226  //
227  // The first argument should be a vector of (scalar or vectorized)
228  // numeric types; the second argument should be a similarly scalar
229  // or vectorized integer type with values valid as indices to the
230  // first argument. The output will be a similarly scalar or
231  // vectorized numeric type.
232  template <typename VectorT>
233  inline
235  eval_index(const VectorT& vec, unsigned int index);
236 
237  //Root function for conjunction
238  template <typename T>
239  inline
240  bool conjunction_root(const T & vec, numeric_library_tag);
241 
242  //Root function for disjunction
243  template <typename T>
244  inline
245  bool disjunction_root(const T & vec, numeric_library_tag);
246 
247  // A function to obtain the conjunction of boolean
248  template <typename T>
249  inline
250  bool conjunction(const T & vec);
251 
252  // A function to obtain the disjunction of boolean
253  template <typename T>
254  inline
255  bool disjunction(const T & vec);
256 
257 } // end namespace Antioch
258 
259 #endif //ANTIOCH_METAPROGRAMMING_DECL_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)
const raw_value_type< T >::type type
bool disjunction_root(const T &vec, eigen_library_tag)
Definition: eigen_utils.h:285
void init_clone(T &output, const T &example)
const value_type< T >::type type
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
enable_if_c< is_eigen< T1 >::value &&is_eigen< T2 >::value, typename state_type< T1 >::type >::type if_else(const Condition &condition, const T1 &if_true, const T2 &if_false)
Definition: eigen_utils.h:250
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
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
const numeric_library_tag type
bool disjunction(const bool &vec)

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