TracktionEngine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
engine::ConstrainedCachedValue< Type > Class Template Reference

A CachedValue that can take a std::function to constrain its value. More...

#include <tracktion_ConstrainedCachedValue.h>

Inherits juce::ValueTree::Listener.

Public Member Functions

 ConstrainedCachedValue ()
 Default constructor.
 
 ConstrainedCachedValue (juce::ValueTree &tree, const juce::Identifier &propertyID, juce::UndoManager *undoManager)
 Constructor.
 
 ConstrainedCachedValue (juce::ValueTree &tree, const juce::Identifier &propertyID, juce::UndoManager *undoManager, const Type &defaultToUse)
 Constructor.
 
void setConstrainer (std::function< Type(Type)> constrainerToUse)
 Sets a std::function to use to constain the value.
 
 operator Type () const noexcept
 Returns the current value of the property.
 
Type get () const noexcept
 Returns the current value of the property.
 
Type & operator* () noexcept
 Dereference operator.
 
Type * operator-> () 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.
 
juce::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.
 
ConstrainedCachedValueoperator= (const Type &newValue)
 Sets the property.
 
void setValue (const Type &newValue, juce::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 (juce::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 (juce::ValueTree &tree, const juce::Identifier &property, juce::UndoManager *)
 Makes the CachedValue refer to the specified property inside the given ValueTree.
 
void referTo (juce::ValueTree &tree, const juce::Identifier &property, juce::UndoManager *, 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.
 
juce::ValueTree & getValueTree () noexcept
 Returns a reference to the ValueTree containing the referenced property.
 
const juce::Identifier & getPropertyID () const noexcept
 Returns the property ID of the referenced property.
 

Detailed Description

template<typename Type>
class engine::ConstrainedCachedValue< Type >

A CachedValue that can take a std::function to constrain its value.

Constructor & Destructor Documentation

◆ ConstrainedCachedValue() [1/3]

template<typename Type >
engine::ConstrainedCachedValue< Type >::ConstrainedCachedValue ( )

Default constructor.

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

◆ ConstrainedCachedValue() [2/3]

template<typename Type >
engine::ConstrainedCachedValue< Type >::ConstrainedCachedValue ( juce::ValueTree &  tree,
const juce::Identifier &  propertyID,
juce::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

◆ ConstrainedCachedValue() [3/3]

template<typename Type >
engine::ConstrainedCachedValue< Type >::ConstrainedCachedValue ( juce::ValueTree &  tree,
const juce::Identifier &  propertyID,
juce::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.

Member Function Documentation

◆ setConstrainer()

template<typename Type >
void engine::ConstrainedCachedValue< Type >::setConstrainer ( std::function< Type(Type)>  constrainerToUse)

Sets a std::function to use to constain the value.

You must call this before setting any of the values.

◆ operator Type()

template<typename Type >
engine::ConstrainedCachedValue< 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().

◆ get()

template<typename Type >
Type engine::ConstrainedCachedValue< Type >::get ( ) const
noexcept

Returns the current value of the property.

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

◆ operator*()

template<typename Type >
Type & engine::ConstrainedCachedValue< Type >::operator* ( )
noexcept

Dereference operator.

Provides direct access to the property.

◆ operator->()

template<typename Type >
Type * engine::ConstrainedCachedValue< Type >::operator-> ( )
noexcept

Dereference operator.

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

◆ operator==()

template<typename Type >
template<typename OtherType >
bool engine::ConstrainedCachedValue< Type >::operator== ( const OtherType &  other) const

Returns true if the current value of the property (or the fallback value) is equal to other.

◆ operator!=()

template<typename Type >
template<typename OtherType >
bool engine::ConstrainedCachedValue< Type >::operator!= ( const OtherType &  other) const

Returns true if the current value of the property (or the fallback value) is not equal to other.

◆ getPropertyAsValue()

template<typename Type >
juce::Value engine::ConstrainedCachedValue< Type >::getPropertyAsValue ( )

Returns the current property as a Value object.

◆ isUsingDefault()

template<typename Type >
bool engine::ConstrainedCachedValue< Type >::isUsingDefault ( ) const

Returns true if the current property does not exist and the CachedValue is using the fallback default value instead.

◆ getDefault()

template<typename Type >
Type engine::ConstrainedCachedValue< Type >::getDefault ( ) const

Returns the current fallback default value.

◆ operator=()

template<typename Type >
ConstrainedCachedValue< Type > & engine::ConstrainedCachedValue< Type >::operator= ( const Type &  newValue)

Sets the property.

This will actually modify the property in the referenced ValueTree.

◆ setValue()

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

Sets the property.

This will actually modify the property in the referenced ValueTree.

◆ resetToDefault() [1/2]

template<typename Type >
void engine::ConstrainedCachedValue< Type >::resetToDefault ( )

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

◆ resetToDefault() [2/2]

template<typename Type >
void engine::ConstrainedCachedValue< Type >::resetToDefault ( juce::UndoManager *  undoManagerToUse)

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

◆ setDefault()

template<typename Type >
void engine::ConstrainedCachedValue< Type >::setDefault ( const Type &  value)

Resets the fallback default value.

References engine::value.

◆ referTo() [1/2]

template<typename Type >
void engine::ConstrainedCachedValue< Type >::referTo ( juce::ValueTree &  tree,
const juce::Identifier &  property,
juce::UndoManager *  um 
)

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

◆ referTo() [2/2]

template<typename Type >
void engine::ConstrainedCachedValue< Type >::referTo ( juce::ValueTree &  tree,
const juce::Identifier &  property,
juce::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.

◆ forceUpdateOfCachedValue()

template<typename Type >
void engine::ConstrainedCachedValue< 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.

◆ getValueTree()

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

Returns a reference to the ValueTree containing the referenced property.

◆ getPropertyID()

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

Returns the property ID of the referenced property.


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