Skip to content

Commit

Permalink
fix(core): follow clang-tidy suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
RiscadoA and github-actions[bot] committed Sep 27, 2023
1 parent 185e053 commit cf27f8d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/include/cubos/core/reflection/traits/fields.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace cubos::core::reflection

/// @brief Move constructs.
/// @param other Other trait.
FieldsTrait(FieldsTrait&& other);
FieldsTrait(FieldsTrait&& other) noexcept ;

/// @brief Adds a field to the type. The getter will be deleted using `delete` and thus
/// must be allocated using `new`.
Expand Down Expand Up @@ -176,7 +176,7 @@ namespace cubos::core::reflection

/// @brief Gets an iterator which represents the end of the field list of a type.
/// @return Iterator.
Iterator end() const;
static Iterator end();

private:
Field* mFirstField;
Expand Down
2 changes: 1 addition & 1 deletion core/samples/reflection/traits/fields/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main()
/// [Accessing the trait]

/// [Iterating over fields]
for (auto& field : fields)
for (const auto& field : fields)
{
CUBOS_INFO("Field '{}' of type '{}'", field.name(), field.type().name());
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/cubos/core/reflection/traits/fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FieldsTrait::FieldsTrait()
}

FieldsTrait::FieldsTrait(FieldsTrait&& other)
: mFirstField(other.mFirstField)
noexcept : mFirstField(other.mFirstField)
, mLastField(other.mLastField)
{
other.mFirstField = nullptr;
Expand All @@ -87,23 +87,23 @@ FieldsTrait::FieldsTrait(FieldsTrait&& other)

FieldsTrait::~FieldsTrait()
{
while (mFirstField)
while (mFirstField != nullptr)
{
auto next = mFirstField->mNext;
auto *next = mFirstField->mNext;
delete mFirstField;
mFirstField = next;
}
}

FieldsTrait&& FieldsTrait::withField(const Type& type, std::string name, AddressOf* addressOf) &&
{
for (auto field = mFirstField; field; field = field->mNext)
for (auto *field = mFirstField; field != nullptr; field = field->mNext)
{
CUBOS_ASSERT(field->mName != name, "Field '{}' already exists", name);
}

auto field = new Field(type, std::move(name), addressOf);
if (mFirstField)
auto *field = new Field(type, std::move(name), addressOf);
if (mFirstField != nullptr)
{
mLastField->mNext = field;
mLastField = field;
Expand All @@ -119,7 +119,7 @@ FieldsTrait&& FieldsTrait::withField(const Type& type, std::string name, Address

const FieldsTrait::Field* FieldsTrait::field(const std::string& name) const
{
for (auto field = mFirstField; field; field = field->mNext)
for (auto *field = mFirstField; field != nullptr; field = field->mNext)
{
if (field->mName == name)
{
Expand All @@ -136,7 +136,7 @@ FieldsTrait::Iterator FieldsTrait::begin() const
return Iterator{mFirstField};
}

FieldsTrait::Iterator FieldsTrait::end() const
FieldsTrait::Iterator FieldsTrait::end()
{
return Iterator{nullptr};
}
6 changes: 3 additions & 3 deletions core/tests/reflection/traits/fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TEST_CASE("reflection::FieldsTrait")
{
auto fields = FieldsTrait().withField("foo", &ObjectType::foo);

auto field = fields.field("foo");
const auto *field = fields.field("foo");
REQUIRE(field != nullptr);
CHECK(field == &*fields.begin());
CHECK(++fields.begin() == fields.end());
Expand All @@ -49,11 +49,11 @@ TEST_CASE("reflection::FieldsTrait")
{
auto fields = FieldsTrait().withField("foo", &ObjectType::foo).withField("bar", &ObjectType::bar);

auto fooField = fields.field("foo");
const auto *fooField = fields.field("foo");
REQUIRE(fooField != nullptr);
CHECK(fooField == &*fields.begin());

auto barField = fields.field("bar");
const auto *barField = fields.field("bar");
REQUIRE(barField != nullptr);
CHECK(barField == &*(++fields.begin()));
CHECK(++(++fields.begin()) == fields.end());
Expand Down

0 comments on commit cf27f8d

Please sign in to comment.