SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
A numbering used in a context. More...
#include <IdSpace.h>
Public Types | |
using | IdType = smtk::markup::IdType |
The plain-old-data type used to hold an identifier. | |
using | IntervalTree = boost::icl::split_interval_map< IdType, std::set< AssignedIds * > > |
The search structure used to index assignments in the space of IDs. | |
using | IntervalMerge = boost::icl::interval_set< IdType > |
A structure that simplifies determining whether assignments cover a range. | |
using | AssignedIdCtor = std::function< std::shared_ptr< AssignedIds >(const std::shared_ptr< IdSpace > &, IdNature, IdType, IdType)> |
Signature of a function to create an assigned-IDs object. | |
Public Member Functions | |
smtkTypeMacro (smtk::markup::IdSpace) | |
smtkSuperclassMacro (smtk::markup::Domain) | |
IdSpace (smtk::string::Token name) | |
IdSpace (const nlohmann::json &data) | |
const std::array< IdSpace::IdType, 2 > & | range () const |
std::array< IdSpace::IdType, 2 > & | range () |
std::shared_ptr< AssignedIds > | requestRange (IdNature nature, std::size_t rangeSize, std::size_t offset=Invalid, AssignedIdCtor ctor=&IdSpace::defaultAssignment) |
Request access to or control of a range of IDs. More... | |
void | insertAssignment (const AssignedIds *assignedIds) |
Insert assigned IDs into the space without checks. More... | |
std::set< std::shared_ptr< AssignedIds > > | assignedIds (IdType begin, IdType end, IdNature nature=IdNature::Unassigned) const |
Return all ID assignments of the given nature overlapping [ begin , end [. More... | |
bool | isRangeEmpty (IdType begin, IdType end, IdNature allowed=IdNature::Unassigned) const |
Test whether the half-open interval from begin to end has any assigned IDs. More... | |
bool | isRangeCovered (IdType begin, IdType end, IdNature allowed=IdNature::Unassigned) const |
Test whether the half-open interval from begin to end is covered by assigned IDs of the given nature. More... | |
bool | rangeHasPrimaryIds (IdType begin, IdType end) const |
If the half-open interval from begin to end has any primary IDs. | |
IdType | numberOfIdsInRangeOfNature (IdType begin, IdType end, IdNature nature=IdNature::Unassigned) const |
Return the number IDs in [ begin, end [ with one or more assignments of the given nature. More... | |
Public Member Functions inherited from smtk::markup::Domain | |
smtkTypeMacroBase (smtk::markup::Domain) | |
Domain (smtk::string::Token name) | |
Domain (const nlohmann::json &data) | |
smtk::string::Token | name () const |
Static Public Member Functions | |
static shared_ptr< AssignedIds > | defaultAssignment (const std::shared_ptr< IdSpace > &space, IdNature nature, IdType begin, IdType end) |
Create a default instance of AssignedIds from a specification. | |
Static Public Attributes | |
static constexpr IdType | Invalid = ~0ull |
A constant used to indicate an invalid ID. | |
Protected Member Functions | |
bool | removeEntry (const AssignedIds &entry) |
This method is called by the AssignedIds destructor to unregister itself from m_entries. | |
Static Protected Member Functions | |
static std::array< IdSpace::IdType, 2 > | clampedRange (const std::array< IdType, 2 > &unclamped, IdType begin, IdType end) |
Protected Attributes | |
std::array< IdSpace::IdType, 2 > | m_range { Invalid, Invalid } |
IntervalTree | m_entries |
A container to hold all the assigned IDs within the space. More... | |
Protected Attributes inherited from smtk::markup::Domain | |
smtk::string::Token | m_name |
Friends | |
class | AssignedIds |
A numbering used in a context.
Identifier spaces hold reservations of IDs assigned to components in a given context using a data structure that allows for fast queries across ranges of IDs.
Examples of id spaces include: node numbers, element numbers, side numbers, pedigree IDs, global IDs.
std::set< std::shared_ptr< AssignedIds > > smtk::markup::IdSpace::assignedIds | ( | IdType | begin, |
IdType | end, | ||
IdNature | nature = IdNature::Unassigned |
||
) | const |
Return all ID assignments of the given nature overlapping [ begin , end [.
If nature is Unassigned (the default), this returns all ID assignments regardless of their nature. Otherwise, only the requested subset is returned.
void smtk::markup::IdSpace::insertAssignment | ( | const AssignedIds * | assignedIds | ) |
Insert assigned IDs into the space without checks.
This method is only intended for deserialization. It accepts an externally-created assignedIds instance and adds it to the interval tree. It will only accept assignedIds if its ID space is a reference to this instance.
bool smtk::markup::IdSpace::isRangeCovered | ( | IdType | begin, |
IdType | end, | ||
IdNature | allowed = IdNature::Unassigned |
||
) | const |
Test whether the half-open interval from begin to end is covered by assigned IDs of the given nature.
If nature is Unassigned (the default), this returns true if the range is covered by any assignments at all and false otherwise.
If nature is Primary, then this returns true if the range is covered by any combination of Primary and NonExclusive assignments – and false otherwise.
If nature is NonExclusive, then this returns true if the range is covered by NonExclusive assignments and false othewise.
If nature is Referential, then this returns true if the range is covered by Referential assignments and false otherwise.
bool smtk::markup::IdSpace::isRangeEmpty | ( | IdType | begin, |
IdType | end, | ||
IdNature | allowed = IdNature::Unassigned |
||
) | const |
Test whether the half-open interval from begin to end has any assigned IDs.
If nature is Unassigned (the default), this returns true if the range has no assignments at all and false otherwise.
If nature is Primary, then this returns true if the range is empty of both Primary and NonExclusive assignments – and false otherwise.
If nature is NonExclusive, then this returns true if the range is empty of NonExclusive assignments and false othewise.
If nature is Referential, then this returns true if the range is empty of Referential assignments and false otherwise.
IdSpace::IdType smtk::markup::IdSpace::numberOfIdsInRangeOfNature | ( | IdType | begin, |
IdType | end, | ||
IdNature | nature = IdNature::Unassigned |
||
) | const |
Return the number IDs in [ begin, end [ with one or more assignments of the given nature.
If nature is IdNature::Unassigned, then the number returned counts IDs without any assignment.
std::shared_ptr< AssignedIds > smtk::markup::IdSpace::requestRange | ( | IdNature | nature, |
std::size_t | rangeSize, | ||
std::size_t | offset = Invalid , |
||
AssignedIdCtor | ctor = &IdSpace::defaultAssignment |
||
) |
Request access to or control of a range of IDs.
The nature of the request determines conditions under which the request may fail.
Upon failure, a null pointer is returned. Upon success, an instance of AssignedIds is constructed and a weak pointer is held by this IdSpace; a shared pointer is returned and must be held by the node using the requested IDs. When the node is deleted, the AssignedIds instance will be deleted and its destructor will remove it from this IdSpace instance.
The offset specifies the starting ID in the request. An offset must be provided for Referential requests. An offset may be provided for requests of other natures.
If offset is specified, then the request will fail if the range [offset, offset + rangeSize] does not meet the conditions required by nature. Otherwise, a starting value for the range will be chosen to satisfy the requirements if that is possible.
If a ctor (constructor) is specified, then it will be invoked to construct the output AssignedIds instance. This is used by discrete geometry subclasses (ImageData and UnstructuredData) to create SequentialAssignedIds or IndirectAssignedIds as needed so that they can provide reverse-lookups between IDs and the index of the corresponding primitive or point. Note that AssignedIds::node() will return a null pointer unless the ctor passes a a non-null value. The defaultAssignment does not.
|
protected |
A container to hold all the assigned IDs within the space.
The container is indexed by the lowest ID within the assignment.