1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #ifndef _Parser_h
26 #define _Parser_h
27
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <mof.h>
32 #include <base/strings.h>
33
34 #ifndef MI_CHAR_TYPE
35 # define MI_CHAR_TYPE 1
36 #endif
37
38 #include <common.h>
39
40 extern "C" void errorCallback(
41 const char* msg,
42 const wchar_t* wmsg,
43 mike 1.1 void*);
44
45 extern "C" void warningCallback(
46 const char* msg,
47 const wchar_t* wmsg,
48 void*);
49
50 extern "C" void pragmaCallback(
51 const char* pragma,
52 const char* value,
53 void*);
54
55 extern "C" void classDeclCallback(
56 const MI_ClassDecl* decl, void*);
57
58 extern "C" void qualifierDeclCallback(
59 const MI_QualifierDecl* decl,
60 void*);
61
62 //==============================================================================
63 //
64 mike 1.1 // Parser
65 // This class wraps the MOF parser adding data structures for maintaining
66 // parsed entities and for looking up those entities.
67 //
68 //==============================================================================
69
70 class Parser
71 {
72 public:
73
74 // Construct a parser that looks for MOF inclusions on these paths.
75 Parser(const std::vector<std::string>& paths, bool warnings);
76
77 // Parse the MOF file and return 0 on success.
78 int parse(const char* path);
79
80 // Return a pointer to the class declaration with the given name (or NULL
81 // if not found).
82 const MI_ClassDecl* findClassDecl(const std::string& name) const;
83
84 // Return an array of all classnames.
85 mike 1.1 void getClassNames(std::vector<std::string>& names) const;
86
87 // Return a pointer to the qualifier declaration with the given name
88 // (or NULL if not found).
89 const MI_QualifierDecl* findQualifierDecl(const std::string& name) const;
90
91 // Get a list of qualifier declaration names.
92 void getQualifierDeclNames(std::vector<std::string>& names) const;
93
94 // Destruct the parser (cleaning up whole parser tree and pointers to
95 // objects returned from findClassDecl() and findQualifierDecl().
96 ~Parser();
97
98 private:
99
100 // Hide the copy constructor.
101 Parser(const Parser&);
102
103 // Hide the assignment operator.
104 Parser& operator=(const Parser&);
105
106 mike 1.1 // Callbacks invoked by the C MOF parser.
107 friend void errorCallback(const char* msg, const wchar_t* wmsg, void*);
108 friend void warningCallback(const char* msg, const wchar_t* wmsg, void*);
109 friend void pragmaCallback(const char* pragma, const char* value, void*);
110 friend void classDeclCallback(const MI_ClassDecl* decl, void*);
111 friend void qualifierDeclCallback(const MI_QualifierDecl* decl, void*);
112
113 // Instance of C MOF parser.
114 MOF_Parser* m_parser;
115
116 // Functor to make map string comparison case insentisive.
117 struct Less
118 {
119 bool operator()(const std::string& x, const std::string& y) const
120 {
121 return Strcasecmp(x.c_str(), y.c_str()) < 0;
122 }
123 };
124
125 // Print warnings if true.
126 bool m_warnings;
127 mike 1.1
128 // Map of qualifier declaration encountered during parsing.
129 typedef std::map<std::string, const MI_QualifierDecl*, Less>
130 QualifierDeclMap;
131 typedef std::pair<std::string, const MI_QualifierDecl*> QualifierDeclPair;
132 QualifierDeclMap m_qualifierDecls;
133
134 typedef std::pair<std::string, const MI_ClassDecl*> ClassDeclPair;
135 typedef std::map<std::string, const MI_ClassDecl*, Less> ClassDeclMap;
136 ClassDeclMap m_classDecls;
137 };
138
139 #endif /* _Parser_h */
|