The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::utils::LockedValue< T > Class Template Reference

Provides a wrapper around a value to ensure that once the value is frozen or locked, it cannot be overwritten again. More...

#include <LockedValue.hpp>

Public Types

typedef T value_type
 Convenient typedef for the value type.
 

Public Member Functions

 LockedValue ()
 This is the LockedValue Default Constructor.
 
 LockedValue (const T &value)
 This is the LockedValue Constructor with initial value as parameter.
 
 LockedValue (const T &value, const bool lock)
 This is the LockedValue Constructor with initial value and lock as parameter.
 
LockedValue< T > & operator= (const LockedValue< T > &)=delete
 Copy-Assignment of a LockedValue to another LockedValue is a deleted function.
 
LockedValue< T > & operator= (const T &value)
 This is the assignment operator of the LockedValue class from a given resource.
 
void setAndLock (const T &value)
 This method assigns a value to LockedValue class and immediately locks it.
 
void lock ()
 Lock the LockedValue instance immediately.
 
bool isLocked () const
 Query if LockedValue instance is locked.
 
const value_typegetValue () const
 Get the value of the underlying resource of the LockedValue.
 
value_typegetValue ()
 get the value of the underlying resource of the lockedvalue.
 
 operator const value_type & () const
 Convert the LockedValue to its underlying resource.
 
 operator value_type & ()
 Convert the LockedValue to its underlying resource.
 
bool operator== (const value_type &value) const
 Overload the compare equal operator for LockedValue class.
 
bool operator!= (const value_type &value) const
 Overload the compare not equal operator for LockedValue class.
 

Detailed Description

template<typename T>
class sparta::utils::LockedValue< T >

Provides a wrapper around a value to ensure that once the value is frozen or locked, it cannot be overwritten again.

std::cout << my_lval.getValue();
my_lval = 16;
my_lval = 32;
std::cout << my_lval.getValue();
my_lval.lock();
my_lval.lock();
EXPECT_THROW(my_lval = 64);
my_lval_2 = 16;
my_lval_2.setAndLock(32);
EXPECT_THROW(my_lval_2 = 2);
my_lval_2.lock();
std::cout << my_lval_2 << "\n";
#define EXPECT_THROW(x)
Determine if the block x correctly throws an exception.
Provides a wrapper around a value to ensure that once the value is frozen or locked,...
void lock()
Lock the LockedValue instance immediately.
void setAndLock(const T &value)
This method assigns a value to LockedValue class and immediately locks it.
const value_type & getValue() const
Get the value of the underlying resource of the LockedValue.

Definition at line 40 of file LockedValue.hpp.

Member Typedef Documentation

◆ value_type

template<typename T >
typedef T sparta::utils::LockedValue< T >::value_type

Convenient typedef for the value type.

Definition at line 43 of file LockedValue.hpp.

Constructor & Destructor Documentation

◆ LockedValue() [1/3]

template<typename T >
sparta::utils::LockedValue< T >::LockedValue ( )
inline

This is the LockedValue Default Constructor.

Definition at line 46 of file LockedValue.hpp.

◆ LockedValue() [2/3]

template<typename T >
sparta::utils::LockedValue< T >::LockedValue ( const T &  value)
inlineexplicit

This is the LockedValue Constructor with initial value as parameter.

Definition at line 49 of file LockedValue.hpp.

◆ LockedValue() [3/3]

template<typename T >
sparta::utils::LockedValue< T >::LockedValue ( const T &  value,
const bool  lock 
)
inline

This is the LockedValue Constructor with initial value and lock as parameter.

Definition at line 52 of file LockedValue.hpp.

Member Function Documentation

◆ getValue() [1/2]

template<typename T >
value_type & sparta::utils::LockedValue< T >::getValue ( )
inline

get the value of the underlying resource of the lockedvalue.

Definition at line 95 of file LockedValue.hpp.

◆ getValue() [2/2]

template<typename T >
const value_type & sparta::utils::LockedValue< T >::getValue ( ) const
inline

Get the value of the underlying resource of the LockedValue.

Definition at line 88 of file LockedValue.hpp.

◆ isLocked()

template<typename T >
bool sparta::utils::LockedValue< T >::isLocked ( ) const
inline

Query if LockedValue instance is locked.

Definition at line 81 of file LockedValue.hpp.

◆ lock()

template<typename T >
void sparta::utils::LockedValue< T >::lock ( )
inline

Lock the LockedValue instance immediately.

Definition at line 76 of file LockedValue.hpp.

◆ operator const value_type &()

template<typename T >
sparta::utils::LockedValue< T >::operator const value_type & ( ) const
inline

Convert the LockedValue to its underlying resource.

Definition at line 102 of file LockedValue.hpp.

◆ operator value_type &()

template<typename T >
sparta::utils::LockedValue< T >::operator value_type & ( )
inline

Convert the LockedValue to its underlying resource.

Definition at line 109 of file LockedValue.hpp.

◆ operator!=()

template<typename T >
bool sparta::utils::LockedValue< T >::operator!= ( const value_type value) const
inline

Overload the compare not equal operator for LockedValue class.

Definition at line 119 of file LockedValue.hpp.

Here is the call graph for this function:

◆ operator=()

template<typename T >
LockedValue< T > & sparta::utils::LockedValue< T >::operator= ( const T &  value)
inline

This is the assignment operator of the LockedValue class from a given resource.

Definition at line 59 of file LockedValue.hpp.

◆ operator==()

template<typename T >
bool sparta::utils::LockedValue< T >::operator== ( const value_type value) const
inline

Overload the compare equal operator for LockedValue class.

Definition at line 114 of file LockedValue.hpp.

◆ setAndLock()

template<typename T >
void sparta::utils::LockedValue< T >::setAndLock ( const T &  value)
inline

This method assigns a value to LockedValue class and immediately locks it.

Definition at line 68 of file LockedValue.hpp.


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