This is a small C++ application (and the table is not huge either) so if possible I would like to avoid include anything other than STL (and boost).
So to the problem:
I have a table of predefined matching of input and output conditions. This table contains 4 input variables (states), and their combination leads to 1 output variable. In essence:
output = f(a,b,c,d)
i.e. "the output variable is a function of 4 input variables"
- The output variable is an alarm and can take one of 3 states (ok,warning,fault).
- "A" can take 1 of 3 states (say 0 or 1 or 2). Similarly
- "B" can take 1 of 5 states
- "C" can take 1 of 3 states
- "D" can take 1 of 2 states
I want to provide the values to the input variables and get the output variable in return from this lookup table.
The table may look a bit like this:
A | B | C | D | output
----------------------
1 | 3 | 0 | 1 | ok
0 | 2 | 1 | 2 | fault
0 | 0 | 0 | 0 | warning
... and so on. So the table will have no more than 150 entries (some optimisation has helped in this) which is not huge, but it is still too large if I try to create nested if-statments. What can I do to avoid huge if
statements?
What I am looking for is a design pattern , or some good reference to read up on.
For example a sort of map
which can hold 4 keys and 1 value would be ideal.
Something like map would probably be ideal.