Input stream for unix file descriptors.
More...
#include <c++-gtk-utils/fdstream.h>
template<class charT, class Traits = std::char_traits<charT>>
class Cgu::basic_fdistream< charT, Traits >
Input stream for unix file descriptors.
- See also
- fdstreams
This class provides standard istream services for unix file descriptors.
◆ basic_fdistream() [1/3]
template<class charT , class Traits = std::char_traits<charT>>
This class cannot be copied. The copy constructor is deleted.
◆ basic_fdistream() [2/3]
template<class charT , class Traits = std::char_traits<charT>>
This is the constructor which passes a file descriptor. It will not throw unless the constructor of std::basic_streambuf or std::basic_istream 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 stream object. |
manage | Whether the stream should manage the file descriptor (that is, close it in its destructor or when a new file descriptor is attached). |
◆ basic_fdistream() [3/3]
template<class charT , class Traits = std::char_traits<charT>>
With this constructor, the file descriptor must be attached later with the attach() method. It will not throw unless the default constructor of std::basic_streambuf or std::basic_istream 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.
◆ attach()
template<class charT , class Traits = std::char_traits<charT>>
Attach a new file descriptor to the stream object (and close any file descriptor at present managed by it). In the case of wide character streams, it also switches off byte swapping, if it was previously on. From version 1.2.6, if any stream state flags were set (eofbit, failbit or badbit), they will be cleared by a call to clear() (prior to that version, the user had to call clear() explicitly to do so). If this method closes a file descriptor at present managed by it and the close fails, failbit is not set and no exception will be thrown. Accordingly, if the user needs to know whether there was an error in this method closing any descriptor, she should call close() explicitly before calling this method. 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 stream object. |
manage | Whether the stream object 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 tellg() or seekg() can succeed. Note that in the seekg(off_type off, ios_base::seekdir dir) variant, on wide character streams the 'off' argument is dimensioned as the number of wchar_t units not the number of bytes (that is, it is bytes/sizeof(char_type)). 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 stream.
◆ close()
template<class charT , class Traits = std::char_traits<charT>>
Close the file descriptor at present attached to the stream object (if any). From version 1.2.6, if the close fails, the failbit will be set with setstate(std::ios_base::failbit). 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.
- Exceptions
-
std::ios_base::failure | From version 1.2.6, this exception will be thrown if an error arises on closing the descriptor and such an exception has been required by a call to the exceptions() method of this class (inherited from std::basic_ios<>). No exception will be thrown if exceptions() has not been called. |
◆ filedesc()
template<class charT , class Traits = std::char_traits<charT>>
Get the file descriptor at present attached to the stream object (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 stream object, 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.
◆ set_byteswap()
template<class charT , class Traits = std::char_traits<charT>>
Causes the underlying stream buffer 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 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 istreams (for example, wfdistream), and not the fdistream narrow character stream. 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 underlying 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.) |
The documentation for this class was generated from the following file: