3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/28/2010 Added this text. :-)
18 #include "rs_system.h"
20 RS_Debug * RS_Debug::uniqueInstance = NULL;
23 * Gets the one and only RS_Debug instance
24 * (creates a new one on first call only)
26 * @return Pointer to the single instance of this
29 RS_Debug * RS_Debug::instance()
31 if (uniqueInstance == NULL)
33 QDateTime now = QDateTime::currentDateTime();
35 nowStr = now.toString("yyyyMMdd_hhmmss");
36 QString fName = QString("debug_%1.log").arg(nowStr);
38 uniqueInstance = new RS_Debug;
39 //uniqueInstance->stream = fopen(fName.latin1(), "wt");
40 uniqueInstance->stream = stderr;
43 return uniqueInstance;
47 * Deletes the one and only RS_Debug instance.
49 void RS_Debug::deleteInstance()
51 if (uniqueInstance != NULL)
53 fclose(uniqueInstance->stream);
54 delete uniqueInstance;
59 * Constructor for a point with default coordinates.
63 debugLevel = D_DEBUGGING;
67 * Sets the debugging level.
69 void RS_Debug::setLevel(RS_DebugLevel level)
72 print("RS_DEBUG: Warnings", D_WARNING);
73 print("RS_DEBUG: Errors", D_ERROR);
74 print("RS_DEBUG: Notice", D_NOTICE);
75 print("RS_DEBUG: Informational", D_INFORMATIONAL);
76 print("RS_DEBUG: Debugging", D_DEBUGGING);
80 * Gets the current debugging level.
82 RS_Debug::RS_DebugLevel RS_Debug::getLevel()
88 * Prints the given message to stdout.
90 void RS_Debug::print(const char * format ...)
92 if (debugLevel == D_DEBUGGING)
96 vfprintf(stream, format, ap);
97 fprintf(stream, "\n");
104 * Prints the given message to stdout if the current debug level
105 * is lower then the given level
107 * @param level Debug level.
109 void RS_Debug::print(RS_DebugLevel level, const char * format ...)
111 if (debugLevel >= level)
114 va_start(ap, format);
115 vfprintf(stream, format, ap);
116 fprintf(stream, "\n");
123 * Prints a time stamp in the format yyyyMMdd_hhmmss.
125 void RS_Debug::timestamp()
127 QDateTime now = QDateTime::currentDateTime();
128 QString nowStr = now.toString("yyyyMMdd_hh:mm:ss:zzz ");
129 fprintf(stream, "%s", nowStr.toLatin1().data());
130 fprintf(stream, "\n");
135 * Prints the unicode for every character in the given string.
137 void RS_Debug::printUnicode(const QString & text)
139 for(int i=0; i<(int)text.length(); i++)
140 print("[%X] %c", text.at(i).unicode(), text.at(i).toLatin1());
143 void RS_Debug::setStream(FILE * s)