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);
Base class for binary file classes.
endian get_native_endianity() const
Returns the native endianity for this computer architecture.
void set_endianity(endian e)
Set the endianity for this class.
void set_native_endianity()
Set the endianity of this class to the native endianity for this computer architecture.
endian
Definition of the endian data type.
bool switch_endianity
Indicates if the endianity of the processed data needs to be changed.
endian native_endianity
The native endianity for this computer architecture.
endian get_endianity() const
Returns the endianity of the class.
Binary in/out-file Class.
~bfstream()
Class Destructor.
~bifstream()
Class Destructor.
Binary arithmetic (boolean) class.
Fstream Interface Facade for Binary Streams.
Fstream_Binfile_Facade & seekp(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
Fstream_Binfile_Facade & get(char &c)
Get single char.
bool good() const
This method returns true is stream state is good.
bool eof() const
This method returns true if eof is reached.
Fstream_Binfile_Facade & putback(char c)
This method attempts to put back single char.
Fstream_Binfile_Facade & get(char *s, std::streamsize n, char delim)
Get multiple chars to c-string without trailing 0.
Fstream_Binfile_Facade & seekg(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
Fstream_Binfile_Facade & write(const char *c, std::streamsize n)
Output multiple characters.
Fstream_Binfile_Facade & unget()
Unget last extracted char.
int get()
Get single char.
int peek()
Peak single char from the top of the buffer.
std::streamsize readsome(char *s, std::streamsize n)
Read up to n available chars from stream.
void exceptions(std::ios_base::iostate except)
Method to set the exceptions mask.
Fstream_Binfile_Facade & get(char *s, std::streamsize n)
Get multiple chars to c-string and add trailing 0.
Fstream_Binfile_Facade & flush()
Flushes stream buffer.
void close()
Method to close corresponding file.
bool is_open()
Open state.
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 operator!() const
Unary not operator to check the stream state.
Fstream_Binfile_Facade & read(char *s, std::streamsize n)
Read n chars from stream.
bool bad() const
This method returns true if badbit is set.
Fstream_Binfile_Facade & put(const char c)
Output single char.
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.
Fstream_Binfile_Facade & getline(char *s, std::streamsize n)
Get multiple chars to c-string without trailing 0.
void clear(std::ios_base::iostate state=std::ios_base::goodbit)
Method to set stream state (overwrites stream state flags)
std::streampos tellp()
Get position.
Fstream_Binfile_Facade & seekp(std::streampos pos)
Set position.
Fstream_Binfile_Facade & seekg(std::streampos pos)
Set position.
bool fail() const
This method returns true if either failbit or badbit is set.
std::ios_base::iostate rdstate() const
Method to read stream state flags.
std::ios_base::iostate exceptions() const
Method to get the exceptions mask.
Fstream_Binfile_Facade & ignore(std::streamsize n=1, int delim=EOF)
Extract and ignore chars.
std::streampos tellg()
Get position.
std::fstream * stream()
Access to internal stream for derived classes.
Ifstream Interface Facade for Binary Streams.
bool operator!() const
Unary not operator to check the stream state.
bool good() const
This method returns true is stream state is good.
Ifstream_Binfile_Facade & seekg(std::streampos pos)
Set position.
Ifstream_Binfile_Facade & unget()
Unget last extracted char.
std::ios_base::iostate rdstate() const
Method to read stream state flags.
bool bad() const
This method returns true if badbit is set.
void clear(std::ios_base::iostate state=std::ios_base::goodbit)
Method to set stream state (overwrites stream state flags)
std::streamsize readsome(char *s, std::streamsize n)
Read up to n available chars from stream.
int peek()
Peak single char from the top of the buffer.
bool fail() const
This method returns true if either failbit or badbit is set.
std::ifstream * stream()
Access to internal stream for derived classes.
Ifstream_Binfile_Facade & get(char *s, std::streamsize n)
Get multiple chars to c-string and add trailing 0.
std::streamsize gcount() const
Last extracted chars count.
Ifstream_Binfile_Facade & read(char *s, std::streamsize n)
Read n chars from stream.
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary)
Method to open corresponding file.
Ifstream_Binfile_Facade & ignore(std::streamsize n=1, int delim=EOF)
Extract and ignore chars.
Ifstream_Binfile_Facade & get(char &c)
Get single char.
std::ios_base::iostate exceptions() const
Method to get the exceptions mask.
Ifstream_Binfile_Facade & get(char *s, std::streamsize n, char delim)
Get multiple chars to c-string without trailing 0.
void close()
Method to close corresponding file.
void setstate(std::ios_base::iostate state)
Method to set the stream state (combines already set flags with flags provide by user)
int get()
Get single char.
std::streampos tellg()
Get position.
Ifstream_Binfile_Facade & putback(char c)
This method attempts to put back single char.
void exceptions(std::ios_base::iostate except)
Method to set the exceptions mask.
bool eof() const
This method returns true if eof is reached.
Ifstream_Binfile_Facade & seekg(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
Ifstream_Binfile_Facade & getline(char *s, std::streamsize n)
Get multiple chars to c-string without trailing 0.
bool is_open()
Open state.
Ofstream Interface Facade for Binary Streams.
bool operator!() const
Unary not operator to check the stream state.
std::streampos tellp()
Get position.
bool is_open()
Open state.
bool eof() const
This method returns true if eof is reached.
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 bad() const
This method returns true if badbit is set.
Ofstream_Binfile_Facade & seekp(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
Ofstream_Binfile_Facade & seekp(std::streampos pos)
Set position.
std::ios_base::iostate rdstate() const
Method to read stream state flags.
bool fail() const
This method returns true if either failbit or badbit is set.
void clear(std::ios_base::iostate state=std::ios_base::goodbit)
Method to set stream state (overwrites stream state flags)
void close()
Method to close corresponding file.
bool good() const
This method returns true is stream state is good.
Ofstream_Binfile_Facade & flush()
Flushes stream buffer.
Ofstream_Binfile_Facade & put(const char c)
Output single char.
std::ofstream * stream()
Access to internal stream for derived classes.
void setstate(std::ios_base::iostate state)
Method to set the stream state (combines already set flags with flags provide by user)
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::out|std::ios_base::binary)
Method to open corresponding file.
Ofstream_Binfile_Facade & write(const char *c, std::streamsize n)
Output multiple characters.
~bofstream()
Class Destructor.
bool exist(const std::string &name)
Checks if a file named name already exists on the disk.
int length(const Vec< T > &v)
Length of vector.
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.