JUCE
|
This class acts as a typed wrapper around a property inside a ValueTree. More...
Public Member Functions | |
CachedValue () | |
Default constructor. More... | |
CachedValue (ValueTree &tree, const Identifier &propertyID, UndoManager *undoManager) | |
Constructor. More... | |
CachedValue (ValueTree &tree, const Identifier &propertyID, UndoManager *undoManager, const Type &defaultToUse) | |
Constructor. More... | |
operator Type () const noexcept | |
Returns the current value of the property. More... | |
Type | get () const noexcept |
Returns the current value of the property. More... | |
Type & | operator* () noexcept |
Dereference operator. More... | |
Type * | operator-> () noexcept |
Dereference operator. More... | |
template<typename OtherType > | |
bool | operator== (const OtherType &other) const |
Returns true if the current value of the property (or the fallback value) is equal to other. More... | |
template<typename OtherType > | |
bool | operator!= (const OtherType &other) const |
Returns true if the current value of the property (or the fallback value) is not equal to other. More... | |
Value | getPropertyAsValue () |
Returns the current property as a Value object. More... | |
bool | isUsingDefault () const |
Returns true if the current property does not exist and the CachedValue is using the fallback default value instead. More... | |
Type | getDefault () const |
Returns the current fallback default value. More... | |
CachedValue & | operator= (const Type &newValue) |
Sets the property. More... | |
void | setValue (const Type &newValue, UndoManager *undoManagerToUse) |
Sets the property. More... | |
void | resetToDefault () |
Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead. More... | |
void | resetToDefault (UndoManager *undoManagerToUse) |
Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead. More... | |
void | setDefault (const Type &value) |
Resets the fallback default value. More... | |
void | referTo (ValueTree &tree, const Identifier &property, UndoManager *um) |
Makes the CachedValue refer to the specified property inside the given ValueTree. More... | |
void | referTo (ValueTree &tree, const Identifier &property, UndoManager *um, const Type &defaultVal) |
Makes the CachedValue refer to the specified property inside the given ValueTree, and specifies a fallback value to use if the property does not exist. More... | |
void | forceUpdateOfCachedValue () |
Force an update in case the referenced property has been changed from elsewhere. More... | |
ValueTree & | getValueTree () noexcept |
Returns a reference to the ValueTree containing the referenced property. More... | |
const Identifier & | getPropertyID () const noexcept |
Returns the property ID of the referenced property. More... | |
This class acts as a typed wrapper around a property inside a ValueTree.
A CachedValue provides an easy way to read and write a ValueTree property with a chosen type. So for example a CachedValue<int> allows you to read or write the property as an int, and a CachedValue<String> lets you work with it as a String.
It also allows efficient access to the value, by caching a copy of it in the type that is being used.
You can give the CachedValue an optional UndoManager which it will use when writing to the underlying ValueTree.
If the property inside the ValueTree is missing, the CachedValue will automatically return an optional default value, which can be specified when initialising the CachedValue.
To create one, you can either use the constructor to attach the CachedValue to a ValueTree, or can create an uninitialised CachedValue with its default constructor and then attach it later with the referTo() methods.
Common types like String, int, double which can be easily converted to a var should work out-of-the-box, but if you want to use more complex custom types, you may need to implement some template specialisations of VariantConverter which this class uses to convert between the type and the ValueTree's internal var.
juce::CachedValue< Type >::CachedValue | ( | ) |
Default constructor.
Creates a default CachedValue not referring to any property. To initialise the object, call one of the referTo() methods.
juce::CachedValue< Type >::CachedValue | ( | ValueTree & | tree, |
const Identifier & | propertyID, | ||
UndoManager * | undoManager | ||
) |
Constructor.
Creates a CachedValue referring to a Value property inside a ValueTree. If you use this constructor, the fallback value will be a default-constructed instance of Type.
tree | The ValueTree containing the property |
propertyID | The identifier of the property |
undoManager | The UndoManager to use when writing to the property |
References juce::ValueTree::addListener().
juce::CachedValue< Type >::CachedValue | ( | ValueTree & | tree, |
const Identifier & | propertyID, | ||
UndoManager * | undoManager, | ||
const Type & | defaultToUse | ||
) |
Constructor.
Creates a default Cached Value referring to a Value property inside a ValueTree, and specifies a fallback value to use if the property does not exist.
tree | The ValueTree containing the property |
propertyID | The identifier of the property |
undoManager | The UndoManager to use when writing to the property |
defaultToUse | The fallback default value to use. |
References juce::ValueTree::addListener().
|
noexcept |
Returns the current value of the property.
If the property does not exist, returns the fallback default value.
This is the same as calling get().
|
noexcept |
Returns the current value of the property.
If the property does not exist, returns the fallback default value.
|
noexcept |
Dereference operator.
Provides direct access to the property.
|
noexcept |
Dereference operator.
Provides direct access to members of the property if it is of object type.
bool juce::CachedValue< Type >::operator== | ( | const OtherType & | other | ) | const |
Returns true if the current value of the property (or the fallback value) is equal to other.
bool juce::CachedValue< Type >::operator!= | ( | const OtherType & | other | ) | const |
Returns true if the current value of the property (or the fallback value) is not equal to other.
References juce::CachedValue< Type >::getPropertyAsValue(), and juce::CachedValue< Type >::isUsingDefault().
Value juce::CachedValue< Type >::getPropertyAsValue | ( | ) |
Returns the current property as a Value object.
References juce::ValueTree::getPropertyAsValue().
Referenced by juce::CachedValue< Type >::operator!=().
bool juce::CachedValue< Type >::isUsingDefault | ( | ) | const |
Returns true if the current property does not exist and the CachedValue is using the fallback default value instead.
References juce::ValueTree::hasProperty().
Referenced by juce::CachedValue< Type >::operator!=(), and juce::CachedValue< Type >::setValue().
Type juce::CachedValue< Type >::getDefault | ( | ) | const |
Returns the current fallback default value.
References juce::CachedValue< Type >::operator=(), juce::CachedValue< Type >::resetToDefault(), and juce::CachedValue< Type >::setValue().
CachedValue< Type > & juce::CachedValue< Type >::operator= | ( | const Type & | newValue | ) |
Sets the property.
This will actually modify the property in the referenced ValueTree.
References juce::CachedValue< Type >::setValue().
Referenced by juce::CachedValue< Type >::getDefault().
void juce::CachedValue< Type >::setValue | ( | const Type & | newValue, |
UndoManager * | undoManagerToUse | ||
) |
Sets the property.
This will actually modify the property in the referenced ValueTree.
References juce::CachedValue< Type >::isUsingDefault(), and juce::ValueTree::setProperty().
Referenced by juce::CachedValue< Type >::getDefault(), and juce::CachedValue< Type >::operator=().
void juce::CachedValue< Type >::resetToDefault | ( | ) |
Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead.
Referenced by juce::CachedValue< Type >::getDefault().
void juce::CachedValue< Type >::resetToDefault | ( | UndoManager * | undoManagerToUse | ) |
Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead.
References juce::CachedValue< Type >::forceUpdateOfCachedValue(), and juce::ValueTree::removeProperty().
void juce::CachedValue< Type >::setDefault | ( | const Type & | value | ) |
Resets the fallback default value.
References juce::CachedValue< Type >::forceUpdateOfCachedValue(), and juce::CachedValue< Type >::referTo().
void juce::CachedValue< Type >::referTo | ( | ValueTree & | tree, |
const Identifier & | property, | ||
UndoManager * | um | ||
) |
Makes the CachedValue refer to the specified property inside the given ValueTree.
Referenced by juce::CachedValue< Type >::setDefault().
void juce::CachedValue< Type >::referTo | ( | ValueTree & | tree, |
const Identifier & | property, | ||
UndoManager * | um, | ||
const Type & | defaultVal | ||
) |
Makes the CachedValue refer to the specified property inside the given ValueTree, and specifies a fallback value to use if the property does not exist.
void juce::CachedValue< Type >::forceUpdateOfCachedValue | ( | ) |
Force an update in case the referenced property has been changed from elsewhere.
Note: The CachedValue is a ValueTree::Listener and therefore will be informed of changes of the referenced property anyway (and update itself). But this may happen asynchronously. forceUpdateOfCachedValue() forces an update immediately.
References juce::ValueTree::addListener(), juce::ValueTree::getPropertyPointer(), and juce::ValueTree::removeListener().
Referenced by juce::CachedValue< Type >::resetToDefault(), and juce::CachedValue< Type >::setDefault().
|
noexcept |
Returns a reference to the ValueTree containing the referenced property.
|
noexcept |
Returns the property ID of the referenced property.
References JUCE_DECLARE_NON_COPYABLE.