Renamed namespaces satcom::lib and satcom::pkf to senf
[senf.git] / Utils / SafeBool.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4
5 #ifndef HH_SafeBool_
6 #define HH_SafeBool_ 1
7
8 // Custom includes
9
10 //#include "SafeBool.mpp"
11 ///////////////////////////////hh.p////////////////////////////////////////
12
13 namespace senf {
14
15     
16     // This is a direct copy of a safe bool solution by Bjorn Karlsson 
17     // from http://www.artima.com/cppsource/safebool.html
18     //
19     // Usage:
20     //    class TestableWithVirtual 
21     //        : public safe_bool<> 
22     //    {
23     //    protected:
24     //        bool boolean_test() const 
25     //        {
26     //            // Perform Boolean logic here
27     //        }
28     //    };
29     //
30     //    class TestableWithoutVirtual 
31     //        : public safe_bool <TestableWithoutVirtual> 
32     //    {
33     //    public:
34     //        bool boolean_test() const 
35     //        {
36     //            // Perform Boolean logic here
37     //        }
38     //    };
39
40     class SafeBoolBase 
41     {
42     protected:
43         typedef void (SafeBoolBase::*bool_type)() const;
44         void this_type_does_not_support_comparisons() const;
45
46         SafeBoolBase();
47         SafeBoolBase(const SafeBoolBase&);
48         SafeBoolBase& operator=(const SafeBoolBase&);
49         ~SafeBoolBase();
50     };
51
52     template <typename T=void> 
53     class SafeBool 
54         : public SafeBoolBase 
55     {
56     public:
57         operator bool_type() const;
58         bool operator !() const;
59
60     protected:
61         ~SafeBool();
62     };
63
64     template <typename T, typename U> 
65     void operator==(const SafeBool<T>& lhs,const SafeBool<U>& rhs);
66
67     template <typename T,typename U> 
68     void operator!=(const SafeBool<T>& lhs,const SafeBool<U>& rhs);
69
70 }
71
72 ///////////////////////////////hh.e////////////////////////////////////////
73 #include "SafeBool.cci"
74 //#include "SafeBool.ct"
75 #include "SafeBool.cti"
76 //#include "SafeBool.mpp"
77 #endif
78
79 \f
80 // Local Variables:
81 // mode: c++
82 // End: