JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::ScopedValueSetter< ValueType > Class Template Reference

Helper class providing an RAII-based mechanism for temporarily setting and then re-setting a value. More...

#include <juce_ScopedValueSetter.h>

Collaboration diagram for juce::ScopedValueSetter< ValueType >:

Public Member Functions

 ScopedValueSetter (ValueType &valueToSet, ValueType newValue)
 Creates a ScopedValueSetter that will immediately change the specified value to the given new value, and will then reset it to its original value when this object is deleted. More...
 
 ScopedValueSetter (ValueType &valueToSet, ValueType newValue, ValueType valueWhenDeleted)
 Creates a ScopedValueSetter that will immediately change the specified value to the given new value, and will then reset it to be valueWhenDeleted when this object is deleted. More...
 
 ~ScopedValueSetter ()
 

Private Attributes

const ValueType originalValue
 
ValueType & value
 

Detailed Description

template<typename ValueType>
class juce::ScopedValueSetter< ValueType >

Helper class providing an RAII-based mechanism for temporarily setting and then re-setting a value.

E.g.

int x = 1;
{
ScopedValueSetter setter (x, 2);
// x is now 2
}
// x is now 1 again
{
ScopedValueSetter setter (x, 3, 4);
// x is now 3
}
// x is now 4

@tags{Core}

Constructor & Destructor Documentation

◆ ScopedValueSetter() [1/2]

template<typename ValueType >
juce::ScopedValueSetter< ValueType >::ScopedValueSetter ( ValueType &  valueToSet,
ValueType  newValue 
)
inline

Creates a ScopedValueSetter that will immediately change the specified value to the given new value, and will then reset it to its original value when this object is deleted.

◆ ScopedValueSetter() [2/2]

template<typename ValueType >
juce::ScopedValueSetter< ValueType >::ScopedValueSetter ( ValueType &  valueToSet,
ValueType  newValue,
ValueType  valueWhenDeleted 
)
inline

Creates a ScopedValueSetter that will immediately change the specified value to the given new value, and will then reset it to be valueWhenDeleted when this object is deleted.

◆ ~ScopedValueSetter()

Member Data Documentation

◆ originalValue

template<typename ValueType >
const ValueType juce::ScopedValueSetter< ValueType >::originalValue
private

◆ value

template<typename ValueType >
ValueType& juce::ScopedValueSetter< ValueType >::value
private

The documentation for this class was generated from the following file:
juce::gl::x
GLdouble x
Definition: juce_gl.h:939
juce::ScopedValueSetter::ScopedValueSetter
ScopedValueSetter(ValueType &valueToSet, ValueType newValue)
Creates a ScopedValueSetter that will immediately change the specified value to the given new value,...
Definition: juce_ScopedValueSetter.h:60