diff --git a/Utils/SafeBool.cci b/Utils/SafeBool.cci new file mode 100644 index 0000000000000000000000000000000000000000..4c49b5b521415704200a2d9a1c3d95e9ada72e55 --- /dev/null +++ b/Utils/SafeBool.cci @@ -0,0 +1,36 @@ +// $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: diff --git a/Utils/SafeBool.cti b/Utils/SafeBool.cti new file mode 100644 index 0000000000000000000000000000000000000000..603ae8aefd2eb445d2d3cf2afec34f2728ec58c2 --- /dev/null +++ b/Utils/SafeBool.cti @@ -0,0 +1,51 @@ +// $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: diff --git a/Utils/SafeBool.hh b/Utils/SafeBool.hh new file mode 100644 index 0000000000000000000000000000000000000000..5bde302818a4f03e2f13e095185792b7a99b0682 --- /dev/null +++ b/Utils/SafeBool.hh @@ -0,0 +1,82 @@ +// $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: