32 #include <itpp/itexports.h> 39 #pragma warning( disable : 4250 ) 49 bool exist(
const std::string& name);
89 if (switch_endianity) {
90 if (native_endianity == l_endian)
96 return native_endianity;
111 if (native_endianity == e)
112 switch_endianity =
false;
114 switch_endianity =
true;
130 namespace binfile_details
161 std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary);
165 void open (
const char * filename,
166 std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary )
167 {_str->open(filename,mode);}
173 {_str->
write(c,n);
return *
this;}
176 {_str->
put(c);
return *
this;};
179 {
return _str->tellp();}
182 {_str->
seekp(pos);
return *
this;}
185 {_str->
seekp(pos,way);
return *
this;}
188 {_str->
flush();
return *
this;}
191 bool good()
const {
return _str->good();}
193 bool eof()
const {
return _str->eof();}
195 bool fail()
const {
return _str->fail();}
197 bool bad()
const {
return _str->bad();}
202 operator bool()
const {
return _str->good();}
205 std::ios_base::iostate
rdstate()
const {
return _str->rdstate();}
207 void setstate (std::ios_base::iostate state) {_str->setstate(state);}
209 void clear (std::ios_base::iostate state = std::ios_base::goodbit) {_str->clear(state);}
211 std::ios_base::iostate
exceptions()
const {
return _str->exceptions();}
213 void exceptions (std::ios_base::iostate except) {_str->exceptions(except);}
251 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary);
254 {
return _str->is_open();}
256 void open (
const char * filename,
257 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary)
258 {_str->open(filename,mode);}
262 std::streamsize
gcount()
const {
return _str->gcount();}
264 int get() {
return _str->get();}
269 {_str->
get(s,n);
return *
this;}
272 {_str->
get(s,n,delim);
return *
this;}
275 {_str->
getline(s,n);
return *
this;}
277 {_str->
getline(s,n,delim);
return *
this;}
280 {_str->
ignore(n,delim);
return *
this;}
282 int peek() {
return _str->peek();}
285 {_str->
read(s,n);
return *
this;}
287 std::streamsize
readsome (
char* s, std::streamsize n)
288 {
return _str->readsome(s,n);}
291 {_str->
putback(c);
return *
this;}
295 std::streampos
tellg() {
return _str->tellg();}
298 {_str->
seekg(pos);
return *
this;}
301 {_str->
seekg(pos,way);
return *
this;}
304 bool good()
const {
return _str->good();}
306 bool eof()
const {
return _str->eof();}
308 bool fail()
const {
return _str->fail();}
310 bool bad()
const {
return _str->bad();}
315 operator bool()
const {
return _str->good();}
318 std::ios_base::iostate
rdstate()
const {
return _str->rdstate();}
320 void setstate (std::ios_base::iostate state) {_str->setstate(state);}
322 void clear (std::ios_base::iostate state = std::ios_base::goodbit) {_str->clear(state);}
324 std::ios_base::iostate
exceptions()
const {
return _str->exceptions();}
326 void exceptions (std::ios_base::iostate except) {_str->exceptions(except);}
365 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out | std::ios_base::binary);
369 void open (
const char * filename,
370 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out | std::ios_base::binary)
371 {_str->open(filename,mode);}
377 {_str->
write(c,n);
return *
this;};
380 {_str->
put(c);
return *
this;};
382 std::streampos
tellp() {
return _str->tellp();}
385 {_str->
seekp(pos);
return *
this;}
388 {_str->
seekp(pos,way);
return *
this;}
392 std::streamsize
gcount()
const {
return _str->gcount();}
394 int get() {
return _str->get();}
399 {_str->
get(s,n);
return *
this;}
402 {_str->
get(s,n,delim);
return *
this;}
405 {_str->
getline(s,n);
return *
this;}
407 {_str->
getline(s,n,delim);
return *
this;}
410 {_str->
ignore(n,delim);
return *
this;}
412 int peek() {
return _str->peek();}
415 {_str->
read(s,n);
return *
this;}
417 std::streamsize
readsome (
char* s, std::streamsize n)
418 {
return _str->readsome(s,n);}
421 {_str->
putback(c);
return *
this;}
424 {_str->
unget();
return *
this;}
426 std::streampos
tellg() {
return _str->tellg();}
429 {_str->
seekg(pos);
return *
this;}
432 {_str->
seekg(pos,way);
return *
this;}
435 bool good()
const {
return _str->good();}
437 bool eof()
const {
return _str->eof();}
439 bool fail()
const {
return _str->fail();}
441 bool bad()
const {
return _str->bad();}
446 operator bool()
const {
return _str->good();}
449 std::ios_base::iostate
rdstate()
const {
return _str->rdstate();}
451 void setstate (std::ios_base::iostate state) {_str->setstate(state);}
453 void clear (std::ios_base::iostate state = std::ios_base::goodbit)
454 {_str->clear(state);}
456 std::ios_base::iostate
exceptions()
const {
return _str->exceptions();}
458 void exceptions (std::ios_base::iostate except) {_str->exceptions(except);}
502 void open(
const std::string& name,
bool trunc =
false,
endian e = b_endian);
564 void open(
const std::string& name,
endian e = b_endian);
630 void open(
const std::string& name,
bool trunc =
false,
endian e = b_endian);
639 void open_readonly(
const std::string& name,
endian e = b_endian);
706 #endif // #ifndef BINFILE_H Ofstream_Binfile_Facade & seekp(std::streampos pos)
Set position.
bool operator!() const
Unary not operator to check the stream state.
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::out|std::ios_base::binary)
Method to open corresponding file.
void clear(std::ios_base::iostate state=std::ios_base::goodbit)
Method to set stream state (overwrites stream state flags)
std::ios_base::iostate exceptions() const
Method to get the exceptions mask.
bool good() const
This method returns true is stream state is good.
void clear(std::ios_base::iostate state=std::ios_base::goodbit)
Method to set stream state (overwrites stream state flags)
int peek()
Peak single char from the top of the buffer.
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary)
Method to open corresponding file.
std::streamsize gcount() const
Last extracted chars count.
bool operator!() const
Unary not operator to check the stream state.
~bofstream()
Class Destructor.
Ifstream_Binfile_Facade & seekg(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
Fstream_Binfile_Facade & seekp(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
Ifstream_Binfile_Facade & putback(char c)
This method attempts to put back single char.
void close()
Method to close corresponding file.
Ofstream Interface Facade for Binary Streams.This class implements std::ofstream facade to make ITPP ...
void setstate(std::ios_base::iostate state)
Method to set the stream state (combines already set flags with flags provide by user) ...
bool fail() const
This method returns true if either failbit or badbit is set.
Fstream_Binfile_Facade & write(const char *c, std::streamsize n)
Output multiple characters.
bool eof() const
This method returns true if eof is reached.
Fstream_Binfile_Facade & seekp(std::streampos pos)
Set position.
void set_native_endianity()
Set the endianity of this class to the native endianity for this computer architecture.
int peek()
Peak single char from the top of the buffer.
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Fstream_Binfile_Facade & seekg(std::streampos pos)
Set position.
std::ios_base::iostate rdstate() const
Method to read stream state flags.
Ifstream_Binfile_Facade & read(char *s, std::streamsize n)
Read n chars from stream.
std::streampos tellp()
Get position.
bool fail() const
This method returns true if either failbit or badbit is set.
Ifstream_Binfile_Facade & unget()
Unget last extracted char.
void close()
Method to close corresponding file.
std::fstream * stream()
Access to internal stream for derived classes.
Ifstream_Binfile_Facade & ignore(std::streamsize n=1, int delim=EOF)
Extract and ignore chars.
Binary in/out-file Class.
int length(const Vec< T > &v)
Length of vector.
std::ios_base::iostate rdstate() const
Method to read stream state flags.
std::ios_base::iostate exceptions() const
Method to get the exceptions mask.
void exceptions(std::ios_base::iostate except)
Method to set the exceptions mask.
bool good() const
This method returns true is stream state is good.
bool switch_endianity
Indicates if the endianity of the processed data needs to be changed.
void set_endianity(endian e)
Set the endianity for this class.
Fstream_Binfile_Facade & unget()
Unget last extracted char.
~bifstream()
Class Destructor.
std::ios_base::iostate rdstate() const
Method to read stream state flags.
Fstream_Binfile_Facade & seekg(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
endian native_endianity
The native endianity for this computer architecture.
Ifstream Interface Facade for Binary Streams.This class implements std::ofstream facade to make ITPP ...
bool eof() const
This method returns true if eof is reached.
std::ofstream * stream()
Access to internal stream for derived classes.
void close()
Method to close corresponding file.
Ofstream_Binfile_Facade & seekp(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
bool bad() const
This method returns true if badbit is set.
int get()
Get single char.
Ofstream_Binfile_Facade & write(const char *c, std::streamsize n)
Output multiple characters.
Ofstream_Binfile_Facade & flush()
Flushes stream buffer.
Fstream_Binfile_Facade & put(const char c)
Output single char.
Fstream_Binfile_Facade & putback(char c)
This method attempts to put back single char.
Base class for binary file classesThis class serves as a base class for the classes bofstream...
bool fail() const
This method returns true if either failbit or badbit is set.
Fstream_Binfile_Facade & ignore(std::streamsize n=1, int delim=EOF)
Extract and ignore chars.
Fstream Interface Facade for Binary Streams.This class implements std::fstream facade to make ITPP bi...
void exceptions(std::ios_base::iostate except)
Method to set the exceptions mask.
std::streampos tellp()
Get position.
void setstate(std::ios_base::iostate state)
Method to set the stream state (combines already set flags with flags provide by user) ...
std::streamsize gcount() const
Last extracted chars count.
bool good() const
This method returns true is stream state is good.
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out|std::ios_base::binary)
Method to open corresponding file.
bool is_open()
Open state.
endian get_endianity() const
Returns the endianity of the class.
Ifstream_Binfile_Facade & seekg(std::streampos pos)
Set position.
endian
Definition of the endian data type.
Fstream_Binfile_Facade & getline(char *s, std::streamsize n)
Get multiple chars to c-string without trailing 0.
bool is_open()
Open state.
bool bad() const
This method returns true if badbit is set.
~bfstream()
Class Destructor.
Binary arithmetic (boolean) class.
Ifstream_Binfile_Facade & getline(char *s, std::streamsize n)
Get multiple chars to c-string without trailing 0.
std::ios_base::iostate exceptions() const
Method to get the exceptions mask.
void setstate(std::ios_base::iostate state)
Method to set the stream state (combines already set flags with flags provide by user) ...
std::streampos tellg()
Get position.
std::streampos tellg()
Get position.
Fstream_Binfile_Facade & flush()
Flushes stream buffer.
int get()
Get single char.
endian get_native_endianity() const
Returns the native endianity for this computer architecture.
void clear(std::ios_base::iostate state=std::ios_base::goodbit)
Method to set stream state (overwrites stream state flags)
bool bad() const
This method returns true if badbit is set.
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
bool is_open()
Open state.
Fstream_Binfile_Facade & read(char *s, std::streamsize n)
Read n chars from stream.
bool operator!() const
Unary not operator to check the stream state.
bool eof() const
This method returns true if eof is reached.
bool exist(const std::string &name)
Checks if a file named name already exists on the disk.
std::streamsize readsome(char *s, std::streamsize n)
Read up to n available chars from stream.
std::streamsize readsome(char *s, std::streamsize n)
Read up to n available chars from stream.
Ofstream_Binfile_Facade & put(const char c)
Output single char.
std::ifstream * stream()
Access to internal stream for derived classes.
void exceptions(std::ios_base::iostate except)
Method to set the exceptions mask.