diff --git a/src/scrollpad.cpp b/src/scrollpad.cpp index 60eeecd3..e01b3c16 100644 --- a/src/scrollpad.cpp +++ b/src/scrollpad.cpp @@ -86,9 +86,11 @@ void Scrollpad::Flush() } itsRealHeight = std::max(itsHeight, itsRealHeight); Recreate(itsWidth, itsRealHeight); - itsBuffer.SetTemp(&s); + // print our modified string + std::swap(s, itsBuffer.itsString); static_cast(*this) << itsBuffer; - itsBuffer.SetTemp(0); + // restore original one + std::swap(s, itsBuffer.itsString); } bool Scrollpad::SetFormatting(short val_b, const std::basic_string &s, short val_e, bool case_sensitive, bool for_each) diff --git a/src/strbuffer.h b/src/strbuffer.h index 7f6772a5..b64cbb97 100644 --- a/src/strbuffer.h +++ b/src/strbuffer.h @@ -35,6 +35,8 @@ namespace NCurses { /// template class basic_buffer { + friend class Scrollpad; + /// Struct used for storing information about /// one color/format flag along with its position /// @@ -62,15 +64,10 @@ template class basic_buffer /// std::list itsFormat; - /// Pointer to temporary string - /// @see SetTemp() - /// - std::basic_string *itsTempString; - public: /// Constructs an empty buffer /// - basic_buffer() : itsTempString(0) { } + basic_buffer() { } /// Constructs a buffer from the existed one /// @param b copied buffer @@ -110,15 +107,6 @@ template class basic_buffer /// void RemoveFormatting(); - /// Sets the pointer to string, that will be passed in operator<<() to window - /// object instead of the internal buffer. This is useful if you took the content - /// of the buffer, modified it somehow and want to print the modified version instead - /// of the original one, but with the original formatting informations. Note that after - /// you're done with the printing etc., this pointer has to be set to null. - /// @param tmp address of the temporary string - /// - void SetTemp(std::basic_string *tmp); - /// Prints to window object given part of the string, loading all needed formatting info /// and cleaning up after. The main goal of this function is to provide interface for /// colorful scrollers. @@ -204,7 +192,7 @@ template class basic_buffer /// the content of buffer to window object friend Window &operator<<(Window &w, const basic_buffer &buf) { - const std::basic_string &s = buf.itsTempString ? *buf.itsTempString : buf.itsString; + const std::basic_string &s = buf.itsString; if (buf.itsFormat.empty()) w << s; else @@ -251,7 +239,7 @@ typedef basic_buffer WBuffer; template basic_buffer::basic_buffer(const basic_buffer &b) - : itsString(b.itsString), itsFormat(b.itsFormat), itsTempString(b.itsTempString) { } + : itsString(b.itsString), itsFormat(b.itsFormat) { } template const std::basic_string &basic_buffer::Str() const { @@ -329,11 +317,6 @@ template void basic_buffer::RemoveFormatting() itsFormat.clear(); } -template void basic_buffer::SetTemp(std::basic_string *tmp) -{ - itsTempString = tmp; -} - template void basic_buffer::Write( Window &w, size_t &start_pos,