56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
|
|
/*
|
|||
|
|
* ValueTrigger.cpp
|
|||
|
|
*
|
|||
|
|
* Created on: 22 <EFBFBD><EFBFBD><EFBFBD>. 2020 <EFBFBD>.
|
|||
|
|
* Author: LeonidTitov
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#include "ValueTrigger.hh"
|
|||
|
|
|
|||
|
|
bool schematic::ValueTrigger::setup(
|
|||
|
|
Type type, Id id, Condition condition, Value value,
|
|||
|
|
std::pair<const char *, std::size_t> threshold ) {
|
|||
|
|
|
|||
|
|
TriggerProviders::iterator iter = triggers.find( type );
|
|||
|
|
|
|||
|
|
if( iter != triggers.end() ) {
|
|||
|
|
|
|||
|
|
systemic::IValue<bool> * trig = iter->second->setup( id, condition, value, threshold );
|
|||
|
|
|
|||
|
|
state = false;
|
|||
|
|
implement = trig;
|
|||
|
|
trigger_interface = iter->second;
|
|||
|
|
} else
|
|||
|
|
reset(false);
|
|||
|
|
|
|||
|
|
return implement;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void schematic::ValueTrigger::reset(bool new_state) {
|
|||
|
|
|
|||
|
|
state = new_state;
|
|||
|
|
implement = nullptr;
|
|||
|
|
trigger_interface = nullptr;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
schematic::ValueTrigger::operator bool() const {
|
|||
|
|
|
|||
|
|
return implement ? *implement : state;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
schematic::ValueTrigger::ValueTrigger( std::pmr::memory_resource * description ) :
|
|||
|
|
implement(nullptr), trigger_interface(nullptr), state(false), triggers(std::less<Type>(),
|
|||
|
|
description)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void schematic::ValueTrigger::get_threshold(
|
|||
|
|
std::pair<char *, std::size_t> buff ) const {
|
|||
|
|
|
|||
|
|
if( trigger_interface )
|
|||
|
|
trigger_interface->get_threshold( buff );
|
|||
|
|
|
|||
|
|
}
|