62 template <
typename Type>
97 UndoManager* undoManager,
const Type& defaultToUse);
105 operator Type() const noexcept {
return cachedValue; }
110 Type
get() const noexcept {
return cachedValue; }
123 template <
typename OtherType>
124 bool operator== (
const OtherType& other)
const {
return cachedValue == other; }
129 template <
typename OtherType>
130 bool operator!= (
const OtherType& other)
const {
return cachedValue != other; }
162 void setDefault (
const Type& value) { defaultValue = value; }
201 Type getTypedValue()
const;
203 void valueTreePropertyChanged (
ValueTree& changedTree,
const Identifier& changedProperty)
override;
205 void valueTreeChildRemoved (ValueTree&, ValueTree&,
int)
override {}
206 void valueTreeChildOrderChanged (ValueTree&,
int,
int)
override {}
207 void valueTreeParentChanged (ValueTree&)
override {}
216 template <
typename Type>
219 template <
typename Type>
221 : targetTree (v), targetProperty (i), undoManager (um),
222 defaultValue(), cachedValue (getTypedValue())
227 template <
typename Type>
229 : targetTree (v), targetProperty (i), undoManager (um),
230 defaultValue (defaultToUse), cachedValue (getTypedValue())
235 template <
typename Type>
238 return targetTree.getPropertyAsValue (targetProperty, undoManager);
241 template <
typename Type>
244 return ! targetTree.hasProperty (targetProperty);
247 template <
typename Type>
250 setValue (newValue, undoManager);
254 template <
typename Type>
257 if (cachedValue != newValue || isUsingDefault())
259 cachedValue = newValue;
264 template <
typename Type>
267 resetToDefault (undoManager);
270 template <
typename Type>
273 targetTree.removeProperty (targetProperty, undoManagerToUse);
274 forceUpdateOfCachedValue();
277 template <
typename Type>
280 referToWithDefault (v, i, um, Type());
283 template <
typename Type>
286 referToWithDefault (v, i, um, defaultVal);
289 template <
typename Type>
292 cachedValue = getTypedValue();
295 template <
typename Type>
298 targetTree.removeListener (
this);
302 defaultValue = defaultVal;
303 cachedValue = getTypedValue();
304 targetTree.addListener (
this);
307 template <
typename Type>
308 inline Type CachedValue<Type>::getTypedValue()
const
310 if (
const var* property = targetTree.getPropertyPointer (targetProperty))
311 return VariantConverter<Type>::fromVar (*property);
316 template <
typename Type>
317 inline void CachedValue<Type>::valueTreePropertyChanged (ValueTree& changedTree,
const Identifier& changedProperty)
319 if (changedProperty == targetProperty && targetTree == changedTree)
320 forceUpdateOfCachedValue();