c++-gtk-utils
Public Types | Public Member Functions | Protected Member Functions | List of all members
Cgu::basic_fdinbuf< charT, Traits > Class Template Reference

Input stream buffer for unix file descriptors. More...

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

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

Public Types

typedef charT char_type
 
typedef Traits traits_type
 
typedef traits_type::int_type int_type
 
typedef traits_type::pos_type pos_type
 
typedef traits_type::off_type off_type
 

Public Member Functions

 basic_fdinbuf (const basic_fdinbuf &)=delete
 
basic_fdinbufoperator= (const basic_fdinbuf &)=delete
 
 basic_fdinbuf (int fd_=-1, bool manage_=true)
 
virtual ~basic_fdinbuf ()
 
void attach_fd (int fd_, bool manage_=true)
 
bool close_fd ()
 
int get_fd () const
 
void set_byteswap (bool swap)
 
bool can_seek () const
 

Protected Member Functions

virtual int_type underflow ()
 
virtual std::streamsize xsgetn (char_type *, std::streamsize)
 
virtual pos_type seekoff (off_type off, std::ios_base::seekdir way, std::ios_base::openmode m=std::ios_base::in|std::ios_base::out)
 
virtual pos_type seekpos (pos_type p, std::ios_base::openmode m=std::ios_base::in|std::ios_base::out)
 

Detailed Description

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.

Member Typedef Documentation

◆ char_type

template<class charT , class Traits = std::char_traits<charT>>
typedef charT Cgu::basic_fdinbuf< charT, Traits >::char_type

◆ int_type

template<class charT , class Traits = std::char_traits<charT>>
typedef traits_type::int_type Cgu::basic_fdinbuf< charT, Traits >::int_type

◆ off_type

template<class charT , class Traits = std::char_traits<charT>>
typedef traits_type::off_type Cgu::basic_fdinbuf< charT, Traits >::off_type

◆ pos_type

template<class charT , class Traits = std::char_traits<charT>>
typedef traits_type::pos_type Cgu::basic_fdinbuf< charT, Traits >::pos_type

◆ traits_type

template<class charT , class Traits = std::char_traits<charT>>
typedef Traits Cgu::basic_fdinbuf< charT, Traits >::traits_type

Constructor & Destructor Documentation

◆ basic_fdinbuf() [1/2]

template<class charT , class Traits = std::char_traits<charT>>
Cgu::basic_fdinbuf< charT, Traits >::basic_fdinbuf ( const basic_fdinbuf< charT, Traits > &  )
delete

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

◆ basic_fdinbuf() [2/2]

template<class charT , class Traits = std::char_traits<charT>>
Cgu::basic_fdinbuf< charT, Traits >::basic_fdinbuf ( int  fd_ = -1,
bool  manage_ = true 
)

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>>
virtual Cgu::basic_fdinbuf< charT, Traits >::~basic_fdinbuf ( )
virtual

The destructor does not throw.

Member Function Documentation

◆ attach_fd()

template<class charT , class Traits = std::char_traits<charT>>
void Cgu::basic_fdinbuf< charT, Traits >::attach_fd ( int  fd_,
bool  manage_ = true 
)

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>>
bool Cgu::basic_fdinbuf< charT, Traits >::can_seek ( ) const

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>>
bool Cgu::basic_fdinbuf< charT, Traits >::close_fd ( )

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>>
int Cgu::basic_fdinbuf< charT, Traits >::get_fd ( ) const
inline

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>>
basic_fdinbuf& Cgu::basic_fdinbuf< charT, Traits >::operator= ( const basic_fdinbuf< charT, Traits > &  )
delete

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
offThe 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)).
wayThe 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).
mThe 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>>
virtual pos_type Cgu::basic_fdinbuf< charT, Traits >::seekpos ( pos_type  p,
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 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
pThe absolute position to which the seek is to be made, obtained by a previous call to seekoff() or to this method.
mThe 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>>
void Cgu::basic_fdinbuf< charT, Traits >::set_byteswap ( bool  swap)

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>>
virtual int_type Cgu::basic_fdinbuf< charT, Traits >::underflow ( )
protectedvirtual

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>>
virtual std::streamsize Cgu::basic_fdinbuf< charT, Traits >::xsgetn ( char_type ,
std::streamsize   
)
protectedvirtual

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: