Doxygen
debug.cpp
浏览该文件的文档.
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2020 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 
16 #include <stdarg.h>
17 #include <algorithm>
18 #include <stdio.h>
19 #include <map>
20 #include <string>
21 #include <chrono>
22 
23 #include "debug.h"
24 #include "message.h"
25 #include "qcstring.h"
26 
27 //------------------------------------------------------------------------
28 
29 static std::map< std::string, Debug::DebugMask > s_labels =
30 {
31  { "findmembers", Debug::FindMembers },
32  { "functions", Debug::Functions },
33  { "variables", Debug::Variables },
34  { "preprocessor", Debug::Preprocessor },
35  { "nolineno", Debug::NoLineNo },
36  { "classes", Debug::Classes },
37  { "commentcnv", Debug::CommentCnv },
38  { "commentscan", Debug::CommentScan },
39  { "validate", Debug::Validate },
40  { "printtree", Debug::PrintTree },
41  { "time", Debug::Time },
42  { "extcmd", Debug::ExtCmd },
43  { "markdown", Debug::Markdown },
44  { "filteroutput", Debug::FilterOutput },
45  { "lex", Debug::Lex },
46  { "plantuml", Debug::Plantuml },
47  { "fortranfixed2free", Debug::FortranFixed2Free },
48  { "cite", Debug::Cite },
49  { "rtf", Debug::Rtf }
50 };
51 
52 //------------------------------------------------------------------------
53 
55 int Debug::curPrio = 0;
56 
57 void Debug::print(DebugMask mask,int prio,const char *fmt,...)
58 {
59  if ((curMask&mask) && prio<=curPrio)
60  {
61  va_list args;
62  va_start(args,fmt);
63  vfprintf(stdout, fmt, args);
64  va_end(args);
65  }
66 }
67 
68 static char asciiToLower(char in) {
69  if (in <= 'Z' && in >= 'A')
70  return in - ('Z' - 'z');
71  return in;
72 }
73 
74 static int labelToEnumValue(const QCString &l)
75 {
76  std::string s = l.str();
77  std::transform(s.begin(),s.end(),s.begin(),asciiToLower);
78  auto it = s_labels.find(s);
79  return (it!=s_labels.end()) ? it->second : 0;
80 }
81 
82 int Debug::setFlag(const QCString &lab)
83 {
84  int retVal = labelToEnumValue(lab);
85  curMask = (DebugMask)(curMask | retVal);
86  return retVal;
87 }
88 
89 void Debug::clearFlag(const QCString &lab)
90 {
92 }
93 
94 void Debug::setPriority(int p)
95 {
96  curPrio = p;
97 }
98 
100 {
101  return (curMask & mask)!=0;
102 }
103 
105 {
106  for (const auto &v : s_labels)
107  {
108  msg("\t%s\n",v.first.c_str());
109  }
110 }
111 
112 //------------------------------------------------------------------------
113 
114 class Timer
115 {
116  public:
117  void start()
118  {
119  m_startTime = std::chrono::system_clock::now();
120  }
121  double elapsedTimeS()
122  {
123  return (std::chrono::duration_cast<
124  std::chrono::microseconds>(
125  std::chrono::system_clock::now() - m_startTime).count()) / 1000000.0;
126  }
127  private:
128  std::chrono::time_point<std::chrono::system_clock> m_startTime;
129 };
130 
132 
134 {
136 }
137 
139 {
140  return g_runningTime.elapsedTimeS();
141 }
142 
Debug::ExtCmd
@ ExtCmd
Definition: debug.h:36
Debug::curPrio
static int curPrio
Definition: debug.h:59
Debug::NoLineNo
@ NoLineNo
Definition: debug.h:43
Debug::Validate
@ Validate
Definition: debug.h:33
Timer::m_startTime
std::chrono::time_point< std::chrono::system_clock > m_startTime
Definition: debug.cpp:128
Debug::printFlags
static void printFlags()
Definition: debug.cpp:104
Debug::Cite
@ Cite
Definition: debug.h:42
Debug::setPriority
static void setPriority(int p)
Definition: debug.cpp:94
Debug::Lex
@ Lex
Definition: debug.h:39
QCString::str
std::string str() const
Definition: qcstring.h:442
asciiToLower
static char asciiToLower(char in)
Definition: debug.cpp:68
qcstring.h
Debug::FortranFixed2Free
@ FortranFixed2Free
Definition: debug.h:41
Debug::CommentScan
@ CommentScan
Definition: debug.h:32
Debug::DebugMask
DebugMask
Definition: debug.h:25
Debug::isFlagSet
static bool isFlagSet(DebugMask mask)
Definition: debug.cpp:99
Debug::FindMembers
@ FindMembers
Definition: debug.h:26
Debug::Preprocessor
@ Preprocessor
Definition: debug.h:29
Debug::CommentCnv
@ CommentCnv
Definition: debug.h:31
Debug::Functions
@ Functions
Definition: debug.h:27
Debug::startTimer
static void startTimer()
Definition: debug.cpp:133
message.h
g_runningTime
static Timer g_runningTime
Definition: debug.cpp:131
Debug::print
static void print(DebugMask mask, int prio, const char *fmt,...)
Definition: debug.cpp:57
Debug::FilterOutput
@ FilterOutput
Definition: debug.h:38
Debug::setFlag
static int setFlag(const QCString &label)
Definition: debug.cpp:82
Timer::elapsedTimeS
double elapsedTimeS()
Definition: debug.cpp:121
Debug::curMask
static DebugMask curMask
Definition: debug.h:58
Debug::elapsedTime
static double elapsedTime()
Definition: debug.cpp:138
Debug::Variables
@ Variables
Definition: debug.h:28
s_labels
static std::map< std::string, Debug::DebugMask > s_labels
Definition: debug.cpp:29
Debug::Quiet
@ Quiet
Definition: debug.h:25
msg
void msg(const char *fmt,...)
Definition: message.cpp:53
Timer::start
void start()
Definition: debug.cpp:117
Debug::Markdown
@ Markdown
Definition: debug.h:37
Debug::Time
@ Time
Definition: debug.h:35
Timer
Definition: debug.cpp:114
Debug::clearFlag
static void clearFlag(const QCString &label)
Definition: debug.cpp:89
Debug::Classes
@ Classes
Definition: debug.h:30
Debug::Rtf
@ Rtf
Definition: debug.h:44
Debug::Plantuml
@ Plantuml
Definition: debug.h:40
labelToEnumValue
static int labelToEnumValue(const QCString &l)
Definition: debug.cpp:74
debug.h
Debug::PrintTree
@ PrintTree
Definition: debug.h:34
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108