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

Jaroslaw Staniek js at iidea.pl
Tue Sep 13 09:47:07 BST 2005


Frans Englich said the following, On 2005-09-11 14:08:

> On Friday 09 September 2005 21:54, Jarosław Staniek wrote:
> 
>>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.
> 
> 
> If one have an appropriate scenario, I understand if one uses the tristate 
> class, considering the convenience and type safety it provides.
> 
> Some humble nit-picking:

Thanks for these points, most things are fixed now:

> 
> * The "cancelled" enum in the Value enumerator should also have enum 
> capitalization, like True and False. (or there's something I'm missing?)
> 
> * Is there any reason to why the variable "value" is not private? 

OK, made private (required to add explicit operator=)

> Calling it m_value could be an idea too. 

OK

> AFAICT, it could be declared const as well.

Hmm, no, this introduces a problem with following code (not working = operator):

   tristate result = myFunc();


> * Call the class KTristate instead of "tristate"?

We have here ...aesthetic issue. For me, "tristate" is a clean extension of
"bool", and as such has only so much common with KDE that the class can be
reused within the project (I've just no higher level to put this class than in
kdelibs...). I can live with this but just prefer this code *less*:

   KTristate result = myFunc();

> * (The Doxygen markup, as per Adriaan)

OK

> If concrete cases could be listed for where it would be used(that people will 
> adjust code), then I think it would be sensible for it to go in.

I've updated docs in the file with more examples and notes.

BTW Even while tristate is usable mostly for higher levels, i.e. apps, I can 
see a candidate for replace in kdelibs itself: KStartupInfoData::TriState in 
kdelibs itself.

-- 
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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: tristate.h
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20050913/58caafa4/attachment.h>


More information about the kde-core-devel mailing list