| 38 | }; |
| 39 | |
| 40 | struct BankAccountCommand : Command |
| 41 | { |
| 42 | BankAccount& account; |
| 43 | enum Action { deposit, withdraw } action; |
| 44 | int amount; |
| 45 | |
| 46 | BankAccountCommand(BankAccount &account, Action action, int amount) : account(account), action(action), |
| 47 | amount(amount) { |
| 48 | succeeded = false; |
| 49 | } |
| 50 | |
| 51 | void call() override { |
| 52 | switch (action) |
| 53 | { |
| 54 | case deposit: |
| 55 | account.deposit(amount); |
| 56 | succeeded = true; |
| 57 | break; |
| 58 | case withdraw: |
| 59 | succeeded = account.withdraw(amount); |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void undo() override { |
| 65 | if (!succeeded) return; |
| 66 | |
| 67 | switch (action) |
| 68 | { |
| 69 | case deposit: |
| 70 | account.withdraw(amount); |
| 71 | break; |
| 72 | case withdraw: |
| 73 | account.deposit(amount); |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | |
| 79 | }; |
| 80 | |
| 81 | int main() |
| 82 | { |
nothing calls this directly
no outgoing calls
no test coverage detected