Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
LinearOffsetMap.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/* LinearOffsetMap.h (C) 2000-2024 */
9/* */
10/* List of linear offsets. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_LINEAROFFSETMAP_H
13#define ARCANE_UTILS_LINEAROFFSETMAP_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include <map>
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30/*!
31 * \internal
32 * \brief List of linear offsets.
33 *
34 * `DataType` must be `Int32` or `Int64`.
35 *
36 * \warning Experimental class. Do not use outside of Arcane.
37 */
38template <typename DataType>
40{
41 public:
42
43 static_assert(std::is_same_v<DataType, Int32> || std::is_same_v<DataType, Int64>);
44
45 public:
46
47 //! Adds an offset \a offset of size \a size
48 ARCANE_UTILS_EXPORT void add(DataType size, DataType offset);
49
50 /*!
51 * \brief Retrieves a sufficient offset for an element of size \a size.
52 *
53 * Returns a negative value if no offset is available. If an offset
54 * is available, it returns its value. The found offset is removed from the list
55 * and an offset is added for the remaining size if it is not zero:
56 * if the found offset is `offset` and the associated size is `offset_size`,
57 * call `add(offset_size - size, offset + size)`.
58 */
59 ARCANE_UTILS_EXPORT DataType getAndRemoveOffset(DataType size);
60
61 //! Number of elements in the table.
62 ARCANE_UTILS_EXPORT Int32 size() const;
63
64 private:
65
66 std::multimap<DataType, DataType> m_offset_map;
67};
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72} // namespace Arcane
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77#endif
Arcane configuration file.
void add(DataType size, DataType offset)
Adds an offset offset of size size.
Int32 size() const
Number of elements in the table.
DataType getAndRemoveOffset(DataType size)
Retrieves a sufficient offset for an element of size size.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Signed integer type of 32 bits.