cverb.h

Go to the documentation of this file.
00001 /**
00002  * @file cverb.h
00003  * verbose output stream
00004  *
00005  * @remark Copyright 2002, 2004 OProfile authors
00006  * @remark Read the file COPYING
00007  *
00008  * @author Philippe Elie
00009  * @author John Levon
00010  */
00011 
00012 #ifndef CVERB_H
00013 #define CVERB_H
00014 
00015 #include <iosfwd>
00016 #include <string>
00017 #include <vector>
00018 
00019 struct cverb_object { };
00020 
00021 /**
00022  * verbose object, all output through this stream are made only
00023  * if a verbose object with a true state is injected in the stream.
00024  */
00025 extern cverb_object cverb;
00026 
00027 /**
00028  * typical use:
00029  * declare some verbose global object:
00030  * verbose debug("debug");
00031  * verbose stats("stats");
00032  * verbose level2("level2");
00033  *
00034  * setup from command line the state of these objects
00035  *
00036  * verbose::setup(command_line_args_to'--verbose=');
00037  *
00038  * cverb << stats << "stats\n";
00039  * cverb << (stats&level2) << "very verbose stats\n"
00040  * cverb << (stats|debug) << "bar\n";
00041  * these will give a compile time error
00042  * cverb << stats << "foo" << debug << "bar"; 
00043  * cout << stats << "foo";
00044  *
00045  * In critical code path cverb can be used in the more efficient way:
00046  * if (cverb << vdebug)
00047  *    cverb << vdebug << "foo" << "bar";
00048  * the condition test the fails bit for the returned stream while the later
00049  * build a sentry object for each << (more efficient even with one level of <<)
00050  */
00051 class verbose {
00052         /// The returned stream is either a null stream or cout.
00053         friend std::ostream & operator<<(cverb_object &, verbose const &);
00054 public:
00055         /**
00056          * create a verbose object named name, the ctor auto-register name
00057          * as a verbose object, the set state can be intialized through
00058          * verbose::setup(name)
00059          */
00060         verbose(char const * name);
00061 
00062         verbose operator|(verbose const &);
00063         verbose operator&(verbose const &);
00064 
00065         /// Return false if this named verbose object has not be registred.
00066         static bool setup(std::string const &);
00067         /// convenient interface calling the above for string in args
00068         static bool setup(std::vector<std::string> const & args);
00069 private:
00070         bool set;
00071 };
00072 
00073 /**
00074  * predefined general purpose verbose object, comment give their names
00075  */
00076 extern verbose vlevel1; /**< named "level1" */
00077 extern verbose vdebug;  /**< named "debug"  */
00078 extern verbose vstats;  /**< named "stats"  */
00079 // all sample filename manipulation.
00080 extern verbose vsfile;  /**< named "sfile" */
00081 extern verbose vxml;  /**< named "xml" */
00082 
00083 #endif /* !CVERB_H */

Generated on Thu Jul 17 19:52:46 2008 for oprofile by  doxygen 1.4.6