blocxx
BLOCXX_NAMESPACE::IFileStream Class Reference

The purpose of this class is to provide an alternative implementation of std::ifstream that is based on a FILE*, and can be created using a FILE*, a raw file descriptor or an instance of blocxx::File. More...

#include <IFileStream.hpp>

Inheritance diagram for BLOCXX_NAMESPACE::IFileStream:
BLOCXX_NAMESPACE::FileBuf

Public Member Functions

 IFileStream ()
 Constructor.
 
 ~IFileStream ()
 Calls close().
 
bool isOpen () const
 
IFileStreamopen (FILE *fp)
 If isOpen() == true, returns 0, otherwise initializes the IFileStream to use fp.
 
IFileStreamopen (AutoDescriptor fd)
 If isOpen() == true, returns 0, otherwise initializes the IFileStream to use fd.
 
IFileStreamopen (const char *path, std::ios_base::openmode mode, mode_t permissions=0666)
 If isOpen() == true, returns 0, otherwise initializes the IFileStream by opening the file identified by path.
 
IFileStreamclose ()
 If isOpen() == false, returns a null pointer.
 

Private Member Functions

 IFileStream (const IFileStream &arg)
 
IFileStreamoperator= (const IFileStream &arg)
 
- Private Member Functions inherited from BLOCXX_NAMESPACE::FileBuf
 FileBuf ()
 Constructor.
 
 ~FileBuf ()
 Calls close().
 
bool isOpen () const
 
FileBufopen (FILE *fp)
 If isOpen() == true, returns 0, otherwise initializes the FileBuf to use fp.
 
FileBufopen (AutoDescriptor fd)
 If isOpen() == true, returns 0, otherwise initializes the FileBuf to use fd.
 
FileBufopen (const char *path, std::ios_base::openmode mode, mode_t permissions=0666)
 If isOpen() == true, returns 0, otherwise initializes the FileBuf by opening the file identified by path.
 
FileBufclose ()
 If isOpen() == false, returns a null pointer.
 
- Private Member Functions inherited from BLOCXX_NAMESPACE::BaseStreamBuffer
 BaseStreamBuffer (EDirectionFlag direction, size_t bufSize=BASE_BUF_SIZE)
 Create a base stream buffer.
 
 ~BaseStreamBuffer ()
 
int underflow ()
 
std::streamsize xsputn (const char *s, std::streamsize n)
 
virtual int overflow (int c)
 
virtual int sync ()
 
virtual void initBuffers ()
 
virtual void initGetBuffer ()
 
virtual void initPutBuffer ()
 

Additional Inherited Members

- Private Types inherited from BLOCXX_NAMESPACE::BaseStreamBuffer
enum  EDirectionFlag { E_IN , E_OUT , E_IN_OUT }
 

Detailed Description

The purpose of this class is to provide an alternative implementation of std::ifstream that is based on a FILE*, and can be created using a FILE*, a raw file descriptor or an instance of blocxx::File.

IFileStream does not support all the operations that a std::ifstream does. IFileStream does not support seeking, character putback, facets, i18n. Basically all it does support is reading.

Definition at line 57 of file IFileStream.hpp.

Constructor & Destructor Documentation

◆ IFileStream() [1/2]

BLOCXX_NAMESPACE::IFileStream::IFileStream ( )

Constructor.

@postcondition isOpen() == false

Definition at line 47 of file IFileStream.cpp.

References BLOCXX_NAMESPACE::FileBuf::FileBuf().

Referenced by IFileStream(), and operator=().

◆ ~IFileStream()

BLOCXX_NAMESPACE::IFileStream::~IFileStream ( )

Calls close().

Definition at line 53 of file IFileStream.cpp.

◆ IFileStream() [2/2]

BLOCXX_NAMESPACE::IFileStream::IFileStream ( const IFileStream & arg)
private

References IFileStream().

Member Function Documentation

◆ close()

IFileStream * BLOCXX_NAMESPACE::IFileStream::close ( )

If isOpen() == false, returns a null pointer.

If a put area exists, calls overflow(EOF) to flush characters. Finally it closes the file. If any of the calls to overflow or std::fclose fails then close fails.

Postcondition
isOpen() == false.
Returns
IFileStream*: this if successful, 0 otherwise.

Definition at line 94 of file IFileStream.cpp.

References BLOCXX_NAMESPACE::FileBuf::close().

◆ isOpen()

bool BLOCXX_NAMESPACE::IFileStream::isOpen ( ) const
Returns
bool: true if a previous call to open succeeded (returned a non-null value) and there has been no intervening call to close.

Definition at line 58 of file IFileStream.cpp.

References BLOCXX_NAMESPACE::FileBuf::isOpen().

◆ open() [1/3]

IFileStream * BLOCXX_NAMESPACE::IFileStream::open ( AutoDescriptor fd)

If isOpen() == true, returns 0, otherwise initializes the IFileStream to use fd.

Parameters
fdThe descriptor to use. The IFileStream will take ownership of fd, so close() will close the descriptor.
Returns
IFileStream*: this if successful, 0 otherwise.

Definition at line 74 of file IFileStream.cpp.

References BLOCXX_NAMESPACE::FileBuf::open().

◆ open() [2/3]

IFileStream * BLOCXX_NAMESPACE::IFileStream::open ( const char * path,
std::ios_base::openmode mode,
mode_t permissions = 0666 )

If isOpen() == true, returns 0, otherwise initializes the IFileStream by opening the file identified by path.

If the open operation succeeds and (mode & ios_base::ate) != 0, positions the file to the end. If the repositioning operation fails, calls close() and returns a null pointer to indicate failure.

Parameters
pathA null-terminated string identifying the file to open.
modeA bitmask of the file open mode flags defined in ios_base. Invalid combinations cause the operation to fail.
permissionsSpecifies the permissions to use in case a new file is created. It is modified by the process's umask in the usual way: the permissions of the created file are (mode & ~umask). Note that this mode only applies to future accesses of the newly created file; the open call that creates a read-only file may well return a read/write file descriptor.
Returns
IFileStream*: this if successful, 0 otherwise.

Definition at line 84 of file IFileStream.cpp.

References BLOCXX_NAMESPACE::FileBuf::open().

◆ open() [3/3]

IFileStream * BLOCXX_NAMESPACE::IFileStream::open ( FILE * fp)

If isOpen() == true, returns 0, otherwise initializes the IFileStream to use fp.

Parameters
fpThe FILE* to use. The IFileStream will take ownership of fp, so close() will call std::fclose() on fp.
Returns
IFileStream*: this if successful, 0 otherwise.

Definition at line 64 of file IFileStream.cpp.

References BLOCXX_NAMESPACE::FileBuf::open().

◆ operator=()

IFileStream & BLOCXX_NAMESPACE::IFileStream::operator= ( const IFileStream & arg)
private

References IFileStream().


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