57 template <
typename Type>
92 UndoManager* undoManager,
const Type& defaultToUse);
100 operator Type() const noexcept {
return cachedValue; }
105 Type
get() const noexcept {
return cachedValue; }
108 const Type&
operator*() const noexcept {
return cachedValue; }
113 const Type*
operator->() const noexcept {
return &cachedValue; }
118 template <
typename OtherType>
121 return cachedValue == other;
127 template <
typename OtherType>
160 void setDefault (
const Type& value) { defaultValue = value; }
199 Type getTypedValue()
const;
201 void valueTreePropertyChanged (
ValueTree& changedTree,
const Identifier& changedProperty)
override;
210 template <
typename Type>
213 template <
typename Type>
215 : targetTree (v), targetProperty (i), undoManager (um),
216 defaultValue(), cachedValue (getTypedValue())
221 template <
typename Type>
223 : targetTree (v), targetProperty (i), undoManager (um),
224 defaultValue (defaultToUse), cachedValue (getTypedValue())
229 template <
typename Type>
232 return targetTree.getPropertyAsValue (targetProperty, undoManager);
235 template <
typename Type>
238 return ! targetTree.hasProperty (targetProperty);
241 template <
typename Type>
244 setValue (newValue, undoManager);
248 template <
typename Type>
251 if (! exactlyEqual (cachedValue, newValue) || isUsingDefault())
253 cachedValue = newValue;
258 template <
typename Type>
261 resetToDefault (undoManager);
264 template <
typename Type>
267 targetTree.removeProperty (targetProperty, undoManagerToUse);
268 forceUpdateOfCachedValue();
271 template <
typename Type>
274 referToWithDefault (v, i, um, Type());
277 template <
typename Type>
280 referToWithDefault (v, i, um, defaultVal);
283 template <
typename Type>
286 cachedValue = getTypedValue();
289 template <
typename Type>
292 targetTree.removeListener (
this);
296 defaultValue = defaultVal;
297 cachedValue = getTypedValue();
298 targetTree.addListener (
this);
301 template <
typename Type>
302 inline Type CachedValue<Type>::getTypedValue()
const
304 if (
const var* property = targetTree.getPropertyPointer (targetProperty))
305 return VariantConverter<Type>::fromVar (*property);
310 template <
typename Type>
311 inline void CachedValue<Type>::valueTreePropertyChanged (ValueTree& changedTree,
const Identifier& changedProperty)
313 if (changedProperty == targetProperty && targetTree == changedTree)
314 forceUpdateOfCachedValue();
UndoManager * getUndoManager() noexcept
bool isUsingDefault() const
const Type & operator*() const noexcept
CachedValue & operator=(const Type &newValue)
void forceUpdateOfCachedValue()
void setValue(const Type &newValue, UndoManager *undoManagerToUse)
void referTo(ValueTree &tree, const Identifier &property, UndoManager *um)
Value getPropertyAsValue()
bool operator==(const OtherType &other) const
void setDefault(const Type &value)
bool operator!=(const OtherType &other) const
Type get() const noexcept
ValueTree & getValueTree() noexcept
const Type * operator->() const noexcept
const Identifier & getPropertyID() const noexcept
void addListener(Listener *listener)