JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::ValueWithDefault Class Reference

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

#include <juce_ValueWithDefault.h>

Collaboration diagram for juce::ValueWithDefault:

Public Member Functions

 ValueWithDefault ()
 Creates an unitialised ValueWithDefault. More...
 
 ValueWithDefault (ValueTree &tree, const Identifier &propertyID, UndoManager *um)
 Creates an ValueWithDefault object. More...
 
 ValueWithDefault (ValueTree &tree, const Identifier &propertyID, UndoManager *um, const var &defaultToUse)
 Creates an ValueWithDefault object. More...
 
 ValueWithDefault (ValueTree &tree, const Identifier &propertyID, UndoManager *um, const var &defaultToUse, StringRef arrayDelimiter)
 Creates an ValueWithDefault object. More...
 
 ValueWithDefault (const ValueWithDefault &other)
 Creates a ValueWithDefault object from another ValueWithDefault object. More...
 
var get () const noexcept
 Returns the current value of the property. More...
 
var getDefault () const
 Returns the current default value. More...
 
Value getPropertyAsValue ()
 Returns the current property as a Value object. More...
 
IdentifiergetPropertyID () noexcept
 Returns the property ID of the referenced property. More...
 
UndoManagergetUndoManager () noexcept
 Returns the UndoManager that is being used. More...
 
ValueTreegetValueTree () noexcept
 Returns a reference to the ValueTree containing the referenced property. More...
 
bool isUsingDefault () const
 Returns true if the property does not exist or is empty. More...
 
ValueWithDefaultoperator= (const var &newValue)
 Sets the property and returns the new ValueWithDefault. More...
 
ValueWithDefaultoperator= (const ValueWithDefault &other)
 
void referTo (ValueTree &tree, const Identifier &property, UndoManager *um)
 Makes the ValueWithDefault refer to the specified property inside the given ValueTree. More...
 
void referTo (ValueTree &tree, const Identifier &property, UndoManager *um, const var &defaultVal)
 Makes the ValueWithDefault refer to the specified property inside the given ValueTree, and specifies a default value to use. More...
 
void referTo (ValueTree &tree, const Identifier &property, UndoManager *um, const var &defaultVal, StringRef arrayDelimiter)
 
void resetToDefault () noexcept
 Removes the property from the referenced ValueTree. More...
 
void setDefault (const var &newDefault)
 Sets the default value to a new var. More...
 
void setValue (const var &newValue, UndoManager *undoManagerToUse)
 Sets the property. More...
 

Public Attributes

std::function< void()> onDefaultChange
 You can assign a lambda to this callback object to have it called when the default value is changed. More...
 

Private Member Functions

Array< vardelimitedStringToVarArray (StringRef input) const noexcept
 
void referToWithDefault (const ValueTree &v, const Identifier &i, UndoManager *um, const var &defaultVal, StringRef del)
 
String varArrayToDelimitedString (const Array< var > &input) const noexcept
 

Private Attributes

var defaultValue
 
String delimiter
 
Identifier targetProperty
 
ValueTree targetTree
 
UndoManagerundoManager = nullptr
 

Detailed Description

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

If the property inside the ValueTree is missing or empty the ValueWithDefault will automatically return a default value, which can be specified when initialising the ValueWithDefault.

{DataStructures}

Constructor & Destructor Documentation

◆ ValueWithDefault() [1/5]

juce::ValueWithDefault::ValueWithDefault ( )
inline

Creates an unitialised ValueWithDefault.

Initialise it using one of the referTo() methods.

◆ ValueWithDefault() [2/5]

juce::ValueWithDefault::ValueWithDefault ( ValueTree tree,
const Identifier propertyID,
UndoManager um 
)
inline

Creates an ValueWithDefault object.

The default value will be an empty var.

◆ ValueWithDefault() [3/5]

juce::ValueWithDefault::ValueWithDefault ( ValueTree tree,
const Identifier propertyID,
UndoManager um,
const var defaultToUse 
)
inline

Creates an ValueWithDefault object.

The default value will be defaultToUse.

◆ ValueWithDefault() [4/5]

juce::ValueWithDefault::ValueWithDefault ( ValueTree tree,
const Identifier propertyID,
UndoManager um,
const var defaultToUse,
StringRef  arrayDelimiter 
)
inline

Creates an ValueWithDefault object.

The default value will be defaultToUse.

Use this constructor if the underlying var object being controlled is an array and it will handle the conversion to/from a delimited String that can be written to XML format.

◆ ValueWithDefault() [5/5]

juce::ValueWithDefault::ValueWithDefault ( const ValueWithDefault other)
inline

Creates a ValueWithDefault object from another ValueWithDefault object.

Member Function Documentation

◆ delimitedStringToVarArray()

Array<var> juce::ValueWithDefault::delimitedStringToVarArray ( StringRef  input) const
inlineprivatenoexcept

◆ get()

var juce::ValueWithDefault::get ( ) const
inlinenoexcept

Returns the current value of the property.

If the property does not exist or is empty, returns the default value.

References defaultValue, delimitedStringToVarArray(), delimiter, juce::String::isNotEmpty(), isUsingDefault(), targetProperty, and targetTree.

◆ getDefault()

var juce::ValueWithDefault::getDefault ( ) const
inline

Returns the current default value.

References defaultValue.

◆ getPropertyAsValue()

Value juce::ValueWithDefault::getPropertyAsValue ( )
inline

Returns the current property as a Value object.

References juce::ValueTree::getPropertyAsValue(), targetProperty, targetTree, and undoManager.

◆ getPropertyID()

Identifier& juce::ValueWithDefault::getPropertyID ( )
inlinenoexcept

Returns the property ID of the referenced property.

References targetProperty.

◆ getUndoManager()

UndoManager* juce::ValueWithDefault::getUndoManager ( )
inlinenoexcept

Returns the UndoManager that is being used.

References undoManager.

◆ getValueTree()

ValueTree& juce::ValueWithDefault::getValueTree ( )
inlinenoexcept

Returns a reference to the ValueTree containing the referenced property.

References targetTree.

◆ isUsingDefault()

bool juce::ValueWithDefault::isUsingDefault ( ) const
inline

Returns true if the property does not exist or is empty.

References juce::ValueTree::getProperty(), juce::ValueTree::hasProperty(), juce::String::isEmpty(), targetProperty, targetTree, and juce::var::toString().

Referenced by get().

◆ operator=() [1/2]

ValueWithDefault& juce::ValueWithDefault::operator= ( const var newValue)
inline

Sets the property and returns the new ValueWithDefault.

This will modify the property in the referenced ValueTree.

References setValue(), and undoManager.

◆ operator=() [2/2]

ValueWithDefault& juce::ValueWithDefault::operator= ( const ValueWithDefault other)
inline

◆ referTo() [1/3]

void juce::ValueWithDefault::referTo ( ValueTree tree,
const Identifier property,
UndoManager um 
)
inline

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

References referToWithDefault().

◆ referTo() [2/3]

void juce::ValueWithDefault::referTo ( ValueTree tree,
const Identifier property,
UndoManager um,
const var defaultVal 
)
inline

Makes the ValueWithDefault refer to the specified property inside the given ValueTree, and specifies a default value to use.

References referToWithDefault().

◆ referTo() [3/3]

void juce::ValueWithDefault::referTo ( ValueTree tree,
const Identifier property,
UndoManager um,
const var defaultVal,
StringRef  arrayDelimiter 
)
inline

References referToWithDefault().

◆ referToWithDefault()

void juce::ValueWithDefault::referToWithDefault ( const ValueTree v,
const Identifier i,
UndoManager um,
const var defaultVal,
StringRef  del 
)
inlineprivate

◆ resetToDefault()

void juce::ValueWithDefault::resetToDefault ( )
inlinenoexcept

Removes the property from the referenced ValueTree.

References juce::ValueTree::removeProperty(), targetProperty, and targetTree.

◆ setDefault()

void juce::ValueWithDefault::setDefault ( const var newDefault)
inline

Sets the default value to a new var.

References defaultValue, and onDefaultChange.

◆ setValue()

void juce::ValueWithDefault::setValue ( const var newValue,
UndoManager undoManagerToUse 
)
inline

Sets the property.

This will actually modify the property in the referenced ValueTree.

References juce::var::getArray(), juce::ValueTree::setProperty(), targetProperty, targetTree, and varArrayToDelimitedString().

Referenced by operator=().

◆ varArrayToDelimitedString()

String juce::ValueWithDefault::varArrayToDelimitedString ( const Array< var > &  input) const
inlineprivatenoexcept

Member Data Documentation

◆ defaultValue

var juce::ValueWithDefault::defaultValue
private

Referenced by get(), getDefault(), operator=(), and setDefault().

◆ delimiter

String juce::ValueWithDefault::delimiter
private

Referenced by get(), and operator=().

◆ onDefaultChange

std::function<void()> juce::ValueWithDefault::onDefaultChange

You can assign a lambda to this callback object to have it called when the default value is changed.

Referenced by setDefault().

◆ targetProperty

Identifier juce::ValueWithDefault::targetProperty
private

◆ targetTree

ValueTree juce::ValueWithDefault::targetTree
private

◆ undoManager

UndoManager* juce::ValueWithDefault::undoManager = nullptr
private

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