Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
IData.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/* IData.h (C) 2000-2025 */
9/* */
10/* Interface of a data item. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_IDATA_H
13#define ARCANE_CORE_IDATA_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28/*!
29 * \brief Interface of a data item.
30 *
31 * This class manages the memory associated with a variable.
32 */
33class ARCANE_CORE_EXPORT IData
34{
36
37 public:
38
39 virtual ~IData() = default;
40
41 public:
42
43 //! Data type
44 virtual eDataType dataType() const = 0;
45
46 //! Dimension. 0 for a scalar, 1 for a mono-dim array, 2 for a bi-dim array.
47 virtual Integer dimension() const = 0;
48
49 //! Multi-tag. 0 if not multiple, 1 if multiple, 2 if multiple for MultiArray variables (obsolete)
50 virtual Integer multiTag() const = 0;
51
52 //! Clone the data. The created instance must be destroyed by the 'delete' operator
53 ARCCORE_DEPRECATED_2020("Use cloneRef() instead")
54 virtual IData* clone() = 0;
55
56 //! Clone the data but without elements. The created instance must be destroyed by the 'delete' operator
57 ARCCORE_DEPRECATED_2020("Use cloneEmptyRef() instead")
58 virtual IData* cloneEmpty() = 0;
59
60 //! Clone the data
61 virtual Ref<IData> cloneRef() = 0;
62
63 //! Clone the data but without elements.
64 virtual Ref<IData> cloneEmptyRef() = 0;
65
66 //! Information about the data container type
68
69 //! Serializes the data by applying the \a operation
70 virtual void serialize(ISerializer* sbuf, IDataOperation* operation) = 0;
71
72 /*!
73 * \brief Resize the data.
74 *
75 * This operation only makes sense for data of dimension 1 or more.
76 * If the new number of elements is greater than the old one, the values added to
77 * the data are not initialized.
78 */
79 virtual void resize(Integer new_size) = 0;
80
81 /*!
82 * \brief Serialize the data for the indices \a ids.
83 *
84 * This operation only makes sense for data of dimension 1 or more.
85 */
86 virtual void serialize(ISerializer* sbuf, Int32ConstArrayView ids, IDataOperation* operation) = 0;
87
88 //! Fills the data with its default value.
89 virtual void fillDefault() = 0;
90
91 //! Sets the name of the data (internal)
92 virtual void setName(const String& name) = 0;
93
94 /*!
95 * \brief Serialize the data.
96 *
97 * For performance reasons, the returned instance may directly reference
98 * the memory area of this data. Consequently, it is only valid as long as this data is not
99 * modified. If you wish to modify this instance, you must
100 * first clone it (via IData::cloneRef()) and then serialize the cloned data.
101 *
102 * If \a use_basic_type is true, the data is serialized for a basic type,
103 * namely #DT_Byte, #DT_Int16, #DT_Int32, #DT_Int64 or #DT_Real. Otherwise,
104 * the type can be a POD, namely #DT_Byte, #DT_Int16, #DT_Int32, #DT_Int64,
105 * #DT_Real, #DT_Real2, #DT_Real3, #DT_Real2x2, #DT_Real3x3.
106 */
107 virtual Ref<ISerializedData> createSerializedDataRef(bool use_basic_type) const = 0;
108
109 /*!
110 * \brief Assign the serialized values \a sdata to the data.
111 *
112 * The buffer containing the serialization values must have
113 * be allocated by calling allocateBufferForSerializedData().
114 */
115 virtual void assignSerializedData(const ISerializedData* sdata) = 0;
116
117 /*!
118 * \brief Allocate memory to read the serialized values \a sdata.
119 *
120 * This method sets sdata->setBuffer(), which will contain the
121 * memory needed to read the serialized data.
122 */
124
125 /*!
126 * \brief Copy the data \a data into the current instance.
127 *
128 * The data \a data must be of the same type as the instance.
129 */
130 virtual void copy(const IData* data) = 0;
131
132 /*!
133 * \brief Swap the values of \a data with those of the instance.
134 *
135 * The data \a IData must be of the same type as the instance. Only
136 * the values are swapped and other possible properties
137 * (such as the name, for example) are not modified.
138 */
139 virtual void swapValues(IData* data) = 0;
140
141 /*!
142 * \brief Compute a hash key on this data.
143 *
144 * The key is added to \a output. The length of the key depends
145 * on the algorithm used.
146 */
147 virtual void computeHash(IHashAlgorithm* algo, ByteArray& output) const = 0;
148
149 /*!
150 * \brief Array shape for a 1D or 2D data item.
151 *
152 * The shape is only considered for dimensions greater than 1.
153 * For a 1D data item, the shape is therefore by default {1}. For a 2D array,
154 * the shape defaults to {dim2_size}. It is possible to change the rank
155 * of the shape and its values as long as shape().totalNbElement()==dim2_size.
156 * For example, if the number of values dim2_size is 12, then it is
157 * possible to have { 12 }, { 6, 2 } or { 3, 2, 2 } as the shape.
158 *
159 * The values are not preserved during a restart, so the shape must
160 * be repositioned in this case. It is up to the user to ensure
161 * that the shape is homogeneous across sub-domains.
162 */
163 virtual ArrayShape shape() const = 0;
164
165 //! Sets the array shape.
166 virtual void setShape(const ArrayShape& new_shape) = 0;
167
168 public:
169
170 //! Sets the allocation information
171 virtual void setAllocationInfo(const DataAllocationInfo& v) = 0;
172
173 //! Allocation information
175
176 public:
177
178 //! Applies the visitor to the data
179 virtual void visit(IDataVisitor* visitor) = 0;
180
181 /*!
182 * \brief Apply the visitor to the data.
183 *
184 * If the data is not scalar, a
185 * NotSupportedException is thrown.
186 */
187 virtual void visitScalar(IScalarDataVisitor* visitor) = 0;
188
189 /*!
190 * \brief Apply the visitor to the data.
191 *
192 * If the data is not a 1D array, an exception
193 * NotSupportedException is thrown.
194 */
195 virtual void visitArray(IArrayDataVisitor* visitor) = 0;
196
197 /*!
198 * \brief Apply the visitor to the data.
199 *
200 * If the data is not a 2D array, an exception
201 * NotSupportedException is thrown.
202 */
203 virtual void visitArray2(IArray2DataVisitor* visitor) = 0;
204
205 /*!
206 * \brief Apply the visitor to the data.
207 *
208 * If the data is not a 2D array, an exception
209 * NotSupportedException is thrown.
210 *
211 * \deprecated This visitor is obsolete because there are no more
212 * IMultiArray2 implementations.
213 */
214 virtual void visitMultiArray2(IMultiArray2DataVisitor* visitor);
215
216 //! \internal
217 virtual IDataInternal* _commonInternal() = 0;
218};
219
220/*---------------------------------------------------------------------------*/
221/*---------------------------------------------------------------------------*/
222
223/*!
224 * \brief Interface of a scalar data item.
225 */
227: public IData
228{
229 public:
230
231 virtual void visit(IDataVisitor* visitor) = 0;
232 //! Applies the visitor to the data.
233 virtual void visit(IScalarDataVisitor* visitor) = 0;
234};
235
236/*---------------------------------------------------------------------------*/
237/*---------------------------------------------------------------------------*/
238
239/*!
240 * \internal
241 * \brief Interface of a scalar data item of type \a T
242 */
243template <class DataType>
245: public IScalarData
246{
247 public:
248
249 typedef IScalarDataT<DataType> ThatClass;
250
251 public:
252
253 //! Data value
254 virtual DataType& value() = 0;
255
256 //! Data value
257 virtual const DataType& value() const = 0;
258
259 //! Clone the data
260 ARCCORE_DEPRECATED_2020("Use cloneTrueRef() instead")
261 virtual ThatClass* cloneTrue() = 0;
262
263 //! Clone the data but without elements.
264 ARCCORE_DEPRECATED_2020("Use cloneTrueEmpty() instead")
265 virtual ThatClass* cloneTrueEmpty() = 0;
266
267 //! Clone the data
268 virtual Ref<ThatClass> cloneTrueRef() = 0;
269
270 //! Clone the data but without elements.
271 virtual Ref<ThatClass> cloneTrueEmptyRef() = 0;
272};
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
277/*!
278 * \brief Interface of a 1D array data item.
279 */
281: public IData
282{
283 public:
284
285 virtual void visit(IDataVisitor* visitor) = 0;
286 //! Applies the visitor to the data.
287 virtual void visit(IArrayDataVisitor* visitor) = 0;
288};
289
290/*---------------------------------------------------------------------------*/
291/*---------------------------------------------------------------------------*/
292
293/*!
294 * \internal
295 * \brief Interface of a 1D array data item of type \a T
296 */
297template <class DataType>
299: public IArrayData
300{
301 public:
302
303 typedef IArrayDataT<DataType> ThatClass;
304
305 public:
306
307 //! Data value
308 ARCCORE_DEPRECATED_2021("Use view() instead.")
309 virtual Array<DataType>& value() = 0;
310
311 //! Constant data value
312 ARCCORE_DEPRECATED_2021("Use view() instead.")
313 virtual const Array<DataType>& value() const = 0;
314
315 public:
316
317 //! Constant view on the data
318 virtual ConstArrayView<DataType> view() const = 0;
319
320 //! View on the data
321 virtual ArrayView<DataType> view() = 0;
322
323 //! Clone the data
324 ARCCORE_DEPRECATED_2020("Use cloneTrueRef() instead")
325 virtual ThatClass* cloneTrue() = 0;
326
327 //! Clone the data but without elements.
328 ARCCORE_DEPRECATED_2020("Use cloneTrueEmptyRef() instead")
329 virtual ThatClass* cloneTrueEmpty() = 0;
330
331 //! Clone the data
332 virtual Ref<ThatClass> cloneTrueRef() = 0;
333
334 //! Clone the data but without elements.
335 virtual Ref<ThatClass> cloneTrueEmptyRef() = 0;
336
337 //! \internal
338 virtual IArrayDataInternalT<DataType>* _internal() = 0;
339};
340
341/*---------------------------------------------------------------------------*/
342/*---------------------------------------------------------------------------*/
343
344/*!
345 * \brief Interface of a 2D array data item.
346 */
348: public IData
349{
350};
351
352/*---------------------------------------------------------------------------*/
353/*---------------------------------------------------------------------------*/
354
355/*!
356 * \brief Interface of a multi 2D array data item.
357 * \deprecated This interface is no longer used.
358 */
360: public IData
361{
362};
363
364/*---------------------------------------------------------------------------*/
365/*---------------------------------------------------------------------------*/
366
367/*!
368 * \internal
369 * \brief Interface of a bi-dimensional array data item of type \a T
370 */
371template <class DataType>
373: public IArray2Data
374{
375 public:
376
377 typedef IArray2DataT<DataType> ThatClass;
378
379 //! Data value
380 ARCCORE_DEPRECATED_2021("Use view() instead.")
381 virtual Array2<DataType>& value() = 0;
382
383 //! Data value
384 ARCCORE_DEPRECATED_2021("Use view() instead.")
385 virtual const Array2<DataType>& value() const = 0;
386
387 public:
388
389 //! Constant view on the data
390 virtual ConstArray2View<DataType> view() const = 0;
391
392 //! View on the data
393 virtual Array2View<DataType> view() = 0;
394
395 //! Clone the data
396 ARCCORE_DEPRECATED_2020("Use cloneTrueRef() instead")
397 virtual ThatClass* cloneTrue() = 0;
398
399 //! Clone the data but without elements.
400 ARCCORE_DEPRECATED_2020("Use cloneTrueEmptyRef() instead")
401 virtual ThatClass* cloneTrueEmpty() = 0;
402
403 //! Clone the data
404 virtual Ref<ThatClass> cloneTrueRef() = 0;
405
406 //! Clone the data but without elements.
407 virtual Ref<ThatClass> cloneTrueEmptyRef() = 0;
408
409 //! \internal
410 virtual IArray2DataInternalT<DataType>* _internal() = 0;
411};
412
413/*---------------------------------------------------------------------------*/
414/*---------------------------------------------------------------------------*/
415
416/*!
417 * \internal
418 * \brief Interface of a multi-sized 2D array data item of type \a T
419 * \deprecated This interface is no longer used.
420 */
421template <class DataType>
423: public IMultiArray2Data
424{
425 public:
426
427 typedef IMultiArray2DataT<DataType> ThatClass;
428
429 //! Data value
431
432 //! Data value
433 virtual const MultiArray2<DataType>& value() const = 0;
434
435 //! Clone the data
436 virtual ThatClass* cloneTrue() = 0;
437
438 //! Clone the data but without elements.
439 virtual ThatClass* cloneTrueEmpty() = 0;
440};
441
442/*---------------------------------------------------------------------------*/
443/*---------------------------------------------------------------------------*/
444
445} // End namespace Arcane
446
447/*---------------------------------------------------------------------------*/
448/*---------------------------------------------------------------------------*/
449
450#endif
Declarations of Arcane's general types.
#define ARCCORE_DECLARE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro to declare the virtual methods managing reference counters.
Class representing a classic 2D array.
Array shape.
Definition ArrayShape.h:42
Modifiable view of an array of type T.
Base class for 1D data vectors.
Constant view of an array of type T.
Information on data allocation.
Type information for a data container.
virtual Ref< ThatClass > cloneTrueRef()=0
virtual Array2< T > & value()=0
virtual ThatClass * cloneTrue()=0
virtual ConstArray2View< T > view() const=0
virtual Ref< ThatClass > cloneTrueEmptyRef()=0
virtual ThatClass * cloneTrueEmpty()=0
Interface of the visitor pattern for a 2D array data item.
Interface of a 2D array data item.
Definition IData.h:349
virtual ThatClass * cloneTrueEmpty()=0
virtual ThatClass * cloneTrue()=0
virtual Ref< ThatClass > cloneTrueRef()=0
virtual Ref< ThatClass > cloneTrueEmptyRef()=0
virtual ConstArrayView< T > view() const=0
virtual Array< T > & value()=0
Interface of the visitor pattern for an array data item.
Interface of a 1D array data item.
Definition IData.h:282
virtual void visit(IDataVisitor *visitor)=0
Applies the visitor to the data.
virtual void visit(IArrayDataVisitor *visitor)=0
Applies the visitor to the data.
Interface of the visitor pattern for a data item.
Interface of a data item.
Definition IData.h:34
virtual Ref< ISerializedData > createSerializedDataRef(bool use_basic_type) const =0
Serialize the data.
virtual void allocateBufferForSerializedData(ISerializedData *sdata)=0
Allocate memory to read the serialized values sdata.
virtual void copy(const IData *data)=0
Copy the data data into the current instance.
virtual DataAllocationInfo allocationInfo() const =0
Allocation information.
virtual void serialize(ISerializer *sbuf, IDataOperation *operation)=0
Serializes the data by applying the operation.
virtual IData * clone()=0
Clone the data. The created instance must be destroyed by the 'delete' operator.
virtual void swapValues(IData *data)=0
Swap the values of data with those of the instance.
virtual IData * cloneEmpty()=0
Clone the data but without elements. The created instance must be destroyed by the 'delete' operator.
virtual void computeHash(IHashAlgorithm *algo, ByteArray &output) const =0
Compute a hash key on this data.
virtual void visitArray2(IArray2DataVisitor *visitor)=0
Apply the visitor to the data.
virtual void setName(const String &name)=0
Sets the name of the data (internal).
virtual void visit(IDataVisitor *visitor)=0
Applies the visitor to the data.
virtual Integer dimension() const =0
Dimension. 0 for a scalar, 1 for a mono-dim array, 2 for a bi-dim array.
virtual void visitArray(IArrayDataVisitor *visitor)=0
Apply the visitor to the data.
virtual Integer multiTag() const =0
Multi-tag. 0 if not multiple, 1 if multiple, 2 if multiple for MultiArray variables (obsolete).
virtual void fillDefault()=0
Fills the data with its default value.
virtual void setAllocationInfo(const DataAllocationInfo &v)=0
Sets the allocation information.
virtual void visitMultiArray2(IMultiArray2DataVisitor *visitor)
Apply the visitor to the data.
Definition Data.cc:56
virtual Ref< IData > cloneRef()=0
Clone the data.
virtual void visitScalar(IScalarDataVisitor *visitor)=0
Apply the visitor to the data.
virtual eDataType dataType() const =0
Data type.
virtual Ref< IData > cloneEmptyRef()=0
Clone the data but without elements.
virtual void resize(Integer new_size)=0
Resize the data.
virtual void setShape(const ArrayShape &new_shape)=0
Sets the array shape.
virtual void assignSerializedData(const ISerializedData *sdata)=0
Assign the serialized values sdata to the data.
virtual DataStorageTypeInfo storageTypeInfo() const =0
Information about the data container type.
virtual ArrayShape shape() const =0
Array shape for a 1D or 2D data item.
Interface of a hashing algorithm.
virtual ThatClass * cloneTrue()=0
Clone the data.
virtual ThatClass * cloneTrueEmpty()=0
Clone the data but without elements.
virtual const MultiArray2< DataType > & value() const =0
Data value.
virtual MultiArray2< DataType > & value()=0
Data value.
Interface of the visitor pattern for a variable-sized 2D array data item.
Interface of a multi 2D array data item.
Definition IData.h:361
virtual ThatClass * cloneTrue()=0
virtual DataType & value()=0
Data value.
virtual Ref< ThatClass > cloneTrueRef()=0
virtual ThatClass * cloneTrueEmpty()=0
virtual const DataType & value() const =0
Data value.
virtual Ref< ThatClass > cloneTrueEmptyRef()=0
Interface of the visitor pattern for a scalar data item.
Interface of a scalar data item.
Definition IData.h:228
virtual void visit(IDataVisitor *visitor)=0
Applies the visitor to the data.
virtual void visit(IScalarDataVisitor *visitor)=0
Applies the visitor to the data.
Base class for multi-sized 2D arrays.
Definition MultiArray2.h:60
Reference to an instance.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
Definition UtilsTypes.h:121
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
eDataType
Data type.
Definition DataTypes.h:41