12#ifndef ARCANE_CORE_ANYITEM_ANYITEMLINKFAMILY_H
13#define ARCANE_CORE_ANYITEM_ANYITEMLINKFAMILY_H
17#include "arcane/core/anyitem/AnyItemGlobal.h"
22namespace Arcane::AnyItem
31template <
typename U,
typename V>
44template <
typename U,
typename V>
77 friend class LinkFamilyInternal;
79#ifdef ARCANE_ANYITEM_USEPACKEDDATA
90 Integer localId()
const {
return (m_packed_data >> m_local_id_shift) & m_integer_mask; }
92 bool operator==(
const LinkData& data)
const {
return m_packed_data == data.m_packed_data; }
96 static const Integer m_integer_size = 26;
97 static const Int64 m_integer_mask = (
Int64(1) << m_integer_size) - 1;
98 static const Integer m_short_size = 8;
99 static const Int64 m_short_mask = (
Int64(1) << m_short_size) - 1;
100 static const Integer m_group_shift = 52;
101 static const Int64 m_group_mask = m_short_mask << m_group_shift;
102 static const Integer m_local_id_shift = m_integer_size;
103 static const Int64 m_local_id_mask = m_integer_mask << m_local_id_shift;
105 inline void setGroupIndex(
Integer group_index)
107 ARCANE_ASSERT(((group_index & ~m_short_mask) == 0), (
"Too large group index %d", group_index));
108 m_packed_data = (m_packed_data & ~m_group_mask) | (
Int64(group_index) << m_group_shift);
109 ARCANE_ASSERT((
groupIndex() == group_index), (
"Corrupted data write detected"));
111 inline void setLocalId(
Integer local_id)
113 ARCANE_ASSERT(((local_id & ~m_integer_mask) == 0), (
"Too large local id %d", local_id));
114 m_packed_data = (m_packed_data & ~m_local_id_mask) | (
Int64(local_id) << m_local_id_shift);
115 ARCANE_ASSERT((
localId() == local_id), (
"Corrupted data write detected"));
117 inline void setVarIndex(
Integer item_local_id)
119 ARCANE_ASSERT(((item_local_id & ~m_integer_mask) == 0), (
"Too large item local id %d", item_local_id));
120 m_packed_data = (m_packed_data & ~m_integer_mask) | item_local_id;
121 ARCANE_ASSERT((
varIndex() == item_local_id), (
"Corrupted data write detected"));
175 inline Integer index()
const {
return m_index; }
196 Enumerator(
const Enumerator& e)
201 inline bool hasNext()
const {
return m_sources.size() != m_index; }
202 inline void operator++() { m_index++; }
233 template <
typename U,
typename V>
245 ARCANE_ASSERT((
m_used ==
true), (
"LinkAdder never used"));
249 template <
typename R,
typename S>
252 ARCANE_ASSERT((
m_used ==
false), (
"VariableAdder already used"));
282 ARCANE_ASSERT((
m_used ==
true), (
"Link never used"));
286 template <
typename U,
typename V>
304 typedef std::set<ILinkFamilyObserver*> LinkFamilyObservers;
327 _notifyFamilyIsReserved();
340 _notifyFamilyIsReserved();
358 _notifyFamilyIsInvalidate();
364 LinkFamilyObservers::const_iterator it =
m_observers.find(&observer);
373 LinkFamilyObservers::const_iterator it =
m_observers.find(&observer);
384 _notifyFamilyIsInvalidate();
395 template <
typename T,
typename V>
402 template <
typename T,
typename V>
409 const LinkData& source(
const LinkIndex& link)
const
421 const Family& family()
const
469 template <
typename T>
473 ARCANE_ASSERT((info != 0), (
"Inconsistent group info while adding new node"));
474 data.setGroupIndex(info->group_index);
476 data.setLocalId(info->local_id_offset + local_index);
477 if (info->is_partial) {
479 data.setVarIndex(local_index);
482 data.setVarIndex(t.localId());
488 template <
typename T>
492 ARCANE_ASSERT((info != 0), (
"Inconsistent group info while adding new node"));
493 data.setGroupIndex(info->group_index);
495 data.setLocalId(info->local_id_offset + local_index);
496 if (info->is_partial) {
497 data.setVarIndex(local_index);
512 void _notifyFamilyIsInvalidate()
515 (*it)->notifyFamilyIsInvalidate();
518 void _notifyFamilyIsReserved()
521 (*it)->notifyFamilyIsReserved();
561 LinkFamily(
const Family& f)
565 LinkFamily(
const LinkFamily& f)
624 template <
typename T,
typename V>
630 template <
typename T,
typename V>
638 LinkFamilyInternal* internal()
const
AnyItem family (flyweight pattern) Aggregation of groups to describe variables / partial variables Co...
SharedPtrT< FamilyInternal > m_internal
Internal family.
void removeObserver(IFamilyObserver &observer) const
Remove an observer.
AnyItem family observer interface.
AnyItem link family observer interface.
const LinkData & front() const
Front link data.
const LinkData & back() const
Back link data.
const Arcane::Array< LinkData > & m_targets
All front data.
const Arcane::Array< LinkData > & m_sources
All back data.
Integer groupIndex() const
Identifier of the group associated with the item referenced by this LinkData.
Integer localId() const
LocalId identifier of the item referenced in its AnyItemFamily.
bool operator==(const LinkData &data) const
Comparison operator.
Integer varIndex() const
LocalId identifier of the item referenced in its original IItemFamily.
unsigned m_group_index
Index of the group from which this item comes.
Integer m_var_index
Index for partials, localId otherwise.
unsigned m_local_id
Identifier in the global indexing of AnyItem::Family.
LinkAdder< U, V > operator()(const ItemGroupT< U > &a, const ItemGroupT< V > &b)
Addition of links for groups a and b.
LinkFamilyInternal & m_family
Link family.
bool m_used
Indicator if the link is used.
Internal AnyItem Link Family The stored data are the local IDs of the items and the group offset with...
LinkFamilyObservers m_observers
Family observers.
void initLinkData(LinkData &data, const ItemEnumeratorT< T > &t, ItemGroupT< T > group) const
Adding link nodes by enumerators.
Arcane::UniqueArray< LinkData > m_source_nodes
Back data.
Integer m_nb_link
Number of links.
Integer capacity() const
returns the capacity
void notifyFamilyIsInvalidate()
Notifies that the family is invalidated.
void removeObserver(ILinkFamilyObserver &observer) const
Removes a family observer.
Enumerator enumerator() const
Link enumerators.
void clear()
Clears the family.
void reserve(Integer size)
Reserves a capacity of links.
void initLinkData(LinkData &data, const T &t, ItemGroupT< T > group) const
Adding link nodes by item type.
LinkFamilyInternal(const Family &family)
Link family for an anyitem family.
Arcane::UniqueArray< LinkData > m_target_nodes
Front data.
Link newLink()
Creation of a new empty link.
Item item(const LinkData &link_data) const
Returns the concrete item associated with this AnyItem.
void notifyFamilyIsIncreased()
Notifies the observer that the family has been increased.
void registerObserver(ILinkFamilyObserver &observer) const
Registers a family observer.
const Family m_family
AnyItem family.
void notifyFamilyIsInvalidate()
Notifies that the family is invalidated.
Enumerator enumerator() const
Link enumerators.
void clear()
Clears the family.
void notifyFamilyIsIncreased()
Notifies that the family is increased.
void registerObserver(ILinkFamilyObserver &observer) const
Registers a family observer.
void removeObserver(ILinkFamilyObserver &observer) const
Removes a family observer.
SharedPtrT< LinkFamilyInternal > m_internal
Internal link family.
Integer capacity() const
returns the capacity
Link newLink()
Creation of a new empty link.
void reserve(Integer size)
Reserves a capacity of links.
Tool to create a pair of items.
Base class for 1D data vectors.
Exception when a fatal error has occurred.
Reference to a group of a given kind.
SharedPtrT< GroupIndexTable > localIdToIndex() const
Table of local ids to a position for all entities in the group.
Base class for a mesh element.
1D data vector with value semantics (STL style).
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
void arcaneCallFunctionAndTerminateIfThrow(std::function< void()> function)
Calls the function function and calls std::terminate() if an exception occurs.
ItemGroupT< U > m_a
Back group.
ItemGroupT< V > m_b
Front group.
void operator<<(const PairT< R, S > &p)
Addition of an item pair.
LinkFamilyInternal & m_family
Link family.
bool m_used
Indicator if the adder is used.