[Avida-SVN] r1214 - in extras: . source/testsuites source/tools
avidaedward at myxo.css.msu.edu
avidaedward at myxo.css.msu.edu
Sat Jan 27 22:16:22 PST 2007
Author: avidaedward
Date: 2007-01-28 01:16:22 -0500 (Sun, 28 Jan 2007)
New Revision: 1214
Added:
extras/source/tools/cConsoleCatcher.cpp
extras/source/tools/cConsoleCatcher.h
Modified:
extras/
extras/SConscript
extras/source/testsuites/nConsoleCatcher.cpp
Log:
r1180 at clearly: kaben | 2006-12-23 15:41:32 -0500
Moved cConsoleCatcher to its own c++ files.
Property changes on: extras
___________________________________________________________________
Name: svk:merge
- 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1178
+ 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1180
Modified: extras/SConscript
===================================================================
--- extras/SConscript 2007-01-28 06:16:19 UTC (rev 1213)
+++ extras/SConscript 2007-01-28 06:16:22 UTC (rev 1214)
@@ -52,10 +52,12 @@
# Library of generic extra tools.
tools_srcs = [
+ 'source/tools/cConsoleCatcher.cpp',
'source/tools/cTestDriver.cpp',
'source/tools/cTestLib.cpp',
]
tools_incs = [
+ 'source/tools/cConsoleCatcher.h',
'source/tools/cTestDriver.h',
'source/tools/cTestLib.h',
'source/tools/lightweight_test.h',
Modified: extras/source/testsuites/nConsoleCatcher.cpp
===================================================================
--- extras/source/testsuites/nConsoleCatcher.cpp 2007-01-28 06:16:19 UTC (rev 1213)
+++ extras/source/testsuites/nConsoleCatcher.cpp 2007-01-28 06:16:22 UTC (rev 1214)
@@ -1,10 +1,7 @@
-//#include "cConsoleCatcher.h"
+#include "cConsoleCatcher.h"
#include "cTestLib.h"
-#include <iostream>
-#include <sstream>
-#include <assert.h>
-#include <signal.h>
+
using namespace std;
namespace nConsoleCatcher {
@@ -55,45 +52,6 @@
stream and streambuf;
*/
- struct cConsoleCatcher {
- /* Temporary storage of the caught stream. */
- ostream *m_stream;
- /* Temporary storage of the caught stream's original streambuf. */
- streambuf *m_streambuf;
- /* Capturing stream receives caught stream's redirected output. */
- stringstream m_capturing_stream;
-
- cConsoleCatcher()
- : m_stream(0)
- , m_streambuf(0)
- , m_capturing_stream("")
- {}
-
- cString Capture(ostream &out){
- cString out_string(Release());
-
- m_stream = &out;
- m_streambuf = m_stream->rdbuf(m_capturing_stream.rdbuf());
-
- return out_string;
- }
- cString Release(){
- // Pull everything from the stream and put into a string.
- cString out_string(m_capturing_stream.str().c_str());
-
- if(m_stream && m_streambuf){
- m_stream->rdbuf(m_streambuf);
- m_stream = 0;
- m_streambuf = 0;
- }
-
- // Clear the stream.
- m_capturing_stream.str("");
-
- return out_string;
- }
- };
-
void test(){
cout << "XXX This is a test stub. It needs filling-in. @kgn" << endl;
// Second iteration : cConsoleCatcher
Added: extras/source/tools/cConsoleCatcher.cpp
===================================================================
--- extras/source/tools/cConsoleCatcher.cpp 2007-01-28 06:16:19 UTC (rev 1213)
+++ extras/source/tools/cConsoleCatcher.cpp 2007-01-28 06:16:22 UTC (rev 1214)
@@ -0,0 +1,33 @@
+#include "cConsoleCatcher.h"
+
+using namespace std;
+
+cConsoleCatcher::cConsoleCatcher()
+: m_stream(0)
+, m_streambuf(0)
+, m_capturing_stream("")
+{}
+
+cString cConsoleCatcher::Capture(std::ostream &out){
+ cString out_string(Release());
+
+ m_stream = &out;
+ m_streambuf = m_stream->rdbuf(m_capturing_stream.rdbuf());
+
+ return out_string;
+}
+cString cConsoleCatcher::Release(){
+ // Pull everything from the stream and put into a string.
+ cString out_string(m_capturing_stream.str().c_str());
+
+ if(m_stream && m_streambuf){
+ m_stream->rdbuf(m_streambuf);
+ m_stream = 0;
+ m_streambuf = 0;
+ }
+
+ // Clear the stream.
+ m_capturing_stream.str("");
+
+ return out_string;
+}
Added: extras/source/tools/cConsoleCatcher.h
===================================================================
--- extras/source/tools/cConsoleCatcher.h 2007-01-28 06:16:19 UTC (rev 1213)
+++ extras/source/tools/cConsoleCatcher.h 2007-01-28 06:16:22 UTC (rev 1214)
@@ -0,0 +1,24 @@
+#ifndef cConsoleCatcher_h
+#define cConsoleCatcher_h
+
+#ifndef cString_h
+#include "cString.h"
+#endif
+
+#include <iostream>
+#include <sstream>
+
+struct cConsoleCatcher {
+ /* Temporary storage of the caught stream. */
+ std::ostream *m_stream;
+ /* Temporary storage of the caught stream's original streambuf. */
+ std::streambuf *m_streambuf;
+ /* Capturing stream receives caught stream's redirected output. */
+ std::stringstream m_capturing_stream;
+
+ cConsoleCatcher();
+ cString Capture(std::ostream &out);
+ cString Release();
+};
+
+#endif
More information about the Avida-cvs
mailing list