mirror of
https://github.com/esphome/esphome.git
synced 2025-09-04 12:22:20 +01:00
Activate owning-memory clang-tidy check (#1891)
* Activate owning-memory clang-tidy check * Lint * Lint * Fix issue with new NfcTag constructor * Update pointers for number and select * Add back the NOLINT to display buffer * Fix merge * DSMR fixes * Nextion fixes * Fix pipsolar * Fix lwip socket * Format * Change socket fix Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -17,7 +17,7 @@ NdefMessage::NdefMessage(std::vector<uint8_t> &data) {
|
||||
|
||||
ESP_LOGVV(TAG, "me=%s, sr=%s, il=%s, tnf=%d", YESNO(me), YESNO(sr), YESNO(il), tnf);
|
||||
|
||||
auto record = new NdefRecord();
|
||||
auto record = make_unique<NdefRecord>();
|
||||
record->set_tnf(tnf);
|
||||
|
||||
uint8_t type_length = data[index++];
|
||||
@@ -62,20 +62,20 @@ NdefMessage::NdefMessage(std::vector<uint8_t> &data) {
|
||||
record->set_payload(payload_str);
|
||||
index += payload_length;
|
||||
|
||||
this->add_record(record);
|
||||
ESP_LOGV(TAG, "Adding record type %s = %s", record->get_type().c_str(), record->get_payload().c_str());
|
||||
this->add_record(std::move(record));
|
||||
|
||||
if (me)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool NdefMessage::add_record(NdefRecord *record) {
|
||||
bool NdefMessage::add_record(std::unique_ptr<NdefRecord> record) {
|
||||
if (this->records_.size() >= MAX_NDEF_RECORDS) {
|
||||
ESP_LOGE(TAG, "Too many records. Max: %d", MAX_NDEF_RECORDS);
|
||||
return false;
|
||||
}
|
||||
this->records_.push_back(record);
|
||||
this->records_.emplace_back(std::move(record));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -83,13 +83,11 @@ bool NdefMessage::add_text_record(const std::string &text) { return this->add_te
|
||||
|
||||
bool NdefMessage::add_text_record(const std::string &text, const std::string &encoding) {
|
||||
std::string payload = to_string(text.length()) + encoding + text;
|
||||
auto r = new NdefRecord(TNF_WELL_KNOWN, "T", payload);
|
||||
return this->add_record(r);
|
||||
return this->add_record(make_unique<NdefRecord>(TNF_WELL_KNOWN, "T", payload));
|
||||
}
|
||||
|
||||
bool NdefMessage::add_uri_record(const std::string &uri) {
|
||||
auto r = new NdefRecord(TNF_WELL_KNOWN, "U", uri);
|
||||
return this->add_record(r);
|
||||
return this->add_record(make_unique<NdefRecord>(TNF_WELL_KNOWN, "U", uri));
|
||||
}
|
||||
|
||||
std::vector<uint8_t> NdefMessage::encode() {
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "ndef_record.h"
|
||||
@@ -11,12 +13,18 @@ static const uint8_t MAX_NDEF_RECORDS = 4;
|
||||
|
||||
class NdefMessage {
|
||||
public:
|
||||
NdefMessage(){};
|
||||
NdefMessage() = default;
|
||||
NdefMessage(std::vector<uint8_t> &data);
|
||||
NdefMessage(const NdefMessage &msg) {
|
||||
records_.reserve(msg.records_.size());
|
||||
for (const auto &r : msg.records_) {
|
||||
records_.emplace_back(make_unique<NdefRecord>(*r));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<NdefRecord *> get_records() { return this->records_; };
|
||||
const std::vector<std::unique_ptr<NdefRecord>> &get_records() { return this->records_; };
|
||||
|
||||
bool add_record(NdefRecord *record);
|
||||
bool add_record(std::unique_ptr<NdefRecord> record);
|
||||
bool add_text_record(const std::string &text);
|
||||
bool add_text_record(const std::string &text, const std::string &encoding);
|
||||
bool add_uri_record(const std::string &uri);
|
||||
@@ -24,7 +32,7 @@ class NdefMessage {
|
||||
std::vector<uint8_t> encode();
|
||||
|
||||
protected:
|
||||
std::vector<NdefRecord *> records_;
|
||||
std::vector<std::unique_ptr<NdefRecord>> records_;
|
||||
};
|
||||
|
||||
} // namespace nfc
|
||||
|
@@ -85,9 +85,9 @@ class NdefRecord {
|
||||
std::vector<uint8_t> encode(bool first, bool last);
|
||||
uint8_t get_tnf_byte(bool first, bool last);
|
||||
|
||||
const std::string &get_type() { return this->type_; };
|
||||
const std::string &get_id() { return this->id_; };
|
||||
const std::string &get_payload() { return this->payload_; };
|
||||
const std::string &get_type() const { return this->type_; };
|
||||
const std::string &get_id() const { return this->id_; };
|
||||
const std::string &get_payload() const { return this->payload_; };
|
||||
|
||||
protected:
|
||||
uint8_t tnf_;
|
||||
|
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "ndef_message.h"
|
||||
|
||||
namespace esphome {
|
||||
@@ -20,27 +23,33 @@ class NfcTag {
|
||||
this->uid_ = uid;
|
||||
this->tag_type_ = tag_type;
|
||||
};
|
||||
NfcTag(std::vector<uint8_t> &uid, const std::string &tag_type, nfc::NdefMessage *ndef_message) {
|
||||
NfcTag(std::vector<uint8_t> &uid, const std::string &tag_type, std::unique_ptr<nfc::NdefMessage> ndef_message) {
|
||||
this->uid_ = uid;
|
||||
this->tag_type_ = tag_type;
|
||||
this->ndef_message_ = ndef_message;
|
||||
this->ndef_message_ = std::move(ndef_message);
|
||||
};
|
||||
NfcTag(std::vector<uint8_t> &uid, const std::string &tag_type, std::vector<uint8_t> &ndef_data) {
|
||||
this->uid_ = uid;
|
||||
this->tag_type_ = tag_type;
|
||||
this->ndef_message_ = new NdefMessage(ndef_data);
|
||||
this->ndef_message_ = make_unique<NdefMessage>(ndef_data);
|
||||
};
|
||||
NfcTag(const NfcTag &rhs) {
|
||||
uid_ = rhs.uid_;
|
||||
tag_type_ = rhs.tag_type_;
|
||||
if (rhs.ndef_message_ != nullptr)
|
||||
ndef_message_ = make_unique<NdefMessage>(*rhs.ndef_message_);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> &get_uid() { return this->uid_; };
|
||||
const std::string &get_tag_type() { return this->tag_type_; };
|
||||
bool has_ndef_message() { return this->ndef_message_ != nullptr; };
|
||||
NdefMessage *get_ndef_message() { return this->ndef_message_; };
|
||||
void set_ndef_message(NdefMessage *ndef_message) { this->ndef_message_ = ndef_message; };
|
||||
const std::unique_ptr<NdefMessage> &get_ndef_message() { return this->ndef_message_; };
|
||||
void set_ndef_message(std::unique_ptr<NdefMessage> ndef_message) { this->ndef_message_ = std::move(ndef_message); };
|
||||
|
||||
protected:
|
||||
std::vector<uint8_t> uid_;
|
||||
std::string tag_type_;
|
||||
NdefMessage *ndef_message_{nullptr};
|
||||
std::unique_ptr<NdefMessage> ndef_message_;
|
||||
};
|
||||
|
||||
} // namespace nfc
|
||||
|
Reference in New Issue
Block a user