]> git.lyx.org Git - lyx.git/blob - src/debug.h
05ab7afc1ab57bab3a27f6c9b226df8b148a80cd
[lyx.git] / src / debug.h
1 // -*- C++ -*-
2
3 #ifndef LYXDEBUG_H
4 #define LYXDEBUG_H
5
6 #include "LString.h"
7 #include "support/lstrings.h"
8
9 /** Ideally this should have been a namespace, but since we try to be
10     compilable on older C++ compilators too, we use a struct instead.
11     This is all the different debug levels that we have.
12 */
13 struct Debug {
14         ///
15         enum type {
16                 ///
17                 NONE = 0,
18                 ///
19                 INFO       = (1 << 0),   // 1
20                 ///
21                 INIT       = (1 << 1),   // 2
22                 ///
23                 KEY        = (1 << 2),   // 4
24                 ///
25                 TOOLBAR    = (1 << 3),   // 8
26                 ///
27                 PARSER     = (1 << 4),   // 16
28                 ///
29                 LYXRC      = (1 << 5),   // 32
30                 ///
31                 KBMAP      = (1 << 6),   // 64
32                 ///
33                 LATEX      = (1 << 7),   // 128
34                 ///
35                 MATHED     = (1 << 8),   // 256 // Alejandro, please use this.
36                 ///
37                 FONT       = (1 << 9),   // 512
38                 ///
39                 TCLASS     = (1 << 10),  // 1024
40                 ///
41                 LYXVC      = (1 << 11),  // 2048
42                 ///
43                 LYXSERVER  = (1 << 12),  // 4096
44                 ///
45                 ROFF       = (1 << 13),  // 8192
46                 ///
47                 ACTION     = (1 << 14)   // 16384
48         };
49         ///
50         static const type ANY = type(INFO | INIT | KEY | TOOLBAR |
51                                      PARSER | LYXRC | KBMAP | LATEX |
52                                      MATHED | FONT | TCLASS | LYXVC |
53                                      LYXSERVER | ROFF | ACTION);
54         ///
55         friend inline void operator|=(Debug::type & d1, Debug::type d2);
56         
57         /** A function to convert symbolic string names on debug levels
58             to their numerical value.
59         */
60         static Debug::type value(string const & val) {
61                 type l = Debug::NONE;
62                 string v(val);
63                 while (!v.empty()) {
64                         string::size_type st = v.find(',');
65                         string tmp(v.substr(0, st));
66                         if (tmp.empty()) break;
67                         if (isStrInt(tmp)) {
68                                 l |= static_cast<type>(strToInt(tmp));
69                                 break;
70                         }
71                         if (!compare_no_case(tmp,"NONE")) 
72                                 l |= Debug::NONE;
73                         else if (!compare_no_case(tmp,"INFO"))  
74                                 l |= Debug::INFO;
75                         else if (!compare_no_case(tmp,"INIT"))  
76                                 l |= Debug::INIT;
77                         else if (!compare_no_case(tmp,"KEY"))  
78                                 l |= Debug::KEY; 
79                         else if (!compare_no_case(tmp,"TOOLBAR"))  
80                                 l |= Debug::TOOLBAR;
81                         else if (!compare_no_case(tmp,"PARSER"))  
82                                 l |= Debug::PARSER; 
83                         else if (!compare_no_case(tmp,"LYXRC"))  
84                                 l |= Debug::LYXRC; 
85                         else if (!compare_no_case(tmp,"KBMAP"))  
86                                 l |= Debug::KBMAP;  
87                         else if (!compare_no_case(tmp,"LATEX"))  
88                                 l |= Debug::LATEX;  
89                         else if (!compare_no_case(tmp,"MATHED"))  
90                                 l |= Debug::MATHED; 
91                         else if (!compare_no_case(tmp,"FONT"))  
92                                 l |= Debug::FONT;   
93                         else if (!compare_no_case(tmp,"TCLASS"))  
94                                 l |= Debug::TCLASS; 
95                         else if (!compare_no_case(tmp,"LYXVC"))  
96                                 l |= Debug::LYXVC;  
97                         else if (!compare_no_case(tmp,"LYXSERVER"))  
98                                 l |= Debug::LYXSERVER;
99                         else if (!compare_no_case(tmp,"ROFF"))  
100                                 l |= Debug::ROFF;
101                         else if (!compare_no_case(tmp,"ACTION"))  
102                                 l |= Debug::ACTION;
103                         else break; // unknown string
104                         if (st == string::npos) break;
105                         v.erase(0, st + 1);
106                 }
107                 return l;
108         }
109 };
110 ///
111 inline void operator|= (Debug::type & d1, Debug::type d2)
112 {
113         d1 = static_cast<Debug::type>(d1 | d2);
114 }
115
116
117 #include "support/DebugStream.h"
118
119 ///
120 ostream & operator<<(ostream & o, Debug::type t);
121
122 extern DebugStream lyxerr;
123
124 #endif