#include "..\include\CharMessageBuffer.h"
using namespace mylog;
CCharMessageBuffer::CCharMessageBuffer() : stream(0) {}
CCharMessageBuffer::~CCharMessageBuffer() {
delete stream;
}
CCharMessageBuffer& CCharMessageBuffer::operator<<(const std::basic_string<char>& msg) {
if (stream == 0) {
buf.append(msg);
} else {
*stream << msg;
}
return *this;
}
CCharMessageBuffer& CCharMessageBuffer::operator<<(const char* msg) {
const char* actualMsg = msg;
if (actualMsg == 0) {
actualMsg = "null";
}
if (stream == 0) {
buf.append(actualMsg);
} else {
*stream << actualMsg;
}
return *this;
}
CCharMessageBuffer& CCharMessageBuffer::operator<<(char* msg) {
return operator<<((const char*) msg);
}
CCharMessageBuffer& CCharMessageBuffer::operator<<(const char msg) {
if (stream == 0) {
buf.append(1, msg);
} else {
buf.assign(1, msg);
*stream << buf;
}
return *this;
}
CCharMessageBuffer::operator std::basic_ostream<char>&() {
if (stream == 0) {
stream = new std::basic_ostringstream<char>();
if (!buf.empty()) {
*stream << buf;
}
}
return *stream;
}
const std::basic_string<char>& CCharMessageBuffer::str(std::basic_ostream<char>&) {
buf = stream->str();
return buf;
}
const std::basic_string<char>& CCharMessageBuffer::str(CCharMessageBuffer&) {
return buf;
}
bool CCharMessageBuffer::hasStream() const {
return (stream != 0);
}
std::ostream& CCharMessageBuffer::operator<<(ios_base_manip manip) {
std::ostream& s = *this;
(*manip)(s);
return s;
}
std::ostream& CCharMessageBuffer::operator<<(bool val) { return ((std::ostream&) *this).operator<<(val); }
std::ostream& CCharMessageBuffer::operator<<(short val) { return ((std::ostream&) *this).operator<<(val); }
std::ostream& CCharMessageBuffer::operator<<(int val) { return ((std::ostream&) *this).operator<<(val); }
std::ostream& CCharMessageBuffer::operator<<(unsigned int val) { return ((std::ostream&) *this).operator<<(val); }
std::ostream& CCharMessageBuffer::operator<<(long val) { return ((std::ostream&) *this).operator<<(val); }
std::ostream& CCharMessageBuffer::operator<<(unsigned long val) { return ((std::ostream&) *this).operator<<(val); }
std::ostream& CCharMessageBuffer::operator<<(float val) { return ((std::ostream&) *this).operator<<(val); }
std::ostream& CCharMessageBuffer::operator<<(double val) { return ((std::ostream&) *this).operator<<(val); }
std::ostream& CCharMessageBuffer::operator<<(long double val) { return ((std::ostream&) *this).operator<<(val); }
std::ostream& CCharMessageBuffer::operator<<(void* val) { return ((std::ostream&) *this).operator<<(val); }