Skip to content

Commit

Permalink
fix(core): follow clang-tidy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 26, 2023
1 parent a021941 commit 4305cf1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 85 deletions.
59 changes: 27 additions & 32 deletions core/include/cubos/core/reflection/external/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ CUBOS_REFLECT_EXTERNAL_TEMPLATE((typename K, typename V), (std::map<K, V>))
[](uintptr_t instance, bool writeable) -> void* {
if (writeable)
{
return new Map::iterator(reinterpret_cast<Map*>(instance)->begin());
}
else
{
return new Map::const_iterator(reinterpret_cast<const Map*>(instance)->cbegin());
return new typename Map::iterator(reinterpret_cast<Map*>(instance)->begin());
}

return new typename Map::const_iterator(reinterpret_cast<const Map*>(instance)->cbegin());

} /*begin*/,
[](uintptr_t instance, const void* key, bool writeable) -> void* {
if (writeable)
Expand All @@ -35,59 +34,55 @@ CUBOS_REFLECT_EXTERNAL_TEMPLATE((typename K, typename V), (std::map<K, V>))
{
return nullptr;
}
return new Map::iterator(it);
return new typename Map::iterator(it);
}
else
{
auto it = reinterpret_cast<const Map*>(instance)->find(*reinterpret_cast<const K*>(key));

auto it = reinterpret_cast<const Map*>(instance)->find(*reinterpret_cast<const K*>(key));
if (it == reinterpret_cast<const Map*>(instance)->end())

Check warning on line 41 in core/include/cubos/core/reflection/external/map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/map.hpp#L40-L41

Added lines #L40 - L41 were not covered by tests
{
return nullptr;

Check warning on line 43 in core/include/cubos/core/reflection/external/map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/map.hpp#L43

Added line #L43 was not covered by tests
}
return new Map::const_iterator(it);
}
return new typename Map::const_iterator(it);

Check warning on line 45 in core/include/cubos/core/reflection/external/map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/map.hpp#L45

Added line #L45 was not covered by tests

} /*find*/,
[](uintptr_t instance, void* iterator, bool writeable) -> bool {
if (writeable)
{
++*static_cast<Map::iterator*>(iterator);
return *static_cast<Map::iterator*>(iterator) != reinterpret_cast<Map*>(instance)->end();
}
else
{
++*static_cast<Map::const_iterator*>(iterator);
return *static_cast<Map::const_iterator*>(iterator) != reinterpret_cast<const Map*>(instance)->cend();
++*static_cast<typename Map::iterator*>(iterator);
return *static_cast<typename Map::iterator*>(iterator) != reinterpret_cast<Map*>(instance)->end();
}

++*static_cast<typename Map::const_iterator*>(iterator);
return *static_cast<typename Map::const_iterator*>(iterator) != reinterpret_cast<const Map*>(instance)->cend();

} /*advance*/,
[](void* iterator, bool writeable) {
if (writeable)
{
delete static_cast<Map::iterator*>(iterator);
delete static_cast<typename Map::iterator*>(iterator);
}
else
{
delete static_cast<Map::const_iterator*>(iterator);
delete static_cast<typename Map::const_iterator*>(iterator);

Check warning on line 66 in core/include/cubos/core/reflection/external/map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/map.hpp#L66

Added line #L66 was not covered by tests
}
} /*stop*/,
[](const void* iterator, bool writeable) -> const void* {
if (writeable)
{
return &(*static_cast<const Map::iterator*>(iterator))->first;
}
else
{
return &(*static_cast<const Map::const_iterator*>(iterator))->first;
return &(*static_cast<const typename Map::iterator*>(iterator))->first;
}

return &(*static_cast<const typename Map::const_iterator*>(iterator))->first;

Check warning on line 75 in core/include/cubos/core/reflection/external/map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/map.hpp#L75

Added line #L75 was not covered by tests

} /*key*/,
[](const void* iterator, bool writeable) -> uintptr_t {
if (writeable)
{
return reinterpret_cast<uintptr_t>(&(*static_cast<const Map::iterator*>(iterator))->second);
}
else
{
return reinterpret_cast<uintptr_t>(&(*static_cast<const Map::const_iterator*>(iterator))->second);
return reinterpret_cast<uintptr_t>(&(*static_cast<const typename Map::iterator*>(iterator))->second);
}

return reinterpret_cast<uintptr_t>(&(*static_cast<const typename Map::const_iterator*>(iterator))->second);

Check warning on line 84 in core/include/cubos/core/reflection/external/map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/map.hpp#L84

Added line #L84 was not covered by tests

} /*value*/);

// We supply the insert functions depending on the constructibility of the value type.
Expand Down Expand Up @@ -118,11 +113,11 @@ CUBOS_REFLECT_EXTERNAL_TEMPLATE((typename K, typename V), (std::map<K, V>))
auto* map = static_cast<Map*>(instance);
if (writeable)
{
map->erase(*static_cast<const Map::iterator*>(iterator));
map->erase(*static_cast<const typename Map::iterator*>(iterator));
}
else
{
map->erase(*static_cast<const Map::const_iterator*>(iterator));
map->erase(*static_cast<const typename Map::const_iterator*>(iterator));

Check warning on line 120 in core/include/cubos/core/reflection/external/map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/map.hpp#L120

Added line #L120 was not covered by tests
}
});

Expand Down
59 changes: 27 additions & 32 deletions core/include/cubos/core/reflection/external/unordered_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ CUBOS_REFLECT_EXTERNAL_TEMPLATE((typename K, typename V), (std::unordered_map<K,
[](uintptr_t instance, bool writeable) -> void* {
if (writeable)
{
return new Map::iterator(reinterpret_cast<Map*>(instance)->begin());
}
else
{
return new Map::const_iterator(reinterpret_cast<const Map*>(instance)->cbegin());
return new typename Map::iterator(reinterpret_cast<Map*>(instance)->begin());
}

return new typename Map::const_iterator(reinterpret_cast<const Map*>(instance)->cbegin());

} /*begin*/,
[](uintptr_t instance, const void* key, bool writeable) -> void* {
if (writeable)
Expand All @@ -35,59 +34,55 @@ CUBOS_REFLECT_EXTERNAL_TEMPLATE((typename K, typename V), (std::unordered_map<K,
{
return nullptr;
}
return new Map::iterator(it);
return new typename Map::iterator(it);
}
else
{
auto it = reinterpret_cast<const Map*>(instance)->find(*reinterpret_cast<const K*>(key));

auto it = reinterpret_cast<const Map*>(instance)->find(*reinterpret_cast<const K*>(key));
if (it == reinterpret_cast<const Map*>(instance)->end())

Check warning on line 41 in core/include/cubos/core/reflection/external/unordered_map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/unordered_map.hpp#L40-L41

Added lines #L40 - L41 were not covered by tests
{
return nullptr;

Check warning on line 43 in core/include/cubos/core/reflection/external/unordered_map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/unordered_map.hpp#L43

Added line #L43 was not covered by tests
}
return new Map::const_iterator(it);
}
return new typename Map::const_iterator(it);

Check warning on line 45 in core/include/cubos/core/reflection/external/unordered_map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/unordered_map.hpp#L45

Added line #L45 was not covered by tests

} /*find*/,
[](uintptr_t instance, void* iterator, bool writeable) {
if (writeable)
{
++*static_cast<Map::iterator*>(iterator);
return *static_cast<Map::iterator*>(iterator) != reinterpret_cast<Map*>(instance)->end();
}
else
{
++*static_cast<Map::const_iterator*>(iterator);
return *static_cast<Map::const_iterator*>(iterator) != reinterpret_cast<const Map*>(instance)->cend();
++*static_cast<typename Map::iterator*>(iterator);
return *static_cast<typename Map::iterator*>(iterator) != reinterpret_cast<Map*>(instance)->end();
}

++*static_cast<typename Map::const_iterator*>(iterator);
return *static_cast<typename Map::const_iterator*>(iterator) != reinterpret_cast<const Map*>(instance)->cend();

} /*advance*/,
[](void* iterator, bool writeable) {
if (writeable)
{
delete static_cast<Map::iterator*>(iterator);
delete static_cast<typename Map::iterator*>(iterator);
}
else
{
delete static_cast<Map::const_iterator*>(iterator);
delete static_cast<typename Map::const_iterator*>(iterator);

Check warning on line 66 in core/include/cubos/core/reflection/external/unordered_map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/unordered_map.hpp#L66

Added line #L66 was not covered by tests
}
} /*stop*/,
[](const void* iterator, bool writeable) -> const void* {
if (writeable)
{
return &(*static_cast<const Map::iterator*>(iterator))->first;
}
else
{
return &(*static_cast<const Map::const_iterator*>(iterator))->first;
return &(*static_cast<const typename Map::iterator*>(iterator))->first;
}

return &(*static_cast<const typename Map::const_iterator*>(iterator))->first;

Check warning on line 75 in core/include/cubos/core/reflection/external/unordered_map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/unordered_map.hpp#L75

Added line #L75 was not covered by tests

} /*key*/,
[](const void* iterator, bool writeable) -> uintptr_t {
if (writeable)
{
return reinterpret_cast<uintptr_t>(&(*static_cast<const Map::iterator*>(iterator))->second);
}
else
{
return reinterpret_cast<uintptr_t>(&(*static_cast<const Map::const_iterator*>(iterator))->second);
return reinterpret_cast<uintptr_t>(&(*static_cast<const typename Map::iterator*>(iterator))->second);
}

return reinterpret_cast<uintptr_t>(&(*static_cast<const typename Map::const_iterator*>(iterator))->second);

Check warning on line 84 in core/include/cubos/core/reflection/external/unordered_map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/unordered_map.hpp#L84

Added line #L84 was not covered by tests

} /*value*/);

// We supply the insert functions depending on the constructibility of the value type.
Expand Down Expand Up @@ -118,11 +113,11 @@ CUBOS_REFLECT_EXTERNAL_TEMPLATE((typename K, typename V), (std::unordered_map<K,
auto* map = static_cast<Map*>(instance);
if (writeable)
{
map->erase(*static_cast<const Map::iterator*>(iterator));
map->erase(*static_cast<const typename Map::iterator*>(iterator));
}
else
{
map->erase(*static_cast<const Map::const_iterator*>(iterator));
map->erase(*static_cast<const typename Map::const_iterator*>(iterator));

Check warning on line 120 in core/include/cubos/core/reflection/external/unordered_map.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/reflection/external/unordered_map.hpp#L120

Added line #L120 was not covered by tests
}
});

Expand Down
4 changes: 2 additions & 2 deletions core/include/cubos/core/reflection/traits/dictionary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ namespace cubos::core::reflection

/// @brief Move constructs.
/// @param other Other iterator.
Iterator(Iterator&& other);
Iterator(Iterator&& other) noexcept ;

/// @brief Gets a pointer to the current key.
/// @note Aborts if @ref isNull() returns true.
Expand Down Expand Up @@ -270,7 +270,7 @@ namespace cubos::core::reflection

/// @brief Move constructs.
/// @param other Other iterator.
ConstIterator(ConstIterator&& other);
ConstIterator(ConstIterator&& other) noexcept ;

/// @brief Gets a pointer to the current key.
/// @note Aborts if @ref isNull() returns true.
Expand Down
2 changes: 1 addition & 1 deletion core/samples/reflection/traits/dictionary/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ int main()
// 4 -> 8
/// [Expected output]
}
/// [Usage]
/// [Usage]
36 changes: 18 additions & 18 deletions core/src/cubos/core/reflection/traits/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ DictionaryTrait::ConstIterator DictionaryTrait::find(const void* instance, const

bool DictionaryTrait::insertDefault(void* instance, const void* key) const
{
if (mInsertDefault)
if (mInsertDefault != nullptr)
{
mInsertDefault(instance, key);
return true;
Expand All @@ -94,7 +94,7 @@ bool DictionaryTrait::insertDefault(void* instance, const void* key) const

bool DictionaryTrait::insertCopy(void* instance, const void* key, const void* value) const
{
if (mInsertCopy)
if (mInsertCopy != nullptr)
{
mInsertCopy(instance, key, value);
return true;
Expand All @@ -105,7 +105,7 @@ bool DictionaryTrait::insertCopy(void* instance, const void* key, const void* va

bool DictionaryTrait::insertMove(void* instance, const void* key, void* value) const
{
if (mInsertMove)
if (mInsertMove != nullptr)
{
mInsertMove(instance, key, value);
return true;
Expand All @@ -118,7 +118,7 @@ bool DictionaryTrait::erase(void* instance, Iterator& iterator) const
{
CUBOS_ASSERT(!iterator.isNull(), "Cannot erase null iterator");

if (mErase)
if (mErase != nullptr)
{
mErase(instance, iterator.mInner, true);
mStop(iterator.mInner, true);
Expand All @@ -133,7 +133,7 @@ bool DictionaryTrait::erase(void* instance, ConstIterator& iterator) const
{
CUBOS_ASSERT(!iterator.isNull(), "Cannot erase null iterator");

Check warning on line 134 in core/src/cubos/core/reflection/traits/dictionary.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/reflection/traits/dictionary.cpp#L134

Added line #L134 was not covered by tests

if (mErase)
if (mErase != nullptr)

Check warning on line 136 in core/src/cubos/core/reflection/traits/dictionary.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/reflection/traits/dictionary.cpp#L136

Added line #L136 was not covered by tests
{
mErase(instance, iterator.mInner, false);
mStop(iterator.mInner, false);
Expand All @@ -146,34 +146,34 @@ bool DictionaryTrait::erase(void* instance, ConstIterator& iterator) const

bool DictionaryTrait::hasInsertDefault() const
{
return mInsertDefault;
return mInsertDefault != nullptr;
}

bool DictionaryTrait::hasInsertCopy() const
{
return mInsertCopy;
return mInsertCopy != nullptr;
}

bool DictionaryTrait::hasInsertMove() const
{
return mInsertMove;
return mInsertMove != nullptr;
}

bool DictionaryTrait::hasErase() const

Check warning on line 162 in core/src/cubos/core/reflection/traits/dictionary.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/reflection/traits/dictionary.cpp#L162

Added line #L162 was not covered by tests
{
return mErase;
return mErase != nullptr;

Check warning on line 164 in core/src/cubos/core/reflection/traits/dictionary.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/reflection/traits/dictionary.cpp#L164

Added line #L164 was not covered by tests
}

DictionaryTrait::Iterator::~Iterator()
{
if (mInner)
if (mInner != nullptr)
{
mTrait.mStop(mInner, true);

Check warning on line 171 in core/src/cubos/core/reflection/traits/dictionary.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/reflection/traits/dictionary.cpp#L171

Added line #L171 was not covered by tests
}
}

DictionaryTrait::Iterator::Iterator(void* iterator, void* instance, const DictionaryTrait& trait)
: mInner(iterator)
DictionaryTrait::Iterator::Iterator(void* inner, void* instance, const DictionaryTrait& trait)
: mInner(inner)
, mInstance(instance)
, mTrait(trait)
{
Expand All @@ -191,7 +191,7 @@ DictionaryTrait::Iterator::Iterator(const Iterator& other)
}

DictionaryTrait::Iterator::Iterator(Iterator&& other)
: mInner(other.mInner)
noexcept : mInner(other.mInner)
, mInstance(other.mInstance)
, mTrait(other.mTrait)

Check warning on line 196 in core/src/cubos/core/reflection/traits/dictionary.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/reflection/traits/dictionary.cpp#L193-L196

Added lines #L193 - L196 were not covered by tests
{
Expand Down Expand Up @@ -230,14 +230,14 @@ bool DictionaryTrait::Iterator::isNull() const

DictionaryTrait::ConstIterator::~ConstIterator()
{
if (mInner)
if (mInner != nullptr)
{
mTrait.mStop(mInner, false);

Check warning on line 235 in core/src/cubos/core/reflection/traits/dictionary.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/reflection/traits/dictionary.cpp#L235

Added line #L235 was not covered by tests
}
}

DictionaryTrait::ConstIterator::ConstIterator(void* iterator, const void* instance, const DictionaryTrait& trait)
: mInner(iterator)
DictionaryTrait::ConstIterator::ConstIterator(void* inner, const void* instance, const DictionaryTrait& trait)
: mInner(inner)
, mInstance(instance)
, mTrait(trait)
{
Expand All @@ -255,7 +255,7 @@ DictionaryTrait::ConstIterator::ConstIterator(const ConstIterator& other)
}

DictionaryTrait::ConstIterator::ConstIterator(ConstIterator&& other)
: mInner(other.mInner)
noexcept : mInner(other.mInner)
, mInstance(other.mInstance)
, mTrait(other.mTrait)

Check warning on line 260 in core/src/cubos/core/reflection/traits/dictionary.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/cubos/core/reflection/traits/dictionary.cpp#L257-L260

Added lines #L257 - L260 were not covered by tests
{
Expand Down Expand Up @@ -290,4 +290,4 @@ bool DictionaryTrait::ConstIterator::advance()
bool DictionaryTrait::ConstIterator::isNull() const
{
return mInner == nullptr;
}
}

0 comments on commit 4305cf1

Please sign in to comment.