00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00022 #ifndef _ARAGELI_factory_hpp_
00023 #define _ARAGELI_factory_hpp_
00024
00025 #include "config.hpp"
00026
00027 #include <complex>
00028
00029 #include "basefuncs.hpp"
00030 #include "std_import.hpp"
00031
00032
00033 namespace Arageli
00034 {
00035
00036
00038
00040 template <typename T> struct factory
00041 {
00042 static const bool is_specialized = true;
00043
00045 static const T& unit ()
00046 {
00047 static const T unit_s = T(1);
00048 return unit_s;
00049 }
00050
00052 static const T& unit (const T& x)
00053 { return unit(); }
00054
00056 static const T& opposite_unit ()
00057 {
00058 static const T opposite_unit_s = T(-1);
00059 return opposite_unit_s;
00060 }
00061
00063 static const T& opposite_unit (const T& x)
00064 { return opposite_unit(); }
00065
00067 static const T& null ()
00068 {
00069 static const T null_s = T(0);
00070 return null_s;
00071 }
00072
00074 static const T& null (const T& x)
00075 { return null(); }
00076
00077 };
00078
00080
00082
00084 template <typename T>
00085 inline const T& unit ()
00086 { return factory<T>::unit(); }
00087
00089 template <typename T>
00090 inline T unit (const T& x)
00091 { return factory<T>::unit(x); }
00092
00094 template <typename T>
00095 inline bool is_unit (const T& x)
00096 { return x == unit<T>(); }
00097
00099 template <typename T>
00100 inline const T& opposite_unit ()
00101 { return factory<T>::opposite_unit(); }
00102
00104 template <typename T>
00105 inline T opposite_unit (const T&x)
00106 { return factory<T>::opposite_unit(x); }
00107
00109 template <typename T>
00110 inline bool is_opposite_unit (const T& x)
00111 { return x == opposite_unit<T>(); }
00112
00114 template <typename T>
00115 inline const T& null ()
00116 { return factory<T>::null(); }
00117
00119 template <typename T>
00120 inline T null (const T&)
00121 { return factory<T>::null(); }
00122
00124 template <typename T>
00125 inline bool is_null (const T& x)
00126 { return x == null<T>(); }
00127
00129 template <typename T>
00130 inline T opposite (const T& x)
00131 { return -x; }
00132
00134 template <typename T>
00135 inline T& opposite (const T& x, T* y)
00136 { return *y = -x; }
00137
00139 template <typename T>
00140 inline T& opposite (T* x)
00141 { return *x = -*x; }
00142
00144 template <typename T>
00145 inline T inverse (const T& x)
00146 { return 1 / x; }
00147
00149 template <typename T>
00150 inline T& inverse (const T& x, T* y)
00151 { return *y = 1 / x; }
00152
00154 template <typename T>
00155 inline T& inverse (T* x)
00156 { return *x = 1 / *x; }
00157
00159
00160
00161
00162
00164
00165
00166
00167
00169
00170
00171
00172
00174
00175
00176
00177
00179
00180
00181
00182
00184
00185
00186
00187
00189
00190
00191
00192
00194
00195
00197 template <typename T2>
00198 struct factory<std::complex<T2> >
00199 {
00200 private:
00201
00202 typedef std::complex<T2> T;
00203 typedef factory<T2> TT2;
00204
00205 public:
00206
00207 static const bool is_specialized = true;
00208
00209 static const T& unit ()
00210 {
00211 static const T unit_s(TT2::unit());
00212 return unit_s;
00213 }
00214
00215 static T unit (const T& x)
00216 { return T(TT2::unit(x.real())); }
00217
00218 static const T& opposite_unit ()
00219 {
00220 static const T opposite_unit_s(TT2::opposite_unit());
00221 return opposite_unit_s;
00222 }
00223
00224 static T opposite_unit (const T& x)
00225 { return T(TT2::opposite_unit(x.real())); }
00226
00227 static const T& null ()
00228 {
00229 static const T null_s;
00230 return null_s;
00231 }
00232
00233 static const T& null (const T& x)
00234 { return T(TT2::null(x.real())); }
00235
00236 };
00237
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 #endif // #ifndef _ARAGELI_factory_hpp_
00249