Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
JSONWriter.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* JSONWriter.h (C) 2000-2023 */
9/* */
10/* Ecrivain au format JSON. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_JSONWRITER_H
13#define ARCANE_UTILS_JSONWRITER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
32class ARCANE_UTILS_EXPORT JSONWriter
33{
34 class Impl;
35
36 public:
37
38 class Object
39 {
40 public:
41
43 : m_writer(writer)
44 {
45 m_writer.beginObject();
46 }
48 : m_writer(writer)
49 {
50 m_writer.writeKey(str);
51 m_writer.beginObject();
52 }
53 ~Object() ARCANE_NOEXCEPT_FALSE
54 {
55 m_writer.endObject();
56 }
57
58 private:
59
60 JSONWriter& m_writer;
61 };
62 class Array
63 {
64 public:
65
67 : m_writer(writer)
68 {
69 m_writer.writeKey(name);
70 m_writer.beginArray();
71 }
72 ~Array() ARCANE_NOEXCEPT_FALSE
73 {
74 m_writer.endArray();
75 }
76
77 private:
78
79 JSONWriter& m_writer;
80 };
81
82 public:
83
84 enum class FormatFlags
85 {
86 None = 0,
87 // Indique qu'on sérialise les réels au format hexadécimal
88 HexFloat = 1,
89
90 Default = HexFloat
91 };
92
93 public:
94
95 JSONWriter(FormatFlags format_flags = FormatFlags::Default);
97
98 public:
99
100 void beginObject();
101 void endObject();
102 void beginArray();
103 void endArray();
104 void writeKey(StringView key);
105 void writeValue(StringView str);
106 void write(StringView key, const char* v);
107 void write(StringView key, std::string_view v);
108 void write(StringView key, bool v);
109 void write(StringView key, long long v) { _writeInt64(key, static_cast<Int64>(v)); }
110 void write(StringView key, long v) { _writeInt64(key, static_cast<Int64>(v)); }
111 void write(StringView key, int v) { _writeInt64(key, static_cast<Int64>(v)); }
112 void write(StringView key, unsigned long long v) { _writeUInt64(key, static_cast<UInt64>(v)); }
113 void write(StringView key, unsigned long v) { _writeUInt64(key, static_cast<UInt64>(v)); }
114 void write(StringView key, unsigned int v) { _writeUInt64(key, static_cast<UInt64>(v)); }
115 void write(StringView key, Real v);
116 void write(StringView key, StringView str);
117 void writeIfNotNull(StringView key, const String& str);
118 void write(StringView key, Span<const Int32> view);
119 void write(StringView key, Span<const Int64> view);
120 void write(StringView key, Span<const Real> view);
121
122 public:
123
124 StringView getBuffer() const;
125
126 private:
127
128 Impl* m_p;
129
130 void _writeInt64(StringView key, Int64 v);
131 void _writeUInt64(StringView key, UInt64 v);
132};
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
137} // namespace Arcane
138
139/*---------------------------------------------------------------------------*/
140/*---------------------------------------------------------------------------*/
141
142#endif
Ecrivain au format JSON.
Definition JSONWriter.h:33
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Vue sur une chaîne de caractères UTF-8.
Definition StringView.h:47
@ Default
Utilise 0 comme valeur par défaut.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::uint64_t UInt64
Type entier non signé sur 64 bits.