Digital.h

Go to the documentation of this file.
00001 
00007 /* Copyright (C) 2002 - 2009, Bernd Speiser */
00008 
00009 /* This file is part of Quantities.
00010 
00011 PhysicalQuantities is free software; you can redistribute it and/or
00012 modify it under the terms of the GNU General Public License
00013 as published by the Free Software Foundation; either version 2
00014 of the License, or (at your option) any later version.
00015 
00016 PhysicalQuantities is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020   
00021 You should have received a copy of the GNU General Public License
00022 along with this program; if not, write to the Free Software
00023 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00024 02111-1307, USA.
00025 */
00026 
00027 #ifndef _Digital_h
00028 #define _Digital_h
00029 
00030 // Quantity includes
00031 #include "Quantity/Variable.h"
00032 #include "Quantity/Constant.h"
00033 
00034 namespace quantity {
00036   namespace digital {
00037 
00039 class Class;
00040 
00042 class Unit;
00043 
00044 /* declaration of Digital units */
00045 class DigitalUnit;
00046 
00048 typedef unit::NonPrefixable<Unit, DigitalUnit> Unity;
00049 
00051 typedef LOKI_TYPELIST_1(Unity) Units;
00052 
00053 /* Digital quantity */
00054 
00055 typedef quantity::Quantity<Class, bool> Quantity;
00056 
00057 class DerivedDigital;
00058 
00059 } // end namespace digital
00060 
00062 //
00063 // specializations of functionality; some application programs may
00064 // need specific requirements for Digital. Such requirements can be
00065 // added here.
00066 //
00068 
00070 //
00071 // GenerateVariable Add and Sub functions for two Quantities, 
00072 // the first of which has storage type bool 
00073 //
00075 
00077 
00082 template<template<typename, typename> class Q1, typename QT1, typename SU1,
00083          template<typename, typename> class Q2, typename QT2, typename SU2, typename ST>
00084   struct GenerateVariable
00085     <Q1<Quantity<QT1, bool>, SU1>, Q2<Quantity<QT2, ST>, SU2> >
00086   {
00087      private:
00088        typedef typename QuantityTraits<QT1>::Dimension Dim1;
00089        typedef typename QuantityTraits<QT2>::Dimension Dim2;
00090 
00092       typedef typename Dim1::template Add<Dim2> AddT;
00093       typedef Quantity<GenericClass<typename AddT::Res>, ST> AddNewQ;
00094 
00096       typedef typename Dim1::template Sub<Dim2> SubT;
00097       typedef Quantity<GenericClass<typename SubT::Res>, ST> SubNewQ;
00098 
00099      public:
00101 
00103        typedef Variable<AddNewQ> Add;
00104 
00106 
00108        typedef Variable<SubNewQ> Sub;
00109   };
00110 
00112 //
00113 // traits templates for Digital
00114 //
00116 
00118 
00120   template<>
00121     struct Standard<digital::Unity, bool>
00122     {
00123       static const bool ratio;
00124       static const bool exact;
00125     };
00126 
00128 template<>
00129   struct QuantityTraits<digital::Class>
00130   {
00131     typedef
00132       dimension::Dimension<BSUtilities::Rational<0>,
00133         BSUtilities::Rational<0>, BSUtilities::Rational<0>,
00134           BSUtilities::Rational<0>, BSUtilities::Rational<0>,
00135             BSUtilities::Rational<0>, BSUtilities::Rational<0> > Dimension;
00136     typedef digital::Unit UnitType;
00137     typedef digital::Units UnitList;
00138     typedef digital::Unity DefaultUnit;
00139 
00140     typedef digital::DerivedDigital DefaultDerivedQuantityType;
00141 
00142     static const std::string NameString;
00143     static const std::string SymbolString;
00144 
00145   };
00146 
00147 // the derived quantity traits template for derived Digital
00148 template<>
00149   struct DerivedQuantityTraits<digital::Class, digital::DerivedDigital>
00150   {
00151     static const bool OverwriteName = false;
00152     static const bool OverwriteSymbol = false;
00153 
00154     static const std::string NameString;
00155     static const std::string SymbolString;
00156 
00157   };
00158 
00159 
00161 typedef Variable<digital::Quantity> Digital;
00162 
00164 typedef Constant<digital::Quantity> DigitalConstant;
00165 
00166 namespace digital{
00168     extern const quantity::DigitalConstant On;
00170     extern const quantity::DigitalConstant Off;
00171                 } // end namespace digital 
00172 
00173   } // end namespace quantity
00174 
00175 #endif /* _Digital_h */

Generated on Mon Jul 27 15:55:44 2009 for Quantities by  doxygen 1.5.3