Changeset c8d1952
- Timestamp:
- Mar 19, 2010, 4:55:28 PM (15 years ago)
- Children:
- 91379c
- Parents:
- 239987d
- git-author:
- Tillmann Crueger <crueger@…> (03/19/10 16:24:47)
- git-committer:
- Tillmann Crueger <crueger@…> (03/19/10 16:55:28)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/Patterns/Cacheable.hpp
r239987d rc8d1952 25 25 public: 26 26 State(Cacheable *_owner) : 27 owner(_owner),28 busy(false)29 {} 30 virtual T &getValue()=0;27 busy(false), 28 owner(_owner) 29 {} 30 virtual T getValue()=0; 31 31 virtual void invalidate()=0; 32 32 virtual bool isValid()=0; … … 46 46 {} 47 47 48 virtual T &getValue(){48 virtual T getValue(){ 49 49 // set the state to valid 50 50 State::owner->switchState(State::owner->validState); … … 72 72 {} 73 73 74 virtual T &getValue(){74 virtual T getValue(){ 75 75 return content; 76 76 } … … 100 100 {} 101 101 102 virtual T &getValue(){102 virtual T getValue(){ 103 103 ASSERT(0,"Cannot get a value from a Cacheable after it's Observable has died"); 104 104 // we have to return a grossly invalid reference, because no value can be produced anymore … … 128 128 129 129 const bool isValid() const; 130 const T &operator*() const;130 const T operator*() const; 131 131 132 132 // methods implemented for base-class Observer … … 173 173 174 174 template<typename T> 175 const T& Cacheable<T>::operator*() const{ 176 return state->getValue(); 175 const T Cacheable<T>::operator*() const{ 176 // we can only use the cacheable when the owner is not changing at the moment 177 if(!owner->isBlocked()){ 178 return state->getValue(); 179 } 180 else{ 181 return recalcMethod(); 182 } 177 183 } 178 184 … … 215 221 216 222 const bool isValid() const; 217 const T &operator*() const;223 const T operator*() const; 218 224 219 225 // methods implemented for base-class Observer … … 231 237 232 238 template<typename T> 233 const T &Cacheable<T>::operator*() const{239 const T Cacheable<T>::operator*() const{ 234 240 return recalcMethod(); 235 241 }
Note:
See TracChangeset
for help on using the changeset viewer.