From ac407b23623aa2ab76ac13ec8facb0b7762b1a00 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 20 Jun 2021 16:46:08 +0200 Subject: [PATCH] macro renamed: PT_HAS_MORM -> PT_HAS_MORM_LIBRARY TextStream::to_string(...) is now TextStream::to_str(...) added: std::string TextStream::to_str() const; added: std::wstring TextStream::to_wstr() const; --- src/log/log.cpp | 4 ++-- src/log/log.h | 2 +- src/space/space.cpp | 10 ++++----- src/space/space.h | 4 ++-- src/textstream/stream.h | 7 +++++-- src/textstream/textstream.h | 41 ++++++++++++++++++++++++++++++++----- 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/log/log.cpp b/src/log/log.cpp index fb7ec91..576b8bb 100644 --- a/src/log/log.cpp +++ b/src/log/log.cpp @@ -41,7 +41,7 @@ #include "date/date.h" #include "utf8/utf8.h" -#ifdef PT_HAS_MORM +#ifdef PT_HAS_MORM_LIBRARY #include "morm.h" #endif @@ -313,7 +313,7 @@ Log & Log::operator<<(const Date & date) } -#ifdef PT_HAS_MORM +#ifdef PT_HAS_MORM_LIBRARY Log & Log::operator<<(morm::Model & model) { operator<<(model.to_string()); diff --git a/src/log/log.h b/src/log/log.h index d5073ae..94d9125 100644 --- a/src/log/log.h +++ b/src/log/log.h @@ -131,7 +131,7 @@ public: virtual Log & operator<<(const Space & space); virtual Log & operator<<(const Date & date); -#ifdef PT_HAS_MORM +#ifdef PT_HAS_MORM_LIBRARY virtual Log & operator<<(morm::Model & model); #endif diff --git a/src/space/space.cpp b/src/space/space.cpp index b115856..05af2be 100644 --- a/src/space/space.cpp +++ b/src/space/space.cpp @@ -954,7 +954,7 @@ std::string Space::to_str() const { TextStream stream; serialize_string_buffer(value.value_wstring.c_str(), value.value_wstring.size(), stream, Escape::no_escape); - stream.to_string(str); + stream.to_str(str); return str; } @@ -1310,7 +1310,7 @@ void Space::serialize_to_space_to(std::string & str, bool pretty_print) const TextStream stream; serialize_to_space_stream(stream, pretty_print); - stream.to_string(str); + stream.to_str(str); } @@ -1319,7 +1319,7 @@ void Space::serialize_to_space_to(std::wstring & str, bool pretty_print) const WTextStream stream; serialize_to_space_stream(stream, pretty_print); - stream.to_string(str); + stream.to_str(str); } @@ -1345,7 +1345,7 @@ void Space::serialize_to_json_to(std::string & str) const TextStream stream; serialize_to_json_stream(stream); - stream.to_string(str); + stream.to_str(str); } @@ -1354,7 +1354,7 @@ void Space::serialize_to_json_to(std::wstring & str) const WTextStream stream; serialize_to_json_stream(stream); - stream.to_string(str); + stream.to_str(str); } diff --git a/src/space/space.h b/src/space/space.h index 227dffd..d4d6881 100644 --- a/src/space/space.h +++ b/src/space/space.h @@ -314,7 +314,7 @@ public: Space & add_stream(const wchar_t * field, StreamType & str) { std::wstring temp; - str.to_string(temp); + str.to_str(temp); return add(field, temp); } @@ -323,7 +323,7 @@ public: Space & add_stream(const std::wstring & field, StreamType & str) { std::wstring temp; - str.to_string(temp); + str.to_str(temp); return add(field, temp); } diff --git a/src/textstream/stream.h b/src/textstream/stream.h index 6bb9a07..d541f47 100644 --- a/src/textstream/stream.h +++ b/src/textstream/stream.h @@ -61,8 +61,11 @@ public: virtual void reserve(size_t len) = 0; virtual size_t capacity() const = 0; - virtual void to_string(std::string & str, bool clear_string = true) const = 0; - virtual void to_string(std::wstring & str, bool clear_string = true) const = 0; + virtual void to_str(std::string & str, bool clear_string = true) const = 0; + virtual void to_str(std::wstring & str, bool clear_string = true) const = 0; + + virtual std::string to_str() const = 0; + virtual std::wstring to_wstr() const = 0; virtual Stream & operator<<(const char * str) = 0; virtual Stream & operator<<(const std::string & str) = 0; diff --git a/src/textstream/textstream.h b/src/textstream/textstream.h index 726d0bb..facd4f6 100644 --- a/src/textstream/textstream.h +++ b/src/textstream/textstream.h @@ -90,8 +90,11 @@ public: // IMPROVE ME // add cbegin(), cend(), rbegin(), rend(), crbegin(), crend() - void to_string(std::string & str, bool clear_string = true) const; - void to_string(std::wstring & str, bool clear_string = true) const; + void to_str(std::string & str, bool clear_string = true) const; + void to_str(std::wstring & str, bool clear_string = true) const; + + std::string to_str() const; + std::wstring to_wstr() const; char_type & operator[](size_t index); char_type operator[](size_t index) const; @@ -224,7 +227,7 @@ TextStreamBase::end() const template -void TextStreamBase::to_string(std::string & str, bool clear_string) const +void TextStreamBase::to_str(std::string & str, bool clear_string) const { if( clear_string ) str.clear(); @@ -250,7 +253,7 @@ void TextStreamBase::to_string(std::stri template -void TextStreamBase::to_string(std::wstring & str, bool clear_string) const +void TextStreamBase::to_str(std::wstring & str, bool clear_string) const { if( clear_string ) str.clear(); @@ -269,13 +272,41 @@ void TextStreamBase::to_string(std::wstr { // IMPROVE ME don't use a temporary object std::string utf8; - to_string(utf8); + to_str(utf8); utf8_to_wide(utf8, str, false); } } +template +std::string TextStreamBase::to_str() const +{ + std::string str; + to_str(str, false); + + return str; +} + + +template +std::wstring TextStreamBase::to_wstr() const +{ + std::wstring str; + to_str(str, false); + + return str; +} + + + + + + + + + + template char_type & TextStreamBase::operator[](size_t index)