01-21-2011 03:03 AM
01-21-2011 08:28 AM
If I were doing this sort of thing (which is a very complex and heavily algorithmic analysis), I would manage the two booleans as a pair, with states representing whether or not they were true or false. For example, if the first boolean were true and the second false, I would identify this with a "T, F" state. Taking all possible combinations into account would yield 4 possible state combinations - lets call them "MetaStates", with values of "F, F", "F, T", "T, F", and finally, "T, T".
The other complexity of this system is monitoring the states of the booleans of interest and combining the boolean values into a single result. This can be done with monitor loops, queues (to pass results around), and the use of special AND operators to generate the MetaState. A simple examination of the MetaState with a case structure can then be used to compute your result. See attached code.
01-21-2011 08:55 AM
When dealing with multiple boolean logic (less than 5 booleans) I find it is much easier to read if I convert teh booleans into an array and cast the number as a descriptive enum.
This way when I come back to the code a year latter I don't have to start working on the boolean logic but can just read the results.
It looks like this.
Ben
01-24-2011 08:53 AM
@Ben wrote:
Ben - Check out Coerce to Type to make typeconverting/casting operations cleaner syntactically and more robust to datatype changes (e.g., what happens if your Enum was typedef'd, and changed from a U16 to a U8? the U16 conversion in the code would be misleading at best and give incorrect results at worst)