Warning, file /include/yaml-cpp/ostream_wrapper.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #ifndef OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0002 #define OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0003
0004 #if defined(_MSC_VER) || \
0005 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
0006 (__GNUC__ >= 4))
0007 #pragma once
0008 #endif
0009
0010 #include <string>
0011 #include <vector>
0012
0013 #include "yaml-cpp/dll.h"
0014
0015 namespace YAML {
0016 class YAML_CPP_API ostream_wrapper {
0017 public:
0018 ostream_wrapper();
0019 explicit ostream_wrapper(std::ostream& stream);
0020 ostream_wrapper(const ostream_wrapper&) = delete;
0021 ostream_wrapper(ostream_wrapper&&) = delete;
0022 ostream_wrapper& operator=(const ostream_wrapper&) = delete;
0023 ostream_wrapper& operator=(ostream_wrapper&&) = delete;
0024 ~ostream_wrapper();
0025
0026 void write(const std::string& str);
0027 void write(const char* str, std::size_t size);
0028
0029 void set_comment() { m_comment = true; }
0030
0031 const char* str() const {
0032 if (m_pStream) {
0033 return nullptr;
0034 } else {
0035 m_buffer[m_pos] = '\0';
0036 return &m_buffer[0];
0037 }
0038 }
0039
0040 std::size_t row() const { return m_row; }
0041 std::size_t col() const { return m_col; }
0042 std::size_t pos() const { return m_pos; }
0043 bool comment() const { return m_comment; }
0044
0045 private:
0046 void update_pos(char ch);
0047
0048 private:
0049 mutable std::vector<char> m_buffer;
0050 std::ostream* const m_pStream;
0051
0052 std::size_t m_pos;
0053 std::size_t m_row, m_col;
0054 bool m_comment;
0055 };
0056
0057 template <std::size_t N>
0058 inline ostream_wrapper& operator<<(ostream_wrapper& stream,
0059 const char (&str)[N]) {
0060 stream.write(str, N - 1);
0061 return stream;
0062 }
0063
0064 inline ostream_wrapper& operator<<(ostream_wrapper& stream,
0065 const std::string& str) {
0066 stream.write(str);
0067 return stream;
0068 }
0069
0070 inline ostream_wrapper& operator<<(ostream_wrapper& stream, char ch) {
0071 stream.write(&ch, 1);
0072 return stream;
0073 }
0074 }
0075
0076 #endif