MotorControlModuleSDFM_TMS3.../Projects/EFC_Application/UMLibrary/systemic/ValueImplementation.hpp

159 lines
3.9 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_ */