00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _ReferencedVariable_h
00025 #define _ReferencedVariable_h
00026
00027 #include "Quantity/Quantity.h"
00028 #include "Quantity/Generic.h"
00029
00030 namespace quantity {
00031
00033
00034
00035
00037
00039
00043 template<class PQ, class SU = typename PQ::DefaultUnit::Unit>
00044 class ReferencedVariable;
00045
00047
00050 template<class BT, class DIM, class UL, class DU, class SU, class ST>
00051 class ReferencedVariable<Quantity<DIM, BT, UL, DU, ST>, SU>
00052 : public Variable<Quantity<DIM, BT, UL, DU, ST>, SU>
00053
00054 {
00055 private:
00057 typedef Variable<Quantity<DIM, BT, UL, DU, ST>, SU> V;
00058
00060 typedef Quantity<DIM, BT, UL, DU, ST> Q;
00061
00063 ST reference_value;
00064
00065 public:
00067
00070 ReferencedVariable (void)
00071 : V (ST(0.0)), reference_value (ST(0.0)) {}
00072
00074
00077 ReferencedVariable (const ST new_value) : V (new_value) {}
00078
00080
00083 ReferencedVariable (const ST new_value, const ST new_reference)
00084 : V (new_value - new_reference),
00085 reference_value (new_reference) {}
00086
00088
00094 template<class NU>
00095 ReferencedVariable
00096 (const ST new_value, const ST new_reference, const NU &)
00097 {
00098 variable_value = Reverse<typename V::Unit>::VAL
00099 (Standardize<typename
00100 CheckAgainstAllUnits<NU, UL>
00101 ::RET>::VAL (new_value - new_reference));
00102 reference_value
00103 = Reverse<typename V::Unit>::VAL (Standardize<NU>::VAL
00104 (new_reference));
00105 }
00106
00108
00118 template<template<class, class> class QR, class BTR, class DIMR,
00119 class ULR, class DUR, class SUR, class STR>
00120 ReferencedVariable (const ST new_value,
00121 const QR<Quantity<DIMR, BTR, ULR, DUR, STR>, SUR>
00122 & new_reference)
00123 {
00124 typedef
00125 QR<Quantity<DIMR, BTR, ULR, DUR, STR>, SUR> Q;
00126 reference_value
00127 = Reverse<typename V::Unit>::VAL
00128 (Standardize<typename CheckAgainstAllUnits<typename
00129 CheckSecondDimension<ReferencedVariable, Q>
00130 ::RET::Unit,
00131 typename
00132 Loki::TL::Append<UL, unit::NonPrefixable<BTR,
00133 unit::GenericUnit> >::Result>::RET>::VAL
00134 (new_reference.value ()));
00135 variable_value = new_value - reference_value;
00136 }
00137
00138
00139
00140
00142
00145 ReferencedVariable (const ReferencedVariable &new_variable)
00146 : V (new_variable.variable_value),
00147 reference_value (new_variable.reference_value)
00148 {
00149 namestring = new_variable.namestring;
00150 symbolstring = new_variable.symbolstring;
00151 };
00152
00153
00154
00156
00162 void reference (const ST new_reference)
00163 {variable_value
00164 = variable_value + reference_value - new_reference;
00165 reference_value = new_reference;
00166 }
00167
00169
00175 template<class NU>
00176 void reference (const ST new_reference, const NU &)
00177 {variable_value = variable_value + reference_value;
00178 reference_value = Reverse<typename V::Unit>::VAL
00179 (Standardize<typename
00180 CheckAgainstAllUnits<NU, UL>::RET>::VAL
00181 (new_reference));
00182 variable_value -= reference_value;
00183 }
00184
00186
00189 ST reference (void) {return reference_value;}
00190
00192
00196 template<class NU>
00197 ST reference (const NU &)
00198 {return Reverse<typename
00199 CheckAgainstAllUnits<NU, UL>::RET>::VAL
00200 (Standardize<typename V::Unit>::VAL (reference_value));}
00201
00203
00204
00205
00206
00207
00208 template<template<class, class> class Q1, class BT1, class DIM1,
00209 class UL1, class DU1, class SU1, class ST1>
00210 ReferencedVariable & operator=
00211 (const Q1<Quantity<DIM1, BT1, UL1, DU1, ST1>, SU1>
00212 &new_variable)
00213 {
00214 void *this_pointer = this;
00215 const void *new_pointer = &new_variable;
00216
00217 if (this_pointer != new_pointer)
00218 {
00219 typedef Q1<Quantity<DIM1, BT1, UL1, DU1, ST1>, SU1> Q;
00220 variable_value = Reverse<typename V::Unit>::VAL
00221 (Standardize<typename CheckAgainstAllUnits<typename
00222 CheckSecondDimension<ReferencedVariable, Q>
00223 ::RET::Unit,
00224 typename Loki::TL::Append<UL,
00225 unit::NonPrefixable<BT1,
00226 unit::GenericUnit> >::Result>::RET>::VAL
00227 (new_variable.value ()))
00228 - reference_value;
00229 }
00230 return *this;
00231 }
00232
00234
00235
00236
00237
00238
00239 ReferencedVariable & operator=
00240 (const ReferencedVariable &new_variable)
00241 {
00242 if (this != &new_variable)
00243 {variable_value =
00244 new_variable.value () - reference_value;
00245 }
00246 return *this;
00247 }
00248
00250
00253 ST value (void) const
00254 {return variable_value + reference_value;}
00255
00257
00260 ST refvalue (void) const {return variable_value;}
00261
00263
00268 template<class NU>
00269 ST value (const NU &) const
00270 {return
00271 Reverse<typename CheckAgainstAllUnits<NU, UL>::RET>::VAL
00272 (Standardize<typename V::Unit>::VAL (variable_value));}
00273
00275
00277 const std::string unitsymbol (void) const
00278 {return SU::Symbol ();}
00279
00281
00283 static std::string Unitsymbol (void) {return SU::Symbol ();}
00284
00286
00288 const std::string unitname (void) const {return SU::Name ();}
00289
00291
00293 static std::string Unitname (void) {return SU::Name ();}
00294
00295 };
00296
00297 }
00298
00299 #endif