aboutsummaryrefslogtreecommitdiffhomepage
path: root/tvmet-1.7.1/include/tvmet/BinaryFunctionals.h
blob: b0f6d18e7da2fa9dd8532fceaad8bca886613bf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 * Tiny Vector Matrix Library
 * Dense Vector Matrix Libary of Tiny size using Expression Templates
 *
 * Copyright (C) 2001 - 2003 Olaf Petzold <opetzold@users.sourceforge.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: BinaryFunctionals.h,v 1.19 2004/10/04 11:40:46 opetzold Exp $
 */

#ifndef TVMET_BINARY_FUNCTIONAL_H
#define TVMET_BINARY_FUNCTIONAL_H

namespace tvmet {


/**
 * \class Fcnl_assign BinaryFunctionals.h "tvmet/BinaryFunctionals.h"
 * \brief Binary operator for assign operations.
 *
 * Unfortunally we have sometimes to cast on assign operations e.g.,
 * on assign on different POD. So we avoid warnings.
 */
template <class T1, class T2>
struct Fcnl_assign : public BinaryFunctional {
  static inline
  void apply_on(T1& _tvmet_restrict lhs, T2 rhs) {
    lhs = static_cast<T1>(rhs);
  }

  static
  void print_xpr(std::ostream& os, int l=0) {
    os << IndentLevel(l) << "fcnl_assign<T1="
       << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">,"
       << std::endl;
  }
};


/** \class Fcnl_add_eq 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_sub_eq 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_mul_eq 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_div_eq 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_mod_eq 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_xor_eq		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_and_eq		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_or_eq		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_shl_eq 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_shr_eq 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
#define TVMET_IMPLEMENT_MACRO(NAME, OP)					\
template <class T1, class T2>						\
struct Fcnl_##NAME : public BinaryFunctional {				\
  typedef void						value_type;	\
									\
  static inline								\
  void apply_on(T1& _tvmet_restrict lhs, T2 rhs) {			\
    lhs OP rhs;								\
  }									\
									\
  static								\
  void print_xpr(std::ostream& os, int l=0) {			\
    os << IndentLevel(l)						\
       << "Fcnl_" << #NAME << "<T1="					\
       << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">,"	\
       << std::endl;							\
  }									\
};

TVMET_IMPLEMENT_MACRO(add_eq, +=)
TVMET_IMPLEMENT_MACRO(sub_eq, -=)
TVMET_IMPLEMENT_MACRO(mul_eq, *=)
TVMET_IMPLEMENT_MACRO(div_eq, /=)
TVMET_IMPLEMENT_MACRO(mod_eq, %=)
TVMET_IMPLEMENT_MACRO(xor_eq, ^=)
TVMET_IMPLEMENT_MACRO(and_eq, &=)
TVMET_IMPLEMENT_MACRO(or_eq, |=)
TVMET_IMPLEMENT_MACRO(shl_eq, <<=)
TVMET_IMPLEMENT_MACRO(shr_eq, >>=)

#undef TVMET_IMPLEMENT_MACRO


/** \class Fcnl_add 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_sub 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_mul 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_div 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_mod 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_bitxor		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_bitand		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_bitor		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_shl 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_shr 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
#define TVMET_IMPLEMENT_MACRO(NAME, OP)					\
template <class T1, class T2>						\
struct Fcnl_##NAME : public BinaryFunctional {				\
  typedef typename  PromoteTraits<T1, T2>::value_type	value_type;	\
  									\
  static inline 							\
  value_type apply_on(T1 lhs, T2 rhs) {					\
    return lhs OP rhs;							\
  }									\
  									\
  static 								\
  void print_xpr(std::ostream& os, int l=0) {			\
    os << IndentLevel(l)						\
       << "Fcnl_" << #NAME << "<T1="					\
       << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">,"	\
       << std::endl;							\
  }									\
};

TVMET_IMPLEMENT_MACRO(add, +)
TVMET_IMPLEMENT_MACRO(sub, -)
TVMET_IMPLEMENT_MACRO(mul, *)
TVMET_IMPLEMENT_MACRO(div, /)
TVMET_IMPLEMENT_MACRO(mod, %)
TVMET_IMPLEMENT_MACRO(bitxor, ^)
TVMET_IMPLEMENT_MACRO(bitand, &)
TVMET_IMPLEMENT_MACRO(bitor, |)
TVMET_IMPLEMENT_MACRO(shl, <<)
TVMET_IMPLEMENT_MACRO(shr, >>)

#undef TVMET_IMPLEMENT_MACRO


/** \class Fcnl_greater 	BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_greater_eq 	BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_less 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_less_eq 	BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_eq 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_not_eq 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_and 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_or 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
#define TVMET_IMPLEMENT_MACRO(NAME, OP)					\
template <class T1, class T2>						\
struct Fcnl_##NAME : public BinaryFunctional {				\
  typedef bool						value_type;	\
  									\
  static inline								\
  bool apply_on(T1 lhs, T2 rhs) {					\
    return lhs OP rhs;							\
  }									\
  									\
  static 								\
  void print_xpr(std::ostream& os, int l=0) {			\
    os << IndentLevel(l)						\
       << "Fcnl_" << #NAME << "<T1="					\
       << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">,"	\
       << std::endl;							\
  }									\
};

TVMET_IMPLEMENT_MACRO(greater, >)
TVMET_IMPLEMENT_MACRO(less, <)
TVMET_IMPLEMENT_MACRO(greater_eq, >=)
TVMET_IMPLEMENT_MACRO(less_eq, <=)
TVMET_IMPLEMENT_MACRO(eq, ==)
TVMET_IMPLEMENT_MACRO(not_eq, !=)
TVMET_IMPLEMENT_MACRO(and, &&)
TVMET_IMPLEMENT_MACRO(or, ||)

#undef TVMET_IMPLEMENT_MACRO


/** \class Fcnl_atan2 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_fmod 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_pow 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
#define TVMET_IMPLEMENT_MACRO(NAME)					\
template <class T1, class T2>						\
struct Fcnl_##NAME : public BinaryFunctional {				\
  typedef typename PromoteTraits<T1, T2>::value_type	value_type;	\
									\
  static inline 							\
  value_type apply_on(T1 lhs, T2 rhs) {					\
    return TVMET_STD_SCOPE(NAME)(lhs, rhs);				\
  }									\
   									\
  static 								\
  void print_xpr(std::ostream& os, int l=0) {			\
    os << IndentLevel(l)						\
       << "Fcnl_" << #NAME << "<T1="					\
       << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">,"	\
       << std::endl;							\
  }									\
};

TVMET_IMPLEMENT_MACRO(atan2)
TVMET_IMPLEMENT_MACRO(fmod)
TVMET_IMPLEMENT_MACRO(pow)

#undef TVMET_IMPLEMENT_MACRO


/** \class Fcnl_drem 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_hypot 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_jn 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
/** \class Fcnl_yn 		BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */
#define TVMET_IMPLEMENT_MACRO(NAME)					\
template <class T1, class T2>						\
struct Fcnl_##NAME : public BinaryFunctional {				\
  typedef typename PromoteTraits<T1, T2>::value_type	value_type;	\
									\
  static inline 							\
  value_type apply_on(T1 lhs, T2 rhs) {					\
    return TVMET_GLOBAL_SCOPE(NAME)(lhs, rhs);				\
  }									\
   									\
  static 								\
  void print_xpr(std::ostream& os, int l=0) {			\
    os << IndentLevel(l)						\
       << "Fcnl_" << #NAME << "<T1="					\
       << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">,"	\
       << std::endl;							\
  }									\
};

TVMET_IMPLEMENT_MACRO(drem)
TVMET_IMPLEMENT_MACRO(hypot)
TVMET_IMPLEMENT_MACRO(jn)
TVMET_IMPLEMENT_MACRO(yn)

#undef TVMET_IMPLEMENT_MACRO


#if defined(EIGEN_USE_COMPLEX)
/**
 * \class Fcnl_polar BinaryFunctionals.h "tvmet/BinaryFunctionals.h"
 * \brief %Functional for polar.
 */
template <class T1, class T2> struct Fcnl_polar : public BinaryFunctional { };


/**
 * \class Fcnl_polar<T,T> BinaryFunctionals.h "tvmet/BinaryFunctionals.h"
 * \brief %Functional for polar.
 * \note  This functional is partialy specialized due to the declaration
 *        of %polar in namespace std <tt>complex<T> polar(T, T)</tt>.
 *        This means especially that type promotion isn't avaible here.
 */
template <class T>
struct Fcnl_polar<T,T> : public BinaryFunctional {
  typedef std::complex<T>                               value_type;

  static inline
  value_type apply_on(T lhs, T rhs) {
    return std::polar(lhs, rhs);
  }

  static
  void print_xpr(std::ostream& os, int l=0) {
    os << IndentLevel(l) << "Fcnl_polar<T1="
       << typeid(T).name() << ", T2=" << typeid(T).name() << ">,"
       << std::endl;
  }
};
#endif // defined(EIGEN_USE_COMPLEX)


/**
 * \class Fcnl_swap BinaryFunctionals.h "tvmet/BinaryFunctionals.h"
 * \brief Binary operator for swapping values using temporaries.
 * \todo check for std::swap implementation; todo before LUdecomp
 */
template <class T1, class T2>
struct Fcnl_swap : public BinaryFunctional {
  static inline
  void apply_on(T1& _tvmet_restrict lhs, T2& _tvmet_restrict rhs) {
    typedef typename  PromoteTraits<T1, T2>::value_type	temp_type;

    temp_type 						temp(lhs);
    lhs = static_cast<T1>(rhs);
    rhs = static_cast<T2>(temp);
  }

  static
  void print_xpr(std::ostream& os, int l=0) {
    os << IndentLevel(l) << "Fcnl_swap<T1="
       << typeid(T1).name() << ", T2" << typeid(T2).name() << ">,"
       << std::endl;
  }
};


} // namespace tvmet

#endif // TVMET_BINARY_FUNCTIONAL_H

// Local Variables:
// mode:C++
// End: