From 8f91c37d6bc87f1109084c55d70aac9695e33d30 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Tue, 16 Apr 2024 12:08:20 +0100 Subject: [PATCH] Make improvements suggested by clang-tidy --- src/include/FlashString/Object.hpp | 11 ++++++++++- src/include/FlashString/ObjectBase.hpp | 1 + src/include/FlashString/ObjectIterator.hpp | 13 ++++++++++--- src/include/FlashString/Stream.hpp | 2 +- src/include/FlashString/String.hpp | 1 + src/include/FlashString/StringPrinter.hpp | 9 +++++++++ src/include/FlashString/Vector.hpp | 8 ++++++-- 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/include/FlashString/Object.hpp b/src/include/FlashString/Object.hpp index 310229a..43c38b0 100644 --- a/src/include/FlashString/Object.hpp +++ b/src/include/FlashString/Object.hpp @@ -148,6 +148,14 @@ template class Object : public ObjectBa { } + ~Object() + { + } + + Object(const Object&& obj) = delete; + Object& operator=(const Object& other) = delete; + Object& operator=(const Object&& other) = delete; + Iterator begin() const { return Iterator(as(), 0); @@ -181,7 +189,7 @@ template class Object : public ObjectBa auto len = self.length(); for(unsigned i = 0; i < len; ++i) { if(self.unsafeValueAt(dataptr, i) == value) { - return i; + return int(i); } } @@ -208,6 +216,7 @@ template class Object : public ObjectBa FSTR_INLINE DataPtrType data() const { + // NOLINTNEXTLINE return reinterpret_cast(ObjectBase::data()); } diff --git a/src/include/FlashString/ObjectBase.hpp b/src/include/FlashString/ObjectBase.hpp index a8217d5..d96b8f6 100644 --- a/src/include/FlashString/ObjectBase.hpp +++ b/src/include/FlashString/ObjectBase.hpp @@ -41,6 +41,7 @@ class ObjectBase return 0; } if(isCopy()) { + // NOLINTNEXTLINE return reinterpret_cast(flashLength_ & ~copyBit)->length(); } return flashLength_; diff --git a/src/include/FlashString/ObjectIterator.hpp b/src/include/FlashString/ObjectIterator.hpp index 5c4ab63..81fe198 100644 --- a/src/include/FlashString/ObjectIterator.hpp +++ b/src/include/FlashString/ObjectIterator.hpp @@ -36,12 +36,19 @@ template class ObjectIterator ObjectIterator() = default; ObjectIterator(const ObjectIterator&) = default; + ObjectIterator(ObjectIterator&&) = default; + ObjectIterator& operator=(const ObjectIterator&) = default; + ObjectIterator& operator=(ObjectIterator&&) = default; ObjectIterator(const ObjectType& object, unsigned index) : data(pointer(object.data())), length(object.length()), index(index) { } + ~ObjectIterator() + { + } + ObjectIterator& operator++() { ++index; @@ -93,9 +100,9 @@ template class ObjectIterator } private: - const pointer data; - size_t length; - unsigned index = 0; + pointer data{}; + size_t length{0}; + unsigned index{0}; }; } // namespace FSTR diff --git a/src/include/FlashString/Stream.hpp b/src/include/FlashString/Stream.hpp index 8d03e21..a79ca87 100644 --- a/src/include/FlashString/Stream.hpp +++ b/src/include/FlashString/Stream.hpp @@ -54,7 +54,7 @@ class Stream : public IDataSourceStream */ int available() override { - return object.length() - readPos; + return int(object.length() - readPos); } uint16_t readMemoryBlock(char* data, int bufSize) override; diff --git a/src/include/FlashString/String.hpp b/src/include/FlashString/String.hpp index 1e46405..2e837fd 100644 --- a/src/include/FlashString/String.hpp +++ b/src/include/FlashString/String.hpp @@ -187,6 +187,7 @@ class String : public Object */ flash_string_t data() const { + // NOLINTNEXTLINE return reinterpret_cast(Object::data()); } diff --git a/src/include/FlashString/StringPrinter.hpp b/src/include/FlashString/StringPrinter.hpp index 06975a1..60d7c48 100644 --- a/src/include/FlashString/StringPrinter.hpp +++ b/src/include/FlashString/StringPrinter.hpp @@ -38,6 +38,15 @@ class StringPrinter { } + StringPrinter(const StringPrinter&) = delete; + StringPrinter(StringPrinter&&) = delete; + StringPrinter& operator=(const StringPrinter&) = delete; + StringPrinter& operator=(StringPrinter&&) = delete; + + ~StringPrinter() + { + } + size_t printTo(Print& p) const; private: diff --git a/src/include/FlashString/Vector.hpp b/src/include/FlashString/Vector.hpp index 4763495..cc3665f 100644 --- a/src/include/FlashString/Vector.hpp +++ b/src/include/FlashString/Vector.hpp @@ -97,7 +97,7 @@ FSTR_CONSTEXPR const struct { \ FSTR::ObjectBase object; \ const ObjectType* data[size]; \ - } name PROGMEM = {{sizeof(name.data)}, __VA_ARGS__}; \ + } name PROGMEM = {{sizeof(name.data)}, {__VA_ARGS__}}; \ FSTR_CHECK_STRUCT(name); namespace FSTR @@ -111,7 +111,11 @@ template class Vector : public Object, con public: using DataPtrType = const ObjectType* const*; - using Object, const ObjectType*>::indexOf; + template + typename std::enable_if::value, int>::type indexOf(const ValueType& value) const + { + return Object, const ObjectType*>::indexOf(value); + } template typename std::enable_if::value, int>::type indexOf(const char* value,