Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
SimpleTableInternalMng.cc
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/* SimpleTableInternalMng.cc (C) 2000-2022 */
9/* */
10/* Class allowing easy modification of a SimpleTableInternal. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/std/SimpleTableInternalMng.h"
15
16#include <optional>
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Arcane
22{
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
29{
30 m_simple_table_internal->clear();
31}
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
37addRow(const String& row_name)
38{
39 if (row_name.empty())
40 return -1;
41
42 Integer position = m_simple_table_internal->m_values.dim1Size();
43 m_simple_table_internal->m_values.resize(position + 1);
44
45 m_simple_table_internal->m_row_names.add(row_name);
46 m_simple_table_internal->m_row_sizes.add(0);
47
48 m_simple_table_internal->m_last_row = position;
49
50 return position;
51}
52
54addRow(const String& row_name, ConstArrayView<Real> elements)
55{
56 if (row_name.empty())
57 return -1;
58
59 Integer position = m_simple_table_internal->m_values.dim1Size();
60 m_simple_table_internal->m_values.resize(position + 1);
61
62 m_simple_table_internal->m_row_names.add(row_name);
63 m_simple_table_internal->m_row_sizes.add(0);
64
65 addElementsInRow(position, elements);
66
67 return position;
68}
69
72{
73 if (rows_names.contains(""))
74 return false;
75
76 Integer size = rows_names.size();
77 if (size == 0)
78 return true;
79
80 Integer position = m_simple_table_internal->m_values.dim1Size();
81 m_simple_table_internal->m_values.resize(position + size);
82
83 m_simple_table_internal->m_row_names.addRange(rows_names);
84 m_simple_table_internal->m_row_sizes.addRange(IntegerUniqueArray(size, 0));
85
86 m_simple_table_internal->m_last_row = position;
87
88 return true;
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
95addColumn(const String& column_name)
96{
97 if (column_name.empty())
98 return -1;
99
100 Integer position = m_simple_table_internal->m_values.dim2Size();
101 m_simple_table_internal->m_values.resize(m_simple_table_internal->m_values.dim1Size(), position + 1);
102
103 m_simple_table_internal->m_column_names.add(column_name);
104 m_simple_table_internal->m_column_sizes.add(0);
105
106 m_simple_table_internal->m_last_column = position;
107
108 return position;
109}
110
112addColumn(const String& column_name, ConstArrayView<Real> elements)
113{
114 if (column_name.empty())
115 return -1;
116
117 Integer position = m_simple_table_internal->m_values.dim2Size();
118 m_simple_table_internal->m_values.resize(m_simple_table_internal->m_values.dim1Size(), position + 1);
119
120 m_simple_table_internal->m_column_names.add(column_name);
121 m_simple_table_internal->m_column_sizes.add(0);
122
123 addElementsInColumn(position, elements);
124
125 return position;
126}
127
129addColumns(StringConstArrayView columns_names)
130{
131 if (columns_names.contains(""))
132 return false;
133
134 Integer size = columns_names.size();
135 if (size == 0)
136 return true;
137
138 Integer position = m_simple_table_internal->m_values.dim2Size();
139 m_simple_table_internal->m_values.resize(m_simple_table_internal->m_values.dim1Size(), position + size);
140
141 m_simple_table_internal->m_column_names.addRange(columns_names);
142 m_simple_table_internal->m_column_sizes.addRange(IntegerUniqueArray(size, 0));
143
144 m_simple_table_internal->m_last_column = position;
145
146 return true;
147}
148
149/*---------------------------------------------------------------------------*/
150/*---------------------------------------------------------------------------*/
151
154{
155 if (position < 0 || position >= m_simple_table_internal->m_values.dim1Size())
156 return false;
157
158 ArrayView<Real> view = m_simple_table_internal->m_values[position];
159 Integer size_row = m_simple_table_internal->m_row_sizes[position];
160
161 if (m_simple_table_internal->m_values.dim2Size() < size_row + 1)
162 return false;
163
164 view[size_row] = element;
165
166 m_simple_table_internal->m_last_row = position;
167 m_simple_table_internal->m_last_column = size_row;
168
169 m_simple_table_internal->m_row_sizes[position]++;
170 // There may be elements in the row after in the same column.
171 // Example: addElementInRow(position=L01, element=NEW):
172 // aaa|C00|C01|C02
173 // L00|123|456|789
174 // L01|147|NEW|
175 // L02|159|753|852
176 // There is 753 so the column size remains equal to 3.
177 m_simple_table_internal->m_column_sizes[size_row] = std::max(position + 1, m_simple_table_internal->m_column_sizes[size_row]);
178
179 return true;
180}
181
183addElementInRow(const String& row_name, Real element, bool create_if_not_exist)
184{
185 std::optional<Integer> position = m_simple_table_internal->m_row_names.span().findFirst(row_name);
186
187 if (position)
188 return addElementInRow(position.value(), element);
189 else if (create_if_not_exist)
190 return addElementInRow(addRow(row_name), element);
191 else
192 return false;
193}
194
197{
198 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1)
199 return false;
200 return addElementInRow(m_simple_table_internal->m_last_row, element);
201}
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
208{
209 if (position < 0 || position >= m_simple_table_internal->m_values.dim1Size())
210 return false;
211
212 ArrayView<Real> view = m_simple_table_internal->m_values[position];
213 Integer size_row = m_simple_table_internal->m_row_sizes[position];
214 Integer min_size = (elements.size() <= m_simple_table_internal->m_values.dim2Size() - size_row
215 ? elements.size()
216 : m_simple_table_internal->m_values.dim2Size() - size_row);
217
218 for (Integer i = 0; i < min_size; i++) {
219 view[i + size_row] = elements[i];
220 m_simple_table_internal->m_column_sizes[i + size_row] = std::max(position + 1, m_simple_table_internal->m_column_sizes[i + size_row]);
221 }
222 m_simple_table_internal->m_row_sizes[position] += min_size;
223
224 m_simple_table_internal->m_last_row = position;
225 m_simple_table_internal->m_last_column = m_simple_table_internal->m_row_sizes[position] - 1;
226
227 return elements.size() <= m_simple_table_internal->m_values.dim2Size() - size_row;
228}
229
231addElementsInRow(const String& row_name, ConstArrayView<Real> elements, bool create_if_not_exist)
232{
233 std::optional<Integer> position = m_simple_table_internal->m_row_names.span().findFirst(row_name);
234
235 if (position)
236 return addElementsInRow(position.value(), elements);
237 // Allows a bool return (otherwise we could simply call addRow(row_name, elements)).
238 else if (create_if_not_exist)
239 return addElementsInRow(addRow(row_name), elements);
240 else
241 return false;
242}
243
246{
247 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1)
248 return false;
249 return addElementsInRow(m_simple_table_internal->m_last_row, elements);
250}
251
252/*---------------------------------------------------------------------------*/
253/*---------------------------------------------------------------------------*/
254
257{
258 if (position < 0 || position >= m_simple_table_internal->m_values.dim2Size())
259 return false;
260
261 Integer size_column = m_simple_table_internal->m_column_sizes[position];
262
263 if (m_simple_table_internal->m_values.dim1Size() < size_column + 1)
264 return false;
265
266 m_simple_table_internal->m_values[size_column][position] = element;
267
268 m_simple_table_internal->m_last_column = position;
269 m_simple_table_internal->m_last_row = size_column;
270
271 m_simple_table_internal->m_column_sizes[position]++;
272 m_simple_table_internal->m_row_sizes[size_column] = std::max(position + 1, m_simple_table_internal->m_row_sizes[size_column]);
273
274 return true;
275}
276
278addElementInColumn(const String& column_name, Real element, bool create_if_not_exist)
279{
280 std::optional<Integer> position = m_simple_table_internal->m_column_names.span().findFirst(column_name);
281
282 if (position)
283 return addElementInColumn(position.value(), element);
284 else if (create_if_not_exist)
285 return addElementInColumn(addColumn(column_name), element);
286 else
287 return false;
288}
289
292{
293 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1)
294 return false;
295 return addElementInColumn(m_simple_table_internal->m_last_column, element);
296}
297
298/*---------------------------------------------------------------------------*/
299/*---------------------------------------------------------------------------*/
300
303{
304 if (position < 0 || position >= m_simple_table_internal->m_values.dim2Size())
305 return false;
306
307 Integer size_column = m_simple_table_internal->m_column_sizes[position];
308 Integer min_size = (elements.size() <= m_simple_table_internal->m_values.dim1Size() - size_column
309 ? elements.size()
310 : m_simple_table_internal->m_values.dim1Size() - size_column);
311
312 for (Integer i = 0; i < min_size; i++) {
313 m_simple_table_internal->m_values[i + size_column][position] = elements[i];
314 m_simple_table_internal->m_row_sizes[i + size_column] = std::max(position + 1, m_simple_table_internal->m_row_sizes[i + size_column]);
315 }
316 m_simple_table_internal->m_column_sizes[position] += min_size;
317
318 m_simple_table_internal->m_last_column = position;
319 m_simple_table_internal->m_last_row = m_simple_table_internal->m_column_sizes[position] - 1;
320
321 return elements.size() <= m_simple_table_internal->m_values.dim1Size() - size_column;
322}
323
325addElementsInColumn(const String& column_name, ConstArrayView<Real> elements, bool create_if_not_exist)
326{
327 std::optional<Integer> position = m_simple_table_internal->m_column_names.span().findFirst(column_name);
328
329 if (position)
330 return addElementsInColumn(position.value(), elements);
331 // Allows a bool return (otherwise we could simply call addColumn(column_name, elements)).
332 else if (create_if_not_exist)
333 return addElementsInColumn(addColumn(column_name), elements);
334 else
335 return false;
336}
337
340{
341 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1)
342 return false;
343 return addElementsInColumn(m_simple_table_internal->m_last_column, elements);
344}
345
346/*---------------------------------------------------------------------------*/
347/*---------------------------------------------------------------------------*/
348
350editElementUp(Real element, bool update_last_position)
351{
352 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1 || m_simple_table_internal->m_last_row - 1 < 0)
353 return false;
354 m_simple_table_internal->m_last_row--;
355
356 // No need to adjust column size because we are sure that m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] >= m_simple_table_internal->m_last_row.
357 if (m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] <= m_simple_table_internal->m_last_column)
358 m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] = m_simple_table_internal->m_last_column + 1;
359
360 m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column] = element;
361 if (!update_last_position)
362 m_simple_table_internal->m_last_row++;
363 return true;
364}
365
367editElementDown(Real element, bool update_last_position)
368{
369 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1 || m_simple_table_internal->m_last_row + 1 >= m_simple_table_internal->m_values.dim1Size())
370 return false;
371 m_simple_table_internal->m_last_row++;
372
373 if (m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] <= m_simple_table_internal->m_last_column)
374 m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] = m_simple_table_internal->m_last_column + 1;
375 if (m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] <= m_simple_table_internal->m_last_row)
376 m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] = m_simple_table_internal->m_last_row + 1;
377
378 m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column] = element;
379 if (!update_last_position)
380 m_simple_table_internal->m_last_row--;
381 return true;
382}
383
385editElementLeft(Real element, bool update_last_position)
386{
387 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1 || m_simple_table_internal->m_last_column - 1 < 0)
388 return false;
389 m_simple_table_internal->m_last_column--;
390
391 // No need to adjust row size because we are sure that m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] >= m_simple_table_internal->m_last_column.
392 if (m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] <= m_simple_table_internal->m_last_row)
393 m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] = m_simple_table_internal->m_last_row + 1;
394
395 m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column] = element;
396 if (!update_last_position)
397 m_simple_table_internal->m_last_column++;
398 return true;
399}
400
402editElementRight(Real element, bool update_last_position)
403{
404 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1 || m_simple_table_internal->m_last_column + 1 >= m_simple_table_internal->m_values.dim2Size())
405 return false;
406 m_simple_table_internal->m_last_column++;
407
408 if (m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] <= m_simple_table_internal->m_last_column)
409 m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] = m_simple_table_internal->m_last_column + 1;
410 if (m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] <= m_simple_table_internal->m_last_row)
411 m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] = m_simple_table_internal->m_last_row + 1;
412
413 m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column] = element;
414 if (!update_last_position)
415 m_simple_table_internal->m_last_column--;
416 return true;
417}
418
419/*---------------------------------------------------------------------------*/
420/*---------------------------------------------------------------------------*/
421
423elementUp(bool update_last_position)
424{
425 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1 || m_simple_table_internal->m_last_row - 1 < 0)
426 return 0;
427
428 // Compared to editElementUp(), if we do not want to update the last position,
429 // we do not check or modify m_simple_table_internal->m_row_sizes.
430 if (update_last_position) {
431 m_simple_table_internal->m_last_row--;
432 // No need to adjust the column size because we are sure that m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] >= m_simple_table_internal->m_last_row.
433 if (m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] <= m_simple_table_internal->m_last_column)
434 m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] = m_simple_table_internal->m_last_column + 1;
435 return m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column];
436 }
437
438 return m_simple_table_internal->m_values[m_simple_table_internal->m_last_row - 1][m_simple_table_internal->m_last_column];
439}
440
442elementDown(bool update_last_position)
443{
444 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1 || m_simple_table_internal->m_last_row + 1 >= m_simple_table_internal->m_values.dim1Size())
445 return 0;
446
447 // Compared to editElementDown(), if we do not want to update the last position,
448 // we do not check or modify m_simple_table_internal->m_row_sizes.
449 if (update_last_position) {
450 m_simple_table_internal->m_last_row++;
451
452 if (m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] <= m_simple_table_internal->m_last_column)
453 m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] = m_simple_table_internal->m_last_column + 1;
454 if (m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] <= m_simple_table_internal->m_last_row)
455 m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] = m_simple_table_internal->m_last_row + 1;
456 return m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column];
457 }
458 return m_simple_table_internal->m_values[m_simple_table_internal->m_last_row + 1][m_simple_table_internal->m_last_column];
459}
460
462elementLeft(bool update_last_position)
463{
464 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1 || m_simple_table_internal->m_last_column - 1 < 0)
465 return 0;
466
467 // Compared to editElementLeft(), if we do not want to update the last position,
468 // we do not check or modify m_simple_table_internal->m_column_sizes.
469 if (update_last_position) {
470 m_simple_table_internal->m_last_column--;
471
472 // No need to adjust the row size because we are sure that m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] >= m_simple_table_internal->m_last_column.
473 if (m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] <= m_simple_table_internal->m_last_row)
474 m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] = m_simple_table_internal->m_last_row + 1;
475 return m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column];
476 }
477 return m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column - 1];
478}
479
481elementRight(bool update_last_position)
482{
483 if (m_simple_table_internal->m_last_row == -1 || m_simple_table_internal->m_last_column == -1 || m_simple_table_internal->m_last_column + 1 >= m_simple_table_internal->m_values.dim2Size())
484 return 0;
485
486 // Compared to editElementRight(), if we do not want to update the last position,
487 // we do not check or modify m_simple_table_internal->m_column_sizes.
488 if (update_last_position) {
489 m_simple_table_internal->m_last_column++;
490
491 if (m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] <= m_simple_table_internal->m_last_column)
492 m_simple_table_internal->m_row_sizes[m_simple_table_internal->m_last_row] = m_simple_table_internal->m_last_column + 1;
493 if (m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] <= m_simple_table_internal->m_last_row)
494 m_simple_table_internal->m_column_sizes[m_simple_table_internal->m_last_column] = m_simple_table_internal->m_last_row + 1;
495 return m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column];
496 }
497 return m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column + 1];
498}
499
500/*---------------------------------------------------------------------------*/
501/*---------------------------------------------------------------------------*/
502
505{
506 m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column] = element;
507 return true;
508}
509
511editElement(Integer position_x, Integer position_y, Real element)
512{
513 if (position_x < 0 || position_x >= m_simple_table_internal->m_values.dim2Size() || position_y < 0 || position_y >= m_simple_table_internal->m_values.dim1Size())
514 return false;
515
516 if (m_simple_table_internal->m_column_sizes[position_x] <= position_y)
517 m_simple_table_internal->m_column_sizes[position_x] = position_y + 1;
518 if (m_simple_table_internal->m_row_sizes[position_y] <= position_x)
519 m_simple_table_internal->m_row_sizes[position_y] = position_x + 1;
520
521 m_simple_table_internal->m_values[position_y][position_x] = element;
522
523 m_simple_table_internal->m_last_row = position_y;
524 m_simple_table_internal->m_last_column = position_x;
525
526 return true;
527}
528
530editElement(const String& column_name, const String& row_name, Real element)
531{
532 std::optional<Integer> position_x = m_simple_table_internal->m_column_names.span().findFirst(column_name);
533 std::optional<Integer> position_y = m_simple_table_internal->m_row_names.span().findFirst(row_name);
534
535 if (position_x && position_y)
536 return editElement(position_x.value(), position_y.value(), element);
537 return false;
538}
539
540/*---------------------------------------------------------------------------*/
541/*---------------------------------------------------------------------------*/
542
544element()
545{
546 return m_simple_table_internal->m_values[m_simple_table_internal->m_last_row][m_simple_table_internal->m_last_column];
547}
548
550element(Integer position_x, Integer position_y, bool update_last_position)
551{
552 if (position_x < 0 || position_x >= m_simple_table_internal->m_values.dim2Size() || position_y < 0 || position_y >= m_simple_table_internal->m_values.dim1Size())
553 return 0;
554
555 if (update_last_position) {
556 m_simple_table_internal->m_last_column = position_x;
557 m_simple_table_internal->m_last_row = position_y;
558 }
559
560 return m_simple_table_internal->m_values[position_y][position_x];
561}
562
564element(const String& column_name, const String& row_name, bool update_last_position)
565{
566 std::optional<Integer> position_x = m_simple_table_internal->m_column_names.span().findFirst(column_name);
567 std::optional<Integer> position_y = m_simple_table_internal->m_row_names.span().findFirst(row_name);
568
569 if (position_x && position_y)
570 return element(position_x.value(), position_y.value(), update_last_position);
571 return 0;
572}
573
574/*---------------------------------------------------------------------------*/
575/*---------------------------------------------------------------------------*/
576
578row(Integer position)
579{
580 Integer size = rowSize(position);
581 RealUniqueArray copie(size);
582 for (Integer i = 0; i < size; i++) {
583 copie[i] = m_simple_table_internal->m_values[position][i];
584 }
585 return copie;
586}
587
589row(const String& row_name)
590{
591 std::optional<Integer> position_y = m_simple_table_internal->m_row_names.span().findFirst(row_name);
592 if (position_y)
593 return row(position_y.value());
594 return RealUniqueArray(0);
595}
596
597/*---------------------------------------------------------------------------*/
598/*---------------------------------------------------------------------------*/
599
601column(Integer position)
602{
603 Integer size = columnSize(position);
604
605 RealUniqueArray copie(size);
606 for (Integer i = 0; i < size; i++) {
607 copie[i] = m_simple_table_internal->m_values[i][position];
608 }
609 return copie;
610}
611
613column(const String& column_name)
614{
615 std::optional<Integer> position_x = m_simple_table_internal->m_column_names.span().findFirst(column_name);
616 if (position_x)
617 return column(position_x.value());
618 return RealUniqueArray(0);
619}
620
621/*---------------------------------------------------------------------------*/
622/*---------------------------------------------------------------------------*/
623
625rowSize(Integer position)
626{
627 if (position < 0 || position >= m_simple_table_internal->m_values.dim1Size())
628 return 0;
629 return m_simple_table_internal->m_row_sizes[position];
630}
631
633rowSize(const String& row_name)
634{
635 std::optional<Integer> position_y = m_simple_table_internal->m_row_names.span().findFirst(row_name);
636 if (position_y)
637 return rowSize(position_y.value());
638 return 0;
639}
640
641/*---------------------------------------------------------------------------*/
642/*---------------------------------------------------------------------------*/
643
645columnSize(Integer position)
646{
647 if (position < 0 || position >= m_simple_table_internal->m_values.dim2Size())
648 return 0;
649 return m_simple_table_internal->m_column_sizes[position];
650}
651
653columnSize(const String& column_name)
654{
655 std::optional<Integer> position_x = m_simple_table_internal->m_column_names.span().findFirst(column_name);
656 if (position_x)
657 return columnSize(position_x.value());
658 return 0;
659}
660
661/*---------------------------------------------------------------------------*/
662/*---------------------------------------------------------------------------*/
663
665rowPosition(const String& row_name)
666{
667 std::optional<Integer> position_y = m_simple_table_internal->m_row_names.span().findFirst(row_name);
668 if (position_y)
669 return position_y.value();
670 return -1;
671}
672
674columnPosition(const String& column_name)
675{
676 std::optional<Integer> position_x = m_simple_table_internal->m_column_names.span().findFirst(column_name);
677 if (position_x)
678 return position_x.value();
679 return -1;
680}
681
682/*---------------------------------------------------------------------------*/
683/*---------------------------------------------------------------------------*/
684
687{
688 return m_simple_table_internal->m_values.dim1Size();
689}
690
693{
694 return m_simple_table_internal->m_values.dim2Size();
695}
696
697/*---------------------------------------------------------------------------*/
698/*---------------------------------------------------------------------------*/
699
701rowName(Integer position)
702{
703 if (position < 0 || position >= m_simple_table_internal->m_values.dim1Size())
704 return "";
705
706 return m_simple_table_internal->m_row_names[position];
707}
708
710columnName(Integer position)
711{
712 if (position < 0 || position >= m_simple_table_internal->m_values.dim2Size())
713 return "";
714
715 return m_simple_table_internal->m_column_names[position];
716}
717
718/*---------------------------------------------------------------------------*/
719/*---------------------------------------------------------------------------*/
720
722editRowName(Integer position, const String& new_name)
723{
724 if (new_name.empty() || position < 0 || position >= m_simple_table_internal->m_values.dim1Size())
725 return false;
726 m_simple_table_internal->m_row_names[position] = new_name;
727 return true;
728}
729
731editRowName(const String& row_name, const String& new_name)
732{
733 std::optional<Integer> position_y = m_simple_table_internal->m_row_names.span().findFirst(row_name);
734 if (position_y)
735 return editRowName(position_y.value(), new_name);
736 return false;
737}
738
740editColumnName(Integer position, const String& new_name)
741{
742 if (new_name.empty() || position < 0 || position >= m_simple_table_internal->m_values.dim2Size())
743 return false;
744 m_simple_table_internal->m_column_names[position] = new_name;
745 return true;
746}
747
749editColumnName(const String& column_name, const String& new_name)
750{
751 std::optional<Integer> position_x = m_simple_table_internal->m_column_names.span().findFirst(column_name);
752 if (position_x)
753 return editColumnName(position_x.value(), new_name);
754 return false;
755}
756
757/*---------------------------------------------------------------------------*/
758/*---------------------------------------------------------------------------*/
759
761addAverageColumn(const String& column_name)
762{
763 if (column_name.empty())
764 return -1;
765
766 Integer position = addColumn(column_name);
767 for (Integer i = 0; i < m_simple_table_internal->m_values.dim1Size(); i++) {
768 Real avg = 0.0;
769 ConstArrayView<Real> view = m_simple_table_internal->m_values[i];
770 for (Integer j = 0; j < view.size() - 1; j++) {
771 avg += view[j];
772 }
773 avg /= view.size() - 1;
774 addElementInColumn(position, avg);
775 }
776 return position;
777}
778
779/*---------------------------------------------------------------------------*/
780/*---------------------------------------------------------------------------*/
781
783internal()
784{
785 return m_simple_table_internal;
786}
787
789setInternal(const Ref<SimpleTableInternal>& simple_table_internal)
790{
791 if (simple_table_internal.isNull())
792 ARCANE_FATAL("The reference passed as a parameter is Null.");
793 m_simple_table_internal = simple_table_internal;
794}
795
796/*---------------------------------------------------------------------------*/
797/*---------------------------------------------------------------------------*/
798
799} // End namespace Arcane
800
801/*---------------------------------------------------------------------------*/
802/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Modifiable view of an array of type T.
Span< const T > span() const
Immutable view of this array.
Constant view of an array of type T.
bool contains(const_reference v) const
true if the array contains the element of value v
constexpr Integer size() const noexcept
Number of elements in the array.
bool isNull() const
Indicates if the counter references a non-null instance.
Reference to an instance.
bool editElementLeft(Real element, bool update_last_position) override
Method to edit an element to the left of the last element most recently manipulated (same row/column ...
bool addElementInRow(Integer position, Real element) override
Method to add an element to a row.
Ref< SimpleTableInternal > internal() override
Method allowing retrieval of a reference to the object SimpleTableInternal used.
Integer rowPosition(const String &row_name) override
Method allowing retrieval of the position of a row.
bool addElementInColumn(Integer position, Real element) override
Method to add an element to a column.
String columnName(Integer position) override
Method allowing retrieval of the name of a column from its position.
bool addElementsInColumn(Integer position, ConstArrayView< Real > elements) override
Method to add multiple elements to a column.
Integer numberOfRows() override
Method allowing retrieval of the number of rows in the table. This is, in a sense,...
RealUniqueArray column(Integer position) override
Method allowing retrieval of a copy of a column.
bool addElementsInSameColumn(ConstArrayView< Real > elements) override
Method to add multiple elements to the column most recently manipulated.
bool addRows(StringConstArrayView rows_names) override
Method to add multiple rows.
bool addElementsInSameRow(ConstArrayView< Real > elements) override
Method to add multiple elements to the row most recently manipulated.
Real elementDown(bool update_last_position) override
Method allowing retrieval of an element below the last element recently manipulated (row below/same c...
void clearInternal() override
Method to clear the content of the SimpleTableInternal.
void setInternal(const Ref< SimpleTableInternal > &simple_table_internal) override
Method allowing setting a reference to a SimpleTableInternal.
Real element() override
Method allowing retrieval of a copy of an element.
bool editElementDown(Real element, bool update_last_position) override
Method to edit an element below the last element most recently manipulated (row below/same column).
Integer addAverageColumn(const String &column_name) override
Method allowing creation of a column containing the average of elements of each row.
bool editColumnName(Integer position, const String &new_name) override
Method allowing changing the name of a column.
bool editRowName(Integer position, const String &new_name) override
Method allowing changing the name of a row.
bool addElementInSameColumn(Real element) override
Method to add an element to the column most recently manipulated.
String rowName(Integer position) override
Method allowing retrieval of the name of a row from its position.
Integer addColumn(const String &column_name) override
Method to add a column.
RealUniqueArray row(Integer position) override
Method allowing retrieval of a copy of a row.
Real elementUp(bool update_last_position) override
Method allowing retrieval of an element above the last element recently manipulated (row above/same c...
bool editElementRight(Real element, bool update_last_position) override
Method allowing editing an element to the right of the last element recently manipulated (same row/co...
bool addElementInSameRow(Real element) override
Method to add an element to the row most recently manipulated.
bool addElementsInRow(Integer position, ConstArrayView< Real > elements) override
Method to add multiple elements to a row.
Integer rowSize(Integer position) override
Method allowing retrieval of the size of a row. Including hypothetical 'gaps' in the row.
Integer columnSize(Integer position) override
Method allowing retrieval of the size of a column. Including hypothetical 'gaps' in the column.
bool editElement(Real element) override
Method allowing modification of an element in the table.
bool editElementUp(Real element, bool update_last_position) override
Method to edit an element above the last element most recently manipulated (row above/same column).
Integer numberOfColumns() override
Method allowing retrieval of the number of columns in the table. This is, in a sense,...
Integer columnPosition(const String &column_name) override
Method allowing retrieval of the position of a column.
Real elementRight(bool update_last_position) override
Method allowing retrieval of an element to the right of the last element recently manipulated (same r...
Integer addRow(const String &row_name) override
Method to add a row.
Real elementLeft(bool update_last_position) override
Method allowing retrieval of an element to the left of the last element recently manipulated (same ro...
bool addColumns(StringConstArrayView columns_names) override
Method to add multiple columns.
std::optional< SizeType > findFirst(const_reference v) const
Definition Span.h:509
bool empty() const
True if the string is empty (null or "").
Definition String.cc:317
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ConstArrayView< String > StringConstArrayView
C equivalent of a 1D array of strings.
Definition UtilsTypes.h:492
Int32 Integer
Type representing an integer.
UniqueArray< Real > RealUniqueArray
Dynamic 1D array of reals.
Definition UtilsTypes.h:349
double Real
Type representing a real number.
UniqueArray< Integer > IntegerUniqueArray
Dynamic 1D array of integers.
Definition UtilsTypes.h:347