[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src PingusStream.cc,1.2,1.3 PingusStream.
From: |
torangan |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src PingusStream.cc,1.2,1.3 PingusStream.hh,1.2,1.3 |
Date: |
7 Jun 2002 11:06:51 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv9160
Modified Files:
PingusStream.cc PingusStream.hh
Log Message:
implemented operator()(int) to allow suppression of debug output
Index: PingusStream.cc
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/PingusStream.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- PingusStream.cc 6 Jun 2002 13:56:48 -0000 1.2
+++ PingusStream.cc 7 Jun 2002 11:06:49 -0000 1.3
@@ -18,6 +18,9 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "PingusStream.hh"
+#include "globals.hh"
+
+NilStream DebugStream::nilstream;
DebugStream::Buffer::Buffer (const std::string& p)
: prefix (p)
@@ -44,10 +47,10 @@
str += *ptr;
if (*ptr == '\n')
- {
- put_line (prefix + str);
- str = "";
- }
+ {
+ put_line (prefix + str);
+ str = "";
+ }
}
str += c;
put_line (str);
@@ -62,10 +65,10 @@
if (!out_streams.empty ())
{
for (std::vector<std::ostream*>::iterator i = out_streams.begin ();
- i != out_streams.end (); ++i)
- {
- *(*i) << line;
- }
+ i != out_streams.end (); ++i)
+ {
+ *(*i) << line;
+ }
}
else
{
@@ -81,13 +84,13 @@
// Walk through the buffer
for (char* c = pbase (); c != pptr (); ++c)
{
- str += *c;
+ str += *c;
if (*c == '\n')
- {
- put_line (prefix + str);
- str = "";
- }
+ {
+ put_line (prefix + str);
+ str = "";
+ }
}
if (!str.empty ()) // Why to we check this?
@@ -124,6 +127,16 @@
DebugStream::~DebugStream ()
{
+}
+
+/// returns self if the debug flag is set, else nilstream
+std::ostream & DebugStream::operator () (int component) {
+
+ if (pingus_debug_flags & component) {
+ return *this;
+ } else {
+ return nilstream;
+ }
}
void
Index: PingusStream.hh
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/PingusStream.hh,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- PingusStream.hh 6 Jun 2002 13:56:48 -0000 1.2
+++ PingusStream.hh 7 Jun 2002 11:06:49 -0000 1.3
@@ -24,15 +24,14 @@
#include <vector>
#include <iostream>
+class NilStream;
-class DebugStream
- : public std::ostream
+class DebugStream : public std::ostream
{
private:
- class Buffer
- : public std::streambuf
+ class Buffer : public std::streambuf
{
private:
@@ -62,14 +61,57 @@
} buffer;
+ static NilStream nilstream;
public:
DebugStream (const std::string& prefix);
virtual ~DebugStream ();
+ std::ostream & operator () (int component);
+
void add (std::ostream& s);
void set_prefix (const std::string & prefix);
+};
+
+
+
+/// Stream used to consume unwanted debugmessages
+class NilStream : public std::ostream
+{
+ private:
+
+ /// Do nothing Buffer for NilStream
+ class NilBuffer : public std::streambuf
+ {
+ private:
+
+ char char_buffer[4];
+
+ public:
+
+ NilBuffer () { setp(char_buffer, char_buffer + 3); setg(0,0,0); }
+ ~NilBuffer () { }
+
+ int overflow () { return 0; }
+ int sync () { return 0; }
+ } buffer;
+
+ NilStream () : std::ostream(&buffer) { }
+ ~NilStream () { }
+
+ NilStream (const NilStream &); ///< not supported
+
+ public:
+
+ // Avoid unneccessary calls to internal buffer and conversions
+ NilStream & operator << (const char *) { return *this; }
+ NilStream & operator << (const std::string &) { return *this; }
+ NilStream & operator << (int &) { return *this; }
+ NilStream & operator << (unsigned int &) { return *this; }
+
+
+ friend class DebugStream;
};
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src PingusStream.cc,1.2,1.3 PingusStream.hh,1.2,1.3,
torangan <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src ActionButton.cc,1.29,1.30 ActionButton.hh,1.20,1.21 ActionData.hh,1.1,1.2 AlphaButton.hh,1.5,1.6 AnimCounter.cc,1.2,1.3 AnimCounter.hh,1.4,1.5 Credits.hh,1.6,1.7
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src CaptureRectangle.hh,1.11,1.12 ColMap.hh,1.13,1.14 Console.hh,1.14,1.15 Credits.hh,1.7,1.8 Cursor.hh,1.4,1.5 DebugGui.hh,1.5,1.6 audio.hh,1.5,1.6 blitter.hh,1.11,1.12
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src ActionButton.cc,1.29,1.30 ActionButton.hh,1.20,1.21 ActionData.hh,1.1,1.2 AlphaButton.hh,1.5,1.6 AnimCounter.cc,1.2,1.3 AnimCounter.hh,1.4,1.5 Credits.hh,1.6,1.7
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src CaptureRectangle.hh,1.11,1.12 ColMap.hh,1.13,1.14 Console.hh,1.14,1.15 Credits.hh,1.7,1.8 Cursor.hh,1.4,1.5 DebugGui.hh,1.5,1.6 audio.hh,1.5,1.6 blitter.hh,1.11,1.12
- Index(es):