external libraries: yaml-cpp version bump
[supercollider.git] / external_libraries / yaml-cpp-0.3.0 / src / ostream.cpp
bloba7f1e14bb8c4412c1c994a786fb0dcaf55953bc3
1 #include "yaml-cpp/ostream.h"
2 #include <cstring>
4 namespace YAML
6 ostream::ostream(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0)
8 reserve(1024);
11 ostream::~ostream()
13 delete [] m_buffer;
16 void ostream::reserve(unsigned size)
18 if(size <= m_size)
19 return;
21 char *newBuffer = new char[size];
22 std::memset(newBuffer, 0, size * sizeof(char));
23 std::memcpy(newBuffer, m_buffer, m_size * sizeof(char));
24 delete [] m_buffer;
25 m_buffer = newBuffer;
26 m_size = size;
29 void ostream::put(char ch)
31 if(m_pos >= m_size - 1) // an extra space for the NULL terminator
32 reserve(m_size * 2);
34 m_buffer[m_pos] = ch;
35 m_pos++;
37 if(ch == '\n') {
38 m_row++;
39 m_col = 0;
40 } else
41 m_col++;
44 ostream& operator << (ostream& out, const char *str)
46 std::size_t length = std::strlen(str);
47 for(std::size_t i=0;i<length;i++)
48 out.put(str[i]);
49 return out;
52 ostream& operator << (ostream& out, const std::string& str)
54 out << str.c_str();
55 return out;
58 ostream& operator << (ostream& out, char ch)
60 out.put(ch);
61 return out;