22#ifndef WXMAXIMA_CACHEDVALUE_H
23#define WXMAXIMA_CACHEDVALUE_H
43template <typename T, typename std::enable_if<std::is_integral<T>::value,
bool>::type =
true>
46 static constexpr T invalid = std::numeric_limits<T>::max();
47 mutable T m_value = invalid;
53 const CachedInteger &operator=(T newValue)
const { SetCached(newValue);
return *
this; }
54 const CachedInteger &operator+=(T delta)
const { SetCached(Get() + delta);
return *
this; }
55 const CachedInteger &operator-=(T delta)
const { SetCached(Get() - delta);
return *
this; }
56 constexpr bool IsValid()
const {
return m_value != invalid; }
57 constexpr bool IsInvalid()
const {
return m_value == invalid; }
58 constexpr void Invalidate()
const { m_value = invalid; }
59 operator T()
const {
return GetOrElse(T{}); }
62 wxASSERT_MSG(m_value != invalid,
"Attempted to use an invalid cached value");
63 return (m_value != invalid) ? m_value : T{};
65 T GetOrElse(T defaultValue)
const
67 return (m_value != invalid) ? m_value : defaultValue;
69 void SetCached(T newValue)
const
71 wxASSERT_MSG(newValue != invalid,
"Attempted to set an out-of-range cached value.");
A cached integer value.
Definition: CachedValue.h:45