trace - Example: // TRACE ('u', "foo =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#ifndef __TRACE_H__ #define __TRACE_H__ # #include <vector> # using namespace std; u // // traceflags - // static class for maintaining global trace flags, each indicated // by a single character. // setflags - // Takes a string argument, and sets a flag for each char in the // string. As a special case, '@', sets all flags. // getflag - // Used by the TRACE macro to check to see if a flag has been set. // Not to be called by user code. // class traceflags { private: static vector<char> flags; public: static void setflags (const string &optflags); static bool getflag (char flag); }; } // // TRACE - // Macro which expands into trace code. First argument is a // trace flag char, second argument is output code that can // be sandwiched between <<. Beware of operator precedence. //
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Example: // TRACE ('u', &quot;foo = &quot; &lt;&lt; foo); // will print two words and a newline if flag 'u' is on. // Traces are preceded by filename, line number, and function. // #define TRACE(FLAG,CODE) { \ if (traceflags::getflag (FLAG)) { \ cerr &lt;&lt; __FILE__ &lt;&lt; &quot;:&quot; &lt;&lt; __LINE__ &lt;&lt; &quot;:&quot; \ &lt;&lt; __func__ &lt;&lt; &quot;: &quot;; \ cerr &lt;&lt; CODE &lt;&lt; endl; \ } \ } // // RCSH, RCSC -// Macros which allow RCS Id information to transfer to object // files and executable binaries. // #define RCSH(NAME,ID) \ static const char __RCS_##NAME = &quot;\0&quot; ID; #define RCSC(NAME,ID) \ static const char __RCS_C_##NAME = &quot;\0&quot; ID \ &quot;\0$Compiled: &quot; __FILE__ &quot; &quot; __DATE__ &quot; &quot; __TIME__ &quot; $&quot;; &quot; RCSH(__trace_h__, &quot;$Id: trace.h,v 1.1 2010-01-21 15:08:53-08 - - $&quot;) &quot; #endif...
View Full Document

Ask a homework question - tutors are online