00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _UniqueConstant_h
00025 #define _UniqueConstant_h
00026
00027
00028 #include "Quantities/Quantity/Variable.h"
00029
00030
00031 #include "loki/Singleton.h"
00032
00033
00034 #include <boost/serialization/base_object.hpp>
00035
00036 namespace quantity {
00037
00039
00040
00041
00043
00045
00051 template<typename BQ, typename DQ = DerivedQuantity<typename BQ::QT,
00052 typename BQ::DU, typename BQ::DDQ> > class UniqueConstant;
00053
00055
00065 template<typename QT, typename ST, typename DQSU, typename DQT>
00066 class UniqueConstant<Quantity<QT, ST>, DerivedQuantity<QT, DQSU, DQT> >
00067 : public Quantity<QT, ST>
00068 {
00069 public:
00071
00073 typedef typename QuantityTraits<QT>::Dimension DIM;
00074
00076
00078 typedef typename QuantityTraits<QT>::UnitType UT;
00079
00081
00083 typedef typename QuantityTraits<QT>::UnitList UL;
00084
00086
00089 typedef Quantity<QT, ST> BQ;
00090
00092
00095 typedef typename BQ::DU DU;
00096
00098
00100 typedef typename unit::ValidUnit<DQSU, UL>::RET SU;
00101
00103
00105 typedef UniqueConstant<BQ, DerivedQuantity<QT, SU, DQT> > UC;
00106
00108
00111 typedef Variable<BQ, DerivedQuantity<QT, SU, DQT> > V;
00112
00114
00117 friend class Loki::CreateUsingNew<UC>;
00118
00119 private:
00121
00125 static const ST default_value_;
00126
00128
00131 ST _value;
00132
00134
00136
00137 private:
00139
00146 UniqueConstant (void) : BQ (), _value (default_value_)
00147 {BQ::name (Name<QT, DQT>::exec ()); BQ::symbol (Symbol<QT, DQT>::exec ());}
00148
00149 private:
00151
00154 UniqueConstant (const UniqueConstant &)
00155 : BQ (), _value (default_value_) {}
00156
00158
00160
00162
00164
00166
00168 private:
00169 ~UniqueConstant (void) {}
00170
00172
00174
00176
00178
00180
00182 private:
00183 UniqueConstant & operator= (const UniqueConstant &);
00184
00186
00188 private:
00189 void operator& ();
00190
00192
00194
00196
00198
00199 public:
00201
00203 ST value (void) const {return _value;}
00204
00206
00209 ST standard_value (void) const
00210 {return unit::Standard<SU>::VAL (_value);}
00211
00213
00219 template<typename NU>
00220 Variable<Quantity<QT, ST>, DerivedQuantity<QT, NU, DQT> >
00221 value (const NU &) const
00222 {return Variable<Quantity<QT, ST>, DerivedQuantity<QT, NU, DQT> >
00223 (unit::Reverse<typename unit::ValidUnit<NU, UL>::RET>::VAL
00224 (unit::Standard<SU>::VAL (_value)));}
00225
00227
00234 ST value (const std::string &unitsymbol)
00235 {
00236 ST value;
00237 value = unit::reverse<UL>::VAL
00238 (unit::Standard<SU>::VAL (_value), unitsymbol);
00239 return value;
00240 }
00241
00243
00245 ST value (const char * unitsymbol)
00246 {return value (std::string (unitsymbol));}
00247
00248 protected:
00250
00254 void name (const std::string &namestring) {BQ::name (namestring);}
00255
00257
00261 void symbol (const std::string &symbolstring) {BQ::symbol (symbolstring);}
00262
00263 public:
00265
00267 std::string unitsymbol (void) const {return SU::Symbol ();}
00268
00270
00272 static std::string Unitsymbol (void) {return SU::Symbol ();}
00273
00275
00277 std::string unitname (void) const {return SU::Name ();}
00278
00280
00282 static std::string Unitname (void) {return SU::Name ();}
00283
00285
00287 std::string name (void) const {return BQ::name ();}
00288
00290
00292 std::string symbol (void) const {return BQ::symbol ();}
00293
00295
00297
00299
00301
00303
00306 typename GenerateVariable<UC, BSUtilities::Rational<1> >::Mult
00307 operator+ (void) const
00308 {typename GenerateVariable<UC, BSUtilities::Rational<1> >::Mult new_constant (*this);
00309 return new_constant;
00310 }
00311
00313
00316 typename GenerateVariable<UC, BSUtilities::Rational<1> >::Mult operator- (void) const
00317 {typename GenerateVariable<UC, BSUtilities::Rational<1> >::Mult new_constant (*this);
00318 return new_constant *= -ST(1.0);
00319 }
00320
00322
00324 template <class Q>
00325 V operator+ (const Q &new_variable) const
00326 {V new_object = *this;
00327 return new_object += new_variable;
00328 }
00329
00331
00334 template <class Q>
00335 V operator- (const Q &new_variable) const
00336 {V new_object = *this;
00337 return new_object -= new_variable;
00338 }
00339
00341
00343 V operator* (const ST factor) const
00344 {V new_object = *this;
00345 return new_object *= factor;
00346 }
00347
00348
00350 friend V operator*
00351 (const ST factor, const UC &variable)
00352 {return V (variable) *= factor;}
00353
00354
00356
00358 V operator/ (const ST factor) const
00359 {V new_object = *this;
00360 return new_object /= factor;
00361 }
00362
00364
00369 template<class Q>
00370 typename GenerateVariable<UniqueConstant, Q>::Add operator*
00371 (const Q &factor)
00372 {
00373 return typename
00374 GenerateVariable<UniqueConstant, Q>::Add
00375 (standard_value () * factor.standard_value ());
00376 }
00377
00379
00384 template<class Q>
00385 typename GenerateVariable<UniqueConstant, Q>::Sub
00386 operator/ (const Q &factor)
00387 {
00388 return typename
00389 GenerateVariable<UniqueConstant, Q>::Sub
00390 (standard_value () / factor.standard_value ());
00391 }
00392
00394
00397 friend
00398 typename GenerateVariable<UniqueConstant, Loki::NullType>::Inv
00399 operator/ (const ST numerator, const UniqueConstant &factor)
00400 {
00401 return typename
00402 GenerateVariable<UniqueConstant, Loki::NullType>::Inv
00403 (numerator / factor.standard_value ());
00404 }
00405
00407
00409
00411
00412
00414
00415 QUANTITY_COMPARISON_OPERATORS(UniqueConstant, operator==, ==)
00416 QUANTITY_COMPARISON_OPERATORS(UniqueConstant, operator!=, !=)
00417 QUANTITY_COMPARISON_OPERATORS(UniqueConstant, operator>, >)
00418 QUANTITY_COMPARISON_OPERATORS(UniqueConstant, operator<, <)
00419 QUANTITY_COMPARISON_OPERATORS(UniqueConstant, operator>=, >=)
00420 QUANTITY_COMPARISON_OPERATORS(UniqueConstant, operator<=, <=)
00421
00423
00425
00427
00433 template<long N, long D>
00434 typename GenerateVariable<UniqueConstant,
00435 BSUtilities::Rational<N, D> >::Mult
00436 pow (const BSUtilities::Rational<N, D> &) const
00437 {return std::pow (standard_value (),
00438 static_cast<double>(N)/static_cast<double>(D));}
00439
00441
00447 template<int I>
00448 typename GenerateVariable<UniqueConstant,
00449 BSUtilities::Rational<I, long(1)> >::Mult
00450 pow (const typename Loki::Int2Type<I>) const
00451 {return std::pow (standard_value (), I);}
00452
00454
00460 template<class T>
00461 Dynamic<ST> pow (const T &exp) const
00462 {return Dynamic<ST>::pow (*this, exp);}
00463
00465
00472 typename
00473 GenerateVariable<UniqueConstant, BSUtilities::Rational<1, 2>
00474 >::Mult sqrt (void) const
00475 {
00476 return typename
00477 GenerateVariable<UniqueConstant, BSUtilities::Rational<1, 2>
00478 >::Mult (std::sqrt(standard_value ()));
00479 }
00480
00482
00485 std::ostream & print_value (std::ostream &os) const
00486 {return os << _value << " " << SU::Symbol ();}
00487
00489
00491 void operator>> (std::string &str) const
00492 {str = BSUtilities::Conversion<UniqueConstant>::to_string
00493 (*this);}
00495
00499 std::ostream & operator>> (std::ostream &os) const
00500 {return this->print (os);}
00501
00502 private:
00504 friend class boost::serialization::access;
00505
00507
00509 template<typename Archive>
00510 void serialize (Archive &ar, const unsigned int )
00511 {
00512 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(BQ);
00513 }
00514
00515 };
00516
00517 }
00518
00519 #endif