32#include <itpp/itexports.h>
39#pragma warning( disable : 4250 )
49bool exist(
const std::string& name);
130namespace binfile_details
150 class ITPP_EXPORT Ofstream_Binfile_Facade
154 Ofstream_Binfile_Facade(
const Ofstream_Binfile_Facade& o);
155 void operator= (
const Ofstream_Binfile_Facade& o);
158 Ofstream_Binfile_Facade ( );
160 explicit Ofstream_Binfile_Facade (
const char * filename,
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);}
172 Ofstream_Binfile_Facade&
write (
const char* c, std::streamsize n)
173 {_str->
write(c,n);
return *
this;}
175 Ofstream_Binfile_Facade&
put (
const char c)
176 {_str->
put(c);
return *
this;};
179 {
return _str->tellp();}
181 Ofstream_Binfile_Facade&
seekp (std::streampos pos)
182 {_str->
seekp(pos);
return *
this;}
184 Ofstream_Binfile_Facade&
seekp (std::streamoff pos, std::ios_base::seekdir way)
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);}
240 class ITPP_EXPORT Ifstream_Binfile_Facade
244 Ifstream_Binfile_Facade(
const Ifstream_Binfile_Facade& o);
245 void operator= (
const Ifstream_Binfile_Facade& o);
248 Ifstream_Binfile_Facade ( );
250 explicit Ifstream_Binfile_Facade (
const char * filename,
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();}
266 Ifstream_Binfile_Facade&
get(
char& c) {_str->
get(c);
return *
this;}
268 Ifstream_Binfile_Facade&
get (
char* s, std::streamsize n)
269 {_str->
get(s,n);
return *
this;}
271 Ifstream_Binfile_Facade&
get (
char* s, std::streamsize n,
char delim)
272 {_str->
get(s,n,delim);
return *
this;}
274 Ifstream_Binfile_Facade&
getline (
char* s, std::streamsize n )
275 {_str->
getline(s,n);
return *
this;}
277 {_str->
getline(s,n,delim);
return *
this;}
279 Ifstream_Binfile_Facade&
ignore (std::streamsize n = 1,
int delim = EOF)
280 {_str->
ignore(n,delim);
return *
this;}
282 int peek() {
return _str->peek();}
284 Ifstream_Binfile_Facade&
read (
char* s, std::streamsize n)
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;}
293 Ifstream_Binfile_Facade&
unget() {_str->
unget();
return *
this;}
295 std::streampos
tellg() {
return _str->tellg();}
297 Ifstream_Binfile_Facade&
seekg (std::streampos pos)
298 {_str->
seekg(pos);
return *
this;}
300 Ifstream_Binfile_Facade&
seekg (std::streamoff pos, std::ios_base::seekdir way)
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);}
354 class ITPP_EXPORT Fstream_Binfile_Facade
358 Fstream_Binfile_Facade(
const Fstream_Binfile_Facade& o);
359 void operator= (
const Fstream_Binfile_Facade& o);
362 Fstream_Binfile_Facade ( );
364 explicit Fstream_Binfile_Facade (
const char * filename,
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);}
376 Fstream_Binfile_Facade&
write (
const char* c, std::streamsize n)
377 {_str->
write(c,n);
return *
this;};
379 Fstream_Binfile_Facade&
put (
const char c)
380 {_str->
put(c);
return *
this;};
382 std::streampos
tellp() {
return _str->tellp();}
384 Fstream_Binfile_Facade&
seekp (std::streampos pos)
385 {_str->
seekp(pos);
return *
this;}
387 Fstream_Binfile_Facade&
seekp (std::streamoff pos, std::ios_base::seekdir way)
388 {_str->
seekp(pos,way);
return *
this;}
390 Fstream_Binfile_Facade&
flush() {_str->
flush();
return *
this;}
392 std::streamsize
gcount()
const {
return _str->gcount();}
394 int get() {
return _str->get();}
396 Fstream_Binfile_Facade&
get(
char& c){_str->
get(c);
return *
this;}
398 Fstream_Binfile_Facade&
get(
char* s, std::streamsize n)
399 {_str->
get(s,n);
return *
this;}
401 Fstream_Binfile_Facade&
get(
char* s, std::streamsize n,
char delim)
402 {_str->
get(s,n,delim);
return *
this;}
404 Fstream_Binfile_Facade&
getline(
char* s, std::streamsize n)
405 {_str->
getline(s,n);
return *
this;}
407 {_str->
getline(s,n,delim);
return *
this;}
409 Fstream_Binfile_Facade&
ignore (std::streamsize n = 1,
int delim = EOF)
410 {_str->
ignore(n,delim);
return *
this;}
412 int peek() {
return _str->peek();}
414 Fstream_Binfile_Facade&
read (
char* s, std::streamsize n)
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();}
428 Fstream_Binfile_Facade&
seekg (std::streampos pos)
429 {_str->
seekg(pos);
return *
this;}
431 Fstream_Binfile_Facade&
seekg (std::streamoff pos, std::ios_base::seekdir way)
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.
bfstream_base(endian e=b_endian)
Class Constructor.
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.
bfstream(const std::string &name, endian e=b_endian)
Class constructor that opens a file and sets the endianity.
bifstream(const std::string &name, endian e=b_endian)
Class constructor that opens a file and sets the endianity.
~bifstream()
Class Destructor.
Binary arithmetic (boolean) class.
Fstream Interface Facade for Binary Streams.
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 & seekg(std::streampos pos)
Set position.
Fstream_Binfile_Facade & put(const char c)
Output single char.
int get()
Get single char.
int peek()
Peak single char from the top of the buffer.
Fstream_Binfile_Facade & read(char *s, std::streamsize n)
Read n chars from stream.
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 & unget()
Unget last extracted char.
void close()
Method to close corresponding file.
bool is_open()
Open state.
Fstream_Binfile_Facade & getline(char *s, std::streamsize n)
Get multiple chars to c-string without trailing 0.
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.
Fstream_Binfile_Facade & get(char &c)
Get single char.
bool operator!() const
Unary not operator to check the stream state.
bool bad() const
This method returns true if badbit is set.
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.
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 & flush()
Flushes stream buffer.
Fstream_Binfile_Facade & seekp(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.
Fstream_Binfile_Facade & seekg(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
std::fstream * stream()
Access to internal stream for derived classes.
Fstream_Binfile_Facade & get(char *s, std::streamsize n)
Get multiple chars to c-string and add trailing 0.
std::ios_base::iostate exceptions() const
Method to get the exceptions mask.
Fstream_Binfile_Facade & seekp(std::streamoff pos, std::ios_base::seekdir way)
Set relative position.
std::streampos tellg()
Get position.
Fstream_Binfile_Facade & write(const char *c, std::streamsize n)
Output multiple characters.
Fstream_Binfile_Facade & get(char *s, std::streamsize n, char delim)
Get multiple chars to c-string without trailing 0.
Fstream_Binfile_Facade & putback(char c)
This method attempts to put back single char.
Fstream_Binfile_Facade & ignore(std::streamsize n=1, int delim=EOF)
Extract and ignore chars.
Ifstream Interface Facade for Binary Streams.
bool operator!() const
Unary not operator to check the stream state.
std::ifstream * stream()
Access to internal stream for derived classes.
bool good() const
This method returns true is stream state is good.
Ifstream_Binfile_Facade & get(char *s, std::streamsize n)
Get multiple chars to c-string and add trailing 0.
std::ios_base::iostate rdstate() const
Method to read stream state flags.
bool bad() const
This method returns true if badbit is set.
Ifstream_Binfile_Facade & read(char *s, std::streamsize n)
Read n chars from stream.
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.
Ifstream_Binfile_Facade & seekg(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.
Ifstream_Binfile_Facade & seekg(std::streampos pos)
Set position.
Ifstream_Binfile_Facade & getline(char *s, std::streamsize n)
Get multiple chars to c-string without trailing 0.
std::streamsize gcount() const
Last extracted chars count.
Ifstream_Binfile_Facade & get(char *s, std::streamsize n, char delim)
Get multiple chars to c-string without trailing 0.
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 & get(char &c)
Get single char.
Ifstream_Binfile_Facade & ignore(std::streamsize n=1, int delim=EOF)
Extract and ignore chars.
std::ios_base::iostate exceptions() const
Method to get the exceptions mask.
Ifstream_Binfile_Facade & unget()
Unget last extracted char.
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.
void exceptions(std::ios_base::iostate except)
Method to set the exceptions mask.
bool eof() const
This method returns true if eof is reached.
bool is_open()
Open state.
Ofstream Interface Facade for Binary Streams.
std::ofstream * stream()
Access to internal stream for derived classes.
bool operator!() const
Unary not operator to check the stream state.
Ofstream_Binfile_Facade & put(const char c)
Output single char.
std::streampos tellp()
Get position.
bool is_open()
Open state.
Ofstream_Binfile_Facade & flush()
Flushes stream buffer.
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.
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.
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 & write(const char *c, std::streamsize n)
Output multiple characters.
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 & seekp(std::streampos pos)
Set position.
~bofstream()
Class Destructor.
bofstream(const std::string &name, endian e=b_endian)
Class constructor that opens a file and sets the endianity.
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.