00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __VARIABLEREFERENCE_HPP
00032 #define __VARIABLEREFERENCE_HPP
00033
00034 #include "libecs.hpp"
00035 #include "Variable.hpp"
00036
00037 namespace libecs
00038 {
00039
00040
00041
00042
00043
00044
00045
00046
00047 class VariableReference
00048 {
00049
00050 public:
00051
00052 class CoefficientLess
00053 {
00054
00055 public:
00056
00057 CoefficientLess()
00058 {
00059 ;
00060 }
00061
00062 bool operator()( VariableReferenceCref aLhs,
00063 VariableReferenceCref aRhs ) const
00064 {
00065 return compare( aLhs.getCoefficient(), aRhs.getCoefficient() );
00066 }
00067
00068 bool operator()( IntegerParam aLhs,
00069 VariableReferenceCref aRhs ) const
00070 {
00071 return compare( aLhs, aRhs.getCoefficient() );
00072 }
00073
00074 bool operator()( VariableReferenceCref aLhs,
00075 IntegerParam aRhs ) const
00076 {
00077 return compare( aLhs.getCoefficient(), aRhs );
00078 }
00079
00080 private:
00081
00082 static const bool compare( IntegerParam aLhs, IntegerParam aRhs )
00083 {
00084 return std::less<Integer>()( aLhs, aRhs );
00085 }
00086
00087 };
00088
00089 class NameLess
00090 {
00091 public:
00092
00093 NameLess()
00094 {
00095 ;
00096 }
00097
00098 bool operator()( VariableReferenceCref aLhs,
00099 VariableReferenceCref aRhs ) const
00100 {
00101 return compare( aLhs.getName(), aRhs.getName() );
00102 }
00103
00104 bool operator()( StringCref aLhs,
00105 VariableReferenceCref aRhs ) const
00106 {
00107 return compare( aLhs, aRhs.getName() );
00108 }
00109
00110 bool operator()( VariableReferenceCref aLhs,
00111 StringCref aRhs ) const
00112 {
00113 return compare( aLhs.getName(), aRhs );
00114 }
00115
00116
00117 private:
00118
00119 static const bool compare( StringCref aLhs, StringCref aRhs )
00120 {
00121 const bool anIsLhsEllipsis( VariableReference::
00122 isEllipsisNameString( aLhs ) );
00123 const bool anIsRhsEllipsis( VariableReference::
00124 isEllipsisNameString( aRhs ) );
00125
00126
00127 if( anIsLhsEllipsis == anIsLhsEllipsis )
00128 {
00129 return std::less<String>()( aLhs, aRhs );
00130 }
00131 else
00132 {
00133 return anIsRhsEllipsis;
00134 }
00135 }
00136
00137 };
00138
00139
00140
00141 class Less
00142 {
00143 public:
00144
00145 Less()
00146 {
00147 ;
00148 }
00149
00150 bool operator()( VariableReferenceCref aLhs,
00151 VariableReferenceCref aRhs ) const
00152 {
00153 static CoefficientLess aCoefficientLess;
00154 if( aCoefficientLess( aLhs, aRhs ) )
00155 {
00156 return true;
00157 }
00158 else if( aCoefficientLess( aRhs, aLhs ) )
00159 {
00160 return false;
00161 }
00162 else
00163 {
00164 return NameLess()( aLhs, aRhs );
00165 }
00166 }
00167
00168 };
00169
00170
00171 public:
00172
00173 VariableReference()
00174 :
00175 theVariablePtr( NULLPTR ),
00176 theCoefficient( 0 ),
00177 theIsAccessor( true )
00178 {
00179 ;
00180 }
00181
00182 VariableReference( StringCref aName,
00183 VariablePtr aVariablePtr,
00184 IntegerParam aCoefficient,
00185 const bool anIsAccessor = true )
00186 :
00187 theName( aName ),
00188 theVariablePtr( aVariablePtr ),
00189 theCoefficient( aCoefficient ),
00190 theIsAccessor( anIsAccessor )
00191 {
00192 ;
00193 }
00194
00195 ~VariableReference() {}
00196
00197 void setName( StringCref aName )
00198 {
00199 theName = aName;
00200 }
00201
00202
00203
00204 const String getName() const
00205 {
00206 return theName;
00207 }
00208
00209 void setVariable( VariablePtr const aVariablePtr )
00210 {
00211 theVariablePtr = aVariablePtr;
00212 }
00213
00214 const VariablePtr getVariable() const
00215 {
00216 return theVariablePtr;
00217 }
00218
00219 void setCoefficient( IntegerParam aCoefficient )
00220 {
00221 theCoefficient = aCoefficient;
00222 }
00223
00224 const Integer getCoefficient() const
00225 {
00226 return theCoefficient;
00227 }
00228
00229 const bool isMutator() const
00230 {
00231 if( theCoefficient == 0 )
00232 {
00233 return false;
00234 }
00235 else
00236 {
00237 return true;
00238 }
00239 }
00240
00241 void setIsAccessor( const bool anIsAccessor )
00242 {
00243 theIsAccessor = anIsAccessor;
00244 }
00245
00246 const bool isAccessor() const
00247 {
00248 return theIsAccessor;
00249 }
00250
00251 void setValue( RealParam aValue ) const
00252 {
00253 theVariablePtr->setValue( aValue );
00254 }
00255
00256 const Real getValue() const
00257 {
00258 return theVariablePtr->getValue();
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 void addValue( RealParam aValue ) const
00271 {
00272 theVariablePtr->addValue( aValue * theCoefficient );
00273 }
00274
00275 const Real getMolarConc() const
00276 {
00277 return theVariablePtr->getMolarConc();
00278 }
00279
00280 const Real getNumberConc() const
00281 {
00282 return theVariablePtr->getNumberConc();
00283 }
00284
00285 const Real getVelocity() const
00286 {
00287 return theVariablePtr->getVelocity();
00288 }
00289
00290 const bool isFixed() const
00291 {
00292 return theVariablePtr->isFixed();
00293 }
00294
00295 void setFixed( const bool aValue ) const
00296 {
00297 theVariablePtr->setFixed( aValue );
00298 }
00299
00300 SystemPtr getSuperSystem() const
00301 {
00302 return theVariablePtr->getSuperSystem();
00303 }
00304
00305 const bool isEllipsisName() const
00306 {
00307 return isEllipsisNameString( theName );
00308 }
00309
00310 const Integer getEllipsisNumber() const;
00311
00312 const bool isDefaultName() const
00313 {
00314 return isDefaultNameString( theName );
00315 }
00316
00317 bool operator==( VariableReferenceCref rhs ) const
00318 {
00319 if( theName == rhs.theName &&
00320 theVariablePtr == rhs.theVariablePtr &&
00321 theCoefficient == rhs.theCoefficient &&
00322 theIsAccessor == rhs.theIsAccessor )
00323 {
00324 return true;
00325 }
00326 else
00327 {
00328 return false;
00329 }
00330 }
00331
00332
00333 static const bool isEllipsisNameString( StringCref aname );
00334 static const bool isDefaultNameString( StringCref aname );
00335
00336
00337 public:
00338
00339 static const String ELLIPSIS_PREFIX;
00340 static const String DEFAULT_NAME;
00341
00342 private:
00343
00344 String theName;
00345 VariablePtr theVariablePtr;
00346 Integer theCoefficient;
00347 bool theIsAccessor;
00348
00349 };
00350
00351
00352
00353 }
00354
00355
00356 #endif
00357