basefuncs.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002     
00003     basefunc.hpp -- additional fuctions that represent each basic operation,
00004         like addition and multiplication, as function that get the result
00005         through the one of the parameters.
00006 
00007     This file is a part of the Arageli library.
00008 
00009     Copyright (C) Nikolai Yu. Zolotykh, 1999--2006
00010     Copyright (C) Sergey S. Lyalin, 2005
00011     University of Nizhni Novgorod, Russia
00012 
00013 *****************************************************************************/
00014 
00023 #ifndef _ARAGELI_basefunc_hpp_
00024 #define _ARAGELI_basefunc_hpp_
00025 
00026 #include "config.hpp"
00027 
00028 namespace Arageli
00029 {
00030 
00031 // The following functions are defined efficiently only for biltin types.
00032 
00033 // Unary functions that don't alternate their argument.
00034 
00035 #define ARAGELI_BASEFUNC_PREFIX_UNARY(NAME, OPER)   \
00036     template <typename T, typename Res>             \
00037     inline Res& NAME (const T& x, Res& res)         \
00038     { return res = OPER x; }
00039 
00040 
00041 ARAGELI_BASEFUNC_PREFIX_UNARY(indirection, *)
00042 ARAGELI_BASEFUNC_PREFIX_UNARY(address, &)
00043 ARAGELI_BASEFUNC_PREFIX_UNARY(unary_plus, +)
00044 ARAGELI_BASEFUNC_PREFIX_UNARY(unary_minus, -)
00045 ARAGELI_BASEFUNC_PREFIX_UNARY(logical_not, !)
00046 ARAGELI_BASEFUNC_PREFIX_UNARY(bitwise_not, ~)
00047 
00048 // Unary functions that alternate their argument.
00049 
00050 template <typename T, typename Res>
00051 inline Res& prefix_increment (T& x, Res& res)
00052 { res = ++x; }
00053 
00054 template <typename T, typename Res>
00055 inline Res& prefix_decrement (T& x, Res& res)
00056 { res = --x; }
00057 
00058 template <typename T, typename Res>
00059 inline Res& postfix_increment (T& x, Res& res)
00060 { res = x++; }
00061 
00062 template <typename T, typename Res>
00063 inline Res& postfix_decrement (T& x, Res& res)
00064 { res = x--; }
00065 
00066 // Binary functions that don't alternate their arguments.
00067 
00068 #define ARAGELI_BASEFUNC_BINARY(NAME, OPER)                 \
00069     template <typename T1, typename T2, typename Res>       \
00070     inline Res& NAME (const T1& x, const T2& y, Res& res)   \
00071     { return res = x OPER y; }
00072 
00073 ARAGELI_BASEFUNC_BINARY(plus, +);
00074 ARAGELI_BASEFUNC_BINARY(minus, -);
00075 ARAGELI_BASEFUNC_BINARY(multiplies, *);
00076 ARAGELI_BASEFUNC_BINARY(divides, /);
00077 ARAGELI_BASEFUNC_BINARY(modulus, %);
00078 ARAGELI_BASEFUNC_BINARY(logical_or, ||);
00079 ARAGELI_BASEFUNC_BINARY(logical_and, &&);
00080 ARAGELI_BASEFUNC_BINARY(equal_to, ==);
00081 ARAGELI_BASEFUNC_BINARY(not_equal_to, !=);
00082 ARAGELI_BASEFUNC_BINARY(greater, >);
00083 ARAGELI_BASEFUNC_BINARY(less, <);
00084 ARAGELI_BASEFUNC_BINARY(greater_equal, >=);
00085 ARAGELI_BASEFUNC_BINARY(less_equal, <=);
00086 ARAGELI_BASEFUNC_BINARY(bitwise_or, |);
00087 ARAGELI_BASEFUNC_BINARY(bitwise_and, &);
00088 ARAGELI_BASEFUNC_BINARY(bitwise_xor, ^);
00089 ARAGELI_BASEFUNC_BINARY(shift_left, <<);
00090 ARAGELI_BASEFUNC_BINARY(shift_right, >>);
00091 
00092 
00093 // Binary functions that alternate their arguments.
00094 
00095 #define ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(NAME, OPER)    \
00096     template <typename T1, typename T2>                 \
00097     inline T1& right_assign_##NAME (T1& x, const T2& y) \
00098     { return x OPER y; }                                \
00099                                                         \
00100     template <typename T1, typename T2>                 \
00101     inline T1& assign_##NAME (T1& x, const T2& y)       \
00102     { return left_assign(x, y); }
00103 
00104 
00105 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(plus, +=);
00106 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(minus, -=);
00107 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(multiplies, *=);
00108 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(divides, /=);
00109 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(modulus, %=);
00110 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(bitwise_or, |=);
00111 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(bitwise_and, &=);
00112 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(bitwise_xor, ^=);
00113 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(shift_left, <<=);
00114 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NATIVE(shift_right, >>=);
00115 
00116 
00117 #define ARAGELI_BASEFUNC_RIGHT_ASSIGN_NOTNATIVE(NAME, OPER) \
00118     template <typename T1, typename T2>                     \
00119     inline T1& right_assign_##NAME (T1& x, const T2& y)     \
00120     { return x = x OPER y; }                                \
00121                                                             \
00122     template <typename T1, typename T2>                     \
00123     inline T1& assign_##NAME (T1& x, const T2& y)           \
00124     { return left_assign(x, y); }
00125 
00126 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NOTNATIVE(logical_or, ||);
00127 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NOTNATIVE(logical_and, &&);
00128 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NOTNATIVE(equal_to, ==);
00129 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NOTNATIVE(not_equal_to, !=);
00130 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NOTNATIVE(greater, >);
00131 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NOTNATIVE(less, <);
00132 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NOTNATIVE(greater_equal, >=);
00133 ARAGELI_BASEFUNC_RIGHT_ASSIGN_NOTNATIVE(less_equal, <=);
00134 
00135 
00136 #define ARAGELI_BASEFUNC_LEFT_ASSIGN(NAME, OPER)        \
00137     template <typename T1, typename T2>                 \
00138     inline T1& left_assign_##NAME (const T1& x, T2& y)  \
00139     { return y = x OPER y; }
00140 
00141 ARAGELI_BASEFUNC_LEFT_ASSIGN(plus, +);
00142 ARAGELI_BASEFUNC_LEFT_ASSIGN(minus, -);
00143 ARAGELI_BASEFUNC_LEFT_ASSIGN(multiplies, *);
00144 ARAGELI_BASEFUNC_LEFT_ASSIGN(divides, /);
00145 ARAGELI_BASEFUNC_LEFT_ASSIGN(modulus, %);
00146 ARAGELI_BASEFUNC_LEFT_ASSIGN(logical_or, ||);
00147 ARAGELI_BASEFUNC_LEFT_ASSIGN(logical_and, &&);
00148 ARAGELI_BASEFUNC_LEFT_ASSIGN(equal_to, ==);
00149 ARAGELI_BASEFUNC_LEFT_ASSIGN(not_equal_to, !=);
00150 ARAGELI_BASEFUNC_LEFT_ASSIGN(greater, >);
00151 ARAGELI_BASEFUNC_LEFT_ASSIGN(less, <);
00152 ARAGELI_BASEFUNC_LEFT_ASSIGN(greater_equal, >=);
00153 ARAGELI_BASEFUNC_LEFT_ASSIGN(less_equal, <=);
00154 ARAGELI_BASEFUNC_LEFT_ASSIGN(bitwise_or, |);
00155 ARAGELI_BASEFUNC_LEFT_ASSIGN(bitwise_and, &);
00156 ARAGELI_BASEFUNC_LEFT_ASSIGN(bitwise_xor, ^);
00157 ARAGELI_BASEFUNC_LEFT_ASSIGN(shift_left, <<);
00158 ARAGELI_BASEFUNC_LEFT_ASSIGN(shift_right, >>);
00159 
00160 #define ARAGELI_BASEFUNC_UNARY_ASSIGN(NAME, OPER)   \
00161     template <typename T>                           \
00162     inline T& assign_##NAME (T& x)                  \
00163     { return x = OPER x; }
00164 
00165 ARAGELI_BASEFUNC_UNARY_ASSIGN(indirection, *)
00166 ARAGELI_BASEFUNC_UNARY_ASSIGN(address, &)
00167 ARAGELI_BASEFUNC_UNARY_ASSIGN(unary_plus, +)
00168 ARAGELI_BASEFUNC_UNARY_ASSIGN(unary_minus, -)
00169 ARAGELI_BASEFUNC_UNARY_ASSIGN(logical_not, !)
00170 ARAGELI_BASEFUNC_UNARY_ASSIGN(bitwise_not, ~)
00171 
00172 }
00173 
00174 
00175 //#ifdef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE
00176 //  #define ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_BASEFUNC
00177 //  #include "basefunc.cpp"
00178 //  #undef  ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_BASEFUNC
00179 //#endif
00180 
00181 
00182 #endif  //  #ifndef _ARAGELI_basefunc_hpp_
00183 

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