/* Copyright 2016, 2017 Michele "King_DuckZ" Santullo This file is part of MyCurry. MyCurry is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. MyCurry is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MyCurry. If not, see . */ #pragma once #include #include #include namespace curry { template class ScalarConstrainer { public: typename boost::call_traits::const_reference operator() ( typename boost::call_traits::param_type parMin, typename boost::call_traits::param_type parMax, typename boost::call_traits::param_type parValue ) { return boost::algorithm::clamp(parValue, parMin, parMax); } }; template > class ConstrainedValue { using T_param = typename boost::call_traits::param_type; public: ConstrainedValue (T_param parMin, T_param parMax, T_param parValue); virtual ~ConstrainedValue() noexcept = default; void set (T_param parNew); typename boost::call_traits::const_reference get() const; typename boost::call_traits::const_reference get_min() const; typename boost::call_traits::const_reference get_max() const; void change_minmax (T_param parMin, T_param parMax); ConstrainedValue& operator= (T_param parValue); private: T m_min; T m_max; T m_value; }; template ConstrainedValue::ConstrainedValue ( T_param parMin, T_param parMax, T_param parValue ) : m_min(parMin), m_max(parMax), m_value(parValue) { assert(parMin <= parMax); } template void ConstrainedValue::set (T_param parNew) { m_value = Constrainer()(m_min, m_max, parNew); } template typename boost::call_traits::const_reference ConstrainedValue::get() const { return m_value; } template typename boost::call_traits::const_reference ConstrainedValue::get_min() const { return m_min; } template typename boost::call_traits::const_reference ConstrainedValue::get_max() const { return m_max; } template void ConstrainedValue::change_minmax ( T_param parMin, T_param parMax ) { assert(parMin <= parMax); m_min = parMin; m_max = parMax; this->set(m_value); } template ConstrainedValue& ConstrainedValue::operator= (T_param parValue) { this->set(parValue); return *this; } } //namespace curry