00001
00002 #ifndef INSTIGATE_ALGEBRA_INTERFACE_HPP
00003 #define INSTIGATE_ALGEBRA_INTERFACE_HPP
00004
00029
00030
00031
00032
00033
00034
00035
00036 namespace instigate {
00037
00038 namespace algebra {
00039 template <typename T> struct interface;
00040 template <> struct interface<int>;
00041 template <> struct interface<float>;
00042 template <> struct interface<long>;
00043 template <> struct interface<unsigned long>;
00044 template <> struct interface<long long>;
00045 template <> struct interface<unsigned long long>;
00046 template <> struct interface<double>;
00047 template <> struct interface<long double>;
00048 template <> struct interface<wchar_t>;
00049 template <> struct interface<unsigned int>;
00050 template <> struct interface<short>;
00051 template <> struct interface<unsigned short>;
00052 template <> struct interface<char>;
00053
00054 }
00055
00056 }
00057
00066 template <typename T>
00067 struct instigate::algebra::interface
00068 {
00077 static T plus(const T& a, const T& b)
00078 {
00079 return a + b;
00080 }
00081
00090 static T minus(const T& a, const T& b)
00091 {
00092 return a - b;
00093 }
00094
00103 static T multiply(const T& a, const T& b)
00104 {
00105 return a * b;
00106 }
00107
00116 static T divide(const T& a, const T& b)
00117 {
00118 return a / b;
00119 }
00121 static const bool is_additive_assocativity = false;
00122
00124 static const bool is_multiplicative_assocativity = false;
00125
00131 static T get_zero()
00132 {
00133 return 0;
00134 }
00135
00141 static T get_one()
00142 {
00143 return 1;
00144 }
00145
00153 static T opposite(const T& a)
00154 {
00155 return -a;
00156 }
00157
00165 static T inverse(const T& a)
00166 {
00167 return get_one() / a;
00168 }
00169
00171 static const bool is_comutativity_addition = false;
00172
00174 static const bool is_comutativity_multiplication = false;
00175
00177 static const bool is_distributivity = false;
00178 };
00179
00184 template <>
00185 struct instigate::algebra::interface<int>
00186 {
00195 static int plus(const int& a, const int& b)
00196 {
00197 return a + b;
00198 }
00199
00208 static int minus(const int& a, const int& b)
00209 {
00210 return a - b;
00211 }
00212
00221 static int multiply(const int& a, const int& b)
00222 {
00223 return a * b;
00224 }
00225
00227 static const bool is_additive_assocativity = true;
00228
00230 static const bool is_multiplicative_assocativity = true;
00231
00237 static int get_zero()
00238 {
00239 return 0;
00240 }
00241
00247 static int get_one()
00248 {
00249 return 1;
00250 }
00251
00259 static int opposite(const int& a)
00260 {
00261 return -a;
00262 }
00263
00265 static const bool is_comutativity_addition = true;
00266
00268 static const bool is_comutativity_multiplication = true;
00269
00271 static const bool is_distributivity = true;
00272 };
00273
00278 template <>
00279 struct instigate::algebra::interface<float>
00280 {
00289 static float plus(const float& a, const float& b)
00290 {
00291 return a + b;
00292 }
00293
00302 static float minus(const float& a, const float& b)
00303 {
00304 return a - b;
00305 }
00306
00315 static float multiply(const float& a, const float& b)
00316 {
00317 return a * b;
00318 }
00319
00328 static float divide(const float& a, const float& b)
00329 {
00330 return a / b;
00331 }
00332
00334 static const bool is_additive_assocativity = true;
00335
00337 static const bool is_multiplicative_assocativity = true;
00338
00344 static float get_zero()
00345 {
00346 return 0;
00347 }
00348
00354 static float get_one()
00355 {
00356 return 1;
00357 }
00358
00366 static float opposite(const float& a)
00367 {
00368 return -a;
00369 }
00370
00378 static float inverse(const float& a)
00379 {
00380 return get_one() / a;
00381 }
00382
00384 static const bool is_comutativity_addition = true;
00385
00387 static const bool is_comutativity_multiplication = true;
00388
00390 static const bool is_distributivity = true;
00391 };
00392
00397 template <>
00398 struct instigate::algebra::interface<unsigned int>
00399 {
00408 static unsigned int plus(const unsigned int& a, const unsigned int& b)
00409 {
00410 return a + b;
00411 }
00412
00421 static unsigned int multiply(const unsigned int& a,
00422 const unsigned int& b)
00423 {
00424 return a * b;
00425 }
00426
00428 static const bool is_additive_assocativity = true;
00429
00431 static const bool is_multiplicative_assocativity = true;
00432
00438 static unsigned int get_zero()
00439 {
00440 return 0;
00441 }
00442
00448 static unsigned int get_one()
00449 {
00450 return 1;
00451 }
00452
00454 static const bool is_comutativity_addition = true;
00455
00457 static const bool is_comutativity_multiplication = true;
00458
00460 static const bool is_distributivity = true;
00461 };
00462
00467 template <>
00468 struct instigate::algebra::interface<long>
00469 {
00478 static long plus(const long& a, const long& b)
00479 {
00480 return a + b;
00481 }
00482
00491 static long minus(const long& a, const long& b)
00492 {
00493 return a - b;
00494 }
00495
00504 static long multiply(const long& a, const long& b)
00505 {
00506 return a * b;
00507 }
00508
00510 static const bool is_additive_assocativity = true;
00511
00513 static const bool is_multiplicative_assocativity = true;
00514
00520 static long get_zero()
00521 {
00522 return 0;
00523 }
00524
00530 static long get_one()
00531 {
00532 return 1;
00533 }
00534
00542 static long opposite(const long& a)
00543 {
00544 return -a;
00545 }
00546
00547
00549 static const bool is_comutativity_addition = true;
00550
00552 static const bool is_comutativity_multiplication = true;
00553
00555 static const bool is_distributivity = true;
00556 };
00557
00562 template <>
00563 struct instigate::algebra::interface<unsigned long>
00564 {
00573 static unsigned long plus(const unsigned long& a,
00574 const unsigned long& b)
00575 {
00576 return a + b;
00577 }
00578
00587 static unsigned long multiply(const unsigned long& a,
00588 const unsigned long& b)
00589 {
00590 return a * b;
00591 }
00592
00594 static const bool is_additive_assocativity = true;
00595
00597 static const bool is_multiplicative_assocativity = true;
00598
00604 static unsigned long get_zero()
00605 {
00606 return 0;
00607 }
00608
00614 static unsigned long get_one()
00615 {
00616 return 1;
00617 }
00618
00620 static const bool is_comutativity_addition = true;
00621
00623 static const bool is_comutativity_multiplication = true;
00624
00626 static const bool is_distributivity = true;
00627 };
00628
00633 template <>
00634 struct instigate::algebra::interface<long long>
00635 {
00644 static long long plus(const long long& a, const long long& b)
00645 {
00646 return a + b;
00647 }
00648
00657 static long long minus(const long long& a, const long long& b)
00658 {
00659 return a - b;
00660 }
00661
00670 static long long multiply(const long& a, const long long& b)
00671 {
00672 return a * b;
00673 }
00674
00676 static const bool is_additive_assocativity = true;
00677
00679 static const bool is_multiplicative_assocativity = true;
00680
00686 static long long get_zero()
00687 {
00688 return 0;
00689 }
00690
00696 static long long get_one()
00697 {
00698 return 1;
00699 }
00700
00708 static long long opposite(const long long& a)
00709 {
00710 return -a;
00711 }
00712
00714 static const bool is_comutativity_addition = true;
00715
00717 static const bool is_comutativity_multiplication = true;
00718
00720 static const bool is_distributivity = true;
00721 };
00722
00727 template <>
00728 struct instigate::algebra::interface<unsigned long long>
00729 {
00738 static unsigned long long plus(const unsigned long long& a,
00739 const unsigned long long& b)
00740 {
00741 return a + b;
00742 }
00743
00752 static unsigned long long multiply(const unsigned long long& a,
00753 const unsigned long long& b)
00754 {
00755 return a * b;
00756 }
00757
00759 static const bool is_additive_assocativity = true;
00760
00762 static const bool is_multiplicative_assocativity = true;
00763
00769 static unsigned long long get_zero()
00770 {
00771 return 0;
00772 }
00773
00779 static unsigned long long get_one()
00780 {
00781 return 1;
00782 }
00783
00785 static const bool is_comutativity_addition = true;
00786
00788 static const bool is_comutativity_multiplication = true;
00789
00791 static const bool is_distributivity = true;
00792 };
00793
00798 template <>
00799 struct instigate::algebra::interface<double>
00800 {
00809 static double plus(const double& a, const double& b)
00810 {
00811 return a + b;
00812 }
00813
00822 static double minus(const double& a, const double& b)
00823 {
00824 return a - b;
00825 }
00826
00835 static double multiply(const double& a, const double& b)
00836 {
00837 return a * b;
00838 }
00839
00848 static double divide(const double& a, const double& b)
00849 {
00850 return a / b;
00851 }
00852
00854 static const bool is_additive_assocativity = true;
00855
00857 static const bool is_multiplicative_assocativity = true;
00858
00864 static double get_zero()
00865 {
00866 return 0;
00867 }
00868
00874 static double get_one()
00875 {
00876 return 1;
00877 }
00878
00886 static double opposite(const double& a)
00887 {
00888 return -a;
00889 }
00890
00898 static double inverse(const double& a)
00899 {
00900 return get_one() / a;
00901 }
00902
00904 static const bool is_comutativity_addition = true;
00905
00907 static const bool is_comutativity_multiplication = true;
00908
00910 static const bool is_distributivity = true;
00911 };
00912
00917 template <>
00918 struct instigate::algebra::interface<long double>
00919 {
00928 static long double plus(const long double& a, const long double& b)
00929 {
00930 return a + b;
00931 }
00932
00941 static long double minus(const long double& a, const long double& b)
00942 {
00943 return a - b;
00944 }
00945
00954 static long double multiply(const long double& a, const long double& b)
00955 {
00956 return a * b;
00957 }
00958
00967 static long double divide(const long double& a, const long double& b)
00968 {
00969 return a / b;
00970 }
00971
00973 static const bool is_additive_assocativity = true;
00974
00976 static const bool is_multiplicative_assocativity = true;
00977
00983 static long double get_zero()
00984 {
00985 return 0;
00986 }
00987
00993 static long double get_one()
00994 {
00995 return 1;
00996 }
00997
01005 static long double opposite(const long double& a)
01006 {
01007 return -a;
01008 }
01009
01017 static long double inverse(const long double& a)
01018 {
01019 return get_one() / a;
01020 }
01021
01023 static const bool is_comutativity_addition = true;
01024
01026 static const bool is_comutativity_multiplication = true;
01027
01029 static const bool is_distributivity = true;
01030 };
01031
01036 template <>
01037 struct instigate::algebra::interface<wchar_t>
01038 {
01047 static wchar_t plus(const wchar_t& a, const wchar_t& b)
01048 {
01049 return a + b;
01050 }
01051
01060 static wchar_t minus(const wchar_t& a, const wchar_t& b)
01061 {
01062 return a - b;
01063 }
01064
01073 static wchar_t multiply(const wchar_t& a, const wchar_t& b)
01074 {
01075 return a * b;
01076 }
01077
01079 static const bool is_additive_assocativity = true;
01080
01082 static const bool is_multiplicative_assocativity = true;
01083
01091 static wchar_t opposite(const wchar_t& a)
01092 {
01093 return -a;
01094 }
01095
01097 static const bool is_comutativity_addition = true;
01098
01100 static const bool is_comutativity_multiplication = true;
01101
01103 static const bool is_distributivity = true;
01104 };
01105
01110 template <>
01111 struct instigate::algebra::interface<short>
01112 {
01121 static short plus(const short& a, const short& b)
01122 {
01123 return a + b;
01124 }
01125
01134 static short minus(const short& a, const short& b)
01135 {
01136 return a - b;
01137 }
01138
01147 static short multiply(const short& a, const short& b)
01148 {
01149 return a * b;
01150 }
01151
01153 static const bool is_additive_assocativity = true;
01154
01156 static const bool is_multiplicative_assocativity = true;
01157
01163 static short get_zero()
01164 {
01165 return 0;
01166 }
01167
01173 static short get_one()
01174 {
01175 return 1;
01176 }
01177
01185 static short opposite(const short& a)
01186 {
01187 return -a;
01188 }
01189
01191 static const bool is_comutativity_addition = true;
01192
01194 static const bool is_comutativity_multiplication = true;
01195
01197 static const bool is_distributivity = true;
01198 };
01199
01204 template <>
01205 struct instigate::algebra::interface<unsigned short>
01206 {
01215 static unsigned short plus(const unsigned short& a, unsigned short& b)
01216 {
01217 return a + b;
01218 }
01219
01228 static unsigned short multiply(const unsigned short& a,
01229 const unsigned short& b)
01230 {
01231 return a * b;
01232 }
01233
01235 static const bool is_additive_assocativity = true;
01236
01238 static const bool is_multiplicative_assocativity = true;
01239
01245 static unsigned short get_zero()
01246 {
01247 return 0;
01248 }
01249
01255 static unsigned short get_one()
01256 {
01257 return 1;
01258 }
01259
01261 static const bool is_comutativity_addition = true;
01262
01264 static const bool is_comutativity_multiplication = true;
01265
01267 static const bool is_distributivity = true;
01268 };
01269
01274 template <char>
01275 struct instigate::algebra::interface<char>
01276 {
01285 static char plus(const char& a, const char& b)
01286 {
01287 return a + b;
01288 }
01289
01298 static char minus(const char& a, const char& b)
01299 {
01300 return a - b;
01301 }
01302
01311 static char multiply(const char& a, const char& b)
01312 {
01313 return a * b;
01314 }
01315
01317 static const bool is_additive_assocativity = true;
01318
01320 static const bool is_multiplicative_assocativity = true;
01321
01323 static const bool is_comutativity_addition = true;
01324
01326 static const bool is_comutativity_multiplication = true;
01327
01329 static const bool is_distributivity = true;
01330 };
01331
01332
01333
01334 #endif // INSTIGATE_ALGEBRA_INTERFACE_HPP