BRE12
ostream_wrapper.h
1 #ifndef OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3 
4 #if defined(_MSC_VER) || \
5  (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
6  (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
7 #pragma once
8 #endif
9 
10 #include <string>
11 #include <vector>
12 
13 #include "yaml-cpp/dll.h"
14 
15 namespace YAML {
16 class YAML_CPP_API ostream_wrapper {
17  public:
19  explicit ostream_wrapper(std::ostream& stream);
20  ~ostream_wrapper();
21 
22  void write(const std::string& str);
23  void write(const char* str, std::size_t size);
24 
25  void set_comment() { m_comment = true; }
26 
27  const char* str() const {
28  if (m_pStream) {
29  return 0;
30  } else {
31  m_buffer[m_pos] = '\0';
32  return &m_buffer[0];
33  }
34  }
35 
36  std::size_t row() const { return m_row; }
37  std::size_t col() const { return m_col; }
38  std::size_t pos() const { return m_pos; }
39  bool comment() const { return m_comment; }
40 
41  private:
42  void update_pos(char ch);
43 
44  private:
45  mutable std::vector<char> m_buffer;
46  std::ostream* const m_pStream;
47 
48  std::size_t m_pos;
49  std::size_t m_row, m_col;
50  bool m_comment;
51 };
52 
53 template <std::size_t N>
54 inline ostream_wrapper& operator<<(ostream_wrapper& stream,
55  const char(&str)[N]) {
56  stream.write(str, N - 1);
57  return stream;
58 }
59 
60 inline ostream_wrapper& operator<<(ostream_wrapper& stream,
61  const std::string& str) {
62  stream.write(str);
63  return stream;
64 }
65 
66 inline ostream_wrapper& operator<<(ostream_wrapper& stream, char ch) {
67  stream.write(&ch, 1);
68  return stream;
69 }
70 }
71 
72 #endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
Definition: DrawableObjectLoader.h:10
Definition: ostream_wrapper.h:16