Reputation: 65
I am getting started with [Boost].SML but i just don't get how to check an variable. I am trying to implement a ATM machine, where you have to put in a Code for getting access. So i was trying this: Guard
const auto right_PIN = [](int pin){ cout << "PIN VALUE: " << pin << endl;
if(pin == 1234){
return true;
}else{
return false;
}
};
transition table like this:
startState + event [right_PIN] = rightState,
startState + event [!right_PIN] = wrontState,
Now before i process the event i want to pass a parameter to the guard to check if its the right pin.
Is this possible?
Upvotes: 0
Views: 1042
Reputation: 65
I think I found a solution.
At first I declared a struct PIN with a value like this:
struct PIN {
int value{};
};
then I updated the guard and implemented it in the struct for implementing the state machine:
const auto right_PIN = [](PIN& pin){ cout << "PIN VALUE: " << pin.value << endl;
return pin.value == 1234;
};
In my main method i created an object of the struct pin and gave it to the state machine:
PIN p;
boost::sml::sm<bk> sm{p};
Then before processing the event i just updated the value of the PIN:
p.value = 1234;
sm.process_event(event());
Upvotes: 1