Commit 72dbc071 authored by David Thompson's avatar David Thompson
Browse files

WIP: Removal of assigned IDs from ID space upon destruction.

parent 125e6efb
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
#include "smtk/markup/AssignedIds.h"
#include "smtk/markup/IdSpace.h"
namespace smtk
{
namespace markup
{
AssignedIds::~AssignedIds() = default;
AssignedIds::~AssignedIds()
{
// Always remove ourselves from our containing IdSpace.
if (auto idspace = m_space.lock())
{
idspace->removeEntry(*this);
}
}
AssignedIds::IdRange AssignedIds::range() const
{
......
......@@ -202,9 +202,14 @@ IdSpace::IdType IdSpace::numberOfIdsInRangeOfNature(IdType begin, IdType end, Na
return count;
}
bool IdSpace::removeEntry(AssignedIds& entry)
bool IdSpace::removeEntry(const AssignedIds& entry)
{
return false;
auto* entryPointer = const_cast<AssignedIds*>(&entry);
auto span = std::make_pair(
discrete_interval<IdType>::right_open(entry.range()[0], entry.range()[1]),
std::set<AssignedIds*>{ entryPointer });
m_entries -= span;
return true;
}
std::array<IdSpace::IdType, 2> IdSpace::clampedRange(
......
......@@ -142,7 +142,7 @@ protected:
friend class AssignedIds;
/// This method is called by the AssignedIds destructor to unregister itself from m_entries.
bool removeEntry(AssignedIds& entry);
bool removeEntry(const AssignedIds& entry);
static std::array<IdSpace::IdType, 2> clampedRange(
const std::array<IdType, 2>& unclamped,
......
......@@ -101,5 +101,13 @@ int TestIds(int argc, char** argv)
test(primary3->range()[0] == 21, "Expected second range to start at 21.");
test(primary3->range()[1] == 31, "Expected second range to end at 31.");
// Now verify that deleting assigned IDs removes them from the id-space.
reference2 = nullptr; // This should cause the assigned IDs to be destroyed.
nn = pointIds->numberOfIdsInRangeOfNature(1, 31, Nature::Referential);
std::cout << nn << " referential IDs in [1,31[ after removing reference2.\n";
test(nn == 10, "Expected 10 referential IDs.");
// TODO: Warn or fail if referential entries would remain in a range when
// removing primary or non-exclusive entries.
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment