Main Page | Class Hierarchy | Compound List | File List | Compound Members

BxBinaryFile Class Reference

Super class for reading and writing binary files (and in the future, text files). More...

#include <BxBinaryFile.h>

Inheritance diagram for BxBinaryFile:

BxObject BxBinaryFileWriter List of all members.

Public Member Functions

 BxBinaryFile ()
long getFileSize ()
long getFilePos ()
void setFilename (char *filename)
void copyFilename (const char *filename)

Static Public Member Functions

BxByteOrder calcMemoryByteOrder ()
void reverseBytes (byte *buffer, int numBytes)

Detailed Description

This class implements the basic services for: Certain limitations and restrictions apply to the current implementation of this class:
  1. The binary files accessible for reading and writing are restricted to files hosted on the machine executing the BinX library. Location of the binary file is restricted because the <stdio> library is used to perform I/O operations, and that library can only access local files.
  2. A file must be specified by a full pathname (which may be formed using local operating system supported path variables).
Since: BinX version 1.0.


Constructor & Destructor Documentation

BxBinaryFile::BxBinaryFile  ) 
 

Default constructor.

Constructs an instance of the class BxBinaryFile. Default attribute values are assigned as follows:

       f_ = NULL;
       readonly_ = false;
       filename_ = NULL;
       datasetptr_ = NULL;
       memByteOrder_ = BIG_ENDIAN or LITTLE_ENDIAN,
                          depending on the byte order of the current host machine
   
The memory byte order of the current host machine may differ from the byte order of data stored in a binary file, which is read into or written from the host machine.


Member Function Documentation

BxByteOrder BxBinaryFile::calcMemoryByteOrder  )  [static]
 

Determine the memory byte order for the executing host machine.

Determine whether the memory system on the executing host machine uses BIG_ENDIAN or LITTLE_ENDIAN byte order.
Implementation Notes:
The byte order is determined by comparing the native 4-byte integer representation for the value 1, with the 4-byte array representation of the value 1 in little-endian format. If the representations do not match, then the executing host machine is using big-endian format.

Returns:
An instance of BxByteOrder having the value BIG_ENDIAN or LITTLE_ENDIAN.

void BxBinaryFile::copyFilename const char *  filename  ) 
 

Set the filename attribute by copying a specified string.

If the filename has been previously set, the memory allocated to the old string in released before a new string is assigned. Memory is allocated for a new string and the string value is copied from the input string. The caller is responsible for releasing memory allocated for the input parameter when that string is not longer needed.
Use Example:

       pBinaryFile->copyFilename("dummy.dat");
   
or
       char * filename = new char[20];
       strcpy(filename, "dummy.dat");
       pBinaryFile->copyFilename(filename);
       ...
       ...
       delete[] filename;
   
Parameters:
filename A pointer to a constant null-terminated string containing the filename.

long BxBinaryFile::getFilePos  ) 
 

Get the current file pointer (absolute) position.

Returns the current absolute byte offset in the binary file. The file must be open for reading or writing.

Returns:
The current file position, if no file I/O error occurs,
-1, if a file I/O error occurs.

long BxBinaryFile::getFileSize  ) 
 

Get the size of the binary file in bytes.

The current file pointer position is maintained by this method.

Returns:
The number of bytes in the binary file, if no file I/O error occur,
-1 or 0, if file I/O errors occur.

void BxBinaryFile::reverseBytes byte *  buffer,
int  numBytes
[static]
 

Convert a byte stream from big-endian to little-endian or vice versa.

Bytes within the input parameter buffer are converted from one byte ordering to the other. The reverse-ordered result is placed in the input buffer, destroying the previous contents of the input buffer.
This method has no knowledge of the data type of the value contained in the input parameter buffer. Hence, in order to achieve a conversion between big-endian and little-endian for a particular data value, it is incumbent on the caller to provide an input buffer pointer and a byte count that is appropriate for the type of data stored in the input buffer.
Implementation Notes:
Algorithm: for (i=0;i<numberOfBytes/2;i++) swap(i,numberOfBytes-i-1)

Parameters:
buffer A byte pointer to the sequence of bytes to be reversed.
numBytes The number of bytes to reversed.

void BxBinaryFile::setFilename char *  filename  ) 
 

Set or reset the filename attribute to a specified string.

If the filename has been previously set, the memory allocated to the old string in released before a new string is assigned.
Upon completion of this method, the input parameter string is tightly related to the BxBinaryFile instance. Destruction of the input string will be managed by the BxBinaryFile instance. The caller must not release the memory allocated to the input string.
Use Warning:
If the input parameter is a constrant string, the use the method BxBinaryFile::copyFilename(const char * filename). Invoking setFilename("dummy.dat") results in an error. Proper use of the method BxBinaryFile::setFilename with a constant string value is as follows:

       char * filename = new char[20];
       strcpy(filename, "dummy.dat");
       pBinaryFile->setFilename(filename);
       ... ...
   
Parameters:
filename A pointer to a null-terminated string containing the filename.


The documentation for this class was generated from the following files:
Generated on Fri May 6 13:36:18 2005 for edikt::BinX by doxygen 1.3.3