JUCE: CachedValue< Type > Class Template Reference

JUCE

- Main Page
- Related Pages
- Topics
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | List of all members
CachedValue< Type > Class Template Reference
juce_data_structures » values

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

`#include <juce_CachedValue.h>`

Inheritance diagram for CachedValue< Type >:

## 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.
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.
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.
CachedValue & | operator= (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.
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.
UndoManager * | getUndoManager () noexcept
| Returns the UndoManager that is being used.

## Detailed Description

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

## Member Function Documentation

## ◆ operator Type()

template<typename Type >

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().

## ◆ get()

template<typename Type >

Type CachedValue< 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 & CachedValue< Type >::operator* | ( |  | ) |
| noexcept

Dereference operator.

Provides direct access to the property.

## ◆ operator->()

template<typename Type >

Type * CachedValue< 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 CachedValue< Type >::operator== | ( | const OtherType & | other | ) | const

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

References JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE, and JUCE_END_IGNORE_WARNINGS_GCC_LIKE.

Referenced by CachedValue< Type >::operator!=().

## ◆ operator!=()

template<typename Type >
template<typename OtherType >

bool 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 CachedValue< Type >::operator==().

## ◆ getDefault()

template<typename Type >

Type CachedValue< Type >::getDefault | ( |  | ) | const

Returns the current fallback default value.

## ◆ setDefault()

template<typename Type >

void CachedValue< Type >::setDefault | ( | const Type & | value | ) |

Resets the fallback default value.

## ◆ getValueTree()

template<typename Type >

ValueTree & CachedValue< Type >::getValueTree | ( |  | ) |
| noexcept

Returns a reference to the ValueTree containing the referenced property.

## ◆ getPropertyID()

template<typename Type >

const Identifier & CachedValue< Type >::getPropertyID | ( |  | ) | const
| noexcept

Returns the property ID of the referenced property.

## ◆ getUndoManager()

template<typename Type >

UndoManager * CachedValue< Type >::getUndoManager | ( |  | ) |
| noexcept

Returns the UndoManager that is being used.

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

- juce_CachedValue.h