From kde-core-devel Mon Oct 04 14:14:16 2004 From: =?iso-8859-2?q?Jaros=B3aw_Staniek?= Date: Mon, 04 Oct 2004 14:14:16 +0000 To: kde-core-devel Subject: Re: RFC: A new helper class Message-Id: <200410041614.16211.js () iidea ! pl> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=109689918827437 Allan Sandfeld Jensen wrote: > On Monday 04 October 2004 14:42, Jarosław Staniek wrote: >> Hello, >> Many of us do not use C++ exceptions, while sometimes it's usable to use >> 3-state logic because boolean is not enough. The 3rd state means >> sometimes 'cancelled' or 'dontKnow'. Moreover, this logic is also havily >> used for relational databases. My proposal is a lightweight 'tristate' >> class as a companion to bool type: >> >> http://www.iidea.pl/~js/kexi/download/tristate.h >> >> As you can see, the class is 'inline' and there are convenient operators. >> I used the class in Kexi's code and thus decreased complexity pretty much >> and cleaned up the code and the API (removed many "bool &cancelled" >> parameters). Example real-life usage: >> >> http://www.iidea.pl/~js/kexi/download/kexidialogbase.cpp >> >> Within KDE CVS the class can be located as koffice/kexi/tristate.h. >> Currently, application developers are free to use the class by copying >> the file (later maybe that it will be moved to more official place?). > > Maybe I am old-fashioned, but I prefer the traditional C-way of > representing this: > int ret; > ret>0 -> true > ret==0 -> false > ret<0 -> error/exception > > It provides more than one abnormal termination type, which you often need, > and this scheme can also handle any function with positive integer > return-types. Depends whether we want to read documentation or have self-documented code. To montion C-style, there is also other standard behaviour where 0 means true. On the other hand, I am (ans we all) also still _using_ ints for wider cases. But there was so many cases for functions using 3-state logic that I've found the class usable. Btw, or would be interesting to have it just in Qt4? :) -- regards / pozdrawiam, Jaroslaw Staniek / OpenOffice Polska Kexi Project: http://www.kexi-project.org, http://koffice.kde.org/kexi QT-KDE Wrapper Project: http://iidea.pl/~js/qkw