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/ArcaneException.h"
40 : m_filename(filename) {}
43 std::ifstream m_istream;
44 Integer m_current_line = 0;
45 Int64 m_file_length = 0;
53TextReader(
const String& filename)
56 std::ios::openmode mode = std::ios::in | std::ios::binary;
57 m_p->m_istream.open(filename.
localstr(),mode);
60 m_p->m_file_length = platform::getFileLength(filename);
78 read(asWritableBytes(values));
85_checkStream(
const char* type,
Int64 nb_read_value)
87 std::istream& s = m_p->m_istream;
89 ARCANE_THROW(IOException,
"Can not read '{0}' (nb_val={1} bad?={2} "
90 "fail?={3} eof?={4} pos={5}) file='{6}'",
91 type, nb_read_value, s.bad(), s.fail(),
92 s.eof(), s.tellg(), m_p->m_filename);
99read(Span<std::byte> values)
101 Int64 nb_value = values.size();
102 _binaryRead(values.data(), nb_value);
103 _checkStream(
"byte[]", nb_value);
110read(Span<Byte> values)
119read(Span<Int64> values)
128read(Span<Int16> values)
137read(Span<Int32> values)
146read(Span<Real> values)
155_binaryRead(
void* values,
Int64 len)
157 std::istream& s = m_p->m_istream;
158 IDataCompressor* d = m_p->m_data_compressor.get();
159 if (d && len > d->minCompressSize()) {
160 UniqueArray<std::byte> compressed_values;
161 Int64 compressed_size = 0;
162 s.read((
char*)&compressed_size,
sizeof(
Int64));
163 compressed_values.resize(compressed_size);
164 s.read((
char*)compressed_values.data(), compressed_size);
165 m_p->m_data_compressor->decompress(compressed_values, Span<std::byte>((std::byte*)values,len));
168 s.read((
char*)values, len);
178 return m_p->m_filename;
185setFileOffset(
Int64 v)
187 m_p->m_istream.seekg(v,std::ios::beg);
194setDataCompressor(Ref<IDataCompressor> dc)
196 m_p->m_data_compressor = dc;
202Ref<IDataCompressor> TextReader::
203dataCompressor()
const
205 return m_p->m_data_compressor;
211std::ifstream& TextReader::
214 return m_p->m_istream;
223 return m_p->m_file_length;
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Exception dans un lecteur ou écrivain.
Chaîne de caractères unicode.
const char * localstr() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
detail::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets modifiables.