14#include "arcane/std/internal/VariableDataInfo.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/JSONWriter.h"
18#include "arcane/utils/JSONReader.h"
19#include "arcane/utils/Array.h"
20#include "arcane/utils/ValueConvert.h"
21#include "arcane/utils/Ref.h"
23#include "arcane/core/ISerializedData.h"
37 static void _addAttribute(XmlNode& node,
const String& attr_name,
Int64 value)
39 node.setAttrValue(attr_name, String::fromNumber(value));
42 static void _addAttribute(XmlNode& node,
const String& attr_name,
const String& value)
44 node.setAttrValue(attr_name, value);
47 static Integer _readInteger(
const XmlNode& node,
const String& attr_name)
49 return node.attr(attr_name,
true).valueAsInteger(
true);
52 static Int64 _readInt64(
const XmlNode& node,
const String& attr_name)
54 return node.attr(attr_name,
true).valueAsInt64(
true);
57 static bool _readBool(
const XmlNode& node,
const String& attr_name)
59 return node.attr(attr_name,
true).valueAsBoolean(
true);
62 static void _addAttribute(JSONWriter& o,
const String& attr_name,
Int64 value)
64 o.write(attr_name, value);
67 static void _addAttribute(JSONWriter& o,
const String& attr_name,
Int32 value)
69 o.write(attr_name, value);
72 static void _addAttribute(JSONWriter& o,
const String& attr_name,
const String& value)
74 o.write(attr_name, value);
77 static void _addAttribute(JSONWriter& o,
const String& attr_name,
bool value)
79 o.write(attr_name, value);
82 static Int32 _readInteger(
const JSONValue& jvalue,
const String& attr_name)
84 return jvalue.expectedChild(attr_name).valueAsInt32();
87 static Int64 _readInt64(
const JSONValue& jvalue,
const String& attr_name)
89 return jvalue.expectedChild(attr_name).valueAsInt64();
92 static bool _readBool(
const JSONValue& jvalue,
const String& attr_name)
94 return jvalue.expectedChild(attr_name).valueAsBool();
102VariableDataInfo(
const String& full_name,
const ISerializedData* sdata)
103: m_full_name(full_name)
104, m_nb_dimension(sdata->nbDimension())
105, m_nb_element(sdata->nbElement())
106, m_nb_base_element(sdata->nbBaseElement())
107, m_is_multi_size(sdata->isMultiSize())
111 if (m_nb_dimension == 2 && !m_is_multi_size) {
112 m_dim1_size = extents[0];
113 m_dim2_size = extents[1];
115 m_dimension_array_size = extents.
size();
116 m_base_data_type = sdata->baseDataType();
117 m_memory_size = sdata->memorySize();
118 m_shape = sdata->shape();
125VariableDataInfo(
const String& full_name,
const XmlNode& element)
126: m_full_name(full_name)
128 m_nb_dimension = _readInteger(element, V_NB_DIMENSION);
129 m_dim1_size = _readInt64(element, V_DIM1_SIZE);
130 m_dim2_size = _readInt64(element, V_DIM2_SIZE);
131 m_nb_element = _readInt64(element, V_NB_ELEMENT);
132 m_nb_base_element = _readInt64(element, V_NB_BASE_ELEMENT);
133 m_dimension_array_size = _readInteger(element, V_DIMENSION_ARRAY_SIZE);
134 m_is_multi_size = _readBool(element, V_IS_MULTI_SIZE);
135 m_base_data_type = (
eDataType)_readInteger(element, V_BASE_DATA_TYPE);
136 m_memory_size = _readInt64(element, V_MEMORY_SIZE);
137 m_file_offset = _readInt64(element, V_FILE_OFFSET);
139 XmlNode shape_attr = element.attr(V_SHAPE);
140 if (!shape_attr.null()) {
141 String shape_str = shape_attr.value();
142 if (!shape_str.empty()) {
143 UniqueArray<Int32> values;
144 if (builtInGetValue(values, shape_str))
145 ARCANE_FATAL(
"Can not read values '{0}' for attribute 'shape'", shape_str);
146 m_shape.setDimensions(values);
151 XmlNode hash_attr = element.attr(V_COMPARISON_HASH);
152 if (!hash_attr.null())
153 m_comparison_hash_value = hash_attr.value();
161VariableDataInfo(
const String& full_name,
const JSONValue& jvalue)
162: m_full_name(full_name)
165 m_nb_dimension = _readInteger(jvalue, V_NB_DIMENSION);
166 m_dim1_size = _readInt64(jvalue, V_DIM1_SIZE);
167 m_dim2_size = _readInt64(jvalue, V_DIM2_SIZE);
168 m_nb_element = _readInt64(jvalue, V_NB_ELEMENT);
169 m_nb_base_element = _readInt64(jvalue, V_NB_BASE_ELEMENT);
170 m_dimension_array_size = _readInteger(jvalue, V_DIMENSION_ARRAY_SIZE);
171 m_is_multi_size = _readBool(jvalue, V_IS_MULTI_SIZE);
172 m_base_data_type = (
eDataType)_readInteger(jvalue, V_BASE_DATA_TYPE);
173 m_memory_size = _readInt64(jvalue, V_MEMORY_SIZE);
174 m_file_offset = _readInt64(jvalue, V_FILE_OFFSET);
177 String shape_str = jvalue.expectedChild(V_SHAPE).valueAsStringView();
178 if (!shape_str.empty()) {
179 UniqueArray<Int32> values;
180 if (builtInGetValue(values, shape_str))
181 ARCANE_FATAL(
"Can not read values '{0}' for attribute 'shape'", shape_str);
182 m_shape.setDimensions(values);
185 m_comparison_hash_value = jvalue.expectedChild(V_COMPARISON_HASH).valueAsStringView();
191void VariableDataInfo::
192write(XmlNode element, JSONWriter& writer)
const
201void VariableDataInfo::
202_write(XmlNode element)
const
204 _addAttribute(element, V_NB_DIMENSION, m_nb_dimension);
205 _addAttribute(element, V_DIM1_SIZE, m_dim1_size);
206 _addAttribute(element, V_DIM2_SIZE, m_dim2_size);
207 _addAttribute(element, V_NB_ELEMENT, m_nb_element);
208 _addAttribute(element, V_NB_BASE_ELEMENT, m_nb_base_element);
209 _addAttribute(element, V_DIMENSION_ARRAY_SIZE, m_dimension_array_size);
210 _addAttribute(element, V_IS_MULTI_SIZE, (m_is_multi_size) ? 1 : 0);
211 _addAttribute(element, V_BASE_DATA_TYPE, (Integer)m_base_data_type);
212 _addAttribute(element, V_MEMORY_SIZE, m_memory_size);
213 _addAttribute(element, V_FILE_OFFSET, m_file_offset);
214 _addAttribute(element, V_SHAPE_SIZE, m_shape.dimensions().size());
215 _addAttribute(element, V_COMPARISON_HASH, m_comparison_hash_value);
219 ARCANE_FATAL(
"Can not write '{0}'", m_shape.dimensions());
220 _addAttribute(element, V_SHAPE, s);
227void VariableDataInfo::
228_write(JSONWriter& writer)
const
230 JSONWriter::Object o(writer, m_full_name);
231 _addAttribute(writer, V_NB_DIMENSION, m_nb_dimension);
232 _addAttribute(writer, V_DIM1_SIZE, m_dim1_size);
233 _addAttribute(writer, V_DIM2_SIZE, m_dim2_size);
234 _addAttribute(writer, V_NB_ELEMENT, m_nb_element);
235 _addAttribute(writer, V_NB_BASE_ELEMENT, m_nb_base_element);
236 _addAttribute(writer, V_DIMENSION_ARRAY_SIZE, m_dimension_array_size);
237 _addAttribute(writer, V_IS_MULTI_SIZE, m_is_multi_size);
238 _addAttribute(writer, V_BASE_DATA_TYPE, (Integer)m_base_data_type);
239 _addAttribute(writer, V_MEMORY_SIZE, m_memory_size);
240 _addAttribute(writer, V_FILE_OFFSET, m_file_offset);
241 _addAttribute(writer, V_SHAPE_SIZE, m_shape.dimensions().size());
242 _addAttribute(writer, V_COMPARISON_HASH, m_comparison_hash_value);
246 ARCANE_FATAL(
"Can not write '{0}'", m_shape.dimensions());
247 _addAttribute(writer, V_SHAPE, s);
257Ref<VariableDataInfo> VariableDataInfoMap::
258_add(VariableDataInfo* v)
261 m_data_info_map.insert(std::make_pair(v->fullName(), vref));
296find(
const String& full_name)
const
298 auto ivar = m_data_info_map.find(full_name);
299 if (ivar != m_data_info_map.end())
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
Interface d'une donnée sérialisée.
Représente une valeur JSON.
Référence à une instance.
Chaîne de caractères unicode.
Informations sur les données d'une variable.
bool builtInPutValue(const String &v, String &s)
Converti la valeur v dans la chaîne s.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int64 > Int64ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.
eDataType
Type d'une donnée.
std::int32_t Int32
Type entier signé sur 32 bits.