1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: RangeTokenMap.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(RANGETOKENMAP_HPP) |
---|
23 | #define RANGETOKENMAP_HPP |
---|
24 | |
---|
25 | // --------------------------------------------------------------------------- |
---|
26 | // Includes |
---|
27 | // --------------------------------------------------------------------------- |
---|
28 | #include <xercesc/util/Mutexes.hpp> |
---|
29 | #include <xercesc/util/RefHashTableOf.hpp> |
---|
30 | |
---|
31 | XERCES_CPP_NAMESPACE_BEGIN |
---|
32 | |
---|
33 | // --------------------------------------------------------------------------- |
---|
34 | // Forward Declaration |
---|
35 | // --------------------------------------------------------------------------- |
---|
36 | class RangeToken; |
---|
37 | class RangeFactory; |
---|
38 | class TokenFactory; |
---|
39 | class XMLStringPool; |
---|
40 | |
---|
41 | class XMLUTIL_EXPORT RangeTokenElemMap : public XMemory |
---|
42 | { |
---|
43 | |
---|
44 | public: |
---|
45 | RangeTokenElemMap(unsigned int categoryId); |
---|
46 | ~RangeTokenElemMap(); |
---|
47 | |
---|
48 | // ----------------------------------------------------------------------- |
---|
49 | // Getter methods |
---|
50 | // ----------------------------------------------------------------------- |
---|
51 | unsigned int getCategoryId() const; |
---|
52 | RangeToken* getRangeToken(const bool complement = false) const; |
---|
53 | |
---|
54 | // ----------------------------------------------------------------------- |
---|
55 | // Setter methods |
---|
56 | // ----------------------------------------------------------------------- |
---|
57 | void setRangeToken(RangeToken* const tok, const bool complement = false); |
---|
58 | void setCategoryId(const unsigned int categId); |
---|
59 | |
---|
60 | private: |
---|
61 | // ----------------------------------------------------------------------- |
---|
62 | // Unimplemented constructors and operators |
---|
63 | // ----------------------------------------------------------------------- |
---|
64 | RangeTokenElemMap(const RangeTokenElemMap&); |
---|
65 | RangeTokenElemMap& operator=(const RangeTokenElemMap&); |
---|
66 | |
---|
67 | // Data members |
---|
68 | unsigned int fCategoryId; |
---|
69 | RangeToken* fRange; |
---|
70 | RangeToken* fNRange; |
---|
71 | }; |
---|
72 | |
---|
73 | |
---|
74 | class XMLUTIL_EXPORT RangeTokenMap : public XMemory |
---|
75 | { |
---|
76 | public: |
---|
77 | // ----------------------------------------------------------------------- |
---|
78 | // Putter methods |
---|
79 | // ----------------------------------------------------------------------- |
---|
80 | void addCategory(const XMLCh* const categoryName); |
---|
81 | void addRangeMap(const XMLCh* const categoryName, |
---|
82 | RangeFactory* const rangeFactory); |
---|
83 | void addKeywordMap(const XMLCh* const keyword, |
---|
84 | const XMLCh* const categoryName); |
---|
85 | |
---|
86 | // ----------------------------------------------------------------------- |
---|
87 | // Instance methods |
---|
88 | // ----------------------------------------------------------------------- |
---|
89 | static RangeTokenMap* instance(); |
---|
90 | |
---|
91 | // ----------------------------------------------------------------------- |
---|
92 | // Setter methods |
---|
93 | // ----------------------------------------------------------------------- |
---|
94 | void setRangeToken(const XMLCh* const keyword, RangeToken* const tok, |
---|
95 | const bool complement = false); |
---|
96 | |
---|
97 | // ----------------------------------------------------------------------- |
---|
98 | // Getter methods |
---|
99 | // ----------------------------------------------------------------------- |
---|
100 | TokenFactory* getTokenFactory() const; |
---|
101 | |
---|
102 | // ----------------------------------------------------------------------- |
---|
103 | // Notification that lazy data has been deleted |
---|
104 | // ----------------------------------------------------------------------- |
---|
105 | static void reinitInstance(); |
---|
106 | |
---|
107 | protected: |
---|
108 | // ----------------------------------------------------------------------- |
---|
109 | // Constructor and destructors |
---|
110 | // ----------------------------------------------------------------------- |
---|
111 | RangeTokenMap(MemoryManager* manager); |
---|
112 | ~RangeTokenMap(); |
---|
113 | |
---|
114 | // ----------------------------------------------------------------------- |
---|
115 | // Getter methods |
---|
116 | // ----------------------------------------------------------------------- |
---|
117 | /* |
---|
118 | * Gets a commonly used RangeToken from the token registry based on the |
---|
119 | * range name - Called by TokenFactory. |
---|
120 | */ |
---|
121 | RangeToken* getRange(const XMLCh* const name, |
---|
122 | const bool complement = false); |
---|
123 | |
---|
124 | RefHashTableOf<RangeTokenElemMap>* getTokenRegistry() const; |
---|
125 | RefHashTableOf<RangeFactory>* getRangeMap() const; |
---|
126 | XMLStringPool* getCategories() const; |
---|
127 | |
---|
128 | private: |
---|
129 | // ----------------------------------------------------------------------- |
---|
130 | // Unimplemented constructors and operators |
---|
131 | // ----------------------------------------------------------------------- |
---|
132 | RangeTokenMap(const RangeTokenMap&); |
---|
133 | RangeTokenMap& operator=(const RangeTokenMap&); |
---|
134 | |
---|
135 | // ----------------------------------------------------------------------- |
---|
136 | // Private Helpers methods |
---|
137 | // ----------------------------------------------------------------------- |
---|
138 | /* |
---|
139 | * Initializes the registry with a set of commonly used RangeToken |
---|
140 | * objects. |
---|
141 | */ |
---|
142 | void initializeRegistry(); |
---|
143 | void buildTokenRanges(); |
---|
144 | void cleanUp(); |
---|
145 | friend class TokenFactory; |
---|
146 | |
---|
147 | // ----------------------------------------------------------------------- |
---|
148 | // Private data members |
---|
149 | // |
---|
150 | // fTokenRegistry |
---|
151 | // Contains a set of commonly used tokens |
---|
152 | // |
---|
153 | // fRangeMap |
---|
154 | // Contains a map between a category name and a RangeFactory object. |
---|
155 | // |
---|
156 | // fCategories |
---|
157 | // Contains range categories names |
---|
158 | // |
---|
159 | // fTokenFactory |
---|
160 | // Token factory object |
---|
161 | // |
---|
162 | // fInstance |
---|
163 | // A RangeTokenMap instance |
---|
164 | // |
---|
165 | // fMutex |
---|
166 | // A mutex object for synchronization |
---|
167 | // ----------------------------------------------------------------------- |
---|
168 | RefHashTableOf<RangeTokenElemMap>* fTokenRegistry; |
---|
169 | RefHashTableOf<RangeFactory>* fRangeMap; |
---|
170 | XMLStringPool* fCategories; |
---|
171 | TokenFactory* fTokenFactory; |
---|
172 | XMLMutex fMutex; |
---|
173 | static RangeTokenMap* fInstance; |
---|
174 | |
---|
175 | friend class XMLInitializer; |
---|
176 | }; |
---|
177 | |
---|
178 | // --------------------------------------------------------------------------- |
---|
179 | // RangeTokenElemMap: Getter methods |
---|
180 | // --------------------------------------------------------------------------- |
---|
181 | inline unsigned int RangeTokenElemMap::getCategoryId() const { |
---|
182 | |
---|
183 | return fCategoryId; |
---|
184 | } |
---|
185 | |
---|
186 | inline RangeToken* RangeTokenElemMap::getRangeToken(const bool complement) const { |
---|
187 | |
---|
188 | return complement ? fNRange : fRange; |
---|
189 | } |
---|
190 | |
---|
191 | // --------------------------------------------------------------------------- |
---|
192 | // RangeTokenElemMap: Setter methods |
---|
193 | // --------------------------------------------------------------------------- |
---|
194 | inline void RangeTokenElemMap::setCategoryId(const unsigned int categId) { |
---|
195 | |
---|
196 | fCategoryId = categId; |
---|
197 | } |
---|
198 | |
---|
199 | inline void RangeTokenElemMap::setRangeToken(RangeToken* const tok, |
---|
200 | const bool complement) { |
---|
201 | |
---|
202 | if (complement) |
---|
203 | fNRange = tok; |
---|
204 | else |
---|
205 | fRange = tok; |
---|
206 | } |
---|
207 | |
---|
208 | // --------------------------------------------------------------------------- |
---|
209 | // RangeTokenMap: Getter methods |
---|
210 | // --------------------------------------------------------------------------- |
---|
211 | inline RefHashTableOf<RangeTokenElemMap>* RangeTokenMap::getTokenRegistry() const { |
---|
212 | |
---|
213 | return fTokenRegistry; |
---|
214 | } |
---|
215 | |
---|
216 | inline RefHashTableOf<RangeFactory>* RangeTokenMap::getRangeMap() const { |
---|
217 | |
---|
218 | return fRangeMap; |
---|
219 | } |
---|
220 | |
---|
221 | inline XMLStringPool* RangeTokenMap::getCategories() const { |
---|
222 | |
---|
223 | return fCategories; |
---|
224 | } |
---|
225 | |
---|
226 | inline TokenFactory* RangeTokenMap::getTokenFactory() const { |
---|
227 | |
---|
228 | return fTokenFactory; |
---|
229 | } |
---|
230 | |
---|
231 | XERCES_CPP_NAMESPACE_END |
---|
232 | |
---|
233 | #endif |
---|
234 | |
---|
235 | /** |
---|
236 | * End file RangeToken.hpp |
---|
237 | */ |
---|