Mailinglist Archive: zypp-commit (266 mails)

< Previous Next >
[zypp-commit] r11801 - /trunk/libzypp/doc/autoinclude/CodePitfalls.doc
  • From: mlandres@xxxxxxxxxxxxxxxx
  • Date: Tue, 25 Nov 2008 15:25:54 -0000
  • Message-id: <20081125152554.C3BB1FB92D@xxxxxxxxxxxxxxxx>
Author: mlandres
Date: Tue Nov 25 16:25:54 2008
New Revision: 11801

URL: http://svn.opensuse.org/viewcvs/zypp?rev=11801&view=rev
Log:
- Add CodePitfalls page to doc and mention TriBool there.

Added:
trunk/libzypp/doc/autoinclude/CodePitfalls.doc

Added: trunk/libzypp/doc/autoinclude/CodePitfalls.doc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/doc/autoinclude/CodePitfalls.doc?rev=11801&view=auto
==============================================================================
--- trunk/libzypp/doc/autoinclude/CodePitfalls.doc (added)
+++ trunk/libzypp/doc/autoinclude/CodePitfalls.doc Tue Nov 25 16:25:54 2008
@@ -0,0 +1,60 @@
+namespace zypp
+{
+/** \page CodePitfalls Code Pitfalls - Frequently made mistakes
+
+\section TriBoolCompare Comparing TriBool values
+
+ Comparing two \ref TriBool values is not as easy as it might look like,
+ because the \c TriBool::operator== and \c TriBool::operator!= return
+ a \ref TriBool.
+
+ For example is <tt>(indeterminate==indeterminate)</tt> not \c true, but
+ \c indeterminate. That's why the following snippet does not do what the
+ author expected:
+
+ \code
+ // buggy option class
+ struct Option
+ {
+ public:
+ Option()
+ : _value( indeterminate )
+ {}
+
+ bool get() const
+ { return ( _value == indeterminate ) ? true : bool(_value); }
+
+ void set( bool new_r )
+ { _value = new_r; }
+
+ private:
+ tribool _value;
+ };
+ \endcode
+
+ You find that \c get() returns \c false as long as the option is unset,
+ and not \c true as the code suggests. That's because
<tt>(_value==indeterminate)</tt>
+ returns \c indeterminate.
+
+ \note Always use \c indeterminate(_value) to test whether a TriBools value
is \c indeterminate:
+
+ \code
+ bool get() const
+ { return indeterminate( _value ) ? true : bool(_value); }
+ \endcode
+
+ \code
+ tribool _value;
+ ...
+ if ( indeterminate( _value ) )
+ { ... } // indeterminate
+ else if ( _value )
+ { ... } // true
+ else
+ { ... } // false
+ \endcode
+<HR>
+
+
+*/
+}

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages