37 #include <itpp/itexports.h> 122 static char file_magic[4];
138 explicit it_ifile(
const std::string& filename);
142 void open(
const std::string& filename);
144 virtual void close();
149 bool read_check_file_header();
154 void low_level_read(
char& x);
156 void low_level_read(uint64_t& x);
158 void low_level_read(
bool &x);
161 void low_level_read(
bin& x);
163 void low_level_read(
short& x);
165 void low_level_read(
int& x);
167 void low_level_read(
float& x);
169 void low_level_read(
double& x);
171 void low_level_read(std::complex<float>& x);
173 void low_level_read(std::complex<double>& x);
176 void low_level_read(bvec& v);
178 void low_level_read(svec& v);
180 void low_level_read(ivec& v);
182 void low_level_read_lo(vec& v);
184 void low_level_read_hi(vec& v);
186 void low_level_read_lo(cvec& v);
188 void low_level_read_hi(cvec& v);
191 void low_level_read(std::string& str);
194 void low_level_read(
bmat& m);
196 void low_level_read(smat& m);
198 void low_level_read(imat& m);
200 void low_level_read_lo(mat& m);
202 void low_level_read_hi(mat& m);
204 void low_level_read_lo(cmat& m);
206 void low_level_read_hi(cmat& m);
221 void low_level_read(
Array<std::complex<float> >& v);
223 void low_level_read_lo(
Array<std::complex<double> >& v);
225 void low_level_read_hi(
Array<std::complex<double> >& v);
228 bool seek(
const std::string& name);
232 void info(std::string& name, std::string& type, std::string& desc,
260 explicit it_file(
const std::string& filename,
bool trunc =
false);
271 void open(
const std::string& filename,
bool trunc =
false);
288 const std::string& description =
"")
289 { next_name() = name; next_desc() = description; }
292 void write_file_header();
294 void write_data_header(
const std::string& type, uint64_t
size);
296 void write_data_header(
const std::string& type,
const std::string& name,
297 uint64_t
size,
const std::string& description =
"");
300 void low_level_write(
char x);
302 void low_level_write(uint64_t x);
304 void low_level_write(
bool x);
307 void low_level_write(
bin x);
309 void low_level_write(
short x);
311 void low_level_write(
int x);
313 void low_level_write(
float x);
315 void low_level_write(
double x);
317 void low_level_write(
const std::complex<float>& x);
319 void low_level_write(
const std::complex<double>& x);
322 void low_level_write(
const bvec& v);
324 void low_level_write(
const svec& v);
326 void low_level_write(
const ivec& v);
328 void low_level_write(
const vec& v);
330 void low_level_write(
const cvec& v);
333 void low_level_write(
const std::string& str);
336 void low_level_write(
const bmat& m);
338 void low_level_write(
const smat& m);
340 void low_level_write(
const imat& m);
342 void low_level_write(
const mat& m);
344 void low_level_write(
const cmat& m);
357 void low_level_write(
const Array<std::complex<float> >& v);
359 void low_level_write(
const Array<std::complex<double> >& v);
365 void remove(
const std::string& name);
367 bool exists(
const std::string& name);
375 void write_data_header_here(
const data_header& h);
385 struct Strings_Holder
387 std::string _next_name;
388 std::string _next_desc;
390 Strings_Holder():_next_name(
""),_next_desc(
""),_fname(
""){}
392 Strings_Holder* _strings;
394 std::string& fname() {
return _strings->_fname;}
432 Name(
const std::string& n,
const std::string& d =
""): name(n), desc(d) {}
460 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f,
char& v);
462 ITPP_EXPORT it_ifile&
operator>>(it_ifile &f,
bool &v);
465 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, bin& v);
467 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f,
short& v);
469 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f,
int& v);
471 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f,
float& v);
473 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f,
double& v);
475 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, std::complex<float>& v);
477 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, std::complex<double>& v);
480 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, bvec& v);
482 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, svec& v);
484 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, ivec& v);
486 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, vec& v);
488 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, cvec& v);
491 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, std::string& str);
496 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, smat& m);
498 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, imat& m);
500 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, mat& m);
502 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, cmat& m);
505 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<bin>& v);
507 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<short>& v);
509 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<int>& v);
511 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<float>& v);
513 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<double>& v);
515 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<std::complex<float> >& v);
517 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<std::complex<double> >& v);
520 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<bvec>& v);
522 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<svec>& v);
524 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<ivec>& v);
526 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<vec>& v);
528 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<cvec>& v);
531 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<std::string>& v);
534 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<bmat>& v);
536 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<smat>& v);
538 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<imat>& v);
540 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<mat>& v);
542 ITPP_EXPORT it_ifile&
operator>>(it_ifile& f, Array<cmat>& v);
546 ITPP_EXPORT it_file&
operator<<(it_file& f,
char x);
548 ITPP_EXPORT it_file&
operator<<(it_file &f,
bool x);
551 ITPP_EXPORT it_file&
operator<<(it_file& f, bin x);
553 ITPP_EXPORT it_file&
operator<<(it_file& f,
short x);
555 ITPP_EXPORT it_file&
operator<<(it_file& f,
int x);
557 ITPP_EXPORT it_file&
operator<<(it_file& f,
float x);
559 ITPP_EXPORT it_file&
operator<<(it_file& f,
double x);
561 ITPP_EXPORT it_file& operator<<(it_file& f, std::complex<float> x);
563 ITPP_EXPORT it_file& operator<<(it_file& f, std::complex<double> x);
566 ITPP_EXPORT it_file&
operator<<(it_file& f,
const bvec& v);
568 ITPP_EXPORT it_file&
operator<<(it_file& f,
const svec& v);
570 ITPP_EXPORT it_file&
operator<<(it_file& f,
const ivec& v);
572 ITPP_EXPORT it_file&
operator<<(it_file& f,
const vec& v);
574 ITPP_EXPORT it_file&
operator<<(it_file& f,
const cvec& v);
577 ITPP_EXPORT it_file&
operator<<(it_file& f,
const std::string& str);
582 ITPP_EXPORT it_file&
operator<<(it_file& f,
const smat& m);
584 ITPP_EXPORT it_file&
operator<<(it_file& f,
const imat& m);
586 ITPP_EXPORT it_file&
operator<<(it_file& f,
const mat& m);
588 ITPP_EXPORT it_file&
operator<<(it_file& f,
const cmat& m);
591 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<bin>& v);
593 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<short>& v);
595 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<int>& v);
597 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<float>& v);
599 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<double>& v);
601 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<std::complex<float> >& v);
603 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<std::complex<double> >& v);
606 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<bvec>& v);
608 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<svec>& v);
610 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<ivec>& v);
612 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<vec>& v);
614 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<cvec>& v);
617 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<std::string>& v);
620 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<bmat>& v);
622 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<smat>& v);
624 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<imat>& v);
626 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<mat>& v);
628 ITPP_EXPORT it_file& operator<<(it_file& f, const Array<cmat>& v);
631 template <
class T>
inline 635 f <<
Name(name) << v;
640 template <
class T>
inline 650 #define it_save_var(v) it_save_var_as(v,#v) 651 #define it_load_var(v) it_load_var_as(v,#v) 696 static char file_magic[4];
717 void open(
const std::string& name);
719 virtual void close();
724 bool read_check_file_header();
726 void read_data_header(data_header& h);
728 void low_level_read(
char& x);
730 void low_level_read(
bin& x);
732 void low_level_read(
short& x);
734 void low_level_read(
int& x);
736 void low_level_read(
float& x);
738 void low_level_read(
double& x);
740 void low_level_read(std::complex<float>& x);
742 void low_level_read(std::complex<double>& x);
744 void low_level_read_lo(vec& v);
746 void low_level_read_hi(vec& v);
748 void low_level_read(ivec& v);
750 void low_level_read(bvec& v);
752 void low_level_read_lo(cvec& v);
754 void low_level_read_hi(cvec& v);
756 void low_level_read(std::string& str);
758 void low_level_read_lo(mat& m);
760 void low_level_read_hi(mat& m);
762 void low_level_read(imat& m);
764 void low_level_read(
bmat& m);
766 void low_level_read_lo(cmat& m);
768 void low_level_read_hi(cmat& m);
781 void low_level_read_lo(
Array<std::complex<float> >& v);
783 void low_level_read_lo(
Array<std::complex<double> >& v);
785 void low_level_read_hi(
Array<std::complex<double> >& v);
788 bool seek(
const std::string& name);
793 void info(std::string& name, std::string& type,
int& bytes);
821 explicit it_file_old(
const std::string& name,
bool trunc =
false);
832 void open(
const std::string& name,
bool trunc =
false);
853 void write_file_header();
855 void write_data_header(
const std::string& type, uint32_t
size);
857 void write_data_header(
const std::string& type,
const std::string& name,
860 void low_level_write(
char x);
862 void low_level_write(
bin x);
864 void low_level_write(
short x);
866 void low_level_write(
int x);
868 void low_level_write(
float x);
870 void low_level_write(
double x);
872 void low_level_write(
const std::complex<float>& x);
874 void low_level_write(
const std::complex<double>& x);
876 void low_level_write(
const vec& v);
878 void low_level_write(
const ivec& v);
880 void low_level_write(
const bvec& v);
882 void low_level_write(
const cvec& v);
884 void low_level_write(
const std::string& str);
886 void low_level_write(
const mat& m);
888 void low_level_write(
const imat& m);
890 void low_level_write(
const bmat& m);
892 void low_level_write(
const cmat& m);
902 void low_level_write(
const Array<std::complex<float> >& v);
904 void low_level_write(
const Array<std::complex<double> >& v);
910 void remove(
const std::string& name);
912 bool exists(
const std::string& name);
920 void write_data_header_here(
const data_header& h);
929 std::string _next_name;
930 String_Holder():_next_name(
""){}
932 String_Holder* _string;
972 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f,
char& v);
975 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, bin& v);
978 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f,
short& v);
981 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f,
int& v);
984 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f,
float& v);
987 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f,
double& v);
990 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, std::complex<float>& v);
993 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, std::complex<double>& v);
996 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, vec& v);
999 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, ivec& v);
1002 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, bvec& v);
1005 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, cvec& v);
1008 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, std::string& str);
1011 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, mat& m);
1014 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, imat& m);
1020 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, cmat& m);
1023 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<float>& v);
1026 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<double>& v);
1029 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<int>& v);
1032 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<bin>& v);
1035 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<std::complex<float> >& v);
1038 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<std::complex<double> >& v);
1041 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<vec>& v);
1044 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<ivec>& v);
1047 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<bvec>& v);
1050 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<cvec>& v);
1053 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<std::string>& v);
1056 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<mat>& v);
1059 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<imat>& v);
1062 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<bmat>& v);
1065 ITPP_EXPORT it_ifile_old&
operator>>(it_ifile_old& f, Array<cmat>& v);
1069 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
char x);
1072 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f, bin x);
1075 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
short x);
1078 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
int x);
1081 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
float x);
1084 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
double x);
1087 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, std::complex<float> x);
1090 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, std::complex<double> x);
1093 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
const vec& v);
1096 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
const ivec& v);
1099 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
const bvec& v);
1102 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
const cvec& v);
1105 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
const std::string& str);
1108 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
const mat& m);
1111 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
const imat& m);
1114 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
const bmat& m);
1117 ITPP_EXPORT it_file_old&
operator<<(it_file_old& f,
const cmat& m);
1120 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<float>& v);
1123 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<double>& v);
1126 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<int>& v);
1129 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<bin>& v);
1132 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<std::complex<float> >& v);
1135 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<std::complex<double> >& v);
1138 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<vec>& v);
1141 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<ivec>& v);
1144 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<bvec>& v);
1147 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<cvec>& v);
1150 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<std::string>& v);
1153 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<mat>& v);
1156 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<imat>& v);
1159 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<bmat>& v);
1162 ITPP_EXPORT it_file_old& operator<<(it_file_old& f, const Array<cmat>& v);
1173 #endif // #ifndef IT_FILE_H bool get_low_precision() const
Get the precision.
bool seek(const std::string &name)
Find the variable name.
Name(const std::string &n, const std::string &d="")
Constructor.
bool low_prec
Low precision flag. If true, use float type, otherwise double.
void flush()
Flush the data to disk.
virtual ~it_file_old()
Destructor.
static char file_version
IT++ file version.
The old (version 2) IT++ file format reading class.
const std::string & desc
The description.
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Base class for it_ifile_old and it_file_old.
Automatic naming when savingAn easy way to give a variable a name and optionally description when sav...
virtual ~it_ifile_old()
Destructor.
The old (version 2) IT++ file format reading and writing class.
const std::string & name
The name string.
Binary in/out-file Class.
it_file & operator<<(it_manip func)
ACTION: ADD DOCUMENTATION FOR THIS MEMBER !!!!!!!!
Definition of Array class (container)
void close()
Close the file.
bfstream s
Protected binary file stream.
Name & operator=(const Name &)
Dummy assignment operator - MSVC++ warning C4512.
void it_save_var_as(const T &v, const std::string &name)
Save the variable v in the file name.it as the name name.
virtual ~it_file()
Destructor.
bool seek(const std::string &name)
Find the variable name.
The IT++ file format reading and writing class.
bfstream & low_level()
Returns pointer to the underlying bfstream used.
int size(const Vec< T > &v)
Length of vector.
virtual ~it_ifile()
Destructor.
std::string & next_desc()
Description to be used for saving the next variable.
it_file & flush(it_file &f)
Flush operatorFlushes the data. Usage:
The IT++ file format reading class.
bfstream & low_level()
Returns pointer to the underlying bfstream used.
static char file_version
ACTION: Add documentation.
bfstream s
Protected binary file stream.
void flush()
Flush the data to disk.
bool low_prec
ACTION: Add documenation for this protected member.
bool get_low_precision()
Get the precision.
Binary arithmetic (boolean) class.
void set_next_name(const std::string &n)
Set the name of the next name to be saved. See also the Name class.
std::string & next_name()
ACTION: Add documenation for this protected member.
void set_low_precision(bool p=true)
Set the precision. Low precision means floats, high means doubles.
bfstream & low_level()
Returns pointer to the underlying bfstream used.
void set_next_name(const std::string &name, const std::string &description="")
Set the name and optionally description of the next variable to be saved.
bfstream & low_level()
Returns pointer to the underlying bfstream used.
Base class for it_ifile and it_file.
it_file_old & operator<<(it_manip func)
ACTION: ADD DOCUMENTATION FOR THIS MEMBER !!!!!!!!
void it_load_var_as(T &v, const std::string &name)
Load the variable v from the file name.it as the name name.
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
Binary file formats definitions.
void set_low_precision(bool p=true)
Set the precision. Low precision means floats, high means doubles.
std::string & next_name()
Name to be used for saving the next variable.
virtual void close()
Close the file.
Mat< bin > bmat
bin matrix
Templated Vector Class Definitions.