00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef PHYSICAL_FIXEDPHYSICAL
00015 #define PHYSICAL_FIXEDPHYSICAL
00016
00017 #include "physical/detail/fixedexponents.hpp"
00018 #include "physical/detail/larger_type.hpp"
00019
00020
00026 namespace physical {
00027
00028 template<class UnitSystem>
00029 struct DynamicPhysical;
00030
00032 template<class UnitSystem, typename T, class Exponents>
00033 struct FixedPhysical{
00034 typedef UnitSystem unitsystem;
00035 typedef Exponents exponents;
00036 typedef T numerical_value_t;
00037 numerical_value_t numerical_value;
00038
00040 explicit FixedPhysical(numerical_value_t v):numerical_value(v){};
00041
00043 FixedPhysical(const FixedPhysical& v): numerical_value(v.numerical_value){};
00044
00046 FixedPhysical(const DynamicPhysical<UnitSystem>& v);
00047
00049 template<typename T2>
00050 FixedPhysical(const FixedPhysical<UnitSystem, T2, exponents>& v): numerical_value(v.numerical_value){};
00051
00052
00053 };
00054
00055
00056
00057 template <class Q1, class Q2> struct FixedPhysicalSum;
00058
00060 template<class UnitSystem, typename T1, typename T2, class Exponents1, class Exponents2>
00061 struct FixedPhysicalSum< FixedPhysical<UnitSystem, T1, Exponents1>, FixedPhysical<UnitSystem, T2, Exponents2> >{
00062 BOOST_STATIC_ASSERT((boost::is_same<typename Exponents1::dimensions, typename Exponents2::dimensions>::type::value ));
00063 typedef typename detail::larger_type<T1, T2>::type numerical_value_t;
00064 typedef FixedPhysical< UnitSystem, numerical_value_t, Exponents1 > type;
00065 };
00066
00067
00068
00069
00070
00071 template <class Q1, class Q2> struct FixedPhysicalRatio;
00072
00074 template<class UnitSystem, typename T1, typename T2, class Exponents1, class Exponents2>
00075 struct FixedPhysicalRatio< FixedPhysical<UnitSystem, T1, Exponents1>, FixedPhysical<UnitSystem, T2, Exponents2> >{
00076 typedef typename detail::larger_type<T1, T2>::type numerical_value_t;
00077 typedef FixedPhysical< UnitSystem, numerical_value_t, typename detail::minus<Exponents1, typename Exponents2>::type > type;
00078 };
00079
00080
00081
00082 template <class Q1, class Q2> struct FixedPhysicalProduct;
00083
00085 template<class UnitSystem, typename T1, typename T2, class Exponents1, class Exponents2>
00086 struct FixedPhysicalProduct< FixedPhysical<UnitSystem, T1, Exponents1>, FixedPhysical<UnitSystem, T2, Exponents2> >{
00087 typedef typename detail::larger_type<T1, T2>::type numerical_value_t;
00088 typedef FixedPhysical< UnitSystem, numerical_value_t, typename detail::plus<Exponents1, Exponents2>::type > type;
00089 };
00090
00091
00092
00093
00094
00095 template<class UnitSystem, typename T1, typename T2, class exponents>
00096 typename FixedPhysicalSum< FixedPhysical<UnitSystem, T1, exponents>, FixedPhysical<UnitSystem, T2, exponents> >::type
00097 operator+(const FixedPhysical<UnitSystem, T1, exponents> a, FixedPhysical<UnitSystem, T2, exponents> b){
00098 typedef FixedPhysicalSum<FixedPhysical<UnitSystem, T1, exponents>, FixedPhysical<UnitSystem, T2, exponents> >::type return_type;
00099 return retrun_type(a.numerical_value + b.numerical_value);
00100 };
00101
00102 template<class UnitSystem, typename T1, typename T2, class exponents>
00103 typename FixedPhysicalSum< FixedPhysical<UnitSystem, T1, exponents>, FixedPhysical<UnitSystem, T2, exponents> >::type
00104 operator-(const FixedPhysical<UnitSystem, T1, exponents> a, FixedPhysical<UnitSystem, T2, exponents> b){
00105 typedef FixedPhysicalSum<FixedPhysical<UnitSystem, T1, exponents>, FixedPhysical<UnitSystem, T2, exponents> >::type return_type;
00106 return retrun_type(a.numerical_value - b.numerical_value);
00107 };
00108
00109 template<class UnitSystem, typename T1, typename T2, class exponents1, class exponents2>
00110 typename FixedPhysicalProduct< FixedPhysical<UnitSystem, T1, exponents1>, FixedPhysical<UnitSystem, T2, exponents2> >::type
00111 operator*(const FixedPhysical<UnitSystem, T1, exponents1> a, FixedPhysical<UnitSystem, T2, exponents2> b){
00112 typedef FixedPhysicalProduct<FixedPhysical<UnitSystem, T1, exponents1>, FixedPhysical<UnitSystem, T2, exponents2> >::type return_type;
00113 return return_type(a.numerical_value * b.numerical_value);
00114 };
00115
00116 template<class UnitSystem, typename T1, typename T2, class exponents1, class exponents2>
00117 typename FixedPhysicalRatio< FixedPhysical<UnitSystem, T1, exponents1>, FixedPhysical<UnitSystem, T2, exponents2> >::type
00118 operator/(const FixedPhysical<UnitSystem, T1, exponents1> a, FixedPhysical<UnitSystem, T2, exponents2> b){
00119 typedef FixedPhysicalRatio<FixedPhysical<UnitSystem, T1, exponents1>, FixedPhysical<UnitSystem, T2, exponents2> >::type return_type;
00120 return return_type(a.numerical_value / b.numerical_value);
00121 };
00122
00123
00124
00125 template<class UnitSystem, typename T1, typename T2, class exponents>
00126 bool
00127 operator==(const FixedPhysical<UnitSystem, T1, exponents> a, FixedPhysical<UnitSystem, T2, exponents> b){
00128 return retrun_type(a.numerical_value == b.numerical_value);
00129 };
00130
00131 template<class UnitSystem, typename T1, typename T2, class exponents>
00132 bool
00133 operator!=(const FixedPhysical<UnitSystem, T1, exponents> a, FixedPhysical<UnitSystem, T2, exponents> b){
00134 return retrun_type(a.numerical_value != b.numerical_value);
00135 };
00136
00137 template<class UnitSystem, typename T1, typename T2, class exponents>
00138 bool
00139 operator>=(const FixedPhysical<UnitSystem, T1, exponents> a, FixedPhysical<UnitSystem, T2, exponents> b){
00140 return retrun_type(a.numerical_value >= b.numerical_value);
00141 };
00142
00143 template<class UnitSystem, typename T1, typename T2, class exponents>
00144 bool
00145 operator<=(const FixedPhysical<UnitSystem, T1, exponents> a, FixedPhysical<UnitSystem, T2, exponents> b){
00146 return retrun_type(a.numerical_value <= b.numerical_value);
00147 };
00148
00149 template<class UnitSystem, typename T1, typename T2, class exponents>
00150 bool
00151 operator>(const FixedPhysical<UnitSystem, T1, exponents> a, FixedPhysical<UnitSystem, T2, exponents> b){
00152 return retrun_type(a.numerical_value > b.numerical_value);
00153 };
00154
00155 template<class UnitSystem, typename T1, typename T2, class exponents>
00156 bool
00157 operator<(const FixedPhysical<UnitSystem, T1, exponents> a, FixedPhysical<UnitSystem, T2, exponents> b){
00158 return retrun_type(a.numerical_value < b.numerical_value);
00159 };
00160
00161
00162 template <class UnitSystem, typename T, int P>
00163 struct FixedPhysicalBase{
00164 typedef FixedPhysical< UnitSystem, T, typename detail::FixExponents<UnitSystem, P>::type > type;
00165 };
00166
00167
00168 template <class UnitSystem, typename T>
00169 struct FixedPhysicalBase<UnitSystem, T, -1>{
00170 typedef FixedPhysical< UnitSystem, T,
00171 detail::FixedExponents<UnitSystem, typename detail::zero_vector<UnitSystem::number_baseunits>::type>
00172 > type;
00173 };
00174
00175
00176
00177 template<class UnitSystem, typename T1, typename T2, class exponents1>
00178 FixedPhysical<UnitSystem, typename detail::larger_type<T1, T2>::type, exponents1>
00179 operator*(const T1 a, const FixedPhysical<UnitSystem, T2, exponents1> b){
00180 typedef FixedPhysical<UnitSystem, typename detail::larger_type<T1, T2>::type, exponents1> return_type;
00181 return return_type(a * b.numerical_value);
00182 };
00183
00184 };
00185
00186 #endif