home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15929 < prev    next >
Encoding:
Text File  |  1992-11-08  |  1.8 KB  |  49 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!pilchuck!fnx!sgihbtn!dkarr
  3. From: dkarr@sierra.com (David Karr)
  4. Subject: Re: Debugging output
  5. Message-ID: <1992Nov6.184126.8975@sierra.com>
  6. Sender: news@sierra.com
  7. Nntp-Posting-Host: dopey
  8. Organization: Sierra Geophysics,  Kirkland WA
  9. X-Newsreader: Tin 1.1 PL4
  10. References: <spuler.720931050@coral>
  11. Date: Fri, 6 Nov 1992 18:41:26 GMT
  12. Lines: 35
  13.  
  14. spuler@coral.cs.jcu.edu.au (David Spuler) writes:
  15. : [Sorry if this is a re-post. The first one seemed to get lost.]
  16. : I was wondering whether anyone has any suggestions as to how to use the neat
  17. : operator << to produce debugging output in a way that it can be removed
  18. : easily from production code.  The obvious method is:
  19. : #ifdef DEBUG
  20. :    cerr << .....
  21. : #endif
  22. : but I'd like to avoid the #ifdef -#endif lines.
  23. : I've been trying to declare my own "dbg" streams by inheriting it
  24. : from the standard "ostream" class and redefining the << operators.
  25.  
  26. I don't know of an elegant way to remove the generated code, but you can
  27. implement a derivative of streambuf that will allow you to suppress the
  28. debug output at run time (from the environment).
  29.  
  30. In the streambuf derivative, override the "overflow" method such that
  31. before sending the data out, call a ptr to function which sends the data to
  32. be sent out to a "filter" function (the ptr to function is set in the
  33. streambuf constructor).  If your environment indicates that you don't want
  34. the debugging output, then your function will return False from the
  35. "filter" function, which will cause "overflow" to not use the characters.
  36.  
  37. I got a hint on how to do this from the book "AT&T C++ Language System",
  38. distributed by CenterLine Software (with ObjectCenter).
  39. --
  40. David M. Karr
  41. Sierra Geophysics, Inc.
  42. ARPA: dkarr@sierra.com, UUNET: uunet!sgihbtn!dkarr
  43. Phone: (206) 822-5200 (x343)
  44.