Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemPrinter.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/* ItemPrinter.h (C) 2000-2025 */
9/* */
10/* Routines for printing an entity. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMPRINTER_H
13#define ARCANE_CORE_ITEMPRINTER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Iostream.h"
18
20#include "arcane/core/Item.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31/*!
32 * \brief Utility class for printing information about an entity.
33 */
34class ARCANE_CORE_EXPORT ItemPrinter
35{
36 public:
37
38 ItemPrinter(ItemInternal* item, eItemKind ik)
39 : m_item(item)
40 , m_item_kind(ik)
41 , m_has_item_kind(true)
42 {}
43 ItemPrinter(ItemInternal* item)
44 : m_item(item)
45 , m_item_kind(IK_Unknown)
46 , m_has_item_kind(false)
47 {}
48 ItemPrinter(const Item& item)
49 : m_item(item.itemBase())
50 , m_item_kind(IK_Unknown)
51 , m_has_item_kind(false)
52 {}
53 ItemPrinter(const Item& item, eItemKind ik)
54 : m_item(item.itemBase())
55 , m_item_kind(ik)
56 , m_has_item_kind(true)
57 {}
58 ItemPrinter(const Node& item)
59 : m_item(item.itemBase())
60 , m_item_kind(IK_Node)
61 , m_has_item_kind(true)
62 {}
63 ItemPrinter(const Edge& item)
64 : m_item(item.itemBase())
65 , m_item_kind(IK_Edge)
66 , m_has_item_kind(true)
67 {}
68 ItemPrinter(const Face& item)
69 : m_item(item.itemBase())
70 , m_item_kind(IK_Face)
71 , m_has_item_kind(true)
72 {}
73 ItemPrinter(const Cell& item)
74 : m_item(item.itemBase())
75 , m_item_kind(IK_Cell)
76 , m_has_item_kind(true)
77 {}
78 ItemPrinter(const Particle& item)
79 : m_item(item.itemBase())
80 , m_item_kind(IK_Particle)
81 , m_has_item_kind(true)
82 {}
83
84 public:
85
86 //! Write to stream of the current Item
87 void print(std::ostream& o) const;
88
89 public:
90
91 impl::ItemBase m_item;
92 eItemKind m_item_kind;
93 bool m_has_item_kind;
94
95 public:
96
97 struct Internal;
98};
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103class ARCANE_CORE_EXPORT FullItemPrinter
104{
105 public:
106
107 explicit FullItemPrinter(const Item& item)
108 : m_item(item.itemBase())
109 {}
110
111 //! Write to stream of the current Item and its sub-items
112 void print(std::ostream& o) const;
113
114 private:
115
116 impl::ItemBase m_item;
117};
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
122class ARCANE_CORE_EXPORT NeighborItemPrinter
123{
124 public:
125
126 explicit NeighborItemPrinter(Item item, const Integer levelmax = 1)
127 : m_item(item.itemBase())
128 , m_level_max(levelmax)
129 {}
130
131 //! Write to stream of the current Item and its sub-items
132 void print(std::ostream& o) const { print(o, m_item, m_level_max, m_level_max); }
133
134 private:
135
136 impl::ItemBase m_item;
137 Integer m_level_max;
138
139 private:
140
141 static std::ostream& indent(std::ostream& o, Integer n);
142 static void print(std::ostream& o, Item item, Integer level, Integer levelmax);
143 static void _printSubItems(std::ostream& ostr, Integer level, Integer levelmax,
144 ItemVectorView sub_items, const char* name);
145};
146
147/*---------------------------------------------------------------------------*/
148/*---------------------------------------------------------------------------*/
149
150inline std::ostream&
151operator<<(std::ostream& o, const ItemPrinter& ip)
152{
153 ip.print(o);
154 return o;
155}
156
157inline std::ostream&
158operator<<(std::ostream& o, const FullItemPrinter& ip)
159{
160 ip.print(o);
161 return o;
162}
163
164inline std::ostream&
165operator<<(std::ostream& o, const NeighborItemPrinter& ip)
166{
167 ip.print(o);
168 return o;
169}
170
171/*---------------------------------------------------------------------------*/
172/*---------------------------------------------------------------------------*/
173
174} // namespace Arcane
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179#endif
Declarations of Arcane's general types.
Cell of a mesh.
Definition Item.h:1300
Edge of a cell.
Definition Item.h:875
Face of a cell.
Definition Item.h:1032
void print(std::ostream &o) const
Write to stream of the current Item and its sub-items.
void print(std::ostream &o) const
Write to stream of the current Item.
View on a vector of entities.
Base class for a mesh element.
Definition Item.h:84
impl::ItemBase itemBase() const
Internal part of the entity.
Definition Item.h:383
void print(std::ostream &o) const
Write to stream of the current Item and its sub-items.
Node of a mesh.
Definition Item.h:598
Particle.
Definition Item.h:1529
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
eItemKind
Mesh entity type.
@ IK_Particle
Particle mesh entity.
@ IK_Node
Node mesh entity.
@ IK_Cell
Cell mesh entity.
@ IK_Unknown
Unknown or uninitialized mesh entity.
@ IK_Face
Face mesh entity.
@ IK_Edge
Edge mesh entity.
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Output operator for a stream.