14#include "arcane/std/internal/TextReader2.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"
22#include "arcane/utils/FixedArray.h"
24#include "arcane/core/ArcaneException.h"
42 : m_filename(filename)
48 std::ifstream m_istream;
49 Integer m_current_line = 0;
50 Int64 m_file_length = 0;
58TextReader2(
const String& filename)
61 std::ios::openmode mode = std::ios::in | std::ios::binary;
62 m_p->m_istream.open(filename.
localstr(), mode);
65 m_p->m_file_length = platform::getFileLength(filename);
83 read(asWritableBytes(values));
90_checkStream(
const char* type,
Int64 nb_read_value)
92 std::istream& s = m_p->m_istream;
94 ARCANE_THROW(IOException,
"Can not read '{0}' (nb_val={1} bad?={2} "
95 "fail?={3} eof?={4} pos={5}) file='{6}'",
96 type, nb_read_value, s.bad(), s.fail(),
97 s.eof(), s.tellg(), m_p->m_filename);
104read(Span<std::byte> values)
106 Int64 nb_value = values.size();
108 _checkStream(
"byte[]", nb_value);
115_binaryRead(Span<std::byte> values)
117 std::istream& s = m_p->m_istream;
118 IDataCompressor* d = m_p->m_data_compressor.get();
119 if (d && values.size() > d->minCompressSize()) {
120 UniqueArray<std::byte> compressed_values;
121 FixedArray<Int64, 1> compressed_size;
123 compressed_values.resize(compressed_size[0]);
125 m_p->m_data_compressor->decompress(compressed_values, values);
138 return m_p->m_filename;
145setFileOffset(
Int64 v)
147 m_p->m_istream.seekg(v, std::ios::beg);
154setDataCompressor(Ref<IDataCompressor> dc)
156 m_p->m_data_compressor = dc;
162Ref<IDataCompressor> TextReader2::
163dataCompressor()
const
165 return m_p->m_data_compressor;
171std::istream& TextReader2::
174 return m_p->m_istream;
183 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.
void binaryRead(std::istream &istr, const Span< std::byte > &bytes)
Lit en binaire le contenu de bytes depuis le flot istr.
detail::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets modifiables.