Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
AnyItemLinkVariableArray.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/* AnyItemLinkVariableArray.h (C) 2000-2025 */
9/* */
10/* 2D variable of links of arbitrary types. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ANYITEM_ANYITEMLINKVARIABLEARRAY_H
13#define ARCANE_CORE_ANYITEM_ANYITEMLINKVARIABLEARRAY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/anyitem/AnyItemGlobal.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane::AnyItem
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28/*
29 * \brief Variable of links of arbitrary types.
30 *
31 * For example:
32 *
33 * AnyItem::Variable<Real> variable(family); // Filled
34 * AnyItem::LinkVariableArray<Real> link_variable(link_family); // Filled with size 3
35 *
36 * Real value = 0;
37 * ENUMERATE_ANY_ITEM_LINK(ilink, link_family) {
38 * if(ilink.index() < 10) {
39 * info() << "back item = [uid=" << family.concreteItem(ilink.back()).uniqueId()
40 * << ",lid=" << family.concreteItem(ilink.back()).localId() << ",kind="
41 * << family.concreteItem(ilink.back()).kind() << "]";
42 * info() << "front item = [uid=" << family.concreteItem(ilink.front()).uniqueId()
43 * << ",lid=" << family.concreteItem(ilink.front()).localId() << ",kind="
44 * << family.concreteItem(ilink.front()).kind() << "]";
45 * }
46 *
47 * for(Integer i = 0; i < 3; ++i)
48 * value += link_variable[ilink][i] + variable[ilink.back()][i] + variable[ilink.front()];
49 * }
50 *
51 */
52template <typename DataType>
53class LinkVariableArray
55{
56 public:
57
58 LinkVariableArray(const LinkFamily& family)
59 : m_size(0)
60 , m_family(family)
61 , m_values(m_family.capacity(), m_size)
62 {
63 m_family.registerObserver(*this);
64 }
65
66 LinkVariableArray(const LinkVariableArray& v)
67 : m_size(v.m_size)
70 {
71 m_family.registerObserver(*this);
72 }
73
74 ~LinkVariableArray()
75 {
76 arcaneCallFunctionAndTerminateIfThrow([&]() { m_family.removeObserver(*this); });
77 }
78
80 inline ArrayView<DataType> operator[](const LinkFamily::LinkIndex& item)
81 {
82 return m_values[item.index()];
83 }
84
86 inline ConstArrayView<DataType> operator[](const LinkFamily::LinkIndex& item) const
87 {
88 return m_values[item.index()];
89 }
90
93 {
94 // If the family changes, we resize
95 m_values.resize(m_family.capacity(), m_size);
96 }
97
100 {
101 // If the family is reserved, we simply resize
102 m_values.resize(m_family.capacity(), m_size);
103 }
104
106 inline void resize(Integer size)
107 {
108 m_size = size;
109 m_values.resize(m_family.capacity(), m_size);
110 }
111
113 inline Integer size() const { return m_size; }
114
115 private:
116
119
122
125};
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
130} // End namespace Arcane::AnyItem
131
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
135#endif
AnyItem link family observer interface.
AnyItem link family (flyweight pattern).
void notifyFamilyIsReserved()
Action if the family is reserved: we resize.
ArrayView< DataType > operator[](const LinkFamily::LinkIndex &item)
Accessor.
void notifyFamilyIsInvalidate()
Action if the family is invalidated: we resize.
ConstArrayView< DataType > operator[](const LinkFamily::LinkIndex &item) const
Accessor const.
Integer size() const
Returns the size of the array.
Arcane::UniqueArray2< DataType > m_values
Values.
void resize(Integer size)
Resizing of the second dimension of the array.
Integer m_size
Size of the 2nd dimension of the array.
Modifiable view of an array of type T.
Constant view of an array of type T.
2D data vector with value semantics (STL style).
Int32 Integer
Type representing an integer.
void arcaneCallFunctionAndTerminateIfThrow(std::function< void()> function)
Calls the function function and calls std::terminate() if an exception occurs.