c++-gtk-utils

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Cgu::basic_fdistream< charT, Traits > Class Template Reference
fdstreams

Input stream for unix file descriptors. More...

`#include <c++-gtk-utils/fdstream.h>`

Inheritance diagram for Cgu::basic_fdistream< charT, Traits >:

## Public Member Functions
| basic_fdistream (const basic_fdistream &)=delete
basic_fdistream & | operator= (const basic_fdistream &)=delete
| basic_fdistream (int fd, bool manage=true)
| basic_fdistream ()
void | attach (int fd, bool manage=true)
void | close ()
int | filedesc () const
void | set_byteswap (bool swap)
bool | can_seek () const

## Detailed Description

### 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.

## Constructor & Destructor Documentation

template<class charT , class Traits = std::char_traits<charT>>

Cgu::basic_fdistream< charT, Traits >::basic_fdistream | ( | const basic_fdistream< charT, Traits > & | ) |  |
| delete

This class cannot be copied. The copy constructor is deleted.

template<class charT , class Traits = std::char_traits<charT>>

Cgu::basic_fdistream< charT, Traits >::basic_fdistream | ( | int | fd,
|  | bool | manage = `true`
| ) |  |
| inline

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).

template<class charT , class Traits = std::char_traits<charT>>

Cgu::basic_fdistream< charT, Traits >::basic_fdistream | ( | ) |  |
| inline

With this constructor, the file descriptor must be attached later with the attach() method. 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.

## Member Function Documentation

template<class charT , class Traits = std::char_traits<charT>>

void Cgu::basic_fdistream< charT, Traits >::attach | ( | int | fd,
|  | bool | manage = `true`
| ) |  |
| inline

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).

template<class charT , class Traits = std::char_traits<charT>>

bool Cgu::basic_fdistream< charT, Traits >::can_seek | ( | ) |  | const
| inline

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.

template<class charT , class Traits = std::char_traits<charT>>

void Cgu::basic_fdistream< charT, Traits >::close | ( | ) |  |
| inline

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.

template<class charT , class Traits = std::char_traits<charT>>

int Cgu::basic_fdistream< charT, Traits >::filedesc | ( | ) |  | const
| inline

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

template<class charT , class Traits = std::char_traits<charT>>

basic_fdistream& Cgu::basic_fdistream< charT, Traits >::operator= | ( | const basic_fdistream< charT, Traits > & | ) |  |
| delete

This class cannot be copied. The assignment operator is deleted.

template<class charT , class Traits = std::char_traits<charT>>

void Cgu::basic_fdistream< charT, Traits >::set_byteswap | ( | bool | swap) |  |
| inline

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:

- fdstream.h