ostream.cpp
Go to the documentation of this file.
00001 #include "yaml-cpp-pm/ostream.h"
00002 #include <cstring>
00003 
00004 namespace YAML_PM
00005 {
00006         ostream::ostream(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0)
00007         {
00008                 reserve(1024);
00009         }
00010         
00011         ostream::~ostream()
00012         {
00013                 delete [] m_buffer;
00014         }
00015         
00016         void ostream::reserve(unsigned size)
00017         {
00018                 if(size <= m_size)
00019                         return;
00020                 
00021                 char *newBuffer = new char[size];
00022                 std::memset(newBuffer, 0, size * sizeof(char));
00023                 std::memcpy(newBuffer, m_buffer, m_size * sizeof(char));
00024                 delete [] m_buffer;
00025                 m_buffer = newBuffer;
00026                 m_size = size;
00027         }
00028         
00029         void ostream::put(char ch)
00030         {
00031                 if(m_pos >= m_size - 1)   // an extra space for the NULL terminator
00032                         reserve(m_size * 2);
00033                 
00034                 m_buffer[m_pos] = ch;
00035                 m_pos++;
00036                 
00037                 if(ch == '\n') {
00038                         m_row++;
00039                         m_col = 0;
00040                 } else
00041                         m_col++;
00042         }
00043 
00044         ostream& operator << (ostream& out, const char *str)
00045         {
00046                 std::size_t length = std::strlen(str);
00047                 for(std::size_t i=0;i<length;i++)
00048                         out.put(str[i]);
00049                 return out;
00050         }
00051         
00052         ostream& operator << (ostream& out, const std::string& str)
00053         {
00054                 out << str.c_str();
00055                 return out;
00056         }
00057         
00058         ostream& operator << (ostream& out, char ch)
00059         {
00060                 out.put(ch);
00061                 return out;
00062         }
00063 }


libpointmatcher
Author(s):
autogenerated on Mon Sep 14 2015 02:59:06