11#include <framework/datastore/StoreArray.h>
12#include <framework/datastore/RelationArray.h>
14#include <boost/multi_index_container.hpp>
15#include <boost/multi_index/ordered_index.hpp>
16#include <boost/multi_index/member.hpp>
81 typedef boost::multi_index::multi_index_container <
83 boost::multi_index::indexed_by <
84 boost::multi_index::ordered_non_unique <
85 boost::multi_index::member<Element, const FROM*, &Element::from>
87 boost::multi_index::ordered_non_unique <
88 boost::multi_index::member<Element, const TO*, &Element::to>
160 B2DEBUG(100,
"Relation " <<
m_storeRel.getName() <<
" does not exist, cannot build index");
169 if (!force && !
m_storeRel.getModified())
return;
171 B2DEBUG(100,
"Building index for " <<
m_storeRel.getName());
187 const unsigned int nRel =
m_storeRel.getEntries();
190 for (
unsigned int i = 0; i < nRel; ++i) {
193 if (idxFrom >= nFrom)
194 B2FATAL(
"Relation " <<
m_storeRel.getName() <<
" is inconsistent: from-index (" << idxFrom <<
") out of range");
195 const FROM* from = storeFrom[idxFrom];
198 const auto& indices = r.getToIndices();
199 const auto& weights = r.getWeights();
200 auto itIdx = indices.begin();
201 auto itWgt = weights.begin();
202 const auto& idxEnd = indices.end();
203 for (; itIdx != idxEnd; ++itIdx, ++itWgt) {
206 B2FATAL(
"Relation " <<
m_storeRel.getName() <<
" is inconsistent: to-index (" << idxTo <<
") out of range");
207 const TO* to = storeTo[idxTo];
Low-level class to create/modify relations between StoreArrays.
Class to store a single element of a relation.
unsigned int index_type
type used for indices.
float weight_type
type used for weights.
Baseclass for all RelationIndexContainers.
virtual void clear()=0
Clear the index (at the end of the event)
virtual ~RelationIndexBase()
Virtual destructor to create vtable.
const AccessorParams & getFromAccessorParams() const
Get the AccessorParams of the StoreArray the relation points from.
RelationIndexContainer(const RelationIndexContainer &)=delete
Restrict copies.
AccessorParams m_storeFrom
RelationIndexContainer(const RelationArray &relArray)
Constructor to create a new IndexContainer.
ElementIndex & index()
Get the index.
const AccessorParams & getToAccessorParams() const
Get the AccessorParams of the StoreArray the relation points to.
const ElementIndex & index() const
Get the index.
virtual void clear() override
Clear the index (at the end of an event)
RelationIndexContainer & operator=(const RelationIndexContainer &)=delete
Restrict copies.
AccessorParams getAccessorParams() const
Get the AccessorParams of the underlying relation.
boost::multi_index::multi_index_container< Element, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::member< Element, const FROM *, &Element::from > >, boost::multi_index::ordered_non_unique< boost::multi_index::member< Element, const TO *, &Element::to > > > > ElementIndex
friend class RelationIndexManager
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
void rebuild(bool force=false)
Rebuild the index.
std::pair< std::string, DataStore::EDurability > AccessorParams
Pair of parameters needed to find an object in the DataStore.
Abstract base class for different kinds of events.
Element type for the index.
const FROM * from
pointer of the element from which the relation points.
const TO * to
pointer of the element to which the relation points.
RelationElement::index_type indexTo
index of the element to which the relation points.
RelationElement::index_type indexFrom
index of the element from which the relation points.
RelationElement::weight_type weight
weight of the relation.
Element(RelationElement::index_type indexFrom_, RelationElement::index_type indexTo_, const FROM *from_, const TO *to_, RelationElement::weight_type weight_)
Create a new element.