C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.1 KiB
73 lines
2.1 KiB
21 years ago
|
#ifndef __MRW_SIMPLETRACE_HPP__
|
||
|
#define __MRW_SIMPLETRACE_HPP__
|
||
|
#include <iostream>
|
||
|
#include <iomanip>
|
||
|
#include <string>
|
||
|
|
||
|
// GENERIC TRACER FOR TESTS ---------------------------------------------------
|
||
|
// (without file/line)
|
||
|
#ifndef __GNUG__
|
||
|
#define METHOD(name) mrw::FnTrace fnTrace(this, name)
|
||
|
#define FUNCTION(name) mrw::FnTrace fnTrace(0, name)
|
||
|
#else
|
||
|
#define METHOD mrw::FnTrace fnTrace(this, __FUNCTION__)
|
||
|
#define FUNCTION mrw::FnTrace fnTrace(0, __FUNCTION__)
|
||
|
#endif
|
||
|
#define CALL(name) fnTrace.call(name)
|
||
|
#define TRACE(name) fnTrace.trace(name)
|
||
|
#define TRACE_OFF mrw::FnTrace::off()
|
||
|
#define TRACE_ON mrw::FnTrace::on()
|
||
|
#define NO_TRACE mrw::NoTrace noTrace;
|
||
|
|
||
|
namespace mrw {
|
||
|
class FnTrace {
|
||
|
public:
|
||
|
FnTrace(const void* addr, const std::string& name):
|
||
|
_addr(addr), _name(name) {
|
||
|
if (_off==0)
|
||
|
std::cout<<std::hex<<std::setw(15)<<_addr<<": "<<std::dec
|
||
|
<<std::setw(2+_level)<<std::setfill(' ')<<"\\ "
|
||
|
<<_name<<std::endl;
|
||
|
++_level;
|
||
|
}
|
||
|
~FnTrace() {
|
||
|
--_level;
|
||
|
if (_off==0)
|
||
|
std::cout<<std::hex<<std::setw(15)<<_addr<<": "<<std::dec
|
||
|
<<std::setw(2+_level)<<std::setfill(' ')<<"/ "<<_name
|
||
|
<<std::endl;
|
||
|
}
|
||
|
void call(const std::string& name) {
|
||
|
if (_off==0)
|
||
|
std::cout<<std::hex<<std::setw(15)<<_addr<<": "<<std::dec
|
||
|
<<std::setw(4+_level)<<std::setfill(' ')<<" -> "<<name
|
||
|
<<std::endl;
|
||
|
}
|
||
|
void trace(const std::string& name) {
|
||
|
if (_off==0)
|
||
|
std::cout<<std::hex<<std::setw(15)<<_addr<<": "<<std::dec
|
||
|
<<std::setw(4+_level)<<std::setfill(' ')<<" **** "<<name
|
||
|
<<" **** "<<std::endl;
|
||
|
}
|
||
|
static void off() {
|
||
|
++_off;
|
||
|
}
|
||
|
static void on() {
|
||
|
if (_off>0) --_off;
|
||
|
}
|
||
|
private:
|
||
|
const void* _addr;
|
||
|
const std::string _name;
|
||
|
static unsigned int _level;
|
||
|
static unsigned int _off;
|
||
|
};
|
||
|
unsigned int FnTrace::_level(0);
|
||
|
unsigned int FnTrace::_off(0);
|
||
|
class NoTrace {
|
||
|
public:
|
||
|
NoTrace() {TRACE_OFF;}
|
||
|
~NoTrace() {TRACE_ON;}
|
||
|
};
|
||
|
}
|
||
|
#endif
|