Skip to content

Commit f9afdc9

Browse files
committed
Add explicit keyword to constructors
Resolves cppcheck warnings noExplicitConstructor, and useInitializationList.
1 parent 15cb6bc commit f9afdc9

File tree

8 files changed

+22
-22
lines changed

8 files changed

+22
-22
lines changed

src/NimBLE2904.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct NimBLE2904Data {
3838
*/
3939
class NimBLE2904 : public NimBLEDescriptor {
4040
public:
41-
NimBLE2904(NimBLECharacteristic* pChr = nullptr);
41+
explicit NimBLE2904(NimBLECharacteristic* pChr = nullptr);
4242
static const uint8_t FORMAT_BOOLEAN = 1;
4343
static const uint8_t FORMAT_UINT2 = 2;
4444
static const uint8_t FORMAT_UINT4 = 3;

src/NimBLEAddress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ class NimBLEAddress : private ble_addr_t {
4444
* @brief Create a blank address, i.e. 00:00:00:00:00:00, type 0.
4545
*/
4646
NimBLEAddress() = default;
47-
NimBLEAddress(const ble_addr_t address);
4847
NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type);
4948
NimBLEAddress(const std::string& stringAddress, uint8_t type);
5049
NimBLEAddress(const uint64_t& address, uint8_t type);
50+
explicit NimBLEAddress(const ble_addr_t address);
5151

5252
bool isRpa() const;
5353
bool isNrpa() const;

src/NimBLEAttValue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class NimBLEAttValue {
8484
* @param[in] init_len The initial size in bytes.
8585
* @param[in] max_len The max size in bytes that the value can be.
8686
*/
87-
NimBLEAttValue(uint16_t init_len = CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
87+
explicit NimBLEAttValue(uint16_t init_len = CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
8888

8989
/**
9090
* @brief Construct with an initial value from a buffer.
@@ -99,7 +99,7 @@ class NimBLEAttValue {
9999
* @param value A pointer to the initial value to set.
100100
* @param[in] max_len The max size in bytes that the value can be.
101101
*/
102-
NimBLEAttValue(const char* value, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN)
102+
explicit NimBLEAttValue(const char* value, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN)
103103
: NimBLEAttValue((uint8_t*)value, (uint16_t)strlen(value), max_len) {}
104104

105105
/**
@@ -115,15 +115,15 @@ class NimBLEAttValue {
115115
* @param str A std::string containing to the initial value to set.
116116
* @param[in] max_len The max size in bytes that the value can be.
117117
*/
118-
NimBLEAttValue(const std::string str, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN)
118+
explicit NimBLEAttValue(const std::string& str, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN)
119119
: NimBLEAttValue(reinterpret_cast<const uint8_t*>(&str[0]), str.length(), max_len) {}
120120

121121
/**
122122
* @brief Construct with an initial value from a std::vector<uint8_t>.
123123
* @param vec A std::vector<uint8_t> containing to the initial value to set.
124124
* @param[in] max_len The max size in bytes that the value can be.
125125
*/
126-
NimBLEAttValue(const std::vector<uint8_t> vec, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN)
126+
explicit NimBLEAttValue(const std::vector<uint8_t>& vec, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN)
127127
: NimBLEAttValue(&vec[0], vec.size(), max_len) {}
128128

129129
# ifdef NIMBLE_CPP_ARDUINO_STRING_AVAILABLE

src/NimBLECharacteristic.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ class NimBLE2904;
3939
*/
4040
class NimBLECharacteristic : public NimBLELocalValueAttribute {
4141
public:
42-
NimBLECharacteristic(const char* uuid,
43-
uint16_t properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE,
44-
uint16_t maxLen = BLE_ATT_ATTR_MAX_LEN,
45-
NimBLEService* pService = nullptr);
46-
NimBLECharacteristic(const NimBLEUUID& uuid,
47-
uint16_t properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE,
48-
uint16_t maxLen = BLE_ATT_ATTR_MAX_LEN,
49-
NimBLEService* pService = nullptr);
42+
explicit NimBLECharacteristic(const char* uuid,
43+
uint16_t properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE,
44+
uint16_t maxLen = BLE_ATT_ATTR_MAX_LEN,
45+
NimBLEService* pService = nullptr);
46+
explicit NimBLECharacteristic(const NimBLEUUID& uuid,
47+
uint16_t properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE,
48+
uint16_t maxLen = BLE_ATT_ATTR_MAX_LEN,
49+
NimBLEService* pService = nullptr);
5050

5151
~NimBLECharacteristic();
5252

src/NimBLEConnInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ class NimBLEConnInfo {
7878

7979
ble_gap_conn_desc m_desc{};
8080
NimBLEConnInfo() {};
81-
NimBLEConnInfo(ble_gap_conn_desc desc) { m_desc = desc; }
81+
explicit NimBLEConnInfo(ble_gap_conn_desc desc) : m_desc(desc) {}
8282
};
8383
#endif

src/NimBLEService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class NimBLEService;
3333
*/
3434
class NimBLEService : public NimBLELocalAttribute {
3535
public:
36-
NimBLEService(const char* uuid);
37-
NimBLEService(const NimBLEUUID& uuid);
36+
explicit NimBLEService(const char* uuid);
37+
explicit NimBLEService(const NimBLEUUID& uuid);
3838
~NimBLEService();
3939

4040
NimBLEServer* getServer() const;

src/NimBLEUUID.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ class NimBLEUUID {
4545
*/
4646
NimBLEUUID() = default;
4747
NimBLEUUID(const ble_uuid_any_t& uuid);
48-
NimBLEUUID(const std::string& uuid);
49-
NimBLEUUID(uint16_t uuid);
50-
NimBLEUUID(uint32_t uuid);
51-
NimBLEUUID(const ble_uuid128_t* uuid);
5248
NimBLEUUID(const uint8_t* pData, size_t size);
5349
NimBLEUUID(uint32_t first, uint16_t second, uint16_t third, uint64_t fourth);
50+
explicit NimBLEUUID(const std::string& uuid);
51+
explicit NimBLEUUID(uint16_t uuid);
52+
explicit NimBLEUUID(uint32_t uuid);
53+
explicit NimBLEUUID(const ble_uuid128_t* uuid);
5454

5555
uint8_t bitSize() const;
5656
const uint8_t* getValue() const;

src/NimBLEUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class NimBLEAddress;
3030
* All items are optional, the m_pHandle will be set in taskWait().
3131
*/
3232
struct NimBLETaskData {
33-
NimBLETaskData(void* pInstance = nullptr, int flags = 0, void* buf = nullptr);
33+
explicit NimBLETaskData(void* pInstance = nullptr, int flags = 0, void* buf = nullptr);
3434
~NimBLETaskData();
3535
void* m_pInstance{nullptr};
3636
mutable int m_flags{0};

0 commit comments

Comments
 (0)