58template <
typename Type>
93 UndoManager* undoManager,
const Type& defaultToUse);
101 operator Type() const noexcept {
return cachedValue; }
106 Type
get() const noexcept {
return cachedValue; }
119 template <
typename OtherType>
120 bool operator== (
const OtherType& other)
const {
return cachedValue == other; }
125 template <
typename OtherType>
126 bool operator!= (
const OtherType& other)
const {
return cachedValue != other; }
158 void setDefault (
const Type& value) { defaultValue = value; }
197 Type getTypedValue()
const;
199 void valueTreePropertyChanged (
ValueTree& changedTree,
const Identifier& changedProperty)
override;
208template <
typename Type>
211template <
typename Type>
213 : targetTree (v), targetProperty (i), undoManager (um),
214 defaultValue(), cachedValue (getTypedValue())
219template <
typename Type>
221 : targetTree (v), targetProperty (i), undoManager (um),
222 defaultValue (defaultToUse), cachedValue (getTypedValue())
227template <
typename Type>
230 return targetTree.getPropertyAsValue (targetProperty, undoManager);
233template <
typename Type>
236 return ! targetTree.hasProperty (targetProperty);
239template <
typename Type>
242 setValue (newValue, undoManager);
246template <
typename Type>
249 if (cachedValue != newValue || isUsingDefault())
251 cachedValue = newValue;
256template <
typename Type>
259 resetToDefault (undoManager);
262template <
typename Type>
265 targetTree.removeProperty (targetProperty, undoManagerToUse);
266 forceUpdateOfCachedValue();
269template <
typename Type>
272 referToWithDefault (v, i, um, Type());
275template <
typename Type>
278 referToWithDefault (v, i, um, defaultVal);
281template <
typename Type>
284 cachedValue = getTypedValue();
287template <
typename Type>
290 targetTree.removeListener (
this);
294 defaultValue = defaultVal;
295 cachedValue = getTypedValue();
296 targetTree.addListener (
this);
299template <
typename Type>
300inline Type CachedValue<Type>::getTypedValue()
const
302 if (
const var* property = targetTree.getPropertyPointer (targetProperty))
303 return VariantConverter<Type>::fromVar (*property);
308template <
typename Type>
309inline void CachedValue<Type>::valueTreePropertyChanged (ValueTree& changedTree,
const Identifier& changedProperty)
311 if (changedProperty == targetProperty && targetTree == changedTree)
312 forceUpdateOfCachedValue();
bool isUsingDefault() const
Type * operator->() noexcept
ValueTree & getValueTree() noexcept
const Identifier & getPropertyID() const noexcept
CachedValue & operator=(const Type &newValue)
void forceUpdateOfCachedValue()
void setValue(const Type &newValue, UndoManager *undoManagerToUse)
UndoManager * getUndoManager() noexcept
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
Type & operator*() noexcept
void addListener(Listener *listener)