source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/util/regx/Token.hpp @ 2674

Revision 2674, 8.0 KB checked in by mattausch, 16 years ago (diff)
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: Token.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22#if !defined(TOKEN_HPP)
23#define TOKEN_HPP
24
25// ---------------------------------------------------------------------------
26//  Includes
27// ---------------------------------------------------------------------------
28#include <xercesc/util/RuntimeException.hpp>
29#include <xercesc/util/PlatformUtils.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33// ---------------------------------------------------------------------------
34//  Forward Declaration
35// ---------------------------------------------------------------------------
36class RangeToken;
37class TokenFactory;
38
39
40class XMLUTIL_EXPORT Token : public XMemory
41{
42public:
43        // -----------------------------------------------------------------------
44    //  Public Constructors and Destructor
45    // -----------------------------------------------------------------------
46        Token(const unsigned short tokType
47        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
48        );
49        virtual ~Token();
50
51        // -----------------------------------------------------------------------
52    //  Public Constants
53    // -----------------------------------------------------------------------
54        // Token types
55        enum {
56                T_CHAR = 0,
57                T_CONCAT = 1,
58                T_UNION = 2,
59                T_CLOSURE = 3,
60                T_RANGE = 4,
61                T_NRANGE = 5,
62                T_PAREN = 6,
63                T_EMPTY = 7,
64                T_ANCHOR = 8,
65                T_NONGREEDYCLOSURE = 9,
66                T_STRING = 10,
67                T_DOT = 11,
68                T_BACKREFERENCE = 12,
69                T_LOOKAHEAD = 20,
70                T_NEGATIVELOOKAHEAD = 21,
71                T_LOOKBEHIND = 22,
72                T_NEGATIVELOOKBEHIND = 23,
73                T_INDEPENDENT = 24,
74                T_MODIFIERGROUP = 25,
75                T_CONDITION = 26
76        };
77
78        static const XMLInt32           UTF16_MAX;
79        static const unsigned short FC_CONTINUE;
80        static const unsigned short FC_TERMINAL;
81        static const unsigned short FC_ANY;
82
83        // -----------------------------------------------------------------------
84    //  Getter methods
85    // -----------------------------------------------------------------------
86        unsigned short       getTokenType() const;
87        int                  getMinLength() const;
88    int                  getMaxLength() const;
89        virtual Token*       getChild(const int index) const;
90        virtual int          size() const;
91    virtual int          getMin() const;
92    virtual int          getMax() const;
93    virtual int          getNoParen() const;
94        virtual int          getReferenceNo() const;
95    virtual const XMLCh* getString() const;
96        virtual XMLInt32     getChar() const;
97
98        // -----------------------------------------------------------------------
99    //  Setter methods
100    // -----------------------------------------------------------------------
101        void setTokenType(const unsigned short tokType);
102        virtual void setMin(const int minVal);
103        virtual void setMax(const int maxVal);
104
105    // -----------------------------------------------------------------------
106    //  Range manipulation methods
107    // -----------------------------------------------------------------------
108        virtual void addRange(const XMLInt32 start, const XMLInt32 end);
109        virtual void mergeRanges(const Token *const tok);
110        virtual void sortRanges();
111        virtual void compactRanges();
112        virtual void subtractRanges(RangeToken* const tok);
113        virtual void intersectRanges(RangeToken* const tok);
114
115        // -----------------------------------------------------------------------
116    //  Putter methods
117    // -----------------------------------------------------------------------
118        virtual void addChild(Token* const child, TokenFactory* const tokFactory);
119
120        // -----------------------------------------------------------------------
121    //  Helper methods
122    // -----------------------------------------------------------------------
123        int analyzeFirstCharacter(RangeToken* const rangeTok, const int options,
124                              TokenFactory* const tokFactory);
125    Token* findFixedString(int options, int& outOptions);
126
127private:
128        // -----------------------------------------------------------------------
129    //  Unimplemented constructors and operators
130    // -----------------------------------------------------------------------
131    Token(const Token&);
132    Token& operator=(const Token&);
133
134    // -----------------------------------------------------------------------
135    //  Private Helper methods
136    // -----------------------------------------------------------------------
137        bool isSet(const int options, const unsigned int flag);
138    bool isShorterThan(Token* const tok);
139
140        // -----------------------------------------------------------------------
141    //  Private data members
142        // -----------------------------------------------------------------------
143        unsigned short fTokenType;
144protected:
145    MemoryManager* const    fMemoryManager;
146};
147
148
149// ---------------------------------------------------------------------------
150//  Token: getter methods
151// ---------------------------------------------------------------------------
152inline unsigned short Token::getTokenType() const {
153
154        return fTokenType;
155}
156
157inline int Token::size() const {
158
159        return 0;
160}
161
162inline Token* Token::getChild(const int) const {
163
164        return 0;
165}
166
167inline int Token::getMin() const {
168
169    return -1;
170}
171
172inline int Token::getMax() const {
173
174    return -1;
175}
176
177inline int Token::getReferenceNo() const {
178
179    return 0;
180}
181
182inline int Token::getNoParen() const {
183
184    return 0;
185}
186
187inline const XMLCh* Token::getString() const {
188
189    return 0;
190}
191
192inline XMLInt32 Token::getChar() const {
193
194    return -1;
195}
196
197// ---------------------------------------------------------------------------
198//  Token: setter methods
199// ---------------------------------------------------------------------------
200inline void Token::setTokenType(const unsigned short tokType) {
201       
202        fTokenType = tokType;
203}
204
205inline void Token::setMax(const int) {
206        // ClosureToken
207}
208
209inline void Token::setMin(const int) {
210        // ClosureToken
211}
212
213inline bool Token::isSet(const int options, const unsigned int flag) {
214
215        return (options & flag) == flag;
216}
217
218// ---------------------------------------------------------------------------
219//  Token: setter methods
220// ---------------------------------------------------------------------------
221inline void Token::addChild(Token* const, TokenFactory* const) {
222
223    ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
224}
225
226// ---------------------------------------------------------------------------
227//  Token: Range manipulation methods
228// ---------------------------------------------------------------------------
229inline void Token::addRange(const XMLInt32, const XMLInt32) {
230
231    ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
232}
233
234inline void Token::mergeRanges(const Token *const) {
235
236    ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
237}
238
239inline void Token::sortRanges() {
240
241    ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
242}
243
244inline void Token::compactRanges() {
245
246    ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
247}
248
249inline void Token::subtractRanges(RangeToken* const) {
250
251    ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
252}
253
254inline void Token::intersectRanges(RangeToken* const) {
255
256    ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
257}
258
259XERCES_CPP_NAMESPACE_END
260
261#endif
262
263/**
264  * End of file Token.hpp
265  */
266
Note: See TracBrowser for help on using the repository browser.