159 lines
4.0 KiB
C++
159 lines
4.0 KiB
C++
/*!\file
|
||
* \brief \todo Описание файла.
|
||
*/
|
||
/*
|
||
* ValueImplementation.hpp
|
||
*
|
||
* Created on: 20 мая 2019 г.
|
||
* Author: titov
|
||
*/
|
||
|
||
#ifndef SOURCE_SYSTEMIC_VALUEIMPLEMENTATION_HPP_
|
||
#define SOURCE_SYSTEMIC_VALUEIMPLEMENTATION_HPP_
|
||
|
||
#include "IValue.hpp"
|
||
#include "IValueOverride.hpp"
|
||
|
||
namespace systemic {
|
||
|
||
template<typename BaseType>
|
||
class ValueImplementation : public IValue<BaseType> {
|
||
|
||
volatile const BaseType * const p_value; //!< Указатель на основное значение.
|
||
|
||
public:
|
||
ValueImplementation( const volatile BaseType & base );
|
||
|
||
IValue<BaseType> * getValue();
|
||
IValueOverride<BaseType> * getValueOverride();
|
||
volatile const BaseType * getBase();
|
||
|
||
virtual operator BaseType() const final;
|
||
|
||
~ValueImplementation() = default;
|
||
};
|
||
|
||
template<typename BaseType>
|
||
class ValueOverrideImplementation : public IValue<BaseType>, public IValueOverride<BaseType> {
|
||
|
||
BaseType override_value; //!< Перезаписываемое значение.
|
||
volatile const BaseType * p_value_process; //!< Указатель на текущее значение.
|
||
volatile const BaseType * const p_value; //!< Указатель на основное значение.
|
||
|
||
public:
|
||
ValueOverrideImplementation( const volatile BaseType & base );
|
||
|
||
IValue<BaseType> * getValue();
|
||
IValueOverride<BaseType> * getValueOverride();
|
||
volatile const BaseType * getBase();
|
||
|
||
virtual operator BaseType() const final;
|
||
virtual void setupOverride() final;
|
||
virtual void setOverrideValue( BaseType value ) final;
|
||
virtual BaseType getHiddenValue() const final;
|
||
virtual void resetOverride() final;
|
||
|
||
~ValueOverrideImplementation() = default;
|
||
};
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline typename systemic::IValue<BaseType> * systemic::ValueImplementation<BaseType>::getValue() {
|
||
|
||
return this;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline typename systemic::IValueOverride<BaseType> * systemic::ValueImplementation<BaseType>::getValueOverride() {
|
||
|
||
return nullptr;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline volatile const BaseType * systemic::ValueImplementation<BaseType>::getBase() {
|
||
|
||
return p_value;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline systemic::ValueImplementation<BaseType>::operator BaseType() const {
|
||
|
||
return *p_value;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline systemic::ValueImplementation<BaseType>::ValueImplementation(
|
||
const volatile BaseType & base) : p_value(&base) {}
|
||
|
||
|
||
//--------------------------------------
|
||
|
||
template<typename BaseType>
|
||
inline typename systemic::IValue<BaseType> * systemic::ValueOverrideImplementation<BaseType>::getValue() {
|
||
|
||
return this;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline typename systemic::IValueOverride<BaseType> * systemic::ValueOverrideImplementation<BaseType>::getValueOverride() {
|
||
|
||
return this;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline volatile const BaseType * systemic::ValueOverrideImplementation<BaseType>::getBase() {
|
||
|
||
return p_value;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline systemic::ValueOverrideImplementation<BaseType>::operator BaseType() const {
|
||
|
||
return *p_value_process;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline void systemic::ValueOverrideImplementation<BaseType>::setupOverride() {
|
||
|
||
override_value = *p_value;
|
||
p_value_process = &override_value;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline void systemic::ValueOverrideImplementation<BaseType>::setOverrideValue(
|
||
BaseType value ) {
|
||
|
||
override_value = value;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline BaseType systemic::ValueOverrideImplementation<BaseType>::getHiddenValue() const {
|
||
|
||
return *p_value;
|
||
|
||
}
|
||
|
||
template<typename BaseType>
|
||
inline systemic::ValueOverrideImplementation<BaseType>::ValueOverrideImplementation(
|
||
const volatile BaseType & base) : p_value(&base), p_value_process(&base), override_value(base) {}
|
||
|
||
template<typename BaseType>
|
||
inline void systemic::ValueOverrideImplementation<BaseType>::resetOverride() {
|
||
|
||
p_value_process = p_value;
|
||
|
||
}
|
||
|
||
#endif /* SOURCE_SYSTEMIC_VALUEIMPLEMENTATION_HPP_ */
|