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