Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
AnyItemUserGroup.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/* AnyItemUserGroup.h (C) 2000-2025 */
9/* */
10/* Aggregated user group of arbitrary types. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ANYITEM_ANYITEMUSERGROUP_H
13#define ARCANE_CORE_ANYITEM_ANYITEMUSERGROUP_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Exception.h"
18
19#include "arcane/core/anyitem/AnyItemGlobal.h"
20#include "arcane/core/anyitem/AnyItemPrivate.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::AnyItem
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
49class UserGroup
50: public Group
51, public IFamilyObserver
52{
53 private:
54
55 typedef Private::GroupIndexMapping GroupIndexMapping;
56
57 public:
58
59 UserGroup(const Family& family)
61 , m_family(family)
62 {
63 m_family.registerObserver(*this);
64 }
65
66 ~UserGroup()
67 {
68 arcaneCallFunctionAndTerminateIfThrow([&]() { m_family.removeObserver(*this); });
69 }
70
72 inline UserGroup& operator<<(GroupBuilder builder)
73 {
74 ItemGroup group = builder.group();
75 if (m_groups.findGroupInfo(group.internal()) != NULL)
76 throw FatalErrorException(String::format("Group '{0}' in user group already registered", group.name()));
77
78 const Private::GroupIndexInfo* info = m_family.internal()->findGroupInfo(group);
79 if (info == NULL)
80 throw FatalErrorException(String::format("Group '{0}' in user group not registered in family", group.name()));
81
82 if (builder.isPartial() != info->is_partial)
83 throw FatalErrorException(String::format("Group '{0}' in user group is not same in family", group.name()));
84
85 m_currents.add(*info);
86 return *this;
87 }
88
90 inline void clear()
91 {
92 m_currents.clear();
93 }
94
97 {
98 // If the family changes, the group is invalidated
99 clear();
100 }
101
104 {
105 // Nothing is done in this case
106 }
107
108 private:
109
112
114 GroupIndexMapping m_currents;
115};
116
117/*---------------------------------------------------------------------------*/
118/*---------------------------------------------------------------------------*/
119
120} // End namespace Arcane::AnyItem
121
122/*---------------------------------------------------------------------------*/
123/*---------------------------------------------------------------------------*/
124
125#endif
AnyItem family (flyweight pattern) Aggregation of groups to describe variables / partial variables Co...
Tool for building a group.
Group(const Private::GroupIndexMapping &groups)
Construction from a Group - offset table (from the family).
const Private::GroupIndexMapping & m_groups
Group - offset table.
AnyItem family observer interface.
void clear()
Clears the group.
GroupIndexMapping m_currents
Group Table - offset.
UserGroup & operator<<(GroupBuilder builder)
Adds an arcane group to the group.
void notifyFamilyIsIncreased()
If the family is increased, no impact on the group.
const Family m_family
AnyItem Family (flyweight copy).
void notifyFamilyIsInvalidate()
Action if the family is invalidated: clears the group.
Mesh entity group.
Definition ItemGroup.h:51
ItemGroupImpl * internal() const
Returns the group implementation.
Definition ItemGroup.h:125
const String & name() const
Group name.
Definition ItemGroup.h:81
void arcaneCallFunctionAndTerminateIfThrow(std::function< void()> function)
Calls the function function and calls std::terminate() if an exception occurs.