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;
349 Cerr <<
"Error while reading in Entree object. Exiting.\n";
355 Cerr <<
" End of file reached." << finl;
357 Cerr <<
" IO error (not an EOF error)." << finl;
386int is_a_binary_file(
Nom& filename)
393 std::ifstream fic(filename.
getChar());
396 while((c = fic.get()) != EOF && n++<1000)
416template<
typename _TYPE_>
417int Entree::get_template(_TYPE_ *ob, std::streamsize n)
426 for (
int i = 0; i < n; i++) (*
this) >> ob[i];
431 char *ptr = (
char*) ob;
432 std::streamsize sz =
sizeof(_TYPE_);
434 istream_->read(ptr, sz);
442 for (
int i = 0; i < n; i++) Entree::operator>>(ob[i]);
444 return (!istream_->fail());
448template int Entree::get_template(
int *ob, std::streamsize n);
449template int Entree::get_template(
long *ob, std::streamsize n);
450template int Entree::get_template(
long long *ob, std::streamsize n);
451template int Entree::get_template(
double *ob, std::streamsize n);
452template int Entree::get_template(
float *ob, std::streamsize n);
455template <
typename _TYPE_>
456Entree& Entree::operator_template(_TYPE_& ob)
469 char *ptr = (
char*) ≺
470 istream_->read(ptr,
sizeof(std::int64_t));
471 if (pr > std::numeric_limits<int>::max())
473 Cerr <<
"Can't read this int64 binary file with an int32 binary: values too big, overflow!!" << finl;
477 ob =
static_cast<_TYPE_
>(pr);
483 char * ptr = (
char*) ≺
484 istream_->read(ptr,
sizeof(
int));
490 char *ptr = (
char*) &ob;
491 istream_->read(ptr,
sizeof(_TYPE_));
502 convert_to(buffer, ob);
514template Entree& Entree::operator_template(
int& ob);
515template Entree& Entree::operator_template(
long& ob);
516template Entree& Entree::operator_template(
long long& ob);
517template Entree& Entree::operator_template(
double& ob);
518template 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)
This function is called by operator>>, 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)
Sets the diffuse flag for this input stream.
virtual int jumpOfLines()
virtual void set_error_action(Error_Action)
Changes the error behaviour of the input; see error_handle_() and get_error_action().
Error_Action error_action_
Entree & operator>>(Entree &(*f)(Entree &))
virtual istream & get_istream()
void set_bin(bool bin) override
Changes the file write mode.
void set_istream(istream *is)
Error_Action get_error_action()
Returns error_action_ for this input (allows modifying it and restoring the previous value afterwards...
virtual void set_check_types(bool flag)
Indicates whether the stream should verify the types of read objects (ints and floating-point numbers...
class Nom: a character string for naming TRUST objects.
const char * getChar() const
const std::string & getString() const
Base class for TRUST objects (Objet_U).
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.