IT++ Logo
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
itpp::bofstream Class Reference

Binary Outfile Class. More...

#include <itpp/base/binfile.h>

Inheritance diagram for itpp::bofstream:
itpp::bfstream_base itpp::binfile_details::Ofstream_Binfile_Facade

Public Types

enum  endian { l_endian , b_endian }
 Definition of the endian data type. More...
 

Public Member Functions

 bofstream (const std::string &name, endian e=b_endian)
 Class constructor that opens a file and sets the endianity. More...
 
 bofstream ()
 Class Constructor. More...
 
 ~bofstream ()
 Class Destructor. More...
 
void open (const std::string &name, bool trunc=false, endian e=b_endian)
 Open a file for writing and set the endianity. More...
 
bofstreamoperator<< (char a)
 Writes a signed char variable to the binary output file. More...
 
bofstreamoperator<< (int8_t a)
 Writes a 8-bit signed integer variable to the binary file. More...
 
bofstreamoperator<< (uint8_t a)
 Writes a 8-bit unsigned integer variable to the binary file. More...
 
bofstreamoperator<< (int16_t a)
 Writes a 16-bit signed integer variable to the binary output file. More...
 
bofstreamoperator<< (uint16_t a)
 Writes a 16-bit unsigned integer variable to the binary output file. More...
 
bofstreamoperator<< (int32_t a)
 Writes a 32-bit signed integer variable to the binary output file. More...
 
bofstreamoperator<< (uint32_t a)
 Writes a 32-bit unsigned integer variable to the binary output file. More...
 
bofstreamoperator<< (int64_t a)
 Writes a 64-bit signed integer variable to the binary output file. More...
 
bofstreamoperator<< (uint64_t a)
 Writes a 64-bit unsigned ingeger variable to the binary output file. More...
 
bofstreamoperator<< (float a)
 Writes a float variable to the binary output file. More...
 
bofstreamoperator<< (double a)
 Writes a double variable to the binary output file. More...
 
bofstreamoperator<< (bin a)
 Writes a binary variable to the binary output file. More...
 
bofstreamoperator<< (const char *a)
 Writes a char* string to the binary output file. More...
 
bofstreamoperator<< (const std::string &a)
 Writes a string variable to the binary output file. More...
 
endian get_endianity () const
 Returns the endianity of the class. More...
 
endian get_native_endianity () const
 Returns the native endianity for this computer architecture. More...
 
void set_endianity (endian e)
 Set the endianity for this class. More...
 
void set_native_endianity ()
 Set the endianity of this class to the native endianity for this computer architecture. More...
 
bool is_open ()
 Open state. More...
 
void open (const char *filename, std::ios_base::openmode mode=std::ios_base::out|std::ios_base::binary)
 Method to open corresponding file. More...
 
void close ()
 Method to close corresponding file. More...
 
Ofstream_Binfile_Facade & write (const char *c, std::streamsize n)
 Output multiple characters. More...
 
Ofstream_Binfile_Facade & put (const char c)
 Output single char. More...
 
std::streampos tellp ()
 Get position. More...
 
Ofstream_Binfile_Facade & seekp (std::streampos pos)
 Set position. More...
 
Ofstream_Binfile_Facade & seekp (std::streamoff pos, std::ios_base::seekdir way)
 Set relative position. More...
 
Ofstream_Binfile_Facade & flush ()
 Flushes stream buffer. More...
 
bool good () const
 This method returns true is stream state is good. More...
 
bool eof () const
 This method returns true if eof is reached. More...
 
bool fail () const
 This method returns true if either failbit or badbit is set. More...
 
bool bad () const
 This method returns true if badbit is set. More...
 
bool operator! () const
 Unary not operator to check the stream state. More...
 
 operator bool () const
 Conversion to bool to validate stream state. More...
 
std::ios_base::iostate rdstate () const
 Method to read stream state flags. More...
 
void setstate (std::ios_base::iostate state)
 Method to set the stream state (combines already set flags with flags provide by user) More...
 
void clear (std::ios_base::iostate state=std::ios_base::goodbit)
 Method to set stream state (overwrites stream state flags) More...
 
std::ios_base::iostate exceptions () const
 Method to get the exceptions mask. More...
 
void exceptions (std::ios_base::iostate except)
 Method to set the exceptions mask. More...
 

Protected Member Functions

std::ofstream * stream ()
 Access to internal stream for derived classes. More...
 

Protected Attributes

bool switch_endianity
 Indicates if the endianity of the processed data needs to be changed. More...
 
endian native_endianity
 The native endianity for this computer architecture. More...
 

Detailed Description

Binary Outfile Class.

Definition at line 474 of file binfile.h.

Member Enumeration Documentation

◆ endian

Definition of the endian data type.

The Endianness defines the order in which multibyte numbers are stored in the file. The two orders are called "Little Endian" (l_endian ) and "Big Endian" (b_endian ).

"Little Endian" means that the low-order byte of the number is stored at the lowest address (i.e. the little end comes first). "Big Endian" means that the high-order byte of the number is stored in memory at the lowest address (i.e. the big end comes first)

Definition at line 74 of file binfile.h.

Constructor & Destructor Documentation

◆ bofstream() [1/2]

itpp::bofstream::bofstream ( const std::string &  name,
endian  e = b_endian 
)

Class constructor that opens a file and sets the endianity.

Parameters
nameThe name of the file to open
eDefines the endianity of the class. Possible values are l_endian for "Little Endian" or b_endian for "Big Endian". The default value is b_endian. Set truncate to true to discard file contents.

Definition at line 125 of file binfile.cpp.

◆ bofstream() [2/2]

itpp::bofstream::bofstream ( )

Class Constructor.

Definition at line 128 of file binfile.cpp.

◆ ~bofstream()

itpp::bofstream::~bofstream ( )
inline

Class Destructor.

Definition at line 492 of file binfile.h.

Member Function Documentation

◆ open() [1/2]

void itpp::bofstream::open ( const std::string &  name,
bool  trunc = false,
endian  e = b_endian 
)

Open a file for writing and set the endianity.

Parameters
nameThe name of the file to open
eDefines the endianity of the class (default value is b_endian ) Set trunc to true to discard file contents.

Definition at line 130 of file binfile.cpp.

References itpp::bfstream_base::native_endianity, and itpp::bfstream_base::switch_endianity.

◆ operator<<() [1/14]

bofstream & itpp::bofstream::operator<< ( char  a)

Writes a signed char variable to the binary output file.

Definition at line 140 of file binfile.cpp.

References itpp::binfile_details::Ofstream_Binfile_Facade::put().

◆ operator<<() [2/14]

bofstream & itpp::bofstream::operator<< ( int8_t  a)

Writes a 8-bit signed integer variable to the binary file.

Definition at line 146 of file binfile.cpp.

References it_assert, and itpp::binfile_details::Ofstream_Binfile_Facade::put().

◆ operator<<() [3/14]

bofstream & itpp::bofstream::operator<< ( uint8_t  a)

Writes a 8-bit unsigned integer variable to the binary file.

Definition at line 153 of file binfile.cpp.

References it_assert, and itpp::binfile_details::Ofstream_Binfile_Facade::put().

◆ operator<<() [4/14]

bofstream & itpp::bofstream::operator<< ( int16_t  a)

Writes a 16-bit signed integer variable to the binary output file.

Definition at line 160 of file binfile.cpp.

References itpp::bfstream_base::switch_endianity.

◆ operator<<() [5/14]

bofstream & itpp::bofstream::operator<< ( uint16_t  a)

Writes a 16-bit unsigned integer variable to the binary output file.

Definition at line 166 of file binfile.cpp.

References itpp::bfstream_base::switch_endianity.

◆ operator<<() [6/14]

bofstream & itpp::bofstream::operator<< ( int32_t  a)

Writes a 32-bit signed integer variable to the binary output file.

Definition at line 172 of file binfile.cpp.

References itpp::bfstream_base::switch_endianity.

◆ operator<<() [7/14]

bofstream & itpp::bofstream::operator<< ( uint32_t  a)

Writes a 32-bit unsigned integer variable to the binary output file.

Definition at line 178 of file binfile.cpp.

References itpp::bfstream_base::switch_endianity.

◆ operator<<() [8/14]

bofstream & itpp::bofstream::operator<< ( int64_t  a)

Writes a 64-bit signed integer variable to the binary output file.

Definition at line 184 of file binfile.cpp.

References itpp::bfstream_base::switch_endianity.

◆ operator<<() [9/14]

bofstream & itpp::bofstream::operator<< ( uint64_t  a)

Writes a 64-bit unsigned ingeger variable to the binary output file.

Definition at line 190 of file binfile.cpp.

References itpp::bfstream_base::switch_endianity.

◆ operator<<() [10/14]

bofstream & itpp::bofstream::operator<< ( float  a)

Writes a float variable to the binary output file.

Definition at line 196 of file binfile.cpp.

References itpp::bfstream_base::switch_endianity.

◆ operator<<() [11/14]

bofstream & itpp::bofstream::operator<< ( double  a)

Writes a double variable to the binary output file.

Definition at line 202 of file binfile.cpp.

References itpp::bfstream_base::switch_endianity.

◆ operator<<() [12/14]

bofstream & itpp::bofstream::operator<< ( bin  a)

Writes a binary variable to the binary output file.

Definition at line 208 of file binfile.cpp.

References itpp::bfstream_base::switch_endianity.

◆ operator<<() [13/14]

bofstream & itpp::bofstream::operator<< ( const char *  a)

Writes a char* string to the binary output file.

Definition at line 215 of file binfile.cpp.

References itpp::binfile_details::Ofstream_Binfile_Facade::write().

◆ operator<<() [14/14]

bofstream & itpp::bofstream::operator<< ( const std::string &  a)

Writes a string variable to the binary output file.

Definition at line 221 of file binfile.cpp.

References itpp::binfile_details::Ofstream_Binfile_Facade::write().

◆ get_endianity()

endian itpp::bfstream_base::get_endianity ( ) const
inlineinherited

Returns the endianity of the class.

Definition at line 88 of file binfile.h.

◆ get_native_endianity()

endian itpp::bfstream_base::get_native_endianity ( ) const
inlineinherited

Returns the native endianity for this computer architecture.

Intel processors use "Little Endian" byte ordering while e.g. Motorola processors use "Big Endian" byte ordering.

Definition at line 105 of file binfile.h.

Referenced by itpp::it_file_old::write_data_header().

◆ set_endianity()

void itpp::bfstream_base::set_endianity ( endian  e)
inlineinherited

Set the endianity for this class.

Definition at line 110 of file binfile.h.

Referenced by itpp::it_ifile_old::read_data_header(), and itpp::it_file_old::write_data_header_here().

◆ set_native_endianity()

void itpp::bfstream_base::set_native_endianity ( )
inlineinherited

Set the endianity of this class to the native endianity for this computer architecture.

Definition at line 121 of file binfile.h.

◆ is_open()

bool itpp::binfile_details::Ofstream_Binfile_Facade::is_open ( )
inlineinherited

Open state.

Definition at line 163 of file binfile.h.

◆ open() [2/2]

void itpp::binfile_details::Ofstream_Binfile_Facade::open ( const char *  filename,
std::ios_base::openmode  mode = std::ios_base::out | std::ios_base::binary 
)
inlineinherited

Method to open corresponding file.

Definition at line 165 of file binfile.h.

◆ close()

void itpp::binfile_details::Ofstream_Binfile_Facade::close ( )
inlineinherited

Method to close corresponding file.

Definition at line 169 of file binfile.h.

◆ write()

Ofstream_Binfile_Facade & itpp::binfile_details::Ofstream_Binfile_Facade::write ( const char *  c,
std::streamsize  n 
)
inlineinherited

Output multiple characters.

Definition at line 172 of file binfile.h.

References itpp::binfile_details::Ofstream_Binfile_Facade::write().

Referenced by operator<<(), and itpp::binfile_details::Ofstream_Binfile_Facade::write().

◆ put()

Ofstream_Binfile_Facade & itpp::binfile_details::Ofstream_Binfile_Facade::put ( const char  c)
inlineinherited

◆ tellp()

std::streampos itpp::binfile_details::Ofstream_Binfile_Facade::tellp ( )
inlineinherited

Get position.

Definition at line 178 of file binfile.h.

◆ seekp() [1/2]

Ofstream_Binfile_Facade & itpp::binfile_details::Ofstream_Binfile_Facade::seekp ( std::streampos  pos)
inlineinherited

◆ seekp() [2/2]

Ofstream_Binfile_Facade & itpp::binfile_details::Ofstream_Binfile_Facade::seekp ( std::streamoff  pos,
std::ios_base::seekdir  way 
)
inlineinherited

Set relative position.

Definition at line 184 of file binfile.h.

References itpp::binfile_details::Ofstream_Binfile_Facade::seekp().

◆ flush()

Ofstream_Binfile_Facade & itpp::binfile_details::Ofstream_Binfile_Facade::flush ( )
inlineinherited

Flushes stream buffer.

Definition at line 187 of file binfile.h.

References itpp::binfile_details::Ofstream_Binfile_Facade::flush().

Referenced by itpp::binfile_details::Ofstream_Binfile_Facade::flush().

◆ good()

bool itpp::binfile_details::Ofstream_Binfile_Facade::good ( ) const
inlineinherited

This method returns true is stream state is good.

Definition at line 191 of file binfile.h.

◆ eof()

bool itpp::binfile_details::Ofstream_Binfile_Facade::eof ( ) const
inlineinherited

This method returns true if eof is reached.

Definition at line 193 of file binfile.h.

◆ fail()

bool itpp::binfile_details::Ofstream_Binfile_Facade::fail ( ) const
inlineinherited

This method returns true if either failbit or badbit is set.

Definition at line 195 of file binfile.h.

◆ bad()

bool itpp::binfile_details::Ofstream_Binfile_Facade::bad ( ) const
inlineinherited

This method returns true if badbit is set.

Definition at line 197 of file binfile.h.

◆ operator!()

bool itpp::binfile_details::Ofstream_Binfile_Facade::operator! ( ) const
inlineinherited

Unary not operator to check the stream state.

Definition at line 200 of file binfile.h.

◆ operator bool()

itpp::binfile_details::Ofstream_Binfile_Facade::operator bool ( ) const
inlineinherited

Conversion to bool to validate stream state.

Definition at line 202 of file binfile.h.

◆ rdstate()

std::ios_base::iostate itpp::binfile_details::Ofstream_Binfile_Facade::rdstate ( ) const
inlineinherited

Method to read stream state flags.

Definition at line 205 of file binfile.h.

◆ setstate()

void itpp::binfile_details::Ofstream_Binfile_Facade::setstate ( std::ios_base::iostate  state)
inlineinherited

Method to set the stream state (combines already set flags with flags provide by user)

Definition at line 207 of file binfile.h.

◆ clear()

void itpp::binfile_details::Ofstream_Binfile_Facade::clear ( std::ios_base::iostate  state = std::ios_base::goodbit)
inlineinherited

Method to set stream state (overwrites stream state flags)

Definition at line 209 of file binfile.h.

◆ exceptions() [1/2]

std::ios_base::iostate itpp::binfile_details::Ofstream_Binfile_Facade::exceptions ( ) const
inlineinherited

Method to get the exceptions mask.

Definition at line 211 of file binfile.h.

◆ exceptions() [2/2]

void itpp::binfile_details::Ofstream_Binfile_Facade::exceptions ( std::ios_base::iostate  except)
inlineinherited

Method to set the exceptions mask.

Definition at line 213 of file binfile.h.

◆ stream()

std::ofstream * itpp::binfile_details::Ofstream_Binfile_Facade::stream ( )
inlineprotectedinherited

Access to internal stream for derived classes.

Definition at line 219 of file binfile.h.

Member Data Documentation

◆ switch_endianity

bool itpp::bfstream_base::switch_endianity
protectedinherited

◆ native_endianity

endian itpp::bfstream_base::native_endianity
protectedinherited

The native endianity for this computer architecture.

Definition at line 127 of file binfile.h.

Referenced by itpp::bfstream_base::bfstream_base(), open(), itpp::bfstream::open(), itpp::bifstream::open(), and itpp::bfstream::open_readonly().


The documentation for this class was generated from the following files:

Generated on Tue Aug 17 2021 10:59:15 for IT++ by Doxygen 1.9.4