Skip to content
Snippets Groups Projects
Commit 270d60a6 authored by g0dil's avatar g0dil
Browse files

add SafeBool

parent dc166b28
No related branches found
No related tags found
No related merge requests found
// $Id$
//
// Copyright (C) 2006
// Definition of inline non-template functions
// Custom includes
#define prefix_ inline
///////////////////////////////cci.p///////////////////////////////////////
prefix_ void satcom::lib::SafeBoolBase::this_type_does_not_support_comparisons()
const
{}
prefix_ satcom::lib::SafeBoolBase::SafeBoolBase()
{}
prefix_ satcom::lib::SafeBoolBase::SafeBoolBase(const SafeBoolBase&)
{}
prefix_ satcom::lib::SafeBoolBase& satcom::lib::SafeBoolBase::operator=(const SafeBoolBase&)
{
return *this;
}
prefix_ satcom::lib::SafeBoolBase::~SafeBoolBase()
{}
///////////////////////////////cci.e///////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// End:
// $Id$
//
// Copyright (C) 2006
// Definition of inline template functions
//#include "SafeBool.ih"
// Custom includes
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
template <typename T>
prefix_ satcom::lib::SafeBool<T>::operator bool_type()
const
{
return (static_cast<const T*>(this))->boolean_test()
? &SafeBoolBase::this_type_does_not_support_comparisons : 0;
}
template <typename T>
prefix_ bool satcom::lib::SafeBool<T>::operator!()
const
{
return ! (static_cast<const T*>(this))->boolean_test();
}
template <typename T>
prefix_ satcom::lib::SafeBool<T>::~SafeBool()
{}
template <typename T, typename U>
prefix_ void satcom::lib::operator==(const SafeBool<T>& lhs, const SafeBool<U>& rhs)
{
lhs.this_type_does_not_support_comparisons();
}
template <typename T, typename U>
prefix_ void satcom::lib::operator!=(const SafeBool<T>& lhs, const SafeBool<U>& rhs)
{
lhs.this_type_does_not_support_comparisons();
}
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// End:
// $Id$
//
// Copyright (C) 2006
#ifndef HH_SafeBool_
#define HH_SafeBool_ 1
// Custom includes
//#include "SafeBool.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace satcom {
namespace lib {
// This is a direct copy of a safe bool solution by Bjorn Karlsson
// from http://www.artima.com/cppsource/safebool.html
//
// Usage:
// class TestableWithVirtual
// : public safe_bool<>
// {
// protected:
// bool boolean_test() const
// {
// // Perform Boolean logic here
// }
// };
//
// class TestableWithoutVirtual
// : public safe_bool <TestableWithoutVirtual>
// {
// public:
// bool boolean_test() const
// {
// // Perform Boolean logic here
// }
// };
class SafeBoolBase
{
protected:
typedef void (SafeBoolBase::*bool_type)() const;
void this_type_does_not_support_comparisons() const;
SafeBoolBase();
SafeBoolBase(const SafeBoolBase&);
SafeBoolBase& operator=(const SafeBoolBase&);
~SafeBoolBase();
};
template <typename T=void>
class SafeBool
: public SafeBoolBase
{
public:
operator bool_type() const;
bool operator !() const;
protected:
~SafeBool();
};
template <typename T, typename U>
void operator==(const SafeBool<T>& lhs,const SafeBool<U>& rhs);
template <typename T,typename U>
void operator!=(const SafeBool<T>& lhs,const SafeBool<U>& rhs);
}}
///////////////////////////////hh.e////////////////////////////////////////
#include "SafeBool.cci"
//#include "SafeBool.ct"
#include "SafeBool.cti"
//#include "SafeBool.mpp"
#endif
// Local Variables:
// mode: c++
// End:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment