Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
AnyItemGroup.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* AnyItemGroup.h (C) 2000-2025 */
9/* */
10/* Aggregated group of arbitrary types. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ANYITEM_ANYITEMGROUP_H
13#define ARCANE_CORE_ANYITEM_ANYITEMGROUP_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include <map>
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22#include "arcane/core/ItemGroup.h"
23#include "arcane/core/ItemInfoListView.h"
24#include "arcane/core/anyitem/AnyItemGlobal.h"
25#include "arcane/core/anyitem/AnyItemPrivate.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane::AnyItem
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36/*
37 * NB: It must be known very early whether we are iterating over a variable
38 * or a partial variable
39 *
40 */
41
45class GroupBuilder
46{
47 public:
48
49 GroupBuilder(ItemGroup g)
50 : m_group(g)
51 , m_is_partial(false)
52 {}
53 ItemGroup group() const { return m_group; }
54 bool isPartial() const { return m_is_partial; }
55
56 protected:
57
58 ItemGroup m_group;
59 bool m_is_partial;
60};
61
65class PartialGroupBuilder
66: public GroupBuilder
67{
68 public:
69
70 PartialGroupBuilder(ItemGroup g)
71 : GroupBuilder(g)
72 {
73 this->m_is_partial = true;
74 }
75};
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
85class Group
86{
87 static ItemInternal* _toInternal(const Item& v)
88 {
89 return ItemCompatibility::_itemInternal(v);
90 }
91
92 public:
93
100 class BlockItemEnumerator
101 {
102 private:
103
104 typedef ItemInternal* ItemInternalPtr;
105
106 public:
107
108 BlockItemEnumerator(const Private::GroupIndexInfo& info)
109 : m_info(info)
110 , m_items(m_info.group->itemInfoListView())
111 , m_local_ids(m_info.group->itemsLocalId().data())
112 , m_index(0)
113 , m_count(m_info.group->size())
114 , m_is_partial(info.is_partial)
115 {}
116
117 BlockItemEnumerator(const BlockItemEnumerator& e)
118 : m_info(e.m_info)
119 , m_items(e.m_items)
120 , m_local_ids(e.m_local_ids)
121 , m_index(e.m_index)
122 , m_count(e.m_count)
123 , m_is_partial(e.m_is_partial)
124 {}
125
127 Item operator*() const { return m_items[m_local_ids[m_index]]; }
128 // TODO: return an 'Item*' similar to ItemEnumerator.
130 ItemInternal* operator->() const { return Group::_toInternal(m_items[m_local_ids[m_index]]); }
132 inline void operator++() { ++m_index; }
134 inline bool hasNext() { return m_index < m_count; }
136 inline Integer count() const { return m_count; }
137
139 inline Integer varIndex() const { return (m_is_partial) ? m_index : m_local_ids[m_index]; }
140
142 inline Integer localId() const { return m_info.local_id_offset + m_index; }
143
145 inline Integer groupIndex() const { return m_info.group_index; }
146
148 inline ItemGroup group() const { return ItemGroup(m_info.group); }
149
150 private:
151
152 const Private::GroupIndexInfo& m_info;
153
154 ItemInfoListView m_items;
155 const Int32* ARCANE_RESTRICT m_local_ids;
156 Integer m_index;
157 Integer m_count;
158 bool m_is_partial;
159 };
160
164 class Enumerator
165 {
166 public:
167
168 Enumerator(const Private::GroupIndexMapping& groups)
169 : m_current(std::begin(groups))
170 , m_end(std::end(groups))
171 {}
172 Enumerator(const Enumerator& e)
173 : m_current(e.m_current)
174 , m_end(e.m_end)
175 {}
176 inline bool hasNext() const { return m_current != m_end; }
177 inline void operator++() { m_current++; }
180 {
181 return BlockItemEnumerator(*m_current);
182 }
183 inline Integer groupIndex() const { return m_current->group_index; }
184 ItemGroup group() const { return ItemGroup(m_current->group); }
185
186 private:
187
190 };
191
192 public:
193
196 : m_groups(groups)
197 {}
198
200 inline Enumerator enumerator() const
201 {
202 return Enumerator(m_groups);
203 }
204
206 inline Integer size() const
207 {
208 return m_groups.size();
209 }
210
211 //private:
212 public:
213
216};
217
218/*---------------------------------------------------------------------------*/
219/*---------------------------------------------------------------------------*/
220
221} // namespace Arcane::AnyItem
222
223/*---------------------------------------------------------------------------*/
224/*---------------------------------------------------------------------------*/
225
226#endif
Integer count() const
Number of elements in the enumerator.
ItemGroup group() const
Current underlying group.
Integer localId() const
localId() of the current entity.
Integer varIndex() const
localId() of the current entity.
Item operator*() const
Dereference to the associated Arcane item.
Integer groupIndex() const
Index in the current AnyItem::Family group.
ItemInternal * operator->() const
Indirect dereference to the associated Arcane item.
bool hasNext()
Test for end of enumerator.
void operator++()
Advancement of the enumerator.
Enumerator of item blocks.
BlockItemEnumerator enumerator()
Enumerator of an item block.
Group(const Private::GroupIndexMapping &groups)
Construction from a Group - offset table (from the family).
Integer size() const
Number of aggregated groups.
Enumerator enumerator() const
Enumerator of the group.
const Private::GroupIndexMapping & m_groups
Group - offset table.
Mesh entity group.
Definition ItemGroup.h:51
View of a list to obtain information about entities.
Internal structure of a mesh entity.
Base class for a mesh element.
Definition Item.h:84
ArrayIterator< const_pointer > const_iterator
Int32 Integer
Type representing an integer.
std::int32_t Int32
Signed integer type of 32 bits.