libzypp  10.5.0
SafeBool.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_BASE_SAFEBOOL_H
00013 #define ZYPP_BASE_SAFEBOOL_H
00014 
00016 namespace zypp
00017 { 
00018 
00019   namespace base
00020   { 
00021 
00022     namespace safebool_detail
00023     {
00024       class SafeBoolBase
00025       {
00026       protected:
00027         typedef void (SafeBoolBase::*bool_type)() const;
00028         void theTrueBoolType() const {}
00029 
00030         SafeBoolBase() {}
00031         SafeBoolBase( const SafeBoolBase & ) {}
00032         ~SafeBoolBase() {}
00033         SafeBoolBase & operator=( const SafeBoolBase & ) { return *this; }
00034       };
00035     }
00036 
00038     //
00039     //  CLASS NAME : SafeBool
00040     //
00069     template<class _Derived>
00070       struct SafeBool : private safebool_detail::SafeBoolBase
00071       {
00072         typedef safebool_detail::SafeBoolBase::bool_type bool_type;
00073         operator bool_type() const
00074         {
00075           return( (static_cast<const _Derived *>(this))->boolTest()
00076                   ? &safebool_detail::SafeBoolBase::theTrueBoolType
00077                   : 0 );
00078         }
00079       protected:
00080         ~SafeBool() {}
00081       };
00083 
00085   } // namespace base
00088 } // namespace zypp
00090 #endif // ZYPP_BASE_SAFEBOOL_H