ESA JPIP server  0.1
data::BaseFile< IO > Class Template Reference

This is a wrapper class for the FILE functions that provides all the functionality to handle files safely. More...

#include <file.h>

Collaboration diagram for data::BaseFile< IO >:

Public Types

typedef SHARED_PTR< BaseFile
< IO > > 
Ptr
 Safe pointer to this class. More...
 

Public Member Functions

 BaseFile ()
 Initialized the internal file pointer to NULL. More...
 
bool Open (const char *file_name, const char *access)
 Opens a file with a specific access mode. More...
 
bool Open (const string &file_name, const char *access)
 Opens a file with a specific access mode. More...
 
template<class IO2 >
bool Open (const BaseFile< IO2 > &file, const char *access)
 Opens a file with a specific access mode given an already opened File object. More...
 
bool OpenForReading (const char *file_name)
 
bool OpenForReading (const string &file_name)
 
template<class IO2 >
bool OpenForReading (const BaseFile< IO2 > &file)
 
bool OpenForWriting (const char *file_name)
 
bool OpenForWriting (const string &file_name)
 
template<class IO2 >
bool OpenForWriting (const BaseFile< IO2 > &file)
 
bool Seek (int offset, int origin=SEEK_SET) const
 Changes the current position of the file. More...
 
void Close ()
 Closes the file. More...
 
uint64_t GetOffset () const
 Returns the current file position. More...
 
int IsEOF () const
 Returns the EOF status (feof) of the file. More...
 
int GetDescriptor () const
 Returns the file descriptor. More...
 
uint64_t GetSize () const
 Return the current size of the file, without modifying the file position. More...
 
int ReadByte () const
 Reads a byte from the file. More...
 
template<typename T >
bool Read (T *value, int num_bytes=sizeof(T)) const
 Reads a value from the file. More...
 
template<typename T >
bool ReadReverse (T *value, int num_bytes=sizeof(T)) const
 Reads a value from the file in reverse order. More...
 
int WriteByte (int c) const
 Writes a byte to the file. More...
 
template<typename T >
bool Write (T *value, int num_bytes=sizeof(T)) const
 Writes a value to the file. More...
 
template<typename T >
bool WriteReverse (T *value, int num_bytes=sizeof(T)) const
 Writes a value to the file in reverse order. More...
 
bool IsValid () const
 Returns true if the file pointer is not NULL. More...
 
 operator bool () const
 Returns true if the file pointer is not NULL. More...
 
virtual ~BaseFile ()
 The destructor closes the file. More...
 

Static Public Member Functions

static bool Exists (const char *file_name)
 Returns true if the given file exists. More...
 

Private Attributes

FILE * file_ptr
 File pointer. More...
 

Detailed Description

template<class IO>
class data::BaseFile< IO >

This is a wrapper class for the FILE functions that provides all the functionality to handle files safely.

It is defined as a template in order to allow to use either the locked or the unlocked API, by means of the structs LockedAccess and UnlockedAccess. The unlocked API is not thread-safe, but it provides faster file operations.

See Also
LockedAccess
UnlockedAccess

Member Typedef Documentation

template<class IO>
typedef SHARED_PTR< BaseFile<IO> > data::BaseFile< IO >::Ptr

Safe pointer to this class.

Constructor & Destructor Documentation

template<class IO>
data::BaseFile< IO >::BaseFile ( )
inline

Initialized the internal file pointer to NULL.

template<class IO>
virtual data::BaseFile< IO >::~BaseFile ( )
inlinevirtual

The destructor closes the file.

Member Function Documentation

template<class IO>
void data::BaseFile< IO >::Close ( )
inline

Closes the file.

Here is the caller graph for this function:

template<class IO>
static bool data::BaseFile< IO >::Exists ( const char *  file_name)
inlinestatic

Returns true if the given file exists.

This is a wrapper of the system funcion stat.

template<class IO>
int data::BaseFile< IO >::GetDescriptor ( ) const
inline

Returns the file descriptor.

Here is the caller graph for this function:

template<class IO>
uint64_t data::BaseFile< IO >::GetOffset ( ) const
inline

Returns the current file position.

Here is the caller graph for this function:

template<class IO>
uint64_t data::BaseFile< IO >::GetSize ( ) const
inline

Return the current size of the file, without modifying the file position.

Here is the caller graph for this function:

template<class IO>
int data::BaseFile< IO >::IsEOF ( ) const
inline

Returns the EOF status (feof) of the file.

template<class IO>
bool data::BaseFile< IO >::IsValid ( ) const
inline

Returns true if the file pointer is not NULL.

Here is the caller graph for this function:

template<class IO>
bool data::BaseFile< IO >::Open ( const char *  file_name,
const char *  access 
)
inline

Opens a file with a specific access mode.

Parameters
file_namePath name of the file to open.
accessAccess mode as a fopen compatible format string.
Returns
true if successful.
template<class IO>
bool data::BaseFile< IO >::Open ( const string &  file_name,
const char *  access 
)
inline

Opens a file with a specific access mode.

Parameters
file_namePath name of the file to open.
accessAccess mode as a fopen compatible format string.
Returns
true if successful.
template<class IO>
template<class IO2 >
bool data::BaseFile< IO >::Open ( const BaseFile< IO2 > &  file,
const char *  access 
)
inline

Opens a file with a specific access mode given an already opened File object.

The descriptor of the opened file is duplicated and re-opened with the access mode given.

Parameters
fileOpened file.
accessAccess mode as a fopen compatible format string.
Returns
true if successful.
template<class IO>
bool data::BaseFile< IO >::OpenForReading ( const char *  file_name)
inline

Here is the caller graph for this function:

template<class IO>
bool data::BaseFile< IO >::OpenForReading ( const string &  file_name)
inline
template<class IO>
template<class IO2 >
bool data::BaseFile< IO >::OpenForReading ( const BaseFile< IO2 > &  file)
inline
template<class IO>
bool data::BaseFile< IO >::OpenForWriting ( const char *  file_name)
inline
template<class IO>
bool data::BaseFile< IO >::OpenForWriting ( const string &  file_name)
inline
template<class IO>
template<class IO2 >
bool data::BaseFile< IO >::OpenForWriting ( const BaseFile< IO2 > &  file)
inline
template<class IO>
data::BaseFile< IO >::operator bool ( ) const
inline

Returns true if the file pointer is not NULL.

template<class IO>
template<typename T >
bool data::BaseFile< IO >::Read ( T *  value,
int  num_bytes = sizeof(T) 
) const
inline

Reads a value from the file.

Parameters
valuePointer to the value where to store.
num_bytesNumber of bytes to read (by default, the size of the value).
Returns
true if successful.

Here is the caller graph for this function:

template<class IO>
int data::BaseFile< IO >::ReadByte ( ) const
inline

Reads a byte from the file.

template<class IO>
template<typename T >
bool data::BaseFile< IO >::ReadReverse ( T *  value,
int  num_bytes = sizeof(T) 
) const
inline

Reads a value from the file in reverse order.

Parameters
valuePointer to the value where to store.
num_bytesNumber of bytes to read (by default, the size of the value).
Returns
true if successful.

Here is the caller graph for this function:

template<class IO>
bool data::BaseFile< IO >::Seek ( int  offset,
int  origin = SEEK_SET 
) const
inline

Changes the current position of the file.

Parameters
offsetOffset to add to the current position.
originOrigin to use for the change ( SEEK_SET by default).
Returns
true if successful.

Here is the caller graph for this function:

template<class IO>
template<typename T >
bool data::BaseFile< IO >::Write ( T *  value,
int  num_bytes = sizeof(T) 
) const
inline

Writes a value to the file.

Parameters
valuePointer to the value.
num_bytesNumber of bytes to write (by default, the size of the value).
Returns
true if successful.

Here is the caller graph for this function:

template<class IO>
int data::BaseFile< IO >::WriteByte ( int  c) const
inline

Writes a byte to the file.

template<class IO>
template<typename T >
bool data::BaseFile< IO >::WriteReverse ( T *  value,
int  num_bytes = sizeof(T) 
) const
inline

Writes a value to the file in reverse order.

Parameters
valuePointer to the value.
num_bytesNumber of bytes to write (by default, the size of the value).
Returns
true if successful.

Member Data Documentation

template<class IO>
FILE* data::BaseFile< IO >::file_ptr
private

File pointer.


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