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"
30 virtual void checkValid() = 0;
39template <
typename T>
class ValueTraits;
40#define VALUE_TRAITS(type_name, basic_type_name) \
41 template <> class ValueTraits<type_name> \
45 static eBasicDataType dataType() { return eBasicDataType::basic_type_name; } \
46 static void getValue(ISerializer* s, type_name& v) { v = s->get##type_name(); } \
49#define VALUE_TRAITS2(type_name) VALUE_TRAITS(type_name, type_name)
59VALUE_TRAITS(Real, Float64);
68template <
typename DataType>
72 using ValueTraitsType = ValueTraits<DataType>;
77 : m_data_type(ValueTraitsType::dataType())
84 Int64 size = m_array_values.size();
86 case ISerializer::ModeReserve:
87 std::cout <<
"ReserveArray type=" << m_data_type <<
" size=" << m_array_values.size() <<
"\n";
93 std::cout <<
"PutArray type=" << m_data_type <<
" size=" << m_array_values.size() <<
"\n";
96 s->
put(m_array_values[0]);
101 ValueTraitsType::getValue(s, m_unique_value);
105 void checkValid()
override
107 std::cout <<
"ref_size=" << m_array_values.size()
108 <<
" result_size=" << m_result_array_values.size() <<
"\n";
109 ASSERT_EQ(m_array_values, m_result_array_values);
110 ASSERT_EQ(m_array_values[0], m_unique_value);
113 void resizeAndFill(Int32 size)
115 m_array_values.resize(size);
116 ValueFiller::fillRandom(542, m_array_values.span());
123 DataType m_unique_value = {};
130class StringSerializeValue
135 explicit StringSerializeValue(
const String& v)
144 case ISerializer::ModeReserve:
148 s->
put(m_ref_string);
151 s->
get(m_result_string);
155 void checkValid()
override
157 ASSERT_EQ(m_ref_string, m_result_string);
189 template <
typename DataType>
void add(Int32 size)
192 sval->resizeAndFill(size);
195 void addString(
const String& v)
217 values.add<
Int8>(6357);
219 values.add<Int16>(16353);
220 values.add<Real>(29123);
221 values.add<Int32>(16);
222 values.add<
Byte>(3289);
223 values.add<Int64>(12932);
225 values.add<
Int128>(32422);
226 values.addString(
"Ceci est un test de chaîne de caractères");
228 serializer->
setMode(ISerializer::ModeReserve);
229 values.doSerialize(serializer);
232 values.doSerialize(serializer);
234 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.
InstanceType * get() const
Associated instance or nullptr if none.
Reference to an instance.
Unicode character string.
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.
eBasicDataType
Type of a basic data item.
@ Unknown
Unknown or uninitialized data type.
unsigned char Byte
Type of a byte.
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.