43namespace binfile_details
71template<
typename T1,
typename T2>
inline
75 char *
c =
reinterpret_cast<char *
>(&data);
84template<
typename T1,
typename T2>
inline
88 char *
c =
reinterpret_cast<char *
>(&data);
98bool exist(
const std::string& name)
101 ifstream
file(name.c_str(), ios::in);
102 if (
file.is_open()) {
114 switch_endianity(
false),
136 Ofstream_Binfile_Facade::open(name.c_str(),
137 truncate? ios::out | ios::binary | ios::trunc : ios::out | ios::binary);
149 put(
static_cast<char>(
a));
156 put(
static_cast<char>(
a));
332 "bifstream::operator>>(): binary input value must be 0 or 1");
345 std::getline(*
stream(),
a,
'\0');
401 put(
static_cast<char>(
a));
408 put(
static_cast<char>(
a));
556 "bfstream::operator>>(): binary input value must be 0 or 1");
569 std::getline(*
stream(),
a,
'\0');
Binary file formats definitions.
int size() const
Returns the number of data elements in the array object.
Base class for binary file classes.
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.
Binary in/out-file Class.
void open_readonly(const std::string &name, endian e=b_endian)
Open a file for reading only and set the endianity.
bfstream & operator>>(char &a)
Reads a char variable from the binary file.
bfstream & operator<<(char a)
Writes an char variable to the binary file.
int length()
Returns the length in bytes of the file.
bfstream()
Class Constructor.
void open(const std::string &name, bool trunc=false, endian e=b_endian)
Open a file for reading and writing and set the endianity.
void open(const std::string &name, endian e=b_endian)
Open a file for reading and set the endianity.
bifstream()
Class Constructor.
int length()
Returns the length in bytes of the file.
bifstream & operator>>(char &a)
Reads a signed char variable from the binary input file.
Binary arithmetic (boolean) class.
Fstream_Binfile_Facade & seekg(std::streampos pos)
Set position.
Fstream_Binfile_Facade & put(const char c)
Output single char.
int get()
Get single char.
virtual ~Fstream_Binfile_Facade()
Destructor.
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()
Default Constructor.
std::fstream * stream()
Access to internal stream for derived classes.
std::streampos tellg()
Get position.
Fstream_Binfile_Facade & write(const char *c, std::streamsize n)
Output multiple characters.
std::ifstream * stream()
Access to internal stream for derived classes.
Ifstream_Binfile_Facade()
Default Constructor.
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.
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary)
Method to open corresponding file.
virtual ~Ifstream_Binfile_Facade()
Destructor.
int get()
Get single char.
std::streampos tellg()
Get position.
Ofstream_Binfile_Facade()
Default Constructor.
Ofstream_Binfile_Facade & put(const char c)
Output single char.
virtual ~Ofstream_Binfile_Facade()
Destructor.
Ofstream_Binfile_Facade & write(const char *c, std::streamsize n)
Output multiple characters.
bofstream & operator<<(char a)
Writes a signed char variable to the binary output file.
void open(const std::string &name, bool trunc=false, endian e=b_endian)
Open a file for writing and set the endianity.
bofstream()
Class Constructor.
#define it_assert(t, s)
Abort if t is not true.
bool exist(const std::string &name)
Checks if a file named name already exists on the disk.
bool is_bigendian()
Returns true if machine endianness is BIG_ENDIAN.
Miscellaneous functions - header file.
void read_endian(T1 &st, T2 &data, bool switch_endian=false)
Read binary data and optionally switch endianness.
void write_endian(T1 &st, T2 data, bool switch_endian=false)
Write binary data and optionally switch endianness.