3-state logical type with three values: true, false and cancelled and convenient operators.
cancelled state can be also called dontKnow, it behaves as null in SQL. A main goal of this class is to improve readibility when there's a need for storing third, cancelled, state, especially in case C++ exceptions are not in use. With it, developer can forget about declaring a specific enum type having just three values: true, false, cancelled.
Objects of this class can be used with similar convenience as standard bool type:
- use as return value when 'cancelled'
- convert from bool (1) or to bool (2)
- clear comparisons
if (t) doSomethingIfTrue();
if (!t) doSomethingIfFalse();
if (~t) doSomethingIfCancelled();
"! ~" can be used as "not cancelled".
With tristate class, developer can also forget about it's additional meaning and treat it just as a bool, if the third state is irrelevant to the current situation.
Other use for tristate class could be to allow cancellation within a callback function or a Qt slot. Example:
Having the single parameter, signals and slots have still simple look. Developers can alter their code (by replacing 'bool *result' with 'tristate *result') in case when a possibility of canceling of, say, data provessing needs to be implemented. Let's say validateData() function uses a QDialog to get some validation from a user. While QDialog::Rejected is returned after cancellation of the validation process, the information about cancellation needs to be transferred up to a higher level of the program. Storing values of type QDialog::DialogCode there could be found as unreadable, and casting these to int is not typesafe. With tristate class it's easier to make it obvious that cancellation should be taken into account.
Definition at line 100 of file KDbTristate.h.