7#include <gtest/gtest.h>
9#include "arccore/serialize/BasicSerializer.h"
12#include "arccore/base/FatalErrorException.h"
13#include "arccore/base/ValueFiller.h"
15#include "arccore/base/Float128.h"
16#include "arccore/base/Int128.h"
17#include "arccore/common/NumArray.h"
18#include "arccore/collections/Array2.h"
19#include "arccore/serialize/SerializerExtension.h"
33 virtual void checkValid() = 0;
42template <
typename T>
class ValueTraits;
43#define VALUE_TRAITS(type_name, basic_type_name) \
44 template <> class ValueTraits<type_name> \
48 static eBasicDataType dataType() { return eBasicDataType::basic_type_name; } \
49 static void getValue(ISerializer* s, type_name& v) { v = s->get##type_name(); } \
52#define VALUE_TRAITS2(type_name) VALUE_TRAITS(type_name, type_name)
62VALUE_TRAITS(Real, Float64);
71template <
typename DataType>
75 using ValueTraitsType = ValueTraits<DataType>;
80 : m_data_type(ValueTraitsType::dataType())
87 Int64 size = m_array_values.size();
89 case ISerializer::ModeReserve:
90 std::cout <<
"ReserveArray type=" << m_data_type <<
" size=" << m_array_values.size() <<
"\n";
96 std::cout <<
"PutArray type=" << m_data_type <<
" size=" << m_array_values.size() <<
"\n";
99 s->
put(m_array_values[0]);
104 ValueTraitsType::getValue(s, m_unique_value);
108 void checkValid()
override
110 std::cout <<
"ref_size=" << m_array_values.size()
111 <<
" result_size=" << m_result_array_values.size() <<
"\n";
112 ASSERT_EQ(m_array_values, m_result_array_values);
113 ASSERT_EQ(m_array_values[0], m_unique_value);
116 void resizeAndFill(Int32 size)
118 m_array_values.resize(size);
119 ValueFiller::fillRandom(542, m_array_values.span());
126 DataType m_unique_value = {};
133class StringSerializeValue
138 explicit StringSerializeValue(
const String& v)
144 m_ref_string.addRange(v);
152 Int64 size = m_ref_string.size();
154 case ISerializer::ModeReserve:
155 std::cout <<
"ReserveArray type=String size=" << m_ref_string.size() <<
"\n";
161 std::cout <<
"PutArray type=String size=" << m_ref_string.size() <<
"\n";
164 s->
put(m_ref_string[0]);
169 s->
get(m_unique_value);
173 void checkValid()
override
175 std::cout <<
"ref_size=" << m_ref_string.size()
176 <<
" result_size=" << m_result_string.size() <<
"\n";
177 for (
Integer i = 0; i < m_ref_string.size(); ++i) {
179 ASSERT_EQ(m_ref_string[i], m_result_string[i]);
181 if (!m_ref_string.empty()) {
183 ASSERT_EQ(m_ref_string[0], m_unique_value);
197template <
typename DataType>
198class Serialize2DValue
201 using ValueTraitsType = ValueTraits<DataType>;
206 : m_data_type(ValueTraitsType::dataType())
215 case ISerializer::ModeReserve:
216 std::cout <<
"ReserveArray type=" << m_data_type <<
" size1=" << m_array_values.dim1Size() <<
" size2=" << m_array_values.dim2Size() <<
"\n";
220 std::cout <<
"PutArray type=" << m_data_type <<
" size1=" << m_array_values.dim1Size() <<
" size2=" << m_array_values.dim2Size() <<
"\n";
221 se.
putArray(m_array_values.constSpan());
228 void checkValid()
override
230 std::cout <<
"ref_size1=" << m_array_values.dim1Size()
231 <<
" ref_size2=" << m_array_values.dim2Size()
232 <<
" result_size1=" << m_result_array_values.dim1Size()
233 <<
" result_size2=" << m_result_array_values.dim2Size() <<
"\n";
234 for (Int32 i = 0; i < m_array_values.dim1Size(); ++i) {
235 ASSERT_EQ(m_array_values[i], m_result_array_values[i]);
239 void resizeAndFill(Int32 size1, Int32 size2)
241 m_array_values.resize(size1, size2);
242 ValueFiller::fillRandom(542, m_array_values.to1DSpan());
255template <
typename DataType,
typename Extents>
256class MDSerializeValue
259 using ValueTraitsType = ValueTraits<DataType>;
264 : m_data_type(ValueTraitsType::dataType())
273 case ISerializer::ModeReserve:
274 std::cout <<
"ReserveArray type=" << m_data_type <<
" dim=" << Extents::rank() <<
" total_size=" << m_array_values.totalNbElement() <<
"\n";
278 std::cout <<
"PutArray type=" << m_data_type <<
" dim=" << Extents::rank() <<
" total_size=" << m_array_values.totalNbElement() <<
"\n";
279 se.
putArray(m_array_values.constSpan());
286 void checkValid()
override
288 std::cout <<
"ref_size=" << m_array_values.totalNbElement()
289 <<
" result_size=" << m_result_array_values.totalNbElement() <<
"\n";
291 ASSERT_EQ(m_array_values.to1DSpan(), m_result_array_values.to1DSpan());
294 void resizeAndFill(
Arcane::MDIndex<Extents::rank(),
typename Extents::ExtentIndexType> size)
296 m_array_values.resize(size);
297 ValueFiller::fillRandom(542, m_array_values.to1DSpan());
330 template <
typename DataType>
334 sval->resizeAndFill(size);
337 void addString(
const String& v)
347 template <
typename DataType>
348 void add(Int32 size1, Int32 size2)
351 sval->resizeAndFill(size1, size2);
355 template <
typename DataType,
typename Extents>
356 void add(
Arcane::MDIndex<Extents::rank(),
typename Extents::ExtentIndexType> size)
359 sval->resizeAndFill(size);
380 values.add<
Int8>(6357);
382 values.add<Int16>(16353);
383 values.add<Real>(29123);
384 values.add<Int32>(16);
385 values.add<
Byte>(3289);
386 values.add<Int64>(12932);
388 values.add<
Int128>(32422);
390 values.addString(
"Ceci est un test de chaîne de caractères");
391 values.addString(
UniqueArray<String>({
"Ceci",
"est",
"un",
"test",
"de",
"chaîne",
"de",
"caractères" }));
393 values.add<Real>(29, 123);
394 values.add<Int32>(16, 23);
407 serializer->
setMode(ISerializer::ModeReserve);
408 values.doSerialize(serializer);
411 values.doSerialize(serializer);
413 values.doSerialize(serializer);
File containing definitions of basic data types managed by Arccore.
Management of references to a C++ class.
Base class for an exception.
@ ModePut
The serializer expects reserve().
@ ModeGet
The serializer expects get().
virtual void allocateBuffer()=0
Allocates the serializer memory.
virtual void setMode(eMode new_mode)=0
Sets the current mode.
Multi-dimensional arrays for numerical types accessible on accelerators.
InstanceType * get() const
Associated instance or nullptr if none.
Reference to an instance.
Class that extends the functionalities of the ISerializer.
void reserveArray(Span2< const Type > values) const
Reserve to save the number of elements and the values elements.
void putArray(Span2< const Type > values) const
Save the number of elements and the values elements.
void getArray(Array2< Type > &values) const
Resize and fill values.
View of an array of elements of type T.
Unicode character string.
2D data vector with value semantics (STL style).
1D data vector with value semantics (STL style).
virtual void reserve(eBasicDataType dt, Int64 n)=0
Reserves memory for n objects of type dt.
virtual void putArray(Span< const Real > values)=0
Save the number of elements and the values elements.
virtual void reserveArray(Span< const Real > values)=0
Reserve to save the number of elements and the values elements.
virtual eMode mode() const =0
Current operating mode.
virtual void getArray(Array< Real > &values)=0
Resize and fill values.
virtual void put(Span< const Real > values)=0
Add the array values.
virtual void get(ArrayView< Real > values)=0
Retrieve the array values.
Int32 Integer
Type representing an integer.
eBasicDataType
Type of a basic data item.
@ Unknown
Unknown or uninitialized data type.
ExtentsV< Int32, DynExtent, DynExtent, DynExtent, DynExtent > MDDim4
Constant for a rank 4 dynamic array.
unsigned char Byte
Type of a byte.
ExtentsV< Int32, DynExtent, DynExtent > MDDim2
Constant for a rank 2 dynamic array.
ExtentsV< Int32, DynExtent > MDDim1
Constant for a rank 1 dynamic array.
ExtentsV< Int32, DynExtent, DynExtent, DynExtent > MDDim3
Constant for a rank 3 dynamic array.
Arcane::Float128 Float128
Type representing a 128-bit float.
Arcane::BFloat16 BFloat16
Type 'Brain Float16'.
float Float32
IEEE-753 single precision floating point type (binary32).
Arcane::Float16 Float16
Type 'Float16' (binary16).
ARCCORE_SERIALIZE_EXPORT Ref< ISerializer > createSerializer()
Creates an instance of ISerializer.
Arcane::Int8 Int8
Type representing an 8-bit integer.
Arcane::Int128 Int128
Type representing a 128-bit integer.