strbuffer: be friend with Scrollpad instead of using shitty hacks

This commit is contained in:
Andrzej Rybczak
2012-08-28 08:23:53 +02:00
parent e61d0a4958
commit 8abae236bb
2 changed files with 9 additions and 24 deletions

View File

@@ -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<Window &>(*this) << itsBuffer;
itsBuffer.SetTemp(0);
// restore original one
std::swap(s, itsBuffer.itsString);
}
bool Scrollpad::SetFormatting(short val_b, const std::basic_string<my_char_t> &s, short val_e, bool case_sensitive, bool for_each)

View File

@@ -35,6 +35,8 @@ namespace NCurses {
///
template <typename C> 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 <typename C> class basic_buffer
///
std::list<FormatPos> itsFormat;
/// Pointer to temporary string
/// @see SetTemp()
///
std::basic_string<C> *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 <typename C> 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<C> *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 <typename C> class basic_buffer
/// the content of buffer to window object
friend Window &operator<<(Window &w, const basic_buffer<C> &buf)
{
const std::basic_string<C> &s = buf.itsTempString ? *buf.itsTempString : buf.itsString;
const std::basic_string<C> &s = buf.itsString;
if (buf.itsFormat.empty())
w << s;
else
@@ -251,7 +239,7 @@ typedef basic_buffer<wchar_t> WBuffer;
template <typename C> basic_buffer<C>::basic_buffer(const basic_buffer &b)
: itsString(b.itsString), itsFormat(b.itsFormat), itsTempString(b.itsTempString) { }
: itsString(b.itsString), itsFormat(b.itsFormat) { }
template <typename C> const std::basic_string<C> &basic_buffer<C>::Str() const
{
@@ -329,11 +317,6 @@ template <typename C> void basic_buffer<C>::RemoveFormatting()
itsFormat.clear();
}
template <typename C> void basic_buffer<C>::SetTemp(std::basic_string<C> *tmp)
{
itsTempString = tmp;
}
template <typename C> void basic_buffer<C>::Write(
Window &w,
size_t &start_pos,