/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2010, Tomasz Sowa * All rights reserved. * */ #ifndef headerfile_winix_core_textstream #define headerfile_winix_core_textstream #include #include "misc.h" template class TextStream { public: typedef typename StringType::value_type CharType; typedef typename StringType::value_type char_type; void Clear(); bool Empty() const; size_t Size() const; const StringType & Str() const; const CharType * CStr() const; TextStream & operator<<(const char * str); TextStream & operator<<(const std::string * str); TextStream & operator<<(const std::string & str); TextStream & operator<<(const wchar_t * str); TextStream & operator<<(const std::wstring * str); TextStream & operator<<(const std::wstring & str); TextStream & operator<<(char); TextStream & operator<<(wchar_t); TextStream & operator<<(int); TextStream & operator<<(long); TextStream & operator<<(unsigned int); TextStream & operator<<(unsigned long); TextStream & operator<<(double); TextStream & operator<<(const void *);// printing a pointer TextStream & Write(const CharType * buf, size_t len); TextStream & write(const CharType * buf, size_t len); // for compatibility with standard library (Ezc uses it) protected: StringType buffer; }; template void TextStream::Clear() { buffer.clear(); } template bool TextStream::Empty() const { return buffer.empty(); } template size_t TextStream::Size() const { return buffer.size(); } template const StringType & TextStream::Str() const { return buffer; } template const typename TextStream::CharType * TextStream::CStr() const { return buffer.c_str(); } template TextStream & TextStream::operator<<(const char * str) { AssignString(str, buffer, false); return *this; } template TextStream & TextStream::operator<<(const std::string * str) { AssignString(*str, buffer, false); return *this; } template TextStream & TextStream::operator<<(const std::string & str) { AssignString(str, buffer, false); return *this; } template TextStream & TextStream::operator<<(const wchar_t * str) { AssignString(str, buffer, false); return *this; } template TextStream & TextStream::operator<<(const std::wstring * str) { AssignString(*str, buffer, false); return *this; } template TextStream & TextStream::operator<<(const std::wstring & str) { AssignString(str, buffer, false); return *this; } template TextStream & TextStream::operator<<(char v) { buffer += v; return *this; } template TextStream & TextStream::operator<<(wchar_t v) { buffer += static_cast(v); return *this; } template TextStream & TextStream::operator<<(int v) { char buf[50]; sprintf(buf, "%d", v); AssignString(buf, buffer, false); return *this; } template TextStream & TextStream::operator<<(long v) { char buf[50]; sprintf(buf, "%ld", v); AssignString(buf, buffer, false); return *this; } template TextStream & TextStream::operator<<(unsigned int v) { char buf[50]; sprintf(buf, "%u", v); AssignString(buf, buffer, false); return *this; } template TextStream & TextStream::operator<<(unsigned long v) { char buf[50]; sprintf(buf, "%lu", v); AssignString(buf, buffer, false); return *this; } template TextStream & TextStream::operator<<(double v) { char buf[50]; sprintf(buf, "%f", v); AssignString(buf, buffer, false); return *this; } template TextStream & TextStream::operator<<(const void * v) { char buf[50]; sprintf(buf, "%p", v); AssignString(buf, buffer, false); return *this; } template TextStream & TextStream::Write(const TextStream::CharType * buf, size_t len) { buffer.reserve(buffer.size() + len); for(size_t i=0 ; i TextStream & TextStream::write(const TextStream::CharType * buf, size_t len) { return Write(buf, len); } #endif