14#include "arcane/std/TextReader.h"
16#include "arcane/utils/IOException.h"
17#include "arcane/utils/Array.h"
18#include "arcane/utils/PlatformUtils.h"
19#include "arcane/utils/Ref.h"
20#include "arcane/utils/FatalErrorException.h"
21#include "arcane/utils/IDataCompressor.h"
23#include "arcane/core/ArcaneException.h"
40 Impl(
const String& filename)
41 : m_filename(filename)
47 std::ifstream m_istream;
49 Int64 m_file_length = 0;
57TextReader(
const String& filename)
58: m_p(new
Impl(filename))
60 std::ios::openmode mode = std::ios::in | std::ios::binary;
61 m_p->m_istream.open(filename.
localstr(), mode);
89_checkStream(
const char* type, Int64 nb_read_value)
91 std::istream& s = m_p->m_istream;
93 ARCANE_THROW(IOException,
"Can not read '{0}' (nb_val={1} bad?={2} "
94 "fail?={3} eof?={4} pos={5}) file='{6}'",
95 type, nb_read_value, s.bad(), s.fail(),
96 s.eof(), s.tellg(), m_p->m_filename);
103read(Span<std::byte> values)
105 Int64 nb_value = values.size();
106 _binaryRead(values.data(), nb_value);
107 _checkStream(
"byte[]", nb_value);
114read(Span<Byte> values)
123read(Span<Int64> values)
132read(Span<Int16> values)
141read(Span<Int32> values)
150read(Span<Real> values)
159_binaryRead(
void* values,
Int64 len)
161 std::istream& s = m_p->m_istream;
162 IDataCompressor* d = m_p->m_data_compressor.get();
163 if (d && len > d->minCompressSize()) {
164 UniqueArray<std::byte> compressed_values;
165 Int64 compressed_size = 0;
166 s.read((
char*)&compressed_size,
sizeof(
Int64));
167 compressed_values.resize(compressed_size);
168 s.read((
char*)compressed_values.data(), compressed_size);
169 m_p->m_data_compressor->decompress(compressed_values, Span<std::byte>((std::byte*)values, len));
172 s.read((
char*)values, len);
182 return m_p->m_filename;
189setFileOffset(
Int64 v)
191 m_p->m_istream.seekg(v, std::ios::beg);
198setDataCompressor(Ref<IDataCompressor> dc)
200 m_p->m_data_compressor = dc;
206Ref<IDataCompressor> TextReader::
207dataCompressor()
const
209 return m_p->m_data_compressor;
215std::ifstream& TextReader::
218 return m_p->m_istream;
227 return m_p->m_file_length;
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
Exception in a reader or writer.
Reference to an instance.
View of an array of elements of type T.
Unicode character string.
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
Impl::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of modifiable bytes.