aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-01-03 20:15:56 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-01-03 20:15:56 +0000
commited1459ace725ef9c8ce8dd49946cdeb1b167fcbb (patch)
treedb288d999b23b5cde96b37e3303354ff5d0ca11a
parent88898b629cd93472cf249f601190466c104e99a5 (diff)
downloadpaludis-ed1459ace725ef9c8ce8dd49946cdeb1b167fcbb.tar.gz
paludis-ed1459ace725ef9c8ce8dd49946cdeb1b167fcbb.tar.xz
BufferOutputStream::anything_to_unbuffer()
-rw-r--r--paludis/util/buffer_output_stream.cc17
-rw-r--r--paludis/util/buffer_output_stream.hh4
-rw-r--r--paludis/util/buffer_output_stream_TEST.cc8
3 files changed, 25 insertions, 4 deletions
diff --git a/paludis/util/buffer_output_stream.cc b/paludis/util/buffer_output_stream.cc
index fdb2106..74315d2 100644
--- a/paludis/util/buffer_output_stream.cc
+++ b/paludis/util/buffer_output_stream.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2009 Ciaran McCreesh
+ * Copyright (c) 2009, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -31,7 +31,7 @@ namespace paludis
template <>
struct Implementation<BufferOutputStreamBuf>
{
- Mutex mutex;
+ mutable Mutex mutex;
std::list<std::string> complete_strings;
std::string active_string;
@@ -102,6 +102,13 @@ BufferOutputStreamBuf::unbuffer(std::ostream & stream)
stream << std::flush;
}
+bool
+BufferOutputStreamBuf::anything_to_unbuffer() const
+{
+ Lock lock(_imp->mutex);
+ return ! _imp->complete_strings.empty();
+}
+
BufferOutputStreamBase::BufferOutputStreamBase()
{
}
@@ -126,5 +133,11 @@ BufferOutputStream::unbuffer(std::ostream & s)
buf.unbuffer(s);
}
+bool
+BufferOutputStream::anything_to_unbuffer() const
+{
+ return buf.anything_to_unbuffer();
+}
+
template class PrivateImplementationPattern<BufferOutputStreamBuf>;
diff --git a/paludis/util/buffer_output_stream.hh b/paludis/util/buffer_output_stream.hh
index d8f8209..d100faf 100644
--- a/paludis/util/buffer_output_stream.hh
+++ b/paludis/util/buffer_output_stream.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2009 Ciaran McCreesh
+ * Copyright (c) 2009, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -39,6 +39,7 @@ namespace paludis
~BufferOutputStreamBuf();
void unbuffer(std::ostream &);
+ bool anything_to_unbuffer() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class PALUDIS_VISIBLE BufferOutputStreamBase
@@ -60,6 +61,7 @@ namespace paludis
~BufferOutputStream();
void unbuffer(std::ostream &);
+ bool anything_to_unbuffer() const PALUDIS_ATTRIBUTE((warn_unused_result));
};
#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
diff --git a/paludis/util/buffer_output_stream_TEST.cc b/paludis/util/buffer_output_stream_TEST.cc
index 023036c..177df56 100644
--- a/paludis/util/buffer_output_stream_TEST.cc
+++ b/paludis/util/buffer_output_stream_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2009 Ciaran McCreesh
+ * Copyright (c) 2009, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -34,6 +34,8 @@ namespace test_cases
void run()
{
BufferOutputStream s;
+ TEST_CHECK(! s.anything_to_unbuffer());
+
std::stringstream t;
for (int n(0), n_end(1000) ; n != n_end ; ++n)
@@ -43,13 +45,17 @@ namespace test_cases
}
std::stringstream ss;
+ TEST_CHECK(s.anything_to_unbuffer());
s.unbuffer(ss);
+ TEST_CHECK(! s.anything_to_unbuffer());
TEST_CHECK_EQUAL(ss.str(), t.str());
s << "foo" << std::endl;
std::stringstream sss;
+ TEST_CHECK(s.anything_to_unbuffer());
s.unbuffer(sss);
+ TEST_CHECK(! s.anything_to_unbuffer());
TEST_CHECK_EQUAL(sss.str(), "foo\n");
}
} test_buffer_output_stream;