Scroom  0.14
Freezable< T > Class Template Reference

#include <view.hh>

Collaboration diagram for Freezable< T >:
Collaboration graph

Public Types

using value_type = T
 
using Me = Freezable< T >
 

Public Member Functions

 Freezable ()=default
 
 Freezable (value_type v)
 
const value_typeget () const
 
bool set (value_type v)
 
void lock ()
 
void unlock ()
 
bool is_locked () const
 
 operator const value_type & () const
 
Meoperator= (value_type v)
 
const value_typeoperator* () const
 
const value_typeoperator-> () const
 
Meoperator+= (value_type v)
 
Meoperator-= (value_type v)
 

Private Attributes

value_type value
 
unsigned locked {0}
 

Detailed Description

template<typename T>
class Freezable< T >

Protect a value from being assigned.

When the presentation position changes, scroll-bars and textboxes need updating, which in turn generate their own value-changed events, sometimes with different values. It is a mess.

By locking the current position, we keep those events from changing (and thereby corrupting) the updated value.

Member Typedef Documentation

◆ Me

template<typename T >
using Freezable< T >::Me = Freezable<T>

◆ value_type

template<typename T >
using Freezable< T >::value_type = T

Constructor & Destructor Documentation

◆ Freezable() [1/2]

template<typename T >
Freezable< T >::Freezable ( )
default

◆ Freezable() [2/2]

template<typename T >
Freezable< T >::Freezable ( value_type  v)
inlineexplicit
55  : value(std::move(v))
56  {
57  }

Member Function Documentation

◆ get()

template<typename T >
const value_type& Freezable< T >::get ( ) const
inline
59 { return value; }

Referenced by View::on_scrollbar_value_changed(), and View::updateXY().

Here is the caller graph for this function:

◆ is_locked()

template<typename T >
bool Freezable< T >::is_locked ( ) const
inline
77 { return locked; }

◆ lock()

template<typename T >
void Freezable< T >::lock ( )
inline
70 { locked++; }

◆ operator const value_type &()

template<typename T >
Freezable< T >::operator const value_type & ( ) const
inline
79 { return value; } // NOLINT(hicpp-explicit-conversions)

◆ operator*()

template<typename T >
const value_type* Freezable< T >::operator* ( ) const
inline
85 { return &value; }

◆ operator+=()

template<typename T >
Me& Freezable< T >::operator+= ( value_type  v)
inline
87 { return operator=(value + v); }

◆ operator-=()

template<typename T >
Me& Freezable< T >::operator-= ( value_type  v)
inline
88 { return operator=(value - v); }

◆ operator->()

template<typename T >
const value_type* Freezable< T >::operator-> ( ) const
inline
86 { return &value; }

◆ operator=()

template<typename T >
Me& Freezable< T >::operator= ( value_type  v)
inline
81  {
82  set(std::move(v));
83  return *this;
84  }

Referenced by Freezable< Scroom::Utils::Point< double > >::operator+=(), and Freezable< Scroom::Utils::Point< double > >::operator-=().

Here is the caller graph for this function:

◆ set()

template<typename T >
bool Freezable< T >::set ( value_type  v)
inline
62  {
63  if(!locked)
64  {
65  value = std::move(v);
66  }
67  return locked;
68  }

Referenced by Freezable< Scroom::Utils::Point< double > >::operator=().

Here is the caller graph for this function:

◆ unlock()

template<typename T >
void Freezable< T >::unlock ( )
inline
73  {
74  require(locked > 0);
75  locked--;
76  }

Member Data Documentation

◆ locked

◆ value


The documentation for this class was generated from the following file:
require
#define require(expr)
Definition: assertions.hh:28
Freezable::value
value_type value
Definition: view.hh:91
Freezable::locked
unsigned locked
Definition: view.hh:92
Freezable::operator=
Me & operator=(value_type v)
Definition: view.hh:80
Freezable::set
bool set(value_type v)
Definition: view.hh:61