Ignore:
Timestamp:
Aug 30, 2013, 10:52:22 PM (12 years ago)
Author:
Frederik Heber <heber@…>
Children:
b324a3
Parents:
f1df08
Message:

Cacheable may be used without an active Observable.

  • this allows to use Cacheable pattern as a simple lazy evaluation. If the actual calculation is expensive but the object never changes, this can be very beneficial.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodePatterns/Cacheable.hpp

    rf1df08 r37d941  
    180180    // we sign on with the best(=lowest) priority, so cached values are recalculated before
    181181    // anybody else might ask for updated values
    182     owner->signOn(this,Observable::PriorityLevel(int(-20)));
     182    if (owner != NULL)
     183      owner->signOn(this,Observable::PriorityLevel(int(-20)));
    183184  }
    184185
     
    192193  const T Cacheable<T>::operator*() const{
    193194    // we can only use the cacheable when the owner is not changing at the moment
    194     if(!owner->isBlocked()){
     195    if ((owner == NULL) || (!owner->isBlocked())) {
    195196      return state->getValue();
    196197    }
     
    203204  Cacheable<T>::~Cacheable()
    204205  {
    205     owner->signOff(this);
     206    if (owner != NULL)
     207      owner->signOff(this);
    206208  }
    207209
Note: See TracChangeset for help on using the changeset viewer.