Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
posix.h
Go to the documentation of this file.
1 /*! \file xstream/posix.h
2  *
3  * \brief POSIX helper objects and functions
4  */
5 
6 #ifndef __XSTREAM_POSIX_H
7 #define __XSTREAM_POSIX_H
8 
9 #include <xstream/config.h>
10 
11 #include <string>
12 #include <iosfwd>
13 #include <ios>
14 
15 namespace xstream{
16 /*!
17  * \brief POSIX objects and functions
18  */
19 namespace posix{
20 
21  /*!
22  * \brief stores a \c strftime format and returns a string representation of the current date
23  *
24  */
26  {
27  public:
28  std::string format; /*!< format string for strftime */
29 
30  /*!
31  * \brief construct specifying strftime format
32  */
33 
35  std::string now() const;
36  };
37 
38  /*!
39  * \brief checks the return code of a syscall and raises apropriate exception if needed
40  *
41  * \param code error code
42  * \param call name of syscall
43  *
44  */
45  void check_return(int code, const std::string& call);
46 
47 #if HAVE_FD
48 
49  /*!
50  * \brief encapsulates a file descriptor
51  *
52  */
53 
54  class fd
55  {
56  protected:
57  int fdn; /*!< the actual file descriptor */
58  bool dest_close; /*<! if close should be called at destruction time */
59 
60  public:
61 
62  /*!
63  * \brief constructs a fd object and specifies properties
64  *
65  * \param fd filedescriptor to operate on
66  * \param close if true closes the file descriptor at destruction, otherwise doesn't do anything
67  *
68  */
69  fd(int fd, bool close=false);
70 
71  /*!
72  * \brief reads at most \c len bytes from fd and stores then in \c buffer
73  *
74  * \param buffer where read data is stored
75  * \param len number of bytes to read
76  *
77  * \return number of read bytes
78  *
79  */
80  std::streamsize read(char* buffer, std::streamsize len);
81 
82  /*!
83  * \brief reads at most \c len bytes
84  *
85  * \return a string with the read data
86  *
87  */
88  std::string read(std::streamsize len);
89 
90  /*!
91  * \brief writes at most \c len bytes from \c buffer to \c fd
92  *
93  * \param buffer where data is read from
94  * \param len number of bytes to write
95  *
96  * \return number of written bytes
97  *
98  */
99  std::streamsize write(const char* buffer, std::streamsize len);
100 
101 #if 0
102  /*!
103  * \brief writes a string to the fd
104  *
105  * \param string data to write
106  *
107  * \return number of written bytes
108  *
109  */
110  void write(const std::string& string);
111 #endif
112 
113  /*!
114  * \brief tries to flush data to disk (or whatever the case)
115  *
116  * \note internally calls \c fdatasync so \c stat data is not updated
117  */
118  void sync();
119 
120  /*!
121  * \brief destructor
122  *
123  * if specified at construct time, fd is closed
124  *
125  */
126  ~fd();
127 
128  };
129 
130 #endif
131 
132 }//namespace posix
133 }//namespace xstream
134 
135 #endif
std::string now() const
Definition: posix.cpp:30
textOut close()
char string[256]
stores a strftime format and returns a string representation of the current date
Definition: posix.h:25
std::string format
Definition: posix.h:28
void check_return(int code, const std::string &call)
checks the return code of a syscall and raises apropriate exception if needed
Definition: posix.cpp:61
buffer management
Definition: common.h:46
date_format(const std::string &format)
construct specifying strftime format
Definition: posix.cpp:28