From e9e5da32b2e154698482b7ec6b7ab2098cd849c8 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 2 Apr 2009 14:33:55 +0000 Subject: Removed some uses of printf in libbu++, I would like to get rid of all of them some day, but I'm not in much of a rush, I just wanted to do a quick survey. Also added the Formatter::flush special stream value, so now you can do a: sio << "hello" << sio.flush; and it'll flush output immediately. I also tweaked a few things in the cachestore and cache so that they actually throw exceptions and the like instead of just printing out some garbage. --- src/archive.cpp | 2 -- src/cache.h | 6 +++--- src/cachestorenids.h | 2 +- src/filter.cpp | 10 ---------- src/formatter.cpp | 14 ++++++++++---- src/formatter.h | 8 +++++++- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/archive.cpp b/src/archive.cpp index c1c89cc..0efa145 100644 --- a/src/archive.cpp +++ b/src/archive.cpp @@ -459,14 +459,12 @@ Bu::Archive &Bu::operator>>(Bu::Archive &s, Bu::Archival &p) Bu::Archive &Bu::operator<<(Bu::Archive &ar, class Bu::Archival *p ) { - printf("Writing a pointer to an archive...\n"); ar << *p; return ar; } Bu::Archive &Bu::operator>>(Bu::Archive &ar, class Bu::Archival *p ) { - printf("Reading a pointer to an archive...\n"); ar >> *p; return ar; } diff --git a/src/cache.h b/src/cache.h index 4ae1aa8..f36c29b 100644 --- a/src/cache.h +++ b/src/cache.h @@ -165,9 +165,9 @@ namespace Bu { if( i.getValue().iRefs > 0 ) { - printf("Error? iRefs=%d for key ", i.getValue().iRefs ); - __tracer_format( i.getKey() ); - printf("!\n"); + // TODO: Throw an error in this case? iRefs != 0 for an + // object when the Cache is destroyed. + throw Bu::ExceptionBase("iRefs not zero."); } pCalc->onUnload( i.getValue().pData, diff --git a/src/cachestorenids.h b/src/cachestorenids.h index c6a00ce..0f7c72c 100644 --- a/src/cachestorenids.h +++ b/src/cachestorenids.h @@ -57,7 +57,7 @@ namespace Bu nStore.initialize( iBlockSize, iPreAllocate ); int iStream = nStore.createStream(); if( iStream != 0 ) - printf("That's...horrible...id = %d.\n\n", iStream ); + throw Bu::ExceptionBase("That's...horrible...id = %d.\n\n", iStream ); NidsStream ns = nStore.openStream( 0 ); Bu::Archive ar( ns, Bu::Archive::save ); ar << hId; diff --git a/src/filter.cpp b/src/filter.cpp index 9f10026..771cf0d 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -14,17 +14,7 @@ Bu::Filter::Filter( Bu::Stream &rNext ) : Bu::Filter::~Filter() { - //printf("-> Bu::Filter::~Filter()\n"); } -/* -void Bu::Filter::start() -{ - printf("-> Bu::Filter::start()\n"); -} - -void Bu::Filter::stop() -{ -}*/ void Bu::Filter::close() { diff --git a/src/formatter.cpp b/src/formatter.cpp index 2fadd96..8c06bde 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp @@ -176,10 +176,16 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, Bu::Formatter::Special s ) switch( s ) { case Formatter::nl: - rOut.write("\n", 1 ); - char ci = rOut.getIndentChar(); - for( int j = 0; j < rOut.getIndent(); j++ ) - rOut.write( &ci, 1 ); + { + rOut.write("\n", 1 ); + char ci = rOut.getIndentChar(); + for( int j = 0; j < rOut.getIndent(); j++ ) + rOut.write( &ci, 1 ); + } + break; + + case Formatter::flush: + rOut.doFlush(); break; } return rOut; diff --git a/src/formatter.h b/src/formatter.h index 5dd7622..30ecf42 100644 --- a/src/formatter.h +++ b/src/formatter.h @@ -179,9 +179,15 @@ namespace Bu enum Special { - nl + nl, + flush }; + void doFlush() + { + rOut.flush(); + } + private: Stream &rOut; Fmt fLast; -- cgit v1.2.3