summaryrefslogtreecommitdiffstats
path: root/external_libs/yaml-cpp/src/ostream.cpp
diff options
context:
space:
mode:
authorWenxian Li <wenxianl@cisco.com>2015-09-08 18:41:17 -0400
committerWenxian Li <wenxianl@cisco.com>2015-09-08 18:41:17 -0400
commit60e901aabaeab7d205da65030849056c05c8b73e (patch)
tree20883ed8ae63c326f3c042992e8dbe668656568e /external_libs/yaml-cpp/src/ostream.cpp
parent9a524989d331f04abecd3faa72d98157a8651739 (diff)
parent463cb7c212e927a732fb5b702a288a06550c5eb8 (diff)
Merge remote-tracking branch
Conflicts: linux/b linux/ws_main.py linux_dpdk/ws_main.py src/bp_sim.h
Diffstat (limited to 'external_libs/yaml-cpp/src/ostream.cpp')
-rw-r--r--external_libs/yaml-cpp/src/ostream.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/external_libs/yaml-cpp/src/ostream.cpp b/external_libs/yaml-cpp/src/ostream.cpp
new file mode 100644
index 00000000..a7f1e14b
--- /dev/null
+++ b/external_libs/yaml-cpp/src/ostream.cpp
@@ -0,0 +1,63 @@
+#include "yaml-cpp/ostream.h"
+#include <cstring>
+
+namespace YAML
+{
+ ostream::ostream(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0)
+ {
+ reserve(1024);
+ }
+
+ ostream::~ostream()
+ {
+ delete [] m_buffer;
+ }
+
+ void ostream::reserve(unsigned size)
+ {
+ if(size <= m_size)
+ return;
+
+ char *newBuffer = new char[size];
+ std::memset(newBuffer, 0, size * sizeof(char));
+ std::memcpy(newBuffer, m_buffer, m_size * sizeof(char));
+ delete [] m_buffer;
+ m_buffer = newBuffer;
+ m_size = size;
+ }
+
+ void ostream::put(char ch)
+ {
+ if(m_pos >= m_size - 1) // an extra space for the NULL terminator
+ reserve(m_size * 2);
+
+ m_buffer[m_pos] = ch;
+ m_pos++;
+
+ if(ch == '\n') {
+ m_row++;
+ m_col = 0;
+ } else
+ m_col++;
+ }
+
+ ostream& operator << (ostream& out, const char *str)
+ {
+ std::size_t length = std::strlen(str);
+ for(std::size_t i=0;i<length;i++)
+ out.put(str[i]);
+ return out;
+ }
+
+ ostream& operator << (ostream& out, const std::string& str)
+ {
+ out << str.c_str();
+ return out;
+ }
+
+ ostream& operator << (ostream& out, char ch)
+ {
+ out.put(ch);
+ return out;
+ }
+}