From ce0348b2d79e4d986955c507a1e981cee11bfd69 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 20 Aug 2022 00:26:12 +0200 Subject: [PATCH] add to Space methods which takes a Stream as an argument - Space::set(const Stream & stream) - Space::add(const Stream & stream) - Space::add(const wchar_t * field, const Stream & stream) - Space::add(const std::wstring & field, const Stream & stream) --- src/space/space.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ src/space/space.h | 4 ++++ 2 files changed, 59 insertions(+) diff --git a/src/space/space.cpp b/src/space/space.cpp index cf31155..dd0c90c 100644 --- a/src/space/space.cpp +++ b/src/space/space.cpp @@ -446,6 +446,20 @@ void Space::set(const std::wstring & str) value.value_wstring = str; } +void Space::set(const Stream & stream) +{ + if( stream.is_char_stream() ) + { + initialize_value_string_if_needed(); + stream.to_str(value.value_string); + } + else + { + initialize_value_wstring_if_needed(); + stream.to_str(value.value_wstring); + } +} + void Space::set(const Space & space) { copy_from(space); @@ -567,6 +581,24 @@ Space & Space::add(const std::wstring & val) return add_generic(val); } +Space & Space::add(const Stream & stream) +{ + if( stream.is_char_stream() ) + { + pt::Space & new_item = add_empty_space(); + new_item.set_empty_string(); + stream.to_str(new_item.value.value_string); + return new_item; + } + else + { + pt::Space & new_item = add_empty_space(); + new_item.set_empty_wstring(); + stream.to_str(new_item.value.value_wstring); + return new_item; + } +} + Space & Space::add(const Space & space) { return add_generic(space); @@ -690,6 +722,24 @@ Space & Space::add(const wchar_t * field, const std::wstring & val) return add_generic(field, val); } +Space & Space::add(const wchar_t * field, const Stream & stream) +{ + if( stream.is_char_stream() ) + { + pt::Space & new_item = add_empty_space(field); + new_item.set_empty_string(); + stream.to_str(new_item.value.value_string); + return new_item; + } + else + { + pt::Space & new_item = add_empty_space(field); + new_item.set_empty_wstring(); + stream.to_str(new_item.value.value_wstring); + return new_item; + } +} + Space & Space::add(const wchar_t * field, const Space & space) { return add_generic(field, space); @@ -822,6 +872,11 @@ Space & Space::add(const std::wstring & field, const std::wstring & val) return add_generic_string(field, val); } +Space & Space::add(const std::wstring & field, const Stream & stream) +{ + return add(field.c_str(), stream); +} + Space & Space::add(const std::wstring & field, const Space & space) { return add_generic_string(field, space); diff --git a/src/space/space.h b/src/space/space.h index 54240d5..82a780f 100644 --- a/src/space/space.h +++ b/src/space/space.h @@ -242,6 +242,7 @@ public: void set(const wchar_t * str, size_t len); void set(const std::string & str); void set(const std::wstring & str); + void set(const Stream & stream); void set(const Space & space); void set(const Space * space); void set(Space && space); @@ -267,6 +268,7 @@ public: Space & add_to_table(const wchar_t * val, size_t len); // the name add would collapse with add(const wchar_t * field, unsigned long val) below; Space & add(const std::string & val); Space & add(const std::wstring & val); + Space & add(const Stream & stream); Space & add(const Space & space); Space & add(const Space * space); Space & add(Space && space); @@ -294,6 +296,7 @@ public: Space & add(const wchar_t * field, const wchar_t * val, size_t len); Space & add(const wchar_t * field, const std::string & val); Space & add(const wchar_t * field, const std::wstring & val); + Space & add(const wchar_t * field, const Stream & stream); Space & add(const wchar_t * field, const Space & space); Space & add(const wchar_t * field, const Space * space); Space & add(const wchar_t * field, Space && space); @@ -318,6 +321,7 @@ public: Space & add(const std::wstring & field, const wchar_t * val, size_t len); Space & add(const std::wstring & field, const std::string & val); Space & add(const std::wstring & field, const std::wstring & val); + Space & add(const std::wstring & field, const Stream & stream); Space & add(const std::wstring & field, const Space & space); Space & add(const std::wstring & field, const Space * space); Space & add(const std::wstring & field, Space && space);