Proposal for addition: tristate class - 3-state logical type

Jaroslaw Staniek js at iidea.pl
Sat Sep 10 00:58:32 BST 2005


Olivier Goffart said the following, On 2005-09-10 01:17:

> Le Vendredi 9 Septembre 2005 23:54, Jarosław Staniek a écrit :
> 
>>File atttached: tristate.h
>>
>>Proposal for using this at kdelibs level.
>>
>>Simple yet readable bool type replacement when you need to return a special
>>"don't know" or "cancelled" state from your function and you detest
>>exceptions like me. I've estarted to use tristate class in apps, including
>>Kexi, in 2004 with relative success: I was able to avoid using error-prone
>>int type whenever people just want to return 0, 1 or 2 (2=="don't know").
>>
>>Contains all necessary casts from bool, operators and special 'cancelled'
>>value.
> 
> That remind me an old thread
> http://lists.kde.org/?t=109689376400005&r=1&w=2
> 
> My objections are still the same:  it can be done with a simple int or an 
> enum. (where, AFAIK, operators like ! and ~ works also)
> 
> Can you point me a place in the code where that class will be usefull ?

I mean, it's purely application-level stuff, not especially for kdelibs. A 
code, which in particular uses threading, and thus usually allows to cancel an 
operation, could return a tristate value.

eg. here tristate is used to avoid adding enums for every single case (and to 
avoid sharing predefined enums like QDialog::DialogCode or so):

http://www.koffice.org/developer/apidocs/kexi/html/keximainwindowimpl_8h-source.html

Like it or not, it's here and waiting for you in case you will find it usable 
for others. Nothing more.

-- 
regards / pozdrawiam,
  Jaroslaw Staniek / OpenOffice Polska / Kexi Team
  http://www.openoffice.com.pl  |  http://www.kexi-project.org
  KDElibs/Windows: http://wiki.kde.org/tiki-index.php?page=KDElibs+for+win32





More information about the kde-core-devel mailing list