Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BLE_PowerBank_HeyFaradey
Fork of BLE_API by
Diff: ble/SafeBool.h
- Revision:
- 1156:e1ea38b576c6
- Parent:
- 1155:e28c7aac64ab
- Child:
- 1179:4ab722f8dca0
--- a/ble/SafeBool.h Wed Apr 06 19:14:34 2016 +0100
+++ b/ble/SafeBool.h Wed Apr 06 19:14:38 2016 +0100
@@ -17,26 +17,32 @@
#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 reduce instantiation of trueTag function
+ * @brief Base class for all intances of SafeBool.
+ * This base class reduces 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 {}
};
@@ -44,71 +50,75 @@
/**
* @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
