57template <
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;
210template <
typename Type>
213template <
typename Type>
215 : targetTree (v), targetProperty (i), undoManager (um),
216 defaultValue(), cachedValue (getTypedValue())
218 targetTree.addListener (
this);
221template <
typename Type>
223 : targetTree (v), targetProperty (i), undoManager (um),
224 defaultValue (defaultToUse), cachedValue (getTypedValue())
226 targetTree.addListener (
this);
229template <
typename Type>
232 return targetTree.getPropertyAsValue (targetProperty, undoManager);
235template <
typename Type>
238 return ! targetTree.hasProperty (targetProperty);
241template <
typename Type>
248template <
typename Type>
253 cachedValue = newValue;
254 targetTree.setProperty (targetProperty, VariantConverter<Type>::toVar (newValue), undoManagerToUse);
258template <
typename Type>
264template <
typename Type>
267 targetTree.removeProperty (targetProperty, undoManagerToUse);
271template <
typename Type>
274 referToWithDefault (v, i, um, Type());
277template <
typename Type>
280 referToWithDefault (v, i, um, defaultVal);
283template <
typename Type>
286 cachedValue = getTypedValue();
289template <
typename Type>
292 targetTree.removeListener (
this);
296 defaultValue = defaultVal;
297 cachedValue = getTypedValue();
298 targetTree.addListener (
this);
301template <
typename Type>
302inline Type CachedValue<Type>::getTypedValue()
const
304 if (
const var* property = targetTree.getPropertyPointer (targetProperty))
305 return VariantConverter<Type>::fromVar (*property);
310template <
typename Type>
311inline void CachedValue<Type>::valueTreePropertyChanged (
ValueTree& changedTree,
const Identifier& changedProperty)
313 if (changedProperty == targetProperty && targetTree == changedTree)
314 forceUpdateOfCachedValue();
bool isUsingDefault() const
ValueTree & getValueTree() noexcept
const Identifier & getPropertyID() const noexcept
CachedValue & operator=(const Type &newValue)
void forceUpdateOfCachedValue()
const Type & operator*() const noexcept
const Type * operator->() const noexcept
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