Skip to content

Commit

Permalink
Make improvements suggested by clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Apr 21, 2024
1 parent d32e12d commit 8f91c37
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/include/FlashString/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ template <class ObjectType, typename ElementType> 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<ObjectType>(), 0);
Expand Down Expand Up @@ -181,7 +189,7 @@ template <class ObjectType, typename ElementType> 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);
}
}

Expand All @@ -208,6 +216,7 @@ template <class ObjectType, typename ElementType> class Object : public ObjectBa

FSTR_INLINE DataPtrType data() const
{
// NOLINTNEXTLINE
return reinterpret_cast<DataPtrType>(ObjectBase::data());
}

Expand Down
1 change: 1 addition & 0 deletions src/include/FlashString/ObjectBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ObjectBase
return 0;
}
if(isCopy()) {
// NOLINTNEXTLINE
return reinterpret_cast<const ObjectBase*>(flashLength_ & ~copyBit)->length();
}
return flashLength_;
Expand Down
13 changes: 10 additions & 3 deletions src/include/FlashString/ObjectIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ template <class ObjectType, typename ElementType> 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;
Expand Down Expand Up @@ -93,9 +100,9 @@ template <class ObjectType, typename ElementType> class ObjectIterator
}

private:
const pointer data;
size_t length;
unsigned index = 0;
pointer data{};
size_t length{0};
unsigned index{0};
};

} // namespace FSTR
2 changes: 1 addition & 1 deletion src/include/FlashString/Stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/include/FlashString/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class String : public Object<String, char>
*/
flash_string_t data() const
{
// NOLINTNEXTLINE
return reinterpret_cast<flash_string_t>(Object::data());
}

Expand Down
9 changes: 9 additions & 0 deletions src/include/FlashString/StringPrinter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions src/include/FlashString/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -111,7 +111,11 @@ template <class ObjectType> class Vector : public Object<Vector<ObjectType>, con
public:
using DataPtrType = const ObjectType* const*;

using Object<Vector<ObjectType>, const ObjectType*>::indexOf;
template <typename ValueType, typename T = ObjectType>
typename std::enable_if<!std::is_same<T, String>::value, int>::type indexOf(const ValueType& value) const
{
return Object<Vector<ObjectType>, const ObjectType*>::indexOf(value);
}

template <typename T = ObjectType>
typename std::enable_if<std::is_same<T, String>::value, int>::type indexOf(const char* value,
Expand Down

0 comments on commit 8f91c37

Please sign in to comment.