Utils: Revamp documentation overview and add some missing docs
[senf.git] / Utils / safe_bool.hh
similarity index 50%
rename from Utils/SafeBool.hh
rename to Utils/safe_bool.hh
index eb116da..50a113a 100644 (file)
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 /** \file
-    \brief SafeBool public header */
+    \brief safe_bool public header */
 
-#ifndef HH_SafeBool_
-#define HH_SafeBool_ 1
+#ifndef HH_safe_bool_
+#define HH_safe_bool_ 1
 
 // Custom includes
 
-//#include "SafeBool.mpp"
+//#include "safe_bool.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
 
 namespace senf {
 
-    /** \brief internal SafeBool base class
+    /** \brief internal safe_bool base class
         \internal
+
+        \see safe_bool
      */
-    class SafeBoolBase
+    class safe_bool_base
     {
     protected:
-        typedef void (SafeBoolBase::*bool_type)() const;
+        typedef void (safe_bool_base::*bool_type)() const;
         void this_type_does_not_support_comparisons() const;
 
         // Just here to make them protected ...
 
-        SafeBoolBase();
-        SafeBoolBase(const SafeBoolBase&);
-        SafeBoolBase& operator=(const SafeBoolBase&);
-        ~SafeBoolBase();
+        safe_bool_base();
+        safe_bool_base(const safe_bool_base&);
+        safe_bool_base& operator=(const safe_bool_base&);
+        ~safe_bool_base();
+    };
+
+    /** \brief Mixin class for safe bool conversion support (comparable classes)
+
+        \see safe_bool
+     */
+    template <typename T>
+    class comparable_safe_bool
+        : public safe_bool_base
+    {
+    public:
+        operator bool_type() const;
+        bool operator !() const;
+
+    protected:
+        ~comparable_safe_bool();
     };
 
     /** \brief Mixin class for safe boolean conversion support
 
-        This is a direct yet simplified copy of a safe bool solution
-        by Bjorn Karlsson from
+        This is a direct yet simplified copy of a safe bool solution by Bjorn Karlsson from
         http://www.artima.com/cppsource/safebool.html
 
-        This mixin provides the client class with safe boolean
-        testing. It is a safe replacement for <tt>operator
-        bool</tt>. <tt>operator bool</tt> is problematic since \c bool
-        is an integer type. This conversion operator makes the class
-        usable in any numeric context, which can be quite
-        dangerous. The <tt>operator void *</tt> solution is much
-        better in this respect but still allows two instances of any
-        class having such a <tt>void *</tt> conversion to be compared
-        for equality. This again will produce absolutely unexpected
-        results since it will not check whether the objects are
-        identical, it will only check, that both return the same
+        This mixin provides the client class with safe boolean testing. It is a safe replacement for
+        <tt>operator bool</tt>. <tt>operator bool</tt> is problematic since \c bool is an integer
+        type. This conversion operator makes the class usable in any numeric context, which can be
+        quite dangerous. The <tt>operator void *</tt> solution is much better in this respect but
+        still allows two instances of any class having such a <tt>void *</tt> conversion to be
+        compared for equality. This again will produce absolutely unexpected results since it will
+        not check whether the objects are identical, it will only check, that both return the same
         boolean state.
 
-        This solutions solves all these problems by returning a
-        pointer-to-member which cannot be converted to any other
-        type. By providing explicit implementations of \c operator==
-        and \c operator!= which fail in an obvious way at compile
-        time, this hazard is removed.
+        This solutions solves all these problems by returning a pointer-to-member which cannot be
+        converted to any other type. By providing explicit implementations of \c operator== and \c
+        operator!= which fail in an obvious way at compile time, this hazard is removed.
 
-        To make a class boolean testable, just inherit from the mixin
-        and implement \c boolean_test:
+        To make a class boolean testable, just inherit from the mixin and implement \c boolean_test:
 
         \code
         class Testable
-            : public SafeBool<Testable>
+            : public safe_bool<Testable>
         {
         public:
             bool boolean_test() const
@@ -95,38 +105,29 @@ namespace senf {
            ...
         }
         \endcode
+        
+        If the class to be made using senf::safe_bool is itself comparable via it's own \c
+        operator==, you must use comparable_safe_bool instead of safe_bool to not loose this
+        capability.
 
-        \todo Either rename intrusive_refcount to IntrusiveRefcount or
-        SafeBool to safe_bool (I tend to the latter ...)
+        \see comparable_safe_bool
      */
     template <typename T>
-    class ComparableSafeBool
-        : public SafeBoolBase
-    {
-    public:
-        operator bool_type() const;
-        bool operator !() const;
-
-    protected:
-        ~ComparableSafeBool();
-    };
-
-    template <typename T>
-    class SafeBool : public ComparableSafeBool<T> {};
+    class safe_bool : public comparable_safe_bool<T> {};
 
     template <typename T, typename U>
-    void operator==(const SafeBool<T>& lhs,const SafeBool<U>& rhs);
+    void operator==(const safe_bool<T>& lhs,const safe_bool<U>& rhs);
 
     template <typename T,typename U>
-    void operator!=(const SafeBool<T>& lhs,const SafeBool<U>& rhs);
+    void operator!=(const safe_bool<T>& lhs,const safe_bool<U>& rhs);
 
 }
 
 ///////////////////////////////hh.e////////////////////////////////////////
-#include "SafeBool.cci"
-//#include "SafeBool.ct"
-#include "SafeBool.cti"
-//#include "SafeBool.mpp"
+#include "safe_bool.cci"
+//#include "safe_bool.ct"
+#include "safe_bool.cti"
+//#include "safe_bool.mpp"
 #endif
 
 \f