14#include "arcane/std/TextWriter.h"
16#include "arcane/utils/ArrayView.h"
17#include "arcane/utils/CheckedConvert.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/FatalErrorException.h"
20#include "arcane/utils/Ref.h"
21#include "arcane/utils/IDataCompressor.h"
23#include "arcane/ArcaneException.h"
40 std::ofstream m_ostream;
48TextWriter(
const String& filename)
76open(
const String& filename)
78 m_p->m_filename = filename;
79 std::ios::openmode mode = std::ios::out | std::ios::binary;
80 m_p->m_ostream.open(filename.localstr(),mode);
82 ARCANE_THROW(ReaderWriterException,
"Can not open file '{0}' for writing", filename);
83 m_p->m_ostream.precision(FloatInfo<Real>::maxDigit() + 2);
90write(Span<const Real> values)
92 _binaryWrite(values.data(), values.size() *
sizeof(
Real));
99write(Span<const Int16> values)
101 _binaryWrite(values.data(), values.size() *
sizeof(
Int16));
108write(Span<const Int32> values)
110 _binaryWrite(values.data(), values.size() *
sizeof(
Int32));
117write(Span<const Int64> values)
119 _binaryWrite(values.data(), values.size() *
sizeof(
Int64));
126write(Span<const Byte> values)
128 _binaryWrite(values.data(), values.size());
135write(Span<const std::byte> values)
137 _binaryWrite(values.data(), values.size());
146 return m_p->m_filename;
150setDataCompressor(Ref<IDataCompressor> dc)
152 m_p->m_data_compressor = dc;
155Ref<IDataCompressor> TextWriter::
156dataCompressor()
const
158 return m_p->m_data_compressor;
164 return m_p->m_ostream.tellp();
168_binaryWrite(
const void* bytes,
Int64 len)
170 std::ostream& o = m_p->m_ostream;
172 IDataCompressor* d = m_p->m_data_compressor.get();
173 if (d && len > d->minCompressSize()) {
174 UniqueArray<std::byte> compressed_values;
175 m_p->m_data_compressor->compress(Span<const std::byte>((
const std::byte*)bytes,len), compressed_values);
176 Int64 compressed_size = compressed_values.largeSize();
177 o.write((
const char *) &compressed_size,
sizeof(
Int64));
178 o.write((
const char *) compressed_values.data(), compressed_size);
182 o.write((
const char *) bytes, len);
188std::ostream& TextWriter::
191 return m_p->m_ostream;
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Chaîne de caractères unicode.