Run clang-format
This commit is contained in:
@@ -1,73 +1,42 @@
|
||||
class bank_machine
|
||||
{
|
||||
messaging::receiver incoming;
|
||||
unsigned balance;
|
||||
class bank_machine {
|
||||
messaging::receiver incoming;
|
||||
unsigned balance;
|
||||
|
||||
public:
|
||||
bank_machine():
|
||||
balance(199)
|
||||
{}
|
||||
void done()
|
||||
{
|
||||
get_sender().send(messaging::close_queue());
|
||||
bank_machine() : balance(199) {}
|
||||
void done() { get_sender().send(messaging::close_queue()); }
|
||||
void run()
|
||||
{
|
||||
try {
|
||||
for (;;) {
|
||||
incoming.wait()
|
||||
.handle<verify_pin>([&](verify_pin const& msg) {
|
||||
if (msg.pin == "1937") {
|
||||
msg.atm_queue.send(pin_verified());
|
||||
}
|
||||
else {
|
||||
msg.atm_queue.send(pin_incorrect());
|
||||
}
|
||||
})
|
||||
.handle<withdraw>([&](withdraw const& msg) {
|
||||
if (balance >= msg.amount) {
|
||||
msg.atm_queue.send(withdraw_ok());
|
||||
balance -= msg.amount;
|
||||
}
|
||||
else {
|
||||
msg.atm_queue.send(withdraw_denied());
|
||||
}
|
||||
})
|
||||
.handle<get_balance>([&](get_balance const& msg) {
|
||||
msg.atm_queue.send(::balance(balance));
|
||||
})
|
||||
.handle<withdrawal_processed>(
|
||||
[&](withdrawal_processed const& msg) {})
|
||||
.handle<cancel_withdrawal>([&](cancel_withdrawal const& msg) {});
|
||||
}
|
||||
}
|
||||
void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
incoming.wait()
|
||||
.handle<verify_pin>(
|
||||
[&](verify_pin const& msg)
|
||||
{
|
||||
if(msg.pin=="1937")
|
||||
{
|
||||
msg.atm_queue.send(pin_verified());
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.atm_queue.send(pin_incorrect());
|
||||
}
|
||||
}
|
||||
)
|
||||
.handle<withdraw>(
|
||||
[&](withdraw const& msg)
|
||||
{
|
||||
if(balance>=msg.amount)
|
||||
{
|
||||
msg.atm_queue.send(withdraw_ok());
|
||||
balance-=msg.amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.atm_queue.send(withdraw_denied());
|
||||
}
|
||||
}
|
||||
)
|
||||
.handle<get_balance>(
|
||||
[&](get_balance const& msg)
|
||||
{
|
||||
msg.atm_queue.send(::balance(balance));
|
||||
}
|
||||
)
|
||||
.handle<withdrawal_processed>(
|
||||
[&](withdrawal_processed const& msg)
|
||||
{
|
||||
}
|
||||
)
|
||||
.handle<cancel_withdrawal>(
|
||||
[&](cancel_withdrawal const& msg)
|
||||
{
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
catch(messaging::close_queue const&)
|
||||
{
|
||||
}
|
||||
}
|
||||
messaging::sender get_sender()
|
||||
{
|
||||
return incoming;
|
||||
catch (messaging::close_queue const&) {
|
||||
}
|
||||
}
|
||||
messaging::sender get_sender() { return incoming; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user