Renamed ostream -> ostream_wrapper

This commit is contained in:
Jesse Beder
2012-05-25 17:28:35 -05:00
parent 2dd1cf4596
commit 1602f78974
6 changed files with 47 additions and 47 deletions

View File

@@ -10,9 +10,9 @@
#include "yaml-cpp/binary.h" #include "yaml-cpp/binary.h"
#include "yaml-cpp/emitterdef.h" #include "yaml-cpp/emitterdef.h"
#include "yaml-cpp/emittermanip.h" #include "yaml-cpp/emittermanip.h"
#include "yaml-cpp/ostream.h"
#include "yaml-cpp/noncopyable.h" #include "yaml-cpp/noncopyable.h"
#include "yaml-cpp/null.h" #include "yaml-cpp/null.h"
#include "yaml-cpp/ostream_wrapper.h"
#include <memory> #include <memory>
#include <string> #include <string>
#include <sstream> #include <sstream>
@@ -114,8 +114,8 @@ namespace YAML
bool CanEmitNewline() const; bool CanEmitNewline() const;
private: private:
ostream m_stream; ostream_wrapper m_stream;
std::auto_ptr <EmitterState> m_pState; std::auto_ptr<EmitterState> m_pState;
}; };
template <typename T> template <typename T>

View File

@@ -1,5 +1,5 @@
#ifndef OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #ifndef OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #define OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once #pragma once
@@ -10,11 +10,11 @@
namespace YAML namespace YAML
{ {
class ostream class ostream_wrapper
{ {
public: public:
ostream(); ostream_wrapper();
~ostream(); ~ostream_wrapper();
void reserve(unsigned size); void reserve(unsigned size);
void put(char ch); void put(char ch);
@@ -35,9 +35,9 @@ namespace YAML
bool m_comment; bool m_comment;
}; };
ostream& operator << (ostream& out, const char *str); ostream_wrapper& operator << (ostream_wrapper& out, const char *str);
ostream& operator << (ostream& out, const std::string& str); ostream_wrapper& operator << (ostream_wrapper& out, const std::string& str);
ostream& operator << (ostream& out, char ch); ostream_wrapper& operator << (ostream_wrapper& out, char ch);
} }
#endif // OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@@ -107,7 +107,7 @@ namespace YAML
return true; return true;
} }
void WriteCodePoint(ostream& out, int codePoint) { void WriteCodePoint(ostream_wrapper& out, int codePoint) {
if (codePoint < 0 || codePoint > 0x10FFFF) { if (codePoint < 0 || codePoint > 0x10FFFF) {
codePoint = REPLACEMENT_CHARACTER; codePoint = REPLACEMENT_CHARACTER;
} }
@@ -185,7 +185,7 @@ namespace YAML
return true; return true;
} }
void WriteDoubleQuoteEscapeSequence(ostream& out, int codePoint) { void WriteDoubleQuoteEscapeSequence(ostream_wrapper& out, int codePoint) {
static const char hexDigits[] = "0123456789abcdef"; static const char hexDigits[] = "0123456789abcdef";
char escSeq[] = "\\U00000000"; char escSeq[] = "\\U00000000";
@@ -208,7 +208,7 @@ namespace YAML
out << escSeq; out << escSeq;
} }
bool WriteAliasName(ostream& out, const std::string& str) { bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
int codePoint; int codePoint;
for(std::string::const_iterator i = str.begin(); for(std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end()); GetNextCodePointAndAdvance(codePoint, i, str.end());
@@ -247,7 +247,7 @@ namespace YAML
return StringFormat::DoubleQuoted; return StringFormat::DoubleQuoted;
} }
bool WriteSingleQuotedString(ostream& out, const std::string& str) bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str)
{ {
out << "'"; out << "'";
int codePoint; int codePoint;
@@ -267,7 +267,7 @@ namespace YAML
return true; return true;
} }
bool WriteDoubleQuotedString(ostream& out, const std::string& str, bool escapeNonAscii) bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str, bool escapeNonAscii)
{ {
out << "\""; out << "\"";
int codePoint; int codePoint;
@@ -297,7 +297,7 @@ namespace YAML
return true; return true;
} }
bool WriteLiteralString(ostream& out, const std::string& str, int indent) bool WriteLiteralString(ostream_wrapper& out, const std::string& str, int indent)
{ {
out << "|\n"; out << "|\n";
out << IndentTo(indent); out << IndentTo(indent);
@@ -314,7 +314,7 @@ namespace YAML
return true; return true;
} }
bool WriteChar(ostream& out, char ch) bool WriteChar(ostream_wrapper& out, char ch)
{ {
if(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) if(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
out << ch; out << ch;
@@ -334,7 +334,7 @@ namespace YAML
return true; return true;
} }
bool WriteComment(ostream& out, const std::string& str, int postCommentIndent) bool WriteComment(ostream_wrapper& out, const std::string& str, int postCommentIndent)
{ {
const unsigned curIndent = out.col(); const unsigned curIndent = out.col();
out << "#" << Indentation(postCommentIndent); out << "#" << Indentation(postCommentIndent);
@@ -354,19 +354,19 @@ namespace YAML
return true; return true;
} }
bool WriteAlias(ostream& out, const std::string& str) bool WriteAlias(ostream_wrapper& out, const std::string& str)
{ {
out << "*"; out << "*";
return WriteAliasName(out, str); return WriteAliasName(out, str);
} }
bool WriteAnchor(ostream& out, const std::string& str) bool WriteAnchor(ostream_wrapper& out, const std::string& str)
{ {
out << "&"; out << "&";
return WriteAliasName(out, str); return WriteAliasName(out, str);
} }
bool WriteTag(ostream& out, const std::string& str, bool verbatim) bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim)
{ {
out << (verbatim ? "!<" : "!"); out << (verbatim ? "!<" : "!");
StringCharSource buffer(str.c_str(), str.size()); StringCharSource buffer(str.c_str(), str.size());
@@ -386,7 +386,7 @@ namespace YAML
return true; return true;
} }
bool WriteTagWithPrefix(ostream& out, const std::string& prefix, const std::string& tag) bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix, const std::string& tag)
{ {
out << "!"; out << "!";
StringCharSource prefixBuffer(prefix.c_str(), prefix.size()); StringCharSource prefixBuffer(prefix.c_str(), prefix.size());
@@ -416,7 +416,7 @@ namespace YAML
return true; return true;
} }
bool WriteBinary(ostream& out, const Binary& binary) bool WriteBinary(ostream_wrapper& out, const Binary& binary)
{ {
WriteDoubleQuotedString(out, EncodeBase64(binary.data(), binary.size()), false); WriteDoubleQuotedString(out, EncodeBase64(binary.data(), binary.size()), false);
return true; return true;

View File

@@ -7,7 +7,7 @@
#include "emitterstate.h" #include "emitterstate.h"
#include "yaml-cpp/ostream.h" #include "yaml-cpp/ostream_wrapper.h"
#include <string> #include <string>
namespace YAML namespace YAML
@@ -20,16 +20,16 @@ namespace YAML
{ {
StringFormat::value ComputeStringFormat(const std::string& str, EMITTER_MANIP strFormat, FlowType::value flowType, bool escapeNonAscii); StringFormat::value ComputeStringFormat(const std::string& str, EMITTER_MANIP strFormat, FlowType::value flowType, bool escapeNonAscii);
bool WriteSingleQuotedString(ostream& out, const std::string& str); bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str);
bool WriteDoubleQuotedString(ostream& out, const std::string& str, bool escapeNonAscii); bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str, bool escapeNonAscii);
bool WriteLiteralString(ostream& out, const std::string& str, int indent); bool WriteLiteralString(ostream_wrapper& out, const std::string& str, int indent);
bool WriteChar(ostream& out, char ch); bool WriteChar(ostream_wrapper& out, char ch);
bool WriteComment(ostream& out, const std::string& str, int postCommentIndent); bool WriteComment(ostream_wrapper& out, const std::string& str, int postCommentIndent);
bool WriteAlias(ostream& out, const std::string& str); bool WriteAlias(ostream_wrapper& out, const std::string& str);
bool WriteAnchor(ostream& out, const std::string& str); bool WriteAnchor(ostream_wrapper& out, const std::string& str);
bool WriteTag(ostream& out, const std::string& str, bool verbatim); bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim);
bool WriteTagWithPrefix(ostream& out, const std::string& prefix, const std::string& tag); bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix, const std::string& tag);
bool WriteBinary(ostream& out, const Binary& binary); bool WriteBinary(ostream_wrapper& out, const Binary& binary);
} }
} }

View File

@@ -6,7 +6,7 @@
#endif #endif
#include "yaml-cpp/ostream.h" #include "yaml-cpp/ostream_wrapper.h"
#include <iostream> #include <iostream>
namespace YAML namespace YAML
@@ -16,7 +16,7 @@ namespace YAML
unsigned n; unsigned n;
}; };
inline ostream& operator << (ostream& out, const Indentation& indent) { inline ostream_wrapper& operator << (ostream_wrapper& out, const Indentation& indent) {
for(unsigned i=0;i<indent.n;i++) for(unsigned i=0;i<indent.n;i++)
out << ' '; out << ' ';
return out; return out;
@@ -27,7 +27,7 @@ namespace YAML
unsigned n; unsigned n;
}; };
inline ostream& operator << (ostream& out, const IndentTo& indent) { inline ostream_wrapper& operator << (ostream_wrapper& out, const IndentTo& indent) {
while(out.col() < indent.n) while(out.col() < indent.n)
out << ' '; out << ' ';
return out; return out;

View File

@@ -1,19 +1,19 @@
#include "yaml-cpp/ostream.h" #include "yaml-cpp/ostream_wrapper.h"
#include <cstring> #include <cstring>
namespace YAML namespace YAML
{ {
ostream::ostream(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0), m_comment(false) ostream_wrapper::ostream_wrapper(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0), m_comment(false)
{ {
reserve(1024); reserve(1024);
} }
ostream::~ostream() ostream_wrapper::~ostream_wrapper()
{ {
delete [] m_buffer; delete [] m_buffer;
} }
void ostream::reserve(unsigned size) void ostream_wrapper::reserve(unsigned size)
{ {
if(size <= m_size) if(size <= m_size)
return; return;
@@ -26,7 +26,7 @@ namespace YAML
m_size = size; m_size = size;
} }
void ostream::put(char ch) void ostream_wrapper::put(char ch)
{ {
if(m_pos >= m_size - 1) // an extra space for the NULL terminator if(m_pos >= m_size - 1) // an extra space for the NULL terminator
reserve(m_size * 2); reserve(m_size * 2);
@@ -42,7 +42,7 @@ namespace YAML
m_col++; m_col++;
} }
ostream& operator << (ostream& out, const char *str) ostream_wrapper& operator << (ostream_wrapper& out, const char *str)
{ {
std::size_t length = std::strlen(str); std::size_t length = std::strlen(str);
for(std::size_t i=0;i<length;i++) for(std::size_t i=0;i<length;i++)
@@ -50,13 +50,13 @@ namespace YAML
return out; return out;
} }
ostream& operator << (ostream& out, const std::string& str) ostream_wrapper& operator << (ostream_wrapper& out, const std::string& str)
{ {
out << str.c_str(); out << str.c_str();
return out; return out;
} }
ostream& operator << (ostream& out, char ch) ostream_wrapper& operator << (ostream_wrapper& out, char ch)
{ {
out.put(ch); out.put(ch);
return out; return out;