Input stream buffer for unix file descriptors.
More...
#include <c++-gtk-utils/fdstream.h>
template<class charT, class Traits = std::char_traits<charT>>
class Cgu::basic_fdinbuf< charT, Traits >
Input stream buffer for unix file descriptors.
- See also
- fdstreams
This class provides an input stream buffer for unix file descriptors. It does the buffering for the basic_fdistream stream class.
◆ char_type
template<class charT , class Traits = std::char_traits<charT>>
◆ int_type
template<class charT , class Traits = std::char_traits<charT>>
◆ off_type
template<class charT , class Traits = std::char_traits<charT>>
◆ pos_type
template<class charT , class Traits = std::char_traits<charT>>
◆ traits_type
template<class charT , class Traits = std::char_traits<charT>>
◆ basic_fdinbuf() [1/2]
template<class charT , class Traits = std::char_traits<charT>>
This class cannot be copied. The copy constructor is deleted.
◆ basic_fdinbuf() [2/2]
template<class charT , class Traits = std::char_traits<charT>>
As this constructor has default argument values, it is also a default constructor. It does not throw unless the default constructor of std::basic_streambuf throws. fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
- Parameters
-
fd_ | The file descriptor to be attached to the streambuffer, or -1 to attach it latter with the attach() method. |
manage_ | Whether the streambuffer should manage the file descriptor (that is, close it in its destructor or when a new file descriptor is attached). |
◆ ~basic_fdinbuf()
template<class charT , class Traits = std::char_traits<charT>>
The destructor does not throw.
◆ attach_fd()
template<class charT , class Traits = std::char_traits<charT>>
Attach a new file descriptor to the streambuffer (and close any file descriptor at present managed by it). In the case of a wide character streambuffer, it also switches off byte swapping, if it was previously on. This method does not throw. fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
- Parameters
-
fd_ | The new file descriptor to be attached to the streambuffer. |
manage_ | Whether the streambuffer should manage the new file descriptor (that is, close it in its destructor or when a further file descriptor is attached). |
◆ can_seek()
template<class charT , class Traits = std::char_traits<charT>>
This method indicates whether the input device concerned supports random access, so that a call to seekoff() or seekpos() can succeed. This method does not throw. fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
- Returns
- true if random access is supported, otherwise false. The result is only meaningful if a file descriptor has been attached to this streambuffer.
◆ close_fd()
template<class charT , class Traits = std::char_traits<charT>>
Close the file descriptor at present attached to the streambuffer (if any). This method does not throw. fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
- Returns
- From version 1.2.6, 'true' if the close succeeded, 'false' if an error arose (including in a case where no descriptor has been attached or it has already been closed). Prior to version 1.2.6, this method had void return type.
◆ get_fd()
template<class charT , class Traits = std::char_traits<charT>>
Get the file descriptor at present attached to the streambuffer (if any). This method does not throw. fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
- Returns
- The file descriptor at present attached to the streambuffer, or -1 if none has been attached
◆ operator=()
template<class charT , class Traits = std::char_traits<charT>>
This class cannot be copied. The copy assignment operator is deleted.
◆ seekoff()
template<class charT , class Traits = std::char_traits<charT>>
virtual pos_type Cgu::basic_fdinbuf< charT, Traits >::seekoff |
( |
off_type |
off, |
|
|
std::ios_base::seekdir |
way, |
|
|
std::ios_base::openmode |
m = std::ios_base::in|std::ios_base::out |
|
) |
| |
|
protectedvirtual |
This method provides random access on input devices that support it, so supporting the tellg() and seekg() methods of the basic_fdistream class. This method does not throw, but if it returns pos_type(off_type(-1)) to indicate failure, it will cause the seekg() or tellg() methods of the relevant stream class to throw std::ios_base::failure if such an exception has been required by an explicit call to the exceptions() method of that class (but not otherwise). fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
- Parameters
-
off | The offset to be applied to the 'way' argument when seeking. It is a signed integer type, and on wide character streams is dimensioned as the number of wchar_t units not the number of bytes (that is, it is bytes/sizeof(char_type)). |
way | The file position to which the 'off' argument is to be applied (either std::ios_base::beg, std::ios_base::cur or std::ios_base::end). |
m | The required read/write status of the file descriptor attached to this streambuffer for this method to attempt a seek. As this is an input streambuffer, the argument should have the std::ios_base::in bit set. Provided that bit is set, it doesn't matter if others are also set. |
- Returns
- If the seek succeeds, a std::char_traits<T>::pos_type object representing the new stream position of the streambuffer after the seek. (This type is std::streampos for narrow character (char) streams, std::wstreampos for wide character (wchar_t) streams, std::u16streampos for the char16_t type and std::u32streampos for the char32_t type.) If the seek failed, pos_type(off_type(-1)) is returned.
◆ seekpos()
template<class charT , class Traits = std::char_traits<charT>>
This method provides random access on input devices that support it, so supporting the seekg() method of the basic_fdistream class. It is equivalent to seekoff(off_type(p), std::ios_base::beg, m). This method does not throw, but if it returns pos_type(off_type(-1)) to indicate failure, it will cause the seekg() method of the relevant stream class to throw std::ios_base::failure if such an exception has been required by an explicit call to the exceptions() method of that class (but not otherwise). fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
- Parameters
-
p | The absolute position to which the seek is to be made, obtained by a previous call to seekoff() or to this method. |
m | The required read/write status of the file descriptor attached to this streambuffer for this method to attempt a seek. As this is an input streambuffer, the argument should have the std::ios_base::in bit set. Provided that bit is set, it doesn't matter if others are also set. |
- Returns
- If the seek succeeds, a std::char_traits<T>::pos_type object representing the new stream position of the streambuffer after the seek. (This type is std::streampos for narrow character (char) streams, std::wstreampos for wide character (wchar_t) streams, std::u16streampos for the char16_t type and std::u32streampos for the char32_t type.) If the seek failed, pos_type(off_type(-1)) is returned.
◆ set_byteswap()
template<class charT , class Traits = std::char_traits<charT>>
Causes the streambuffer to swap bytes in the incoming text, so as to convert big endian text to little endian text, or little endian text to big endian text. It is called by the user in response to finding a byte order marker (BOM) 0xfffe (UTF-16) or 0xfffe0000 (UTF-32) as the first character of a newly opened file/stream, or if the user knows by some other means that the native endianness of the machine doing the reading differs from the endianness of the file/stream being read. This only has effect on wide character input streambuffers (for example, wfdinbuf), and not the fdinbuf narrow character stream buffer. This method does not throw. fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
- Parameters
-
swap | 'true' if byte swapping is to be turned on, 'false' if it is to be turned off. This will affect all characters extracted from the streambuffer after this call is made. If any previously extracted character is to be putback(), it must be put back before this function is called (or unget() should be called instead) to avoid a putback mismatch, because this call will byte-swap anything already in the buffers. (Characters extracted after the call to this method may be putback normally.) |
◆ underflow()
template<class charT , class Traits = std::char_traits<charT>>
This method will not throw. This means that the input functions of stream objects which have this streambuffer as a member will not throw unless the underlying functions of the std::basic_istream class throw, which they would not normally do unless they have been required to do so on failbit, badbit or eofbit being set by an explicit call to the exceptions() method of that class. fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
◆ xsgetn()
template<class charT , class Traits = std::char_traits<charT>>
This method will not throw. This means that the input functions of stream objects which have this streambuffer as a member will not throw unless the underlying functions of the std::basic_istream class throw, which they would not normally do unless they have been required to do so on failbit, badbit or eofbit being set by an explicit call to the exceptions() method of that class. fdstreams do not offer concurrent access from multiple threads to the same stream object, and if that is required users should provide their own synchronisation.
The documentation for this class was generated from the following file: