Remove dynamic exceptions
[anna.git] / source / test / Menu.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <iostream>
10
11 #include <anna/comm/Communicator.hpp>
12
13 #include <anna/test/Menu.hpp>
14
15 using namespace std;
16 using namespace anna;
17 using namespace anna::comm;
18
19 const char* test::Menu::EventData = "test::Menu::Data";
20
21 test::Menu::Menu (Communicator* communicator) :
22    Handler (communicator, Type::Custom, false),
23    a_status (0)
24 {
25    setfd (2);
26 }
27
28 void test::Menu::paint () const
29       
30 {
31    switch (a_status) {
32       case 0:
33          cout << "Elija operacion [+|-|*|/|q = quit]: " << flush;  
34          break;
35       case 1:
36          cout << "Indique primer operador: " << flush;
37          break;
38       case 2:
39          cout << "Indique segundo operador: " << flush;
40          break;
41    }
42 }
43
44 void test::Menu::apply ()
45    noexcept(false)
46 {
47    switch (a_status) {
48       case 0: 
49          cin >> a_data.a_operation;
50          switch (a_data.a_operation) {
51             case 'q':
52             case 'Q':
53                a_communicator->requestStop ();
54                break;
55             case '+':
56             case '-':
57             case '*':
58             case '/':         
59                a_status = 1;
60                paint ();
61                break;
62          }
63          break;
64       case 1:
65          cin >> a_data.a_op1;
66          a_status = 2;
67          paint ();
68          break;
69       case 2:
70          cin >> a_data.a_op2;
71          a_communicator->eventUser (EventData, &a_data);
72          a_status = 0;
73          paint ();
74          break;         
75    };
76 }
77
78