MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/schematic/action/ValueSetAction.hpp
2024-06-07 11:12:56 +03:00

64 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* ValueSetAction.hpp
*
* Created on: 6 июл. 2020 г.
* Author: LeonidTitov
*/
#ifndef UMLIBRARY_SCHEMATIC_ACTION_VALUESETACTION_HPP_
#define UMLIBRARY_SCHEMATIC_ACTION_VALUESETACTION_HPP_
#include "../../systemic/IFunctor.hh"
#include "../../systemic/IValueAsync.hpp"
namespace schematic { namespace functor {
template<typename ValueType>
class ValueSetAction : public systemic::IValueType<ValueType> {
typedef systemic::IValueType<ValueType> Value;
typedef systemic::IFunctor<void> Action;
Value & value;
Action & action;
public:
enum ActionSequence {
Before,
After
};
const ActionSequence sequence;
void set( ValueType );
ValueType get() const;
ValueSetAction( Value & value, Action & action, ActionSequence sequence ) : value(value), action(action), sequence(sequence) {}
};
}}
template<typename ValueType>
inline void schematic::functor::ValueSetAction<ValueType>::set( ValueType new_value ) {
if( sequence == Before )
action();
value.set(new_value);
if( sequence == After )
action();
}
template<typename ValueType>
inline ValueType schematic::functor::ValueSetAction<ValueType>::get() const {
return value.get();
}
#endif /* UMLIBRARY_SCHEMATIC_ACTION_VALUESETACTION_HPP_ */