Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

Dimension.h

Go to the documentation of this file.
00001 
00005 /* Copyright (C) 2002 - 2004, Bernd Speiser */
00006 /* This file is part of Quantity.
00007 
00008 Quantity is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 Quantity is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017   
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00021 02111-1307, USA.
00022 */
00023 
00024 #ifndef _Dimension_h
00025 #define _Dimension_h
00026 
00027 #include <string>
00028 
00029 #include "NullType.h"
00030 #include "TypeManip.h"
00031 
00032 #include "TemplateTools.h"
00033 
00035 namespace Dimensions {
00036 
00038 //
00039 //  Helper classes and structs for manipulation of dimensions and
00040 //  lists of Rational numbers coding dimensions
00041 //
00043 
00045 
00047 template<class TL> struct Dimensionality;
00049 
00056 template<class Head, class Tail>
00057   struct Dimensionality<Loki::Typelist<Head, Tail> >
00058   {
00060 
00063     enum {IsDimensionless = 
00064             ((Head::numerator == 0) && 
00065                (Dimensionality<Tail>::IsDimensionless == 1)) ? 1 : 0};
00066   };
00067 
00069 
00072 template<>
00073   struct Dimensionality<Loki::NullType>
00074   {
00076     enum {IsDimensionless = 1};
00077   };
00078 
00080 
00082 template<class D1, class D2> struct DimensionEquality;
00083 
00085 
00089 template<class D1Head, class D2Head, class D1Tail, class D2Tail> 
00090   struct DimensionEquality<Loki::Typelist<D1Head, D1Tail>, 
00091                                         Loki::Typelist<D2Head, D2Tail> >
00092   {
00094 
00101     enum {RET = (BSUtilities::RationalEquality<D1Head, D2Head>::RET
00102                     && DimensionEquality<D1Tail, D2Tail>::RET) ? 1 : 0};
00103   };
00104 
00106 
00109 template<class D1Head, class D2Head> 
00110   struct DimensionEquality<Loki::Typelist<D1Head, Loki::NullType>, 
00111                                 Loki::Typelist<D2Head, Loki::NullType> >
00112   {
00114 
00117     enum {RET = BSUtilities::RationalEquality<D1Head, D2Head>::RET};
00118   };
00119 
00121 //
00122 //  Dimensions base class for all dimensions
00123 //
00125 
00127 class Dimensions
00128   {
00129     public:
00131 
00133       static std::string version (void)
00134         {static const std::string v_string ("Dimensions version 1.0"); 
00135                                                        return v_string;}
00136 
00137   };
00138 
00140 //
00141 //  the Dimension of a quantity
00142 //
00144 
00146 
00156 template<class GT>
00157   class Dimension : public Dimensions
00158   {
00159     public:
00160       typedef typename GT::DimTL DimTL;
00161 
00163 
00166       static const bool IsDimensionless 
00167                  = Dimensionality<typename GT::DimTL>::IsDimensionless;
00168 
00170 
00173     template<class GT1>
00174       struct Add
00175       {
00176         private:
00177           typedef typename BSUtilities::RationalAdd<typename 
00178             Loki::TL::TypeAt<typename GT::DimTL,0>::Result, 
00179               typename 
00180                 Loki::TL::TypeAt<typename GT1::DimTL,0>::Result>::RET
00181                                                                      A0;
00182           typedef typename BSUtilities::RationalAdd<typename 
00183             Loki::TL::TypeAt<typename GT::DimTL,1>::Result, 
00184               typename 
00185                 Loki::TL::TypeAt<typename GT1::DimTL,1>::Result>::RET 
00186                                                                      A1;
00187           typedef typename BSUtilities::RationalAdd<typename 
00188             Loki::TL::TypeAt<typename GT::DimTL,2>::Result, 
00189               typename 
00190                 Loki::TL::TypeAt<typename GT1::DimTL,2>::Result>::RET
00191                                                                      A2;
00192           typedef typename BSUtilities::RationalAdd<typename 
00193             Loki::TL::TypeAt<typename GT::DimTL,3>::Result, 
00194               typename 
00195                 Loki::TL::TypeAt<typename GT1::DimTL,3>::Result>::RET
00196                                                                      A3;
00197           typedef typename BSUtilities::RationalAdd<typename 
00198             Loki::TL::TypeAt<typename GT::DimTL,4>::Result, 
00199               typename 
00200                 Loki::TL::TypeAt<typename GT1::DimTL,4>::Result>::RET
00201                                                                      A4;
00202           typedef typename BSUtilities::RationalAdd<typename 
00203             Loki::TL::TypeAt<typename GT::DimTL,5>::Result, 
00204               typename 
00205                 Loki::TL::TypeAt<typename GT1::DimTL,5>::Result>::RET
00206                                                                      A5;
00207           typedef typename BSUtilities::RationalAdd<typename 
00208             Loki::TL::TypeAt<typename GT::DimTL,6>::Result, 
00209               typename 
00210                 Loki::TL::TypeAt<typename GT1::DimTL,6>::Result>::RET
00211                                                                      A6;
00212 
00213         public:
00215 
00218           class Class 
00219             {
00220               public:
00221                 typedef TYPELIST_7(A0, A1, A2, A3, A4, A5, A6) DimTL;
00222             };
00223 
00225 
00227           typedef Dimension<Class> RET;         
00228 
00229       };
00230 
00232 
00235     template<class GT1>
00236       struct Sub
00237       {
00238         private:
00239           typedef typename BSUtilities::RationalSub<typename 
00240             Loki::TL::TypeAt<typename GT::DimTL,0>::Result, 
00241               typename 
00242                 Loki::TL::TypeAt<typename GT1::DimTL,0>::Result>::RET
00243                                                                      A0;
00244           typedef typename BSUtilities::RationalSub<typename 
00245             Loki::TL::TypeAt<typename GT::DimTL,1>::Result, 
00246               typename 
00247                 Loki::TL::TypeAt<typename GT1::DimTL,1>::Result>::RET
00248                                                                      A1;
00249           typedef typename BSUtilities::RationalSub<typename 
00250             Loki::TL::TypeAt<typename GT::DimTL,2>::Result, 
00251               typename 
00252                 Loki::TL::TypeAt<typename GT1::DimTL,2>::Result>::RET
00253                                                                      A2;
00254           typedef typename BSUtilities::RationalSub<typename 
00255             Loki::TL::TypeAt<typename GT::DimTL,3>::Result, 
00256               typename 
00257                 Loki::TL::TypeAt<typename GT1::DimTL,3>::Result>::RET
00258                                                                      A3;
00259           typedef typename BSUtilities::RationalSub<typename 
00260             Loki::TL::TypeAt<typename GT::DimTL,4>::Result, 
00261               typename 
00262                 Loki::TL::TypeAt<typename GT1::DimTL,4>::Result>::RET
00263                                                                      A4;
00264           typedef typename BSUtilities::RationalSub<typename 
00265             Loki::TL::TypeAt<typename GT::DimTL,5>::Result, 
00266               typename 
00267                 Loki::TL::TypeAt<typename GT1::DimTL,5>::Result>::RET
00268                                                                      A5;
00269           typedef typename BSUtilities::RationalSub<typename 
00270             Loki::TL::TypeAt<typename GT::DimTL,6>::Result, 
00271               typename 
00272                 Loki::TL::TypeAt<typename GT1::DimTL,6>::Result>::RET
00273                                                                      A6;
00274 
00275         public:
00277 
00280           class Class 
00281             {
00282               public:
00283                 typedef TYPELIST_7(A0, A1, A2, A3, A4, A5, A6) DimTL;
00284             };
00285 
00287 
00289           typedef Dimension<Class> RET;         
00290     };
00291 
00293 
00297     template<long N, long D>
00298       struct Mult
00299       {
00300         private:
00301           typedef typename BSUtilities::RationalMult<typename 
00302             Loki::TL::TypeAt<typename GT::DimTL,0>::Result, 
00303                                   BSUtilities::Rational<N, D> >::RET A0;
00304           typedef typename BSUtilities::RationalMult<typename 
00305             Loki::TL::TypeAt<typename GT::DimTL,1>::Result,
00306                                   BSUtilities::Rational<N, D> >::RET A1;
00307           typedef typename BSUtilities::RationalMult<typename 
00308             Loki::TL::TypeAt<typename GT::DimTL,2>::Result, 
00309                                   BSUtilities::Rational<N, D> >::RET A2;
00310           typedef typename BSUtilities::RationalMult<typename 
00311             Loki::TL::TypeAt<typename GT::DimTL,3>::Result, 
00312                                   BSUtilities::Rational<N, D> >::RET A3;
00313           typedef typename BSUtilities::RationalMult<typename 
00314             Loki::TL::TypeAt<typename GT::DimTL,4>::Result, 
00315                                   BSUtilities::Rational<N, D> >::RET A4;
00316           typedef typename BSUtilities::RationalMult<typename 
00317             Loki::TL::TypeAt<typename GT::DimTL,5>::Result, 
00318                                   BSUtilities::Rational<N, D> >::RET A5;
00319           typedef typename BSUtilities::RationalMult<typename 
00320             Loki::TL::TypeAt<typename GT::DimTL,6>::Result, 
00321                                   BSUtilities::Rational<N, D> >::RET A6;
00322 
00323         public:
00325 
00328           class Class 
00329             {
00330               public:
00331                 typedef TYPELIST_7(A0, A1, A2, A3, A4, A5, A6) DimTL;
00332             };
00333 
00335 
00337           typedef Dimension<Class> RET;         
00338     };
00339 
00341 
00344     struct Neg
00345     {
00346       private:
00347         typedef typename BSUtilities::RationalNeg<typename 
00348                 Loki::TL::TypeAt<typename GT::DimTL,0>::Result>::RET A0;
00349         typedef typename BSUtilities::RationalNeg<typename 
00350                 Loki::TL::TypeAt<typename GT::DimTL,1>::Result>::RET A1;
00351         typedef typename BSUtilities::RationalNeg<typename 
00352                 Loki::TL::TypeAt<typename GT::DimTL,2>::Result>::RET A2;
00353         typedef typename BSUtilities::RationalNeg<typename 
00354                 Loki::TL::TypeAt<typename GT::DimTL,3>::Result>::RET A3;
00355         typedef typename BSUtilities::RationalNeg<typename 
00356                 Loki::TL::TypeAt<typename GT::DimTL,4>::Result>::RET A4;
00357         typedef typename BSUtilities::RationalNeg<typename 
00358                 Loki::TL::TypeAt<typename GT::DimTL,5>::Result>::RET A5;
00359         typedef typename BSUtilities::RationalNeg<typename 
00360                 Loki::TL::TypeAt<typename GT::DimTL,6>::Result>::RET A6;
00361 
00362       public:
00364 
00367         class Class 
00368           {
00369             public:
00370               typedef TYPELIST_7(A0, A1, A2, A3, A4, A5, A6) DimTL;
00371           };
00372 
00374 
00376         typedef Dimension<Class> RET;         
00377 
00378     };
00379   };
00380 
00382 //
00383 //  Helper class for Manipulation of Dimension<>
00384 //
00386 
00388 
00390 template<class D1, class D2> struct Equal;
00391 
00393 
00398 template<class GT1, class GT2>
00399   struct Equal<Dimension<GT1>, Dimension<GT2> >
00400   {
00402 
00405     enum {RET = 
00406       DimensionEquality<typename GT1::DimTL, typename GT2::DimTL>::RET};
00407   };
00408 }
00409 
00410 #endif /* _Dimension_h */

Generated on Sun Jan 15 13:57:59 2006 for Quantity by doxygen 1.3.6