JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Public Member Functions | List of all members
juce::CachedValue< Type > Class Template Reference

This class acts as a typed wrapper around a property inside a ValueTree. More...

#include "juce_CachedValue.h"

Inheritance diagram for juce::CachedValue< Type >:
juce::ValueTree::Listener

Public Member Functions

 CachedValue ()
 Default constructor.
 
 CachedValue (ValueTree &tree, const Identifier &propertyID, UndoManager *undoManager)
 Constructor.
 
 CachedValue (ValueTree &tree, const Identifier &propertyID, UndoManager *undoManager, const Type &defaultToUse)
 Constructor.
 
 operator Type () const noexcept
 Returns the current value of the property.
 
Type get () const noexcept
 Returns the current value of the property.
 
const Type & operator* () const noexcept
 Dereference operator.
 
const Type * operator-> () const noexcept
 Dereference operator.
 
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.
 
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.
 
Value getPropertyAsValue ()
 Returns the current property as a Value object.
 
bool isUsingDefault () const
 Returns true if the current property does not exist and the CachedValue is using the fallback default value instead.
 
Type getDefault () const
 Returns the current fallback default value.
 
CachedValueoperator= (const Type &newValue)
 Sets the property.
 
void setValue (const Type &newValue, UndoManager *undoManagerToUse)
 Sets the property.
 
void resetToDefault ()
 Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead.
 
void resetToDefault (UndoManager *undoManagerToUse)
 Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead.
 
void setDefault (const Type &value)
 Resets the fallback default value.
 
void referTo (ValueTree &tree, const Identifier &property, UndoManager *um)
 Makes the CachedValue refer to the specified property inside the given ValueTree.
 
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.
 
void forceUpdateOfCachedValue ()
 Force an update in case the referenced property has been changed from elsewhere.
 
ValueTreegetValueTree () noexcept
 Returns a reference to the ValueTree containing the referenced property.
 
const IdentifiergetPropertyID () const noexcept
 Returns the property ID of the referenced property.
 
UndoManagergetUndoManager () noexcept
 Returns the UndoManager that is being used.
 

Detailed Description

template<typename Type>
class juce::CachedValue< Type >

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.

@tags{DataStructures}

Definition at line 58 of file juce_CachedValue.h.

Constructor & Destructor Documentation

◆ CachedValue() [1/3]

template<typename Type >
juce::CachedValue< Type >::CachedValue ( )
default

Default constructor.

Creates a default CachedValue not referring to any property. To initialise the object, call one of the referTo() methods.

◆ CachedValue() [2/3]

template<typename Type >
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.

Parameters
treeThe ValueTree containing the property
propertyIDThe identifier of the property
undoManagerThe UndoManager to use when writing to the property

Definition at line 214 of file juce_CachedValue.h.

◆ CachedValue() [3/3]

template<typename Type >
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.

Parameters
treeThe ValueTree containing the property
propertyIDThe identifier of the property
undoManagerThe UndoManager to use when writing to the property
defaultToUseThe fallback default value to use.

Definition at line 222 of file juce_CachedValue.h.

Member Function Documentation

◆ forceUpdateOfCachedValue()

template<typename Type >
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.

Definition at line 284 of file juce_CachedValue.h.

◆ get()

template<typename Type >
Type juce::CachedValue< Type >::get ( ) const
noexcept

Returns the current value of the property.

If the property does not exist, returns the fallback default value.

Definition at line 105 of file juce_CachedValue.h.

◆ getDefault()

template<typename Type >
Type juce::CachedValue< Type >::getDefault ( ) const

Returns the current fallback default value.

Definition at line 140 of file juce_CachedValue.h.

◆ getPropertyAsValue()

template<typename Type >
Value juce::CachedValue< Type >::getPropertyAsValue ( )

Returns the current property as a Value object.

Definition at line 230 of file juce_CachedValue.h.

◆ getPropertyID()

template<typename Type >
const Identifier & juce::CachedValue< Type >::getPropertyID ( ) const
noexcept

Returns the property ID of the referenced property.

Definition at line 184 of file juce_CachedValue.h.

◆ getUndoManager()

template<typename Type >
UndoManager * juce::CachedValue< Type >::getUndoManager ( )
noexcept

Returns the UndoManager that is being used.

Definition at line 187 of file juce_CachedValue.h.

◆ getValueTree()

template<typename Type >
ValueTree & juce::CachedValue< Type >::getValueTree ( )
noexcept

Returns a reference to the ValueTree containing the referenced property.

Definition at line 181 of file juce_CachedValue.h.

◆ isUsingDefault()

template<typename Type >
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.

Definition at line 236 of file juce_CachedValue.h.

◆ operator Type()

template<typename Type >
juce::CachedValue< Type >::operator Type ( ) const
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().

Definition at line 100 of file juce_CachedValue.h.

◆ operator!=()

template<typename Type >
template<typename OtherType >
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.

Definition at line 128 of file juce_CachedValue.h.

◆ operator*()

template<typename Type >
const Type & juce::CachedValue< Type >::operator* ( ) const
noexcept

Dereference operator.

Provides direct access to the property.

Definition at line 108 of file juce_CachedValue.h.

◆ operator->()

template<typename Type >
const Type * juce::CachedValue< Type >::operator-> ( ) const
noexcept

Dereference operator.

Provides direct access to members of the property if it is of object type.

Definition at line 113 of file juce_CachedValue.h.

◆ operator=()

template<typename Type >
CachedValue< Type > & juce::CachedValue< Type >::operator= ( const Type &  newValue)

Sets the property.

This will actually modify the property in the referenced ValueTree.

Definition at line 242 of file juce_CachedValue.h.

◆ operator==()

template<typename Type >
template<typename OtherType >
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.

Definition at line 119 of file juce_CachedValue.h.

◆ referTo() [1/2]

template<typename Type >
void juce::CachedValue< Type >::referTo ( ValueTree tree,
const Identifier property,
UndoManager um 
)

Makes the CachedValue refer to the specified property inside the given ValueTree.

Definition at line 272 of file juce_CachedValue.h.

◆ referTo() [2/2]

template<typename Type >
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.

Definition at line 278 of file juce_CachedValue.h.

◆ resetToDefault() [1/2]

template<typename Type >
void juce::CachedValue< Type >::resetToDefault ( )

Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead.

Definition at line 259 of file juce_CachedValue.h.

◆ resetToDefault() [2/2]

template<typename Type >
void juce::CachedValue< Type >::resetToDefault ( UndoManager undoManagerToUse)

Removes the property from the referenced ValueTree and makes the CachedValue return the fallback default value instead.

Definition at line 265 of file juce_CachedValue.h.

◆ setDefault()

template<typename Type >
void juce::CachedValue< Type >::setDefault ( const Type &  value)

Resets the fallback default value.

Definition at line 160 of file juce_CachedValue.h.

◆ setValue()

template<typename Type >
void juce::CachedValue< Type >::setValue ( const Type &  newValue,
UndoManager undoManagerToUse 
)

Sets the property.

This will actually modify the property in the referenced ValueTree.

Definition at line 249 of file juce_CachedValue.h.


The documentation for this class was generated from the following file: