1
2
3
4
5
6 #include <sngxml/xpath/XPathDebug.hpp>
7
8 namespace sngxml { namespace xpath {
9
10 class XPathDebugInfo
11 {
12 public:
13 static void Init();
14 static void Done();
15 static XPathDebugInfo& Instance();
16 bool DebugParsing() const { return debugParsing; }
17 void SetDebugParsing() { debugParsing = true; }
18 bool DebugQuery() const { return debugQuery; }
19 void SetDebugQuery() { debugQuery = true; }
20 void SetQueryDom(std::std::unique_ptr<dom::Node>&&queryDom_){queryDom = std::move(queryDom_);}
21 std::std::unique_ptr<dom::Node>GetQueryDom(){returnstd::move(queryDom);}
22 void SetQueryDuration(std::chrono::nanoseconds duration) { queryDuration = duration; }
23 std::chrono::nanoseconds GetQueryDuration() const { return queryDuration; }
24 void SetExecuteDuration(std::chrono::nanoseconds duration) { executeDuration = duration; }
25 std::chrono::nanoseconds GetExecuteDuration() const { return executeDuration; }
26 private:
27 static std::unique_ptr<XPathDebugInfo> instance;
28 XPathDebugInfo();
29 bool debugParsing;
30 bool debugQuery;
31 std::unique_ptr<dom::Node> queryDom;
32 std::chrono::nanoseconds queryDuration;
33 std::chrono::nanoseconds executeDuration;
34 };
35
36 std::unique_ptr<XPathDebugInfo> XPathDebugInfo::instance;
37
38 XPathDebugInfo::XPathDebugInfo() : debugParsing(false), debugQuery(false), queryDuration(0), executeDuration(0)
39 {
40 }
41
42 void XPathDebugInfo::Init()
43 {
44 instance.reset(new XPathDebugInfo());
45 }
46
47 void XPathDebugInfo::Done()
48 {
49 instance.reset();
50 }
51
52 XPathDebugInfo& XPathDebugInfo::Instance()
53 {
54 return *instance;
55 }
56
57 bool XPathDebugParsing()
58 {
59 return XPathDebugInfo::Instance().DebugParsing();
60 }
61
62 void SetXPathDebugParsing()
63 {
64 XPathDebugInfo::Instance().SetDebugParsing();
65 }
66
67 bool XPathDebugQuery()
68 {
69 return XPathDebugInfo::Instance().DebugQuery();
70 }
71
72 void SetXPathDebugQuery()
73 {
74 XPathDebugInfo::Instance().SetDebugQuery();
75 }
76
77 void SetXPathQueryDom(std::std::unique_ptr<sngxml::dom::Node>&&queryDom)
78 {
79 XPathDebugInfo::Instance().SetQueryDom(std::move(queryDom));
80 }
81
82 std::std::unique_ptr<sngxml::dom::Node>GetXPathQueryDom()
83 {
84 return XPathDebugInfo::Instance().GetQueryDom();
85 }
86
87 void SetXPathQueryDuration(std::chrono::nanoseconds duration)
88 {
89 XPathDebugInfo::Instance().SetQueryDuration(duration);
90 }
91
92 std::chrono::nanoseconds XPathQueryDuration()
93 {
94 return XPathDebugInfo::Instance().GetQueryDuration();
95 }
96
97 void SetXPathExecuteDuration(std::chrono::nanoseconds duration)
98 {
99 XPathDebugInfo::Instance().SetExecuteDuration(duration);
100 }
101
102 std::chrono::nanoseconds XPathExecuteDuration()
103 {
104 return XPathDebugInfo::Instance().GetExecuteDuration();
105 }
106
107 void InitDebug()
108 {
109 XPathDebugInfo::Init();
110 }
111
112 void DoneDebug()
113 {
114 XPathDebugInfo::Done();
115 }
116
117 } }