ostream.cpp
Go to the documentation of this file.
1 #include "yaml-cpp-pm/ostream.h"
2 #include <cstring>
3 
4 namespace YAML_PM
5 {
6  ostream::ostream(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0)
7  {
8  reserve(1024);
9  }
10 
12  {
13  delete [] m_buffer;
14  }
15 
16  void ostream::reserve(unsigned size)
17  {
18  if(size <= m_size)
19  return;
20 
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;
27  }
28 
29  void ostream::put(char ch)
30  {
31  if(m_pos >= m_size - 1) // an extra space for the NULL terminator
32  reserve(m_size * 2);
33 
34  m_buffer[m_pos] = ch;
35  m_pos++;
36 
37  if(ch == '\n') {
38  m_row++;
39  m_col = 0;
40  } else
41  m_col++;
42  }
43 
44  ostream& operator << (ostream& out, const char *str)
45  {
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;
50  }
51 
53  {
54  out << str.c_str();
55  return out;
56  }
57 
58  ostream& operator << (ostream& out, char ch)
59  {
60  out.put(ch);
61  return out;
62  }
63 }
unsigned m_pos
Definition: ostream.h:29
::std::string string
Definition: gtest.h:1979
char * m_buffer
Definition: ostream.h:28
Emitter & operator<<(Emitter &emitter, const std::string &v)
Definition: emitter.h:148
const char * str() const
Definition: ostream.h:21
void reserve(unsigned size)
Definition: ostream.cpp:16
void put(char ch)
Definition: ostream.cpp:29
unsigned m_size
Definition: ostream.h:30
unsigned m_col
Definition: ostream.h:32
unsigned m_row
Definition: ostream.h:32


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:38:02