tristate Class Reference
#include <tristate.h>
Detailed Description
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'
tristate doSomething();
- convert from bool (1) or to bool (2)
tristate t = true; //(1) setVisible(t); //(2)
- clear comparisons
tristate t = doSomething(); 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:
public slots: void validateData(tristate& result);
- Author:
- Jaroslaw Staniek
Definition at line 97 of file tristate.h.
Public Member Functions | |
| tristate () | |
| Default constructor, object has cancelled value set. | |
| tristate (bool boolValue) | |
| Constructor accepting a boolean value. | |
| tristate (char c) | |
| Constructor accepting a char value. | |
| tristate (int intValue) | |
| Constructor accepting an integer value. | |
| bool | operator! () const |
| Casting to bool type with negation: true is only returned if the original tristate value is equal to false. | |
| bool | operator~ () const |
| Special casting to bool type: true is only returned if the original tristate value is equal to cancelled. | |
| tristate & | operator= (const tristate &tsValue) |
| QString | toString () const |
Friends | |
| bool | operator== (bool boolValue, tristate tsValue) |
Equality operator comparing a bool value boolValue and a tristate value tsValue. | |
| bool | operator== (tristate tsValue, bool boolValue) |
Equality operator comparing a tristate value tsValue and a bool value boolValue. | |
| bool | operator!= (bool boolValue, tristate tsValue) |
Inequality operator comparing a bool value boolValue and a tristate value tsValue. | |
| bool | operator!= (tristate tsValue, bool boolValue) |
Inequality operator comparing a tristate value tsValue and a bool value boolValue. | |
Constructor & Destructor Documentation
|
|
Default constructor, object has cancelled value set.
Definition at line 103 of file tristate.h. |
|
|
Constructor accepting a boolean value.
Definition at line 111 of file tristate.h. |
|
|
Constructor accepting a char value. It is converted in the following way:
Definition at line 123 of file tristate.h. |
|
|
Constructor accepting an integer value. It is converted in the following way:
Definition at line 134 of file tristate.h. |
Member Function Documentation
|
|
Casting to bool type with negation: true is only returned if the original tristate value is equal to false.
Definition at line 143 of file tristate.h. |
|
|
Definition at line 151 of file tristate.h. References m_value. |
|
|
Special casting to bool type: true is only returned if the original tristate value is equal to cancelled.
Definition at line 149 of file tristate.h. |
|
|
Definition at line 164 of file tristate.h. Referenced by SQLite2ToSQLite3Migration::cancelClicked(), KexiBLOBBuffer::objectForId(), SQLite2ToSQLite3Migration::processExited(), and KexiTableDesignerView::storeData(). |
Friends And Related Function Documentation
|
||||||||||||
|
Inequality operator comparing a tristate value
Definition at line 204 of file tristate.h. |
|
||||||||||||
|
Inequality operator comparing a bool value
Definition at line 194 of file tristate.h. |
|
||||||||||||
|
Equality operator comparing a tristate value
Definition at line 217 of file tristate.h. |
|
||||||||||||
|
Equality operator comparing a bool value
Definition at line 230 of file tristate.h. |
The documentation for this class was generated from the following file:
