00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "orsa_error.h"
00026
00027 #include <cstdio>
00028 #include <cassert>
00029
00030 namespace orsa {
00031
00032 using namespace std;
00033
00034 void Debug::construct()
00035 {
00036 if (!m_instance) m_instance = new Debug;
00037 }
00038 Debug::Debug() :
00039 doTrace(false),
00040 doDefaultOutput(false)
00041 { }
00042 Debug::~Debug()
00043 {
00044 m_instance = 0;
00045 }
00046
00047 Debug * Debug::obj() {
00048 assert(m_instance != 0);
00049 return m_instance;
00050 }
00051 void Debug::setDefaultOutput(bool d) {
00052 obj()->doDefaultOutput = d;
00053 }
00054 void Debug::set(const char *msg, const char *file, const int line) {
00055 fprintf(stderr, "ORSA[%s:%i] %s ", file, line, msg);
00056 doTrace = true;
00057 }
00058 void Debug::trace(const char *fmt, ...) {
00059 va_list ap;
00060 va_start(ap, fmt);
00061 if (doTrace) vtrace(fmt, ap);
00062 doTrace = false;
00063 }
00064 void Debug::vtrace(const char *fmt, va_list ap) {
00065 vfprintf(stderr, fmt, ap);
00066 fprintf(stderr, "\n");
00067 }
00068
00069 Debug * Debug::m_instance = 0;
00070
00071 }
00072