00001 // $Id: safe_bool.hh 1742 2010-11-04 14:51:56Z g0dil $ 00002 // 00003 // Copyright (C) 2007 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 #ifndef HH_SENF_Utils_safe_bool_ 00027 #define HH_SENF_Utils_safe_bool_ 1 00028 00029 // Custom includes 00030 00031 //#include "safe_bool.mpp" 00032 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00033 00034 namespace senf { 00035 00041 class safe_bool_base 00042 { 00043 protected: 00044 typedef void (safe_bool_base::*bool_type)() const; 00045 void this_type_does_not_support_comparisons() const; 00046 00047 // Just here to make them protected ... 00048 00049 safe_bool_base(); 00050 safe_bool_base(const safe_bool_base&); 00051 safe_bool_base& operator=(const safe_bool_base&); 00052 ~safe_bool_base(); 00053 }; 00054 00059 template <typename T> 00060 class comparable_safe_bool 00061 : public safe_bool_base 00062 { 00063 public: 00064 operator bool_type() const; 00065 bool operator !() const; 00066 00067 protected: 00068 ~comparable_safe_bool(); 00069 }; 00070 00115 template <typename T> 00116 class safe_bool : public comparable_safe_bool<T> {}; 00117 00118 template <typename T, typename U> 00119 void operator==(const safe_bool<T>& lhs,const safe_bool<U>& rhs); 00120 00121 template <typename T,typename U> 00122 void operator!=(const safe_bool<T>& lhs,const safe_bool<U>& rhs); 00123 00124 } 00125 00126 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00127 #include "safe_bool.cci" 00128 //#include "safe_bool.ct" 00129 #include "safe_bool.cti" 00130 //#include "safe_bool.mpp" 00131 #endif 00132 00133 00134 // Local Variables: 00135 // mode: c++ 00136 // fill-column: 100 00137 // c-file-style: "senf" 00138 // indent-tabs-mode: nil 00139 // ispell-local-dictionary: "american" 00140 // compile-command: "scons -u test" 00141 // comment-column: 40 00142 // End: