Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dater.h
Go to the documentation of this file.
1 /*! \file xstream/dater.h
2  *
3  * \brief C++ objects to date output lines
4  */
5 
6 #ifndef __XSTREAM_DATER_H
7 #define __XSTREAM_DATER_H
8 
9 #include <xstream/config.h>
10 
11 #include <xstream/common.h>
12 #include <xstream/posix.h>
13 
14 #include <streambuf>
15 #include <string>
16 
17 namespace xstream{
18 
19 /*!
20  * \brief filter that add a time stamp on the begining of each line
21  *
22  */
24 {
25  private:
26  std::streambuf* _sb; /*!< streambuf were data is written to */
28  char separator; /*!< data is written after this character */
29  bool write_next;
30 
31  /*!
32  * \brief writes the current date to the streambuf
33  *
34  */
35  void write_date();
36 
37  /*!
38  * \brief tries to write as much data as possible (overloaded from streambuf)
39  *
40  * */
41  int sync();
42 
43  /*!
44  * \brief write a character that surpasses buffer end (overloaded from streambuf)
45  *
46  */
47  int overflow(int c);
48 
49  /*!
50  * \brief write an entire buffer (overloaded from streambuf)
51  *
52  */
53  std::streamsize xsputn(const char *buffer, std::streamsize n);
54 
55  public:
56  /*!
57  * \brief construct using another streambuf
58  *
59  * \param sb streambuf to write data to
60  * \param format format string for \c strftime defaults to [%c] the preferred date and time representation for the current locale
61  * \param separator character that signal a change of line, defaults to newline
62  * \param write_first if true date is written right before the first write. default is true
63  *
64  */
65 
66  dater(std::streambuf* sb, const std::string& format="[%c] ", char separator='\n', bool write_first=true);
67 
68  /*! destructor
69  *
70  * */
71  ~dater();
72 };
73 
74 }//namespace xstream
75 
76 #endif
char string[256]
#define c
posix::date_format date
Definition: dater.h:27
dater(std::streambuf *sb, const std::string &format="[%c] ", char separator='\n', bool write_first=true)
construct using another streambuf
Definition: src/dater.cpp:10
void write_date()
writes the current date to the streambuf
Definition: src/dater.cpp:63
std::streambuf * _sb
Definition: dater.h:26
stores a strftime format and returns a string representation of the current date
Definition: posix.h:25
bool write_next
Definition: dater.h:29
int sync()
tries to write as much data as possible (overloaded from streambuf)
Definition: src/dater.cpp:16
char separator
Definition: dater.h:28
std::streamsize xsputn(const char *buffer, std::streamsize n)
write an entire buffer (overloaded from streambuf)
Definition: src/dater.cpp:37
int overflow(int c)
write a character that surpasses buffer end (overloaded from streambuf)
Definition: src/dater.cpp:21
buffer management
Definition: common.h:46
common objects
filter that add a time stamp on the begining of each line
Definition: dater.h:23
POSIX helper objects and functions.