Skip to content

Commit

Permalink
feat(reflection): add clear to dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Nov 12, 2023
1 parent 24cfdaa commit 0b411f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/include/cubos/core/reflection/traits/dictionary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ namespace cubos::core::reflection
/// @param iterator Iterator.
void erase(Iterator& iterator) const;

/// @copydoc erase(Iterator&) const
void erase(Iterator&& iterator) const;

/// @brief Clears the dictionary.
/// @note Aborts if @ref DictionaryTrait::hasErase() returns false.
void clear() const;

private:
const DictionaryTrait& mTrait;
void* mInstance;
Expand Down
15 changes: 15 additions & 0 deletions core/src/cubos/core/reflection/traits/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ void DictionaryTrait::View::erase(Iterator& iterator) const
iterator.mInner = nullptr;
}

void DictionaryTrait::View::erase(Iterator&& iterator) const
{
this->erase(iterator);
}

void DictionaryTrait::View::clear() const
{
// This really inefficient, but if it ever becomes a problem its easy to improve, we could just
// add yet another function pointer to the trait, which each dictionary type sets.
while (this->length() > 0)
{
this->erase(this->begin());
}
}

DictionaryTrait::ConstView::ConstView(const DictionaryTrait& trait, const void* instance)
: mTrait(trait)
, mInstance(instance)
Expand Down

0 comments on commit 0b411f1

Please sign in to comment.