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: TokenFactory.hpp,v 1.9 2004/09/08 13:56:47 peiyongz Exp $
|
---|
19 | */
|
---|
20 |
|
---|
21 | #if !defined(TOKENFACTORY_HPP)
|
---|
22 | #define TOKENFACTORY_HPP
|
---|
23 |
|
---|
24 | // ---------------------------------------------------------------------------
|
---|
25 | // Includes
|
---|
26 | // ---------------------------------------------------------------------------
|
---|
27 | #include <xercesc/util/RefVectorOf.hpp>
|
---|
28 | #include <xercesc/util/regx/Token.hpp>
|
---|
29 | #include <xercesc/util/Mutexes.hpp>
|
---|
30 |
|
---|
31 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
32 |
|
---|
33 | // ---------------------------------------------------------------------------
|
---|
34 | // Forward Declaration
|
---|
35 | // ---------------------------------------------------------------------------
|
---|
36 | class RangeToken;
|
---|
37 | class CharToken;
|
---|
38 | class ClosureToken;
|
---|
39 | class ConditionToken;
|
---|
40 | class ConcatToken;
|
---|
41 | class ModifierToken;
|
---|
42 | class ParenToken;
|
---|
43 | class StringToken;
|
---|
44 | class UnionToken;
|
---|
45 |
|
---|
46 | class XMLUTIL_EXPORT TokenFactory : public XMemory
|
---|
47 | {
|
---|
48 |
|
---|
49 | public:
|
---|
50 | // -----------------------------------------------------------------------
|
---|
51 | // Constructors and destructors
|
---|
52 | // -----------------------------------------------------------------------
|
---|
53 | TokenFactory(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
54 | ~TokenFactory();
|
---|
55 |
|
---|
56 | // -----------------------------------------------------------------------
|
---|
57 | // Factory methods
|
---|
58 | // -----------------------------------------------------------------------
|
---|
59 | Token* createToken(const unsigned short tokType);
|
---|
60 |
|
---|
61 | ParenToken* createLook(const unsigned short tokType, Token* const token);
|
---|
62 | ParenToken* createParenthesis(Token* const token, const int noGroups);
|
---|
63 | ClosureToken* createClosure(Token* const token, bool isNonGreedy = false);
|
---|
64 | ConcatToken* createConcat(Token* const token1, Token* const token2);
|
---|
65 | UnionToken* createUnion(const bool isConcat = false);
|
---|
66 | RangeToken* createRange(const bool isNegRange = false);
|
---|
67 | CharToken* createChar(const XMLUInt32 ch, const bool isAnchor = false);
|
---|
68 | StringToken* createBackReference(const int refNo);
|
---|
69 | StringToken* createString(const XMLCh* const literal);
|
---|
70 | ModifierToken* createModifierGroup(Token* const child,
|
---|
71 | const int add, const int mask);
|
---|
72 | ConditionToken* createCondition(const int refNo, Token* const condition,
|
---|
73 | Token* const yesFlow, Token* const noFlow);
|
---|
74 |
|
---|
75 |
|
---|
76 | //static void printUnicode();
|
---|
77 |
|
---|
78 | // -----------------------------------------------------------------------
|
---|
79 | // Getter methods
|
---|
80 | // -----------------------------------------------------------------------
|
---|
81 | /*
|
---|
82 | * Gets a commonly used RangeToken from the token registry based on the
|
---|
83 | * range name.
|
---|
84 | */
|
---|
85 | RangeToken* getRange(const XMLCh* const name,const bool complement=false);
|
---|
86 | Token* getLineBegin();
|
---|
87 | Token* getLineBegin2();
|
---|
88 | Token* getLineEnd();
|
---|
89 | Token* getStringBegin();
|
---|
90 | Token* getStringEnd();
|
---|
91 | Token* getStringEnd2();
|
---|
92 | Token* getWordEdge();
|
---|
93 | Token* getNotWordEdge();
|
---|
94 | Token* getWordBegin();
|
---|
95 | Token* getWordEnd();
|
---|
96 | Token* getDot();
|
---|
97 | Token* getCombiningCharacterSequence();
|
---|
98 | Token* getGraphemePattern();
|
---|
99 | MemoryManager* getMemoryManager() const;
|
---|
100 |
|
---|
101 | // -----------------------------------------------------------------------
|
---|
102 | // Notification that lazy data has been deleted
|
---|
103 | // -----------------------------------------------------------------------
|
---|
104 | static void reinitTokenFactoryMutex();
|
---|
105 |
|
---|
106 | private:
|
---|
107 | // -----------------------------------------------------------------------
|
---|
108 | // Unimplemented constructors and operators
|
---|
109 | // -----------------------------------------------------------------------
|
---|
110 | TokenFactory(const TokenFactory&);
|
---|
111 | TokenFactory& operator=(const TokenFactory&);
|
---|
112 |
|
---|
113 | // -----------------------------------------------------------------------
|
---|
114 | // Private Helpers methods
|
---|
115 | // -----------------------------------------------------------------------
|
---|
116 | /*
|
---|
117 | * Initializes the registry with a set of commonly used RangeToken
|
---|
118 | * objects.
|
---|
119 | */
|
---|
120 | void initializeRegistry();
|
---|
121 | friend class RangeTokenMap;
|
---|
122 |
|
---|
123 | // -----------------------------------------------------------------------
|
---|
124 | // Private data members
|
---|
125 | //
|
---|
126 | // fRangeInitialized
|
---|
127 | // Indicates whether we have initialized the RangeFactory instance or
|
---|
128 | // not
|
---|
129 | //
|
---|
130 | // fToken
|
---|
131 | // Contains user created Token objects. Used for memory cleanup.
|
---|
132 | // -----------------------------------------------------------------------
|
---|
133 | static bool fRangeInitialized;
|
---|
134 | RefVectorOf<Token>* fTokens;
|
---|
135 | Token* fEmpty;
|
---|
136 | Token* fLineBegin;
|
---|
137 | Token* fLineBegin2;
|
---|
138 | Token* fLineEnd;
|
---|
139 | Token* fStringBegin;
|
---|
140 | Token* fStringEnd;
|
---|
141 | Token* fStringEnd2;
|
---|
142 | Token* fWordEdge;
|
---|
143 | Token* fNotWordEdge;
|
---|
144 | Token* fWordEnd;
|
---|
145 | Token* fWordBegin;
|
---|
146 | Token* fDot;
|
---|
147 | Token* fCombiningChar;
|
---|
148 | Token* fGrapheme;
|
---|
149 | MemoryManager* fMemoryManager;
|
---|
150 | };
|
---|
151 |
|
---|
152 | inline MemoryManager* TokenFactory::getMemoryManager() const
|
---|
153 | {
|
---|
154 | return fMemoryManager;
|
---|
155 | }
|
---|
156 |
|
---|
157 | XERCES_CPP_NAMESPACE_END
|
---|
158 |
|
---|
159 | #endif
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * End file TokenFactory
|
---|
163 | */
|
---|
164 |
|
---|