00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef PHYSICAL_DYNAMICPHYSICAL
00015 #define PHYSICAL_DYNAMICPHYSICAL
00016
00017 #include "physical/fixedphysical.hpp"
00018 #include "physical/dynamicunit.hpp"
00019 #include "physical/exception.hpp"
00020
00021
00022 namespace physical {
00023
00024 template<class UnitSystem>
00025 struct DynamicPhysical {
00026 detail::DynamicExponents<UnitSystem> exponents;
00027 double numerical_value;
00028
00029 template<class UnitSystem, typename T, class Exponents>
00030 DynamicPhysical(FixedPhysical<UnitSystem, T, Exponents> q)
00031 : numerical_value(q.numerical_value)
00032 , exponents(Exponents())
00033 {};
00034
00035
00036 DynamicPhysical(double v=0., detail::DynamicExponents<UnitSystem> exponents = detail::DynamicExponents<UnitSystem>())
00037 : numerical_value(v)
00038 , exponents(exponents)
00039 {};
00040
00041 DynamicPhysical& operator*=(DynamicPhysical b);
00042 };
00043
00044
00045
00046 template<class UnitSystem> DynamicPhysical<UnitSystem> operator+(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00047 template<class UnitSystem> DynamicPhysical<UnitSystem> operator-(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00048 template<class UnitSystem> DynamicPhysical<UnitSystem> operator*(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00049 template<class UnitSystem> DynamicPhysical<UnitSystem> operator*(double a, DynamicPhysical<UnitSystem> b);
00050 template<class UnitSystem> DynamicPhysical<UnitSystem> operator/(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00051
00052
00053
00054 template<class UnitSystem> bool operator==(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00055 template<class UnitSystem> bool operator!=(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00056 template<class UnitSystem> bool operator>=(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00057 template<class UnitSystem> bool operator<=(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00058 template<class UnitSystem> bool operator>(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00059 template<class UnitSystem> bool operator<(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b);
00060
00061
00062
00063 template<class UnitSystem> DynamicPhysical<UnitSystem> power(DynamicPhysical<UnitSystem> a, int n);
00064 template<class UnitSystem> DynamicPhysical<UnitSystem> operator*(double real, const DynamicUnit<UnitSystem>& unit);
00065 template<class UnitSystem> DynamicPhysical<UnitSystem> operator/(DynamicPhysical<UnitSystem> quantity, const DynamicUnit<UnitSystem> unit);
00066
00067
00068
00069 template<class UnitSystem, typename T, class Exponents>
00070 FixedPhysical<UnitSystem, T, Exponents>::FixedPhysical(const DynamicPhysical<UnitSystem>& v) {
00071
00072 detail::DynamicExponents<UnitSystem> dynexp( (typename exponents()) );
00073
00074 if (dynexp==v.exponents) {
00075 numerical_value = v.numerical_value;
00076 } else {
00077
00078 throw IncompatibleUnitException("attempt of conversion between incompatible quantities");
00079 };
00080 }
00081
00082
00083 };
00084
00085
00086
00087 #include "physical/detail/dynamicphysical_impl.hpp"
00088
00089 #endif
00090