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