Arcane  4.2.1.0
User documentation
Loading...
Searching...
No Matches
ArrayViewDumper.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/* ArrayViewDumper.h (C) 2000-2026 */
9/* */
10/* Functions to dump values of Arccore array views (ArrayView, Span, ...) */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_BASE_ARRAYVIEWDUMPER_H
13#define ARCCORE_BASE_ARRAYVIEWDUMPER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include <iosfwd>
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::Impl
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29/*!
30 * \brief Helper class to dump an array view on a stream.
31 *
32 * The method \a dumpArray() is templated on the stream type so we do not
33 * need to include the header 'iostream' in this header. The goal is to reduce
34 * compilation time. The user has to include 'iostream' if he needs to
35 * dump the array.
36 */
37template <typename ViewType>
39{
40 public:
41
42 template <typename Stream> static void
43 dumpArray(Stream& o, ViewType val, int max_print)
44 {
45 using size_type = typename ViewType::size_type;
46 size_type n = val.size();
47 if (max_print > 0 && n > max_print) {
48 // Only displays the first (max_print/2) and the last (max_print/2)
49 // otherwise if the array is very large it can generate enormous
50 // output listings.
51 size_type z = (max_print / 2);
52 size_type z2 = n - z;
53 o << "[0]=\"" << val[0] << '"';
54 for (size_type i = 1; i < z; ++i)
55 o << " [" << i << "]=\"" << val[i] << '"';
56 o << " ... ... (skipping indexes " << z << " to " << z2 << " ) ... ... ";
57 for (size_type i = (z2 + 1); i < n; ++i)
58 o << " [" << i << "]=\"" << val[i] << '"';
59 }
60 else {
61 for (size_type i = 0; i < n; ++i) {
62 if (i != 0)
63 o << ' ';
64 o << "[" << i << "]=\"" << val[i] << '"';
65 }
66 }
67 }
68};
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73} // namespace Arcane::Impl
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
78#endif
Definitions and globals of Arccore.
Helper class to dump an array view on a stream.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:325