BTK
0.3dev.0
Open-source library to visualize/process biomechanical data
|
An abstract class which read/write binary file in VAX and IEEE floating format with the corresponding byte order. More...
#include <btkBinaryFileStream.h>
Public Types | |
typedef std::ios_base::iostate | IOState |
typedef std::ios_base::openmode | OpenMode |
typedef std::ios_base::seekdir | SeekDir |
typedef std::streamoff | StreamOffset |
typedef std::streampos | StreamPosition |
Public Member Functions | |
bool | Bad () const |
void | Clear (IOState flags=GoodBit) |
void | Close () |
bool | EndFile () const |
bool | Fail () const |
size_t | Fill (size_t nb) |
IOState | GetExceptions () |
const RawFileStream * | GetStream () const |
bool | Good () const |
bool | IsOpen () const |
void | Open (const std::string &filename, OpenMode mode) |
char | ReadChar () |
void | ReadChar (size_t nb, char *values) |
void | ReadChar (std::vector< char > &values) |
std::vector< char > | ReadChar (size_t nb) |
virtual double | ReadDouble ()=0 |
void | ReadDouble (size_t nb, double *values) |
void | ReadDouble (std::vector< double > &values) |
std::vector< double > | ReadDouble (size_t nb) |
virtual float | ReadFloat ()=0 |
void | ReadFloat (size_t nb, float *values) |
void | ReadFloat (std::vector< float > &values) |
std::vector< float > | ReadFloat (size_t nb) |
virtual int16_t | ReadI16 ()=0 |
void | ReadI16 (size_t nb, int16_t *values) |
void | ReadI16 (std::vector< int16_t > &values) |
std::vector< int16_t > | ReadI16 (size_t nb) |
virtual int32_t | ReadI32 ()=0 |
void | ReadI32 (size_t nb, int32_t *values) |
void | ReadI32 (std::vector< int32_t > &values) |
std::vector< int32_t > | ReadI32 (size_t nb) |
int8_t | ReadI8 () |
void | ReadI8 (size_t nb, int8_t *values) |
void | ReadI8 (std::vector< int8_t > &values) |
std::vector< int8_t > | ReadI8 (size_t nb) |
std::string | ReadString (size_t nbChar) |
void | ReadString (size_t nb, size_t nbChar, std::string *values) |
void | ReadString (size_t nbChar, std::vector< std::string > &values) |
std::vector< std::string > | ReadString (size_t nb, size_t nbChar) |
virtual uint16_t | ReadU16 ()=0 |
void | ReadU16 (size_t nb, uint16_t *values) |
void | ReadU16 (std::vector< uint16_t > &values) |
std::vector< uint16_t > | ReadU16 (size_t nb) |
virtual uint32_t | ReadU32 ()=0 |
void | ReadU32 (size_t nb, uint32_t *values) |
void | ReadU32 (std::vector< uint32_t > &values) |
std::vector< uint32_t > | ReadU32 (size_t nb) |
uint8_t | ReadU8 () |
void | ReadU8 (size_t nb, uint8_t *values) |
void | ReadU8 (std::vector< uint8_t > &values) |
std::vector< uint8_t > | ReadU8 (size_t nb) |
void | SeekRead (StreamOffset offset, SeekDir dir) |
void | SeekWrite (StreamOffset offset, SeekDir dir) |
void | SetExceptions (IOState except) |
void | SwapStream (BinaryFileStream *toSwap) |
StreamPosition | TellRead () const |
size_t | Write (int8_t i8) |
size_t | Write (const std::vector< int8_t > &rVectorI8) |
size_t | Write (uint8_t u8) |
size_t | Write (const std::vector< uint8_t > &rVectorU8) |
virtual size_t | Write (int16_t i16)=0 |
size_t | Write (const std::vector< int16_t > &rVectorI16) |
virtual size_t | Write (uint16_t u16)=0 |
size_t | Write (const std::vector< uint16_t > &rVectorU16) |
virtual size_t | Write (int32_t i32)=0 |
size_t | Write (const std::vector< int32_t > &rVectorI32) |
virtual size_t | Write (uint32_t u32)=0 |
size_t | Write (const std::vector< uint32_t > &rVectorU32) |
virtual size_t | Write (float f)=0 |
size_t | Write (const std::vector< float > &rVectorFloat) |
size_t | Write (const std::string &rString) |
size_t | Write (const std::vector< std::string > &rVectorString) |
virtual | ~BinaryFileStream () |
Static Public Attributes | |
static const IOState | BadBit = std::ios_base::badbit |
static const SeekDir | Begin = std::ios_base::beg |
static const SeekDir | Current = std::ios_base::cur |
static const SeekDir | End = std::ios_base::end |
static const IOState | EndFileBit = std::ios_base::eofbit |
static const IOState | FailBit = std::ios_base::failbit |
static const IOState | GoodBit = std::ios_base::goodbit |
static const OpenMode | In = std::ios_base::in |
static const OpenMode | Out = std::ios_base::out |
static const OpenMode | Truncate = std::ios_base::trunc |
Protected Member Functions | |
BinaryFileStream () | |
BinaryFileStream (const std::string &filename, OpenMode mode) | |
Protected Attributes | |
RawFileStream * | mp_Stream |
An abstract class which read/write binary file in VAX and IEEE floating format with the corresponding byte order.
Especially, this file stream can:
The simplest way to use this binary file stream is to use the class btk::NativeBinaryFileStream. It creates a stream to read/write binary file encoded in the format of the porcessor used to compile the code.
As the file stream classes in the standard library you can indicates if the file is to read or write data. The following code presents the definion of input and output streams in binary format.
This class has also exceptions. To use them, you have to set the exception mask. For example:
Bitmask type to represent stream error state flags.
Flags describing the requested I/O mode for the file.
Flags representing the seeking direction of a stream seeking operation.
Type to represent position offsets in a stream.
Type to represent positions in a stream.
|
inlinevirtual |
Destroys the abstract binary file stream.
|
inlineprotected |
Default abstract constructor.
|
inlineprotected |
Associates the file with the filename filename using the option mode to this object.
If the opening is not successfull, then the FailBit is set. You can check its state by using the method Fail().
|
inline |
Checks if badbit is set.
|
inline |
Closes file.
|
inline |
Checks if eofbit is set.
|
inline |
Checks if either failbit or badbit is set.
size_t btk::BinaryFileStream::Fill | ( | size_t | nb | ) |
Fills nb bytes with 0x00 in the stream.
|
inline |
Gets exception mask.
|
inline |
Return the raw stream associated with this binary file stream.
|
inline |
Checks if the state of the stream is good for I/O operations.
|
inline |
Checks if a file is open.
|
inline |
Opens file.
char btk::BinaryFileStream::ReadChar | ( | ) |
Extracts one character from the stream.
void btk::BinaryFileStream::ReadChar | ( | size_t | nb, |
char * | values | ||
) |
Extracts nb chars and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb characters and return them as a vector.
|
pure virtual |
Extracts one double.
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
void btk::BinaryFileStream::ReadDouble | ( | size_t | nb, |
double * | values | ||
) |
Extracts nb doubles and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb doubles and return them as a vector.
|
pure virtual |
Extracts one float.
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
void btk::BinaryFileStream::ReadFloat | ( | size_t | nb, |
float * | values | ||
) |
Extracts nb floats and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb floats and return them as a vector.
|
pure virtual |
Extracts one signed 16-bit integer.
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
void btk::BinaryFileStream::ReadI16 | ( | size_t | nb, |
int16_t * | values | ||
) |
Extracts nb signed 16-bit integers and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb signed 16-bit integers and return them as a vector.
|
pure virtual |
Extracts one signed 32-bit integer.
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
void btk::BinaryFileStream::ReadI32 | ( | size_t | nb, |
int32_t * | values | ||
) |
Extracts nb signed 32-bit integers and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb signed 32-bit integers and return them as a vector.
int8_t btk::BinaryFileStream::ReadI8 | ( | ) |
Extracts one signed 8-bit integer.
void btk::BinaryFileStream::ReadI8 | ( | size_t | nb, |
int8_t * | values | ||
) |
Extracts nb signed 8-bit integers and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb signed 8-bit integers and return them as a vector.
std::string btk::BinaryFileStream::ReadString | ( | size_t | nbChar | ) |
Extracts one string with nbChar characters.
void btk::BinaryFileStream::ReadString | ( | size_t | nb, |
size_t | nbChar, | ||
std::string * | values | ||
) |
Extracts nb unsigned 8-bit integers and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb strings with nb Charcharacters and return them as a vector.
|
pure virtual |
Extracts one unsigned 16-bit integer.
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
void btk::BinaryFileStream::ReadU16 | ( | size_t | nb, |
uint16_t * | values | ||
) |
Extracts nb unsigned 16-bit integers and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb unsigned 16-bit integers and return them as a vector.
|
pure virtual |
Extracts one unsigned 32-bit integer.
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
void btk::BinaryFileStream::ReadU32 | ( | size_t | nb, |
uint32_t * | values | ||
) |
Extracts nb unsigned 32-bit integers and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb unsigned 32-bit integers and return them as a vector.
uint8_t btk::BinaryFileStream::ReadU8 | ( | ) |
Extracts one unsigned 8-bit integer.
void btk::BinaryFileStream::ReadU8 | ( | size_t | nb, |
uint8_t * | values | ||
) |
Extracts nb unsigned 8-bit integers and set them in the array values.
|
inline |
Extracts exactly the number of elements set in the vector values
|
inline |
Extracts nb unsigned 8-bit integers and return them as a vector.
|
inline |
Moves the get pointer by nb bytes in the seeking direction dir.
|
inline |
Moves the set pointer by nb bytes in the seeking direction dir.
|
inline |
Sets exception mask.
void btk::BinaryFileStream::SwapStream | ( | BinaryFileStream * | toSwap | ) |
Swap streams.
|
inline |
Get position of the get pointer.
size_t btk::BinaryFileStream::Write | ( | int8_t | i8 | ) |
Writes the character c in the stream an return its size. Writes the signed 8-bit integer i8 in the stream an return its size.
size_t btk::BinaryFileStream::Write | ( | const std::vector< int8_t > & | rVectorI8 | ) |
Writes the vector of signed 8-bit integers rVectorI8 in the stream an return its size.
size_t btk::BinaryFileStream::Write | ( | uint8_t | u8 | ) |
Writes the unsigned 8-bit integer u8 in the stream an return its size.
size_t btk::BinaryFileStream::Write | ( | const std::vector< uint8_t > & | rVectorU8 | ) |
Writes the vector of unsigned 8-bit integers rVectorU8 in the stream an return its size.
|
pure virtual |
Extracts one signed 16-bit integer.
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
size_t btk::BinaryFileStream::Write | ( | const std::vector< int16_t > & | rVectorI16 | ) |
Writes the vector of signed 16-bit integers rVectorI16 in the stream an return its size.
|
pure virtual |
Extracts one unsigned 16-bit integer.
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
size_t btk::BinaryFileStream::Write | ( | const std::vector< uint16_t > & | rVectorU16 | ) |
Writes the vector of unsigned 16-bit integers rVectorU16 in the stream an return its size.
|
pure virtual |
Write one 32-bit signed integer
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
size_t btk::BinaryFileStream::Write | ( | const std::vector< int32_t > & | rVectorI32 | ) |
Writes the vector of signed 32-bit integers rVectorI32 in the stream an return its size.
|
pure virtual |
Write one 32-bit unsigned integer
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
size_t btk::BinaryFileStream::Write | ( | const std::vector< uint32_t > & | rVectorU32 | ) |
Writes the vector of unsigned 32-bit integers rVectorU32 in the stream an return its size.
|
pure virtual |
Write one float.
Implemented in btk::IEEEBigEndianBinaryFileStream, btk::IEEELittleEndianBinaryFileStream, and btk::VAXLittleEndianBinaryFileStream.
size_t btk::BinaryFileStream::Write | ( | const std::vector< float > & | rVectorFloat | ) |
Writes the vector of floats rVectorFloat in the stream an return its size.
size_t btk::BinaryFileStream::Write | ( | const std::string & | rString | ) |
Writes the string rString in the stream an return its size.
size_t btk::BinaryFileStream::Write | ( | const std::vector< std::string > & | rVectorString | ) |
Writes the vector of strings rVectorString in the stream an return its size.
|
static |
Error due to the failure of an input/output operation on the stream buffer.
|
static |
Beginning of the stream buffer.
|
static |
Current position in the stream buffer.
|
static |
End of the stream buffer.
|
static |
End-of-File reached while performing an extracting operation on an input stream.
|
static |
The last input operation failed because of an error related to the internal logic of the operation itself.
|
static |
No error. Represents the absence of all the above (the value zero).
|
static |
Allows input operations on the stream.
|
protected |
Binary stream which read/write data.
|
static |
Allows output operations on the stream.
|
static |
Any content is erased.The file is assumed to be zero-length.