Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fd.h
Go to the documentation of this file.
1 /*! \file xstream/fd.h
2  *
3  * \brief C++ streambuf to work with file descriptors
4  *
5  */
6 
7 #ifndef __XSTREAM_FD_H
8 #define __XSTREAM_FD_H
9 
10 #include <xstream/config.h>
11 
12 #include <xstream/common.h>
13 #include <xstream/posix.h>
14 #include <streambuf>
15 #include <set>
16 
17 namespace xstream{
18 
19 /*!
20  * \brief file descriptor streambuf objects
21  *
22  */
23 namespace fd{
24 
25 /*!
26  * \brief file descriptor streambuf
27  *
28  * allows to use a streambuf to read/write data to/from a file descriptor
29  *
30  * \todo implement seek operation when possible
31  *
32  */
33 class streambuf: public xstream::ostreambuf, private xstream::posix::fd {
34  private:
35 
36  xstream::buffer rbuf; /*!< were read data is stored */
37  xstream::buffer wbuf; /*!< were data to be written is stored */
38 
39 
40  /*!
41  * \brief flush as much data as possible (overloaded from streambuf)
42  *
43  * */
44  int sync();
45 
46  /*!
47  * \brief write a character that surpasses buffer end (overloaded from streambuf)
48  *
49  */
50  int overflow(int c);
51 
52  /*!
53  * \brief write an entire buffer (overloaded from streambuf)
54  *
55  */
56  std::streamsize xsputn(const char* buffer, std::streamsize n);
57 
58  /*!
59  * \brief reads \c n characters to \c buffer (overloaded from streambuf)
60  *
61  */
62  std::streamsize xsgetn(char *buffer, std::streamsize n);
63 
64  /*!
65  * \brief requests that input buffer be reloaded (overloaded from streambuf)
66  */
67  int underflow();
68 
69  void reset_write();
70 
71  void flush_write();
72 
73  public:
74  /*!
75  * \brief construct specifying the file descriptor
76  *
77  * \param fd filedescriptor
78  * \param close if true closes the file descriptor at destruction
79  */
80  streambuf(int fd, bool close=true);
81 
82  /*!
83  * \brief closes the streambuf stream
84  *
85  */
86  ~streambuf();
87 
88 };
89 
90 
91 }//namespace fd
92 }//namespace xstream
93 
94 #endif
xstream::buffer rbuf
Definition: fd.h:36
textOut close()
int underflow()
requests that input buffer be reloaded (overloaded from streambuf)
#define c
~streambuf()
closes the streambuf stream
xstream::buffer wbuf
Definition: fd.h:37
int overflow(int c)
write a character that surpasses buffer end (overloaded from streambuf)
streambuf(int fd, bool close=true)
construct specifying the file descriptor
file descriptor streambuf
Definition: fd.h:33
int sync()
flush as much data as possible (overloaded from streambuf)
std::streamsize xsputn(const char *buffer, std::streamsize n)
write an entire buffer (overloaded from streambuf)
std::streamsize xsgetn(char *buffer, std::streamsize n)
reads n characters to buffer (overloaded from streambuf)
buffer management
Definition: common.h:46
common objects
POSIX helper objects and functions.