57template <
typename Type>
100 operator Type()
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;
210template <
typename Type>
213template <
typename Type>
215 : targetTree (v), targetProperty (i), undoManager (
um),
216 defaultValue(), cachedValue (getTypedValue())
221template <
typename Type>
223 : targetTree (v), targetProperty (i), undoManager (
um),
224 defaultValue (
defaultToUse), cachedValue (getTypedValue())
229template <
typename Type>
232 return targetTree.getPropertyAsValue (targetProperty, undoManager);
235template <
typename Type>
238 return ! targetTree.hasProperty (targetProperty);
241template <
typename Type>
244 setValue (newValue, undoManager);
248template <
typename Type>
251 if (!
exactlyEqual (cachedValue, newValue) || isUsingDefault())
253 cachedValue = newValue;
258template <
typename Type>
261 resetToDefault (undoManager);
264template <
typename Type>
268 forceUpdateOfCachedValue();
271template <
typename Type>
274 referToWithDefault (v, i,
um, Type());
277template <
typename Type>
283template <
typename Type>
286 cachedValue = getTypedValue();
289template <
typename Type>
292 targetTree.removeListener (
this);
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>
314 forceUpdateOfCachedValue();
This class acts as a typed wrapper around a property inside a ValueTree.
bool isUsingDefault() const
Returns true if the current property does not exist and the CachedValue is using the fallback default...
Type getDefault() const
Returns the current fallback default value.
CachedValue()
Default constructor.
ValueTree & getValueTree() noexcept
Returns a reference to the ValueTree containing the referenced property.
const Identifier & getPropertyID() const noexcept
Returns the property ID of the referenced property.
CachedValue & operator=(const Type &newValue)
Sets the property.
void forceUpdateOfCachedValue()
Force an update in case the referenced property has been changed from elsewhere.
const Type & operator*() const noexcept
Dereference operator.
const Type * operator->() const noexcept
Dereference operator.
void setValue(const Type &newValue, UndoManager *undoManagerToUse)
Sets the property.
UndoManager * getUndoManager() noexcept
Returns the UndoManager that is being used.
void resetToDefault()
Removes the property from the referenced ValueTree and makes the CachedValue return the fallback defa...
void referTo(ValueTree &tree, const Identifier &property, UndoManager *um)
Makes the CachedValue refer to the specified property inside the given ValueTree.
Value getPropertyAsValue()
Returns the current property as a Value object.
bool operator==(const OtherType &other) const
Returns true if the current value of the property (or the fallback value) is equal to other.
void setDefault(const Type &value)
Resets the fallback default value.
bool operator!=(const OtherType &other) const
Returns true if the current value of the property (or the fallback value) is not equal to other.
Type get() const noexcept
Returns the current value of the property.
Represents a string identifier, designed for accessing properties by name.
Manages a list of undo/redo commands.
Listener class for events that happen to a ValueTree.
A powerful tree structure that can be used to hold free-form data, and which can handle its own undo ...
void addListener(Listener *listener)
Adds a listener to receive callbacks when this tree is changed in some way.
Represents a shared variant value.
#define JUCE_DECLARE_WEAK_REFERENCEABLE(Class)
Macro to easily allow a class to be made weak-referenceable.
constexpr bool exactlyEqual(Type a, Type b)
Equivalent to operator==, but suppresses float-equality warnings.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
This template-overloaded class can be used to convert between var and custom types.