Updated
Fork of BLE_API by
Diff: ble/SafeBool.h
- Revision:
- 1155:e28c7aac64ab
- Parent:
- 1150:45226f13ae5c
- Child:
- 1156:e1ea38b576c6
diff -r 702de9e6b049 -r e28c7aac64ab ble/SafeBool.h --- a/ble/SafeBool.h Wed Apr 06 19:14:32 2016 +0100 +++ b/ble/SafeBool.h Wed Apr 06 19:14:34 2016 +0100 @@ -17,32 +17,26 @@ #ifndef BLE_API_SAFE_BOOL_H_ #define BLE_API_SAFE_BOOL_H_ -/* Safe bool idiom, see : http://www.artima.com/cppsource/safebool.html */ +//safe bool idiom, see : http://www.artima.com/cppsource/safebool.html namespace SafeBool_ { /** - * @brief Base class for all intances of SafeBool. - * This base class reduces instantiation of trueTag function. + * @brief Base class for all intances of SafeBool, + * This base class reduce instantiation of trueTag function */ class base { template<typename> friend class SafeBool; protected: - /** - * The bool type is a pointer to method which can be used in boolean context. - */ - typedef void (base::*BoolType_t)() const; + //the bool type is a pointer to method which can be used in boolean context + typedef void (base::*BoolType_t)() const; - /** - * Non implemented call, use to disallow conversion between unrelated types. - */ - void invalidTag() const; + // non implemented call, use to disallow conversion between unrelated types + void invalidTag() const; - /** - * Member function which indicate true value. - */ - void trueTag() const {} + // member function which indicate true value + void trueTag() const {} }; @@ -50,75 +44,71 @@ /** * @brief template class SafeBool use CRTP to made boolean conversion easy and correct. - * Derived class should implement the function bool toBool() const to make this work. Inheritance + * Derived class should implement the function bool toBool() const to make this work. Inheritance * should be public. * * @tparam T Type of the derived class - * - * @code - * - * class A : public SafeBool<A> { + * + * \code + * + * class A : public SafeBool<A> { * public: - * + * * // boolean conversion - * bool toBool() { - * - * } + * bool toBool() { + * + * } * }; - * - * class B : public SafeBool<B> { + * + * class B : public SafeBool<B> { * public: - * + * * // boolean conversion - * bool toBool() const { - * - * } + * bool toBool() const { + * + * } * }; - * + * * A a; * B b; - * - * // will compile - * if(a) { - * + * + * // will compile + * if(a) { + * * } - * - * // compilation error - * if(a == b) { - * + * + * // compilation error + * if(a == b) { + * * } - * - * - * @endcode + * + * + * \endcode */ -template <typename T> +template <typename T> class SafeBool : public SafeBool_::base { public: - /** - * Bool operator implementation, derived class has to provide bool toBool() const function. - */ - operator BoolType_t() const { - return (static_cast<const T*>(this))->toBool() - ? &SafeBool<T>::trueTag : 0; - } + /** + * bool operator implementation, derived class has to provide bool toBool() const function. + */ + operator BoolType_t() const { + return (static_cast<const T*>(this))->toBool() + ? &SafeBool<T>::trueTag : 0; + } }; -/** - * Avoid conversion to bool between different classes. - */ +//Avoid conversion to bool between different classes template <typename T, typename U> void operator==(const SafeBool<T>& lhs,const SafeBool<U>& rhs) { lhs.invalidTag(); - // return false; +// return false; } -/** - * Avoid conversion to bool between different classes. - */ +//Avoid conversion to bool between different classes template <typename T,typename U> void operator!=(const SafeBool<T>& lhs,const SafeBool<U>& rhs) { - lhs.invalidTag(); - // return false; + lhs.invalidTag(); +// return false; } #endif /* BLE_API_SAFE_BOOL_H_ */ \ No newline at end of file