33 istream_ =
new istream(is.rdbuf());
76 istream_ =
new istream(is.rdbuf());
113 for (i = 0; i < bufsize-1; i++)
115 (*istream_).read(ob+i,
sizeof(
char));
134 std::streamsize len = std::min(
static_cast<std::streamsize
>(temp.size()), bufsize - 1);
135 std::memcpy(ob, temp.c_str(), len);
139 if (ob[bufsize-1] == 0)
148 Cerr <<
"Error in Entree::lire(char* ob, int bufsize) : buffer too small" << finl;
151 return (!istream_->fail());
154void error_convert(
const char * s,
const char * type)
156 Cerr <<
"Error converting a string to type " << type <<
" : string = " << s << finl;
163void convert_to(
const char *s,
int& ob)
167 ob = (int)strtol(s, &errorptr, 0 );
168 if (errno || *errorptr != 0) error_convert(s,
"int");
171void convert_to(
const char *s,
long& ob)
175 ob = strtol(s, &errorptr, 0 );
176 if (errno || *errorptr != 0) error_convert(s,
"long");
179void convert_to(
const char *s,
long long& ob)
184 ob = strtol(s, &errorptr, 0 );
187 ob = _strtoi64(s, &errorptr, 0 );
189 ob = strtoll(s, &errorptr, 0 );
192 if (errno || *errorptr != 0) error_convert(s,
"long long");
195void convert_to(
const char *s,
float& ob)
199 ob = strtof(s, &errorptr);
200 if (errno || *errorptr != 0) error_convert(s,
"float");
203void convert_to(
const char *s,
double& ob)
207 ob = strtod(s, &errorptr);
208 if (errno || *errorptr != 0) error_convert(s,
"double");
219int Entree::get(
double * ob, std::streamsize n) {
return get_template<double>(ob,n); }
222int Entree::get(
int * ob, std::streamsize n) {
return get_template<int>(ob,n); }
225int Entree::get(
float * ob, std::streamsize n) {
return get_template<float>(ob,n); }
228int Entree::get(
long * ob, std::streamsize n) {
return get_template<long>(ob,n); }
231int Entree::get(
long long * ob, std::streamsize n) {
return get_template<long long>(ob,n); }
243 char tmp=(char)istream_->peek();
249 tmp=(char)istream_->peek();
259 return (istream_->eof());
266 return (istream_->fail());
273 return (istream_->good());
296 Cerr<<
"Error you cant change binary format after open "<<finl;
352 Cerr <<
"Error while reading in Entree object. Exiting.\n";
358 Cerr <<
" End of file reached." << finl;
360 Cerr <<
" IO error (not an EOF error)." << finl;
389int is_a_binary_file(
Nom& filename)
396 std::ifstream fic(filename.
getChar());
399 while((c = fic.get()) != EOF && n++<1000)
417template<
typename _TYPE_>
418int Entree::get_template(_TYPE_ *ob, std::streamsize n)
427 for (
int i = 0; i < n; i++) (*
this) >> ob[i];
432 char *ptr = (
char*) ob;
433 std::streamsize sz =
sizeof(_TYPE_);
435 istream_->read(ptr, sz);
443 for (
int i = 0; i < n; i++) Entree::operator>>(ob[i]);
445 return (!istream_->fail());
449template int Entree::get_template(
int *ob, std::streamsize n);
450template int Entree::get_template(
long *ob, std::streamsize n);
451template int Entree::get_template(
long long *ob, std::streamsize n);
452template int Entree::get_template(
double *ob, std::streamsize n);
453template int Entree::get_template(
float *ob, std::streamsize n);
456template <
typename _TYPE_>
457Entree& Entree::operator_template(_TYPE_& ob)
470 char *ptr = (
char*) ≺
471 istream_->read(ptr,
sizeof(std::int64_t));
472 if (pr > std::numeric_limits<int>::max())
474 Cerr <<
"Can't read this int64 binary file with an int32 binary: values too big, overflow!!" << finl;
478 ob =
static_cast<_TYPE_
>(pr);
484 char * ptr = (
char*) ≺
485 istream_->read(ptr,
sizeof(
int));
491 char *ptr = (
char*) &ob;
492 istream_->read(ptr,
sizeof(_TYPE_));
503 convert_to(buffer, ob);
515template Entree& Entree::operator_template(
int& ob);
516template Entree& Entree::operator_template(
long& ob);
517template Entree& Entree::operator_template(
long long& ob);
518template Entree& Entree::operator_template(
double& ob);
519template Entree& Entree::operator_template(
float& ob);
bool bin_
Is this a binary flux?
bool is_64b_
Will we be reading/writing in 64b? (Init in ctor to avoid including arch.h probably).
bool must_convert() const
Whether to convert an int into a long when reading/writing out data.
Class defining operators and methods for all reading operation in an input flow (file,...
virtual int error_handle_(int fail_flag)
Cette fonction est appellee par operateur>>, get, get_nom ouvrir, fermer, lire, etc.
int error_handle(int fail_flag)
Entree & operator=(istream &is)
virtual int get(int *ob, std::streamsize n)
virtual void set_diffuse(bool diffuse)
ToDo TMA : commenter.
virtual int jumpOfLines()
virtual void set_error_action(Error_Action)
Change le comportement en cas d'erreur de l'entree, voir error_handle_() et get_error_action().
Error_Action error_action_
Entree & operator>>(Entree &(*f)(Entree &))
virtual istream & get_istream()
void set_bin(bool bin) override
Change le mode d'ecriture du fichier.
void set_istream(istream *is)
Error_Action get_error_action()
renvoie error_action_ pour cette entree (permet de la modifier et de restaurer ensuite la valeur ante...
virtual void set_check_types(bool flag)
indique si le stream doit verifier les types des objets lus (ints et nombres flottants).
class Nom Une chaine de caractere pour nommer les objets de TRUST
const char * getChar() const
const std::string & getString() const
classe Objet_U Cette classe est la classe de base des Objets de TRUST
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.