factory.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002     
00003     factory.hpp -- default factory template class.
00004 
00005     This file is a part of the Arageli library.
00006 
00007     Copyright (C) Nikolai Yu. Zolotykh, 1999--2006
00008     Copyright (C) Sergey S. Lyalin, 2005
00009     University of Nizhni Novgorod, Russia
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)  // WARNING.  Making a copy.
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)  // WARNING.  Making a copy.
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&)    // WARNING.  Making a copy.
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 //template <typename T>
00160 //inline T bitwise_not (const T& x)
00161 //{ return ~x; }
00162 //
00164 //template <typename T>
00165 //inline T& bitwise_not (const T& x, T* y)
00166 //{ return *y = ~x; }
00167 //
00169 //template <typename T>
00170 //inline T& bitwise_not (T* x)
00171 //{ return *x = ~*x; }
00172 //
00174 //template <typename T>
00175 //inline T logical_not (const T& x)
00176 //{ return !x; }
00177 //
00179 //template <typename T>
00180 //inline bool blogical_not (const T& x)
00181 //{ return !x; }
00182 //
00184 //template <typename T>
00185 //inline T& logical_not (const T& x, T* y)
00186 //{ return *y = !x; }
00187 //
00189 //template <typename T>
00190 //inline T& logical_not (T* x)
00191 //{ return *x = !*x; }
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 //#ifdef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE
00242 //  #define ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_FACTORY
00243 //  #include "factory.cpp"
00244 //  #undef  ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_FACTORY
00245 //#endif
00246 
00247 
00248 #endif  //  #ifndef _ARAGELI_factory_hpp_
00249 

Generated on Thu Aug 31 17:38:05 2006 for Arageli by  doxygen 1.4.7