Skip to content

Commit 76722fe

Browse files
committed
BLE: Improve SafeBool.h documentation.
1 parent 4209e88 commit 76722fe

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

features/FEATURE_BLE/ble/SafeBool.h

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,23 @@
1919

2020
/* Safe bool idiom, see : http://www.artima.com/cppsource/safebool.html */
2121

22+
/**
23+
* @file
24+
* @addtogroup ble
25+
* @{
26+
* @addtogroup common
27+
* @{
28+
*/
29+
30+
/**
31+
* Private namespace used to host details of the SafeBool implementation.
32+
*/
2233
namespace SafeBool_ {
2334
/**
24-
* @brief Base class for all intances of SafeBool.
25-
* This base class reduces instantiation of trueTag function.
35+
* Base class of all SafeBool instances.
36+
*
37+
* This non template base class exists to reduces the number of instantiation of
38+
* the trueTag function.
2639
*/
2740
class base {
2841
template<typename>
@@ -40,7 +53,7 @@ class base {
4053
void invalidTag() const;
4154

4255
/**
43-
* Member function which indicate true value.
56+
* Special member function which indicate a true value.
4457
*/
4558
void trueTag() const {}
4659
};
@@ -49,9 +62,14 @@ class base {
4962
}
5063

5164
/**
52-
* @brief template class SafeBool use CRTP to made boolean conversion easy and correct.
53-
* Derived class should implement the function bool toBool() const to make this work. Inheritance
54-
* should be public.
65+
* Safe conversion of objects in boolean context.
66+
*
67+
* Classes wanting to evaluation of their instances in boolean context must
68+
* derive publicly from this class rather than implementing the easy to misuse
69+
* operator bool().
70+
*
71+
* Descendant classes must implement the function bool toBool() const to enable
72+
* the safe conversion in boolean context.
5573
*
5674
* @tparam T Type of the derived class
5775
*
@@ -61,7 +79,7 @@ class base {
6179
* public:
6280
*
6381
* // boolean conversion
64-
* bool toBool() {
82+
* bool toBool() const {
6583
*
6684
* }
6785
* };
@@ -87,38 +105,50 @@ class base {
87105
* if(a == b) {
88106
*
89107
* }
90-
*
91-
*
92108
* @endcode
93109
*/
94110
template <typename T>
95111
class SafeBool : public SafeBool_::base {
96112
public:
97113
/**
98-
* Bool operator implementation, derived class has to provide bool toBool() const function.
114+
* Bool operator implementation, derived class must provide a bool
115+
* toBool() const function.
99116
*/
100-
operator BoolType_t() const {
117+
operator BoolType_t() const
118+
{
101119
return (static_cast<const T*>(this))->toBool()
102120
? &SafeBool<T>::trueTag : 0;
103121
}
104122
};
105123

106124
/**
107125
* Avoid conversion to bool between different classes.
126+
*
127+
* @important Will generate a compile time error if instantiated.
108128
*/
109129
template <typename T, typename U>
110-
void operator==(const SafeBool<T>& lhs,const SafeBool<U>& rhs) {
130+
void operator==(const SafeBool<T>& lhs,const SafeBool<U>& rhs)
131+
{
111132
lhs.invalidTag();
112133
// return false;
113134
}
114135

115136
/**
116137
* Avoid conversion to bool between different classes.
138+
*
139+
* @important Will generate a compile time error if instantiated.
117140
*/
118141
template <typename T,typename U>
119-
void operator!=(const SafeBool<T>& lhs,const SafeBool<U>& rhs) {
142+
void operator!=(const SafeBool<T>& lhs,const SafeBool<U>& rhs)
143+
{
120144
lhs.invalidTag();
121145
// return false;
122146
}
123147

148+
/**
149+
* @}
150+
* @}
151+
*/
152+
153+
124154
#endif /* BLE_API_SAFE_BOOL_H_ */

0 commit comments

Comments
 (0)