|
blocxx
|
The purpose of this class is to provide an alternative implementation of std::filebuf 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 <FileBuf.hpp>
Public Member Functions | |
| FileBuf () | |
| Constructor. | |
| ~FileBuf () | |
| Calls close(). | |
| bool | isOpen () const |
| FileBuf * | open (FILE *fp) |
| If isOpen() == true, returns 0, otherwise initializes the FileBuf to use fp. | |
| FileBuf * | open (AutoDescriptor fd) |
| If isOpen() == true, returns 0, otherwise initializes the FileBuf to use fd. | |
| FileBuf * | open (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. | |
| FileBuf * | close () |
| If isOpen() == false, returns a null pointer. | |
Public Member Functions inherited from BLOCXX_NAMESPACE::BaseStreamBuffer | |
| BaseStreamBuffer (EDirectionFlag direction, size_t bufSize=BASE_BUF_SIZE) | |
| Create a base stream buffer. | |
| ~BaseStreamBuffer () | |
Private Member Functions | |
| virtual int | buffer_to_device (const char *c, int n) |
| Writes the buffer to the "device". | |
| virtual int | buffer_from_device (char *c, int n) |
| Fill the buffer from the "device". | |
| std::ios_base::openmode | posixModeToCppMode (int posixMode) |
| Converts POSIX io open mode flags to C++ iostream open mode. | |
| int | cppModeToPOSIXMode (std::ios_base::openmode cppMode) |
| Converts C++ iostream open mode to POSIX io open mode. | |
| const char * | cppModeToCMode (std::ios_base::openmode cppMode) |
| Converts C++ iostream open mode to C stdio file open mode or the empty string on error (never returns null) | |
| FileBuf (const FileBuf &arg) | |
| FileBuf & | operator= (const FileBuf &arg) |
Private Attributes | |
| ::FILE * | m_file |
Additional Inherited Members | |
Public Types inherited from BLOCXX_NAMESPACE::BaseStreamBuffer | |
| enum | EDirectionFlag { E_IN , E_OUT , E_IN_OUT } |
Protected Member Functions inherited from BLOCXX_NAMESPACE::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 () |
The purpose of this class is to provide an alternative implementation of std::filebuf that is based on a FILE*, and can be created using a FILE*, a raw file descriptor or an instance of blocxx::File.
FileBuf does not support all the operations that a std::filebuf does. FileBuf does not support seeking, character putback, facets, i18n. Basically all it does is support reading and writing.
Definition at line 58 of file FileBuf.hpp.
| BLOCXX_NAMESPACE::FileBuf::FileBuf | ( | ) |
| BLOCXX_NAMESPACE::FileBuf::~FileBuf | ( | ) |
Fill the buffer from the "device".
| c | A pointer to the beginning of the buffer |
| n | The number of bytes to be read into the buffer. |
| IOException | on failure. |
Reimplemented from BLOCXX_NAMESPACE::BaseStreamBuffer.
Definition at line 206 of file FileBuf.cpp.
References BLOCXX_THROW_ERRNO_MSG, isOpen(), m_file, and BLOCXX_NAMESPACE::operator==().
Writes the buffer to the "device".
| c | A pointer to the start of the buffer |
| n | the number of bytes to write |
Reimplemented from BLOCXX_NAMESPACE::BaseStreamBuffer.
Definition at line 192 of file FileBuf.cpp.
References m_file, and BLOCXX_NAMESPACE::operator==().
| FileBuf * BLOCXX_NAMESPACE::FileBuf::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.
Definition at line 181 of file FileBuf.cpp.
References isOpen(), m_file, and BLOCXX_NAMESPACE::operator==().
Referenced by BLOCXX_NAMESPACE::IFileStream::close(), and ~FileBuf().
Converts C++ iostream open mode to C stdio file open mode or the empty string on error (never returns null)
| cppMode | C++ iostream mode |
Definition at line 280 of file FileBuf.cpp.
References BLOCXX_NAMESPACE::operator==().
|
private |
Converts C++ iostream open mode to POSIX io open mode.
| cppMode | The C++ iostream open mode flags. |
Definition at line 252 of file FileBuf.cpp.
References BLOCXX_NAMESPACE::operator==().
Referenced by open().
| bool BLOCXX_NAMESPACE::FileBuf::isOpen | ( | ) | const |
Definition at line 68 of file FileBuf.cpp.
References m_file.
Referenced by buffer_from_device(), close(), BLOCXX_NAMESPACE::IFileStream::isOpen(), open(), open(), and open().
| FileBuf * BLOCXX_NAMESPACE::FileBuf::open | ( | AutoDescriptor | fd | ) |
If isOpen() == true, returns 0, otherwise initializes the FileBuf to use fd.
| fd | The descriptor to use. The FileBuf will take ownership of fd, so close() will close the descriptor. |
Definition at line 86 of file FileBuf.cpp.
References cppModeToCMode(), isOpen(), m_file, BLOCXX_NAMESPACE::operator==(), and posixModeToCppMode().
| FileBuf * BLOCXX_NAMESPACE::FileBuf::open | ( | 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.
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.
| path | A null-terminated string identifying the file to open. |
| mode | A bitmask of the file open mode flags defined in ios_base. Invalid combinations cause the operation to fail. |
| permissions | Specifies 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. |
Definition at line 146 of file FileBuf.cpp.
References BLOCXX_INVALID_HANDLE, cppModeToCMode(), cppModeToPOSIXMode(), isOpen(), m_file, open(), and BLOCXX_NAMESPACE::operator==().
If isOpen() == true, returns 0, otherwise initializes the FileBuf to use fp.
| fp | The FILE* to use. The FileBuf will take ownership of fp, so close() will call std::fclose() on fp. |
Definition at line 74 of file FileBuf.cpp.
References isOpen(), m_file, and BLOCXX_NAMESPACE::operator==().
Referenced by BLOCXX_NAMESPACE::IFileStream::open(), open(), BLOCXX_NAMESPACE::IFileStream::open(), and BLOCXX_NAMESPACE::IFileStream::open().
|
private |
Converts POSIX io open mode flags to C++ iostream open mode.
| posixMode | The POSIX io open mode flags. |
Definition at line 235 of file FileBuf.cpp.
References BLOCXX_NAMESPACE::operator==().
Referenced by open().
|
private |
Definition at line 183 of file FileBuf.hpp.
Referenced by buffer_from_device(), buffer_to_device(), close(), isOpen(), open(), open(), and open().