source: icXML/icXML-devel/src/xercesc/util/regx/RangeTokenMap.hpp

Last change on this file was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 7.9 KB
Line 
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 678879 2008-07-22 20:05:05Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_RANGETOKENMAP_HPP)
23#define XERCESC_INCLUDE_GUARD_RANGETOKENMAP_HPP
24
25// ---------------------------------------------------------------------------
26//  Includes
27// ---------------------------------------------------------------------------
28#include <xercesc/util/Mutexes.hpp>
29#include <icxercesc/util/RefHashTableOf.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33// ---------------------------------------------------------------------------
34//  Forward Declaration
35// ---------------------------------------------------------------------------
36class RangeToken;
37class RangeFactory;
38class TokenFactory;
39class XMLStringPool;
40
41class XMLUTIL_EXPORT RangeTokenElemMap : public XMemory
42{
43
44public:
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
60private:
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
74class XMLUTIL_EXPORT RangeTokenMap : public XMemory
75{
76public:
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
102protected:
103    // -----------------------------------------------------------------------
104    //  Constructor and destructors
105    // -----------------------------------------------------------------------
106    RangeTokenMap(MemoryManager* manager);
107    ~RangeTokenMap();
108
109    // -----------------------------------------------------------------------
110    //  Getter methods
111    // -----------------------------------------------------------------------
112    /*
113     *  Gets a commonly used RangeToken from the token registry based on the
114     *  range name - Called by TokenFactory.
115     */
116     RangeToken* getRange(const XMLCh* const name,
117                          const bool complement = false);
118
119     RefHashTableOf<RangeTokenElemMap>* getTokenRegistry() const;
120     RefHashTableOf<RangeFactory>* getRangeMap() const;
121     XMLStringPool* getCategories() const;
122
123private:
124    // -----------------------------------------------------------------------
125    //  Unimplemented constructors and operators
126    // -----------------------------------------------------------------------
127    RangeTokenMap(const RangeTokenMap&);
128    RangeTokenMap& operator=(const RangeTokenMap&);
129
130    // -----------------------------------------------------------------------
131    //  Private Helpers methods
132    // -----------------------------------------------------------------------
133    /*
134     *  Initializes the registry with a set of commonly used RangeToken
135     *  objects.
136     */
137    void initializeRegistry();
138    void buildTokenRanges();
139    void cleanUp();
140    friend class TokenFactory;
141
142    // -----------------------------------------------------------------------
143    //  Private data members
144    //
145    //  fTokenRegistry
146    //      Contains a set of commonly used tokens
147    //
148    //  fRangeMap
149    //      Contains a map between a category name and a RangeFactory object.
150    //
151    //  fCategories
152    //      Contains range categories names
153    //
154    //  fTokenFactory
155    //      Token factory object
156    //
157    //  fInstance
158    //      A RangeTokenMap instance
159    //
160    //  fMutex
161    //      A mutex object for synchronization
162    // -----------------------------------------------------------------------
163    RefHashTableOf<RangeTokenElemMap>* fTokenRegistry;
164    RefHashTableOf<RangeFactory>*      fRangeMap;
165    XMLStringPool*                     fCategories;
166    TokenFactory*                      fTokenFactory;
167    XMLMutex                           fMutex;
168    static RangeTokenMap*              fInstance;
169
170    friend class XMLInitializer;
171};
172
173// ---------------------------------------------------------------------------
174//  RangeTokenElemMap: Getter methods
175// ---------------------------------------------------------------------------
176inline unsigned int RangeTokenElemMap::getCategoryId() const {
177
178    return fCategoryId;
179}
180
181inline RangeToken* RangeTokenElemMap::getRangeToken(const bool complement) const {
182
183    return complement ? fNRange : fRange;
184}
185
186// ---------------------------------------------------------------------------
187//  RangeTokenElemMap: Setter methods
188// ---------------------------------------------------------------------------
189inline void RangeTokenElemMap::setCategoryId(const unsigned int categId) {
190
191    fCategoryId = categId;
192}
193
194inline void RangeTokenElemMap::setRangeToken(RangeToken* const tok,
195                                      const bool complement) {
196
197    if (complement)
198        fNRange = tok;
199    else
200        fRange = tok;
201}
202
203// ---------------------------------------------------------------------------
204//  RangeTokenMap: Getter methods
205// ---------------------------------------------------------------------------
206inline RefHashTableOf<RangeTokenElemMap>* RangeTokenMap::getTokenRegistry() const {
207
208    return fTokenRegistry;
209}
210
211inline RefHashTableOf<RangeFactory>* RangeTokenMap::getRangeMap() const {
212
213    return fRangeMap;
214}
215
216inline XMLStringPool* RangeTokenMap::getCategories() const {
217
218    return fCategories;
219}
220
221inline TokenFactory* RangeTokenMap::getTokenFactory() const {
222
223    return fTokenFactory;
224}
225
226XERCES_CPP_NAMESPACE_END
227
228#endif
229
230/**
231  *    End file RangeToken.hpp
232  */
Note: See TracBrowser for help on using the repository browser.