C:/nobackup/private/physical_svn/trunk/include/physical/dynamicphysical.hpp

Go to the documentation of this file.
00001 
00002 /*=============================================================================
00003     physical quantities / units / constants
00004     Copyright (c) 2006, 2007 Martin Schulz
00005     http://physical.sourceforge.net
00006   
00007     This is private code by Martin Schulz.
00008   
00009     Use, modification and distribution is subject to the Boost Software
00010     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
00011     http://www.boost.org/LICENSE_1_0.txt)
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         // arithmetic operators
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         // comparision operators
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         // other functions
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         // templated member definition (of FixedPhysical) moved here to avoid header dependency
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                         // incompatible dimension, throw exception:
00078                         throw IncompatibleUnitException("attempt of conversion between incompatible quantities");
00079                 };
00080         }
00081 
00082 
00083 }; // namspeace physical
00084 
00085 
00086 // include the implementation deatils
00087 #include "physical/detail/dynamicphysical_impl.hpp"
00088 
00089 #endif
00090 

Generated on Mon Apr 2 22:25:03 2007 for physical_svn by  doxygen 1.5.1-p1
hosted on SourceForge.net Logo