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: TokenFactory.hpp 678879 2008-07-22 20:05:05Z amassari $
20 */
21
22 #if !defined(XERCESC_INCLUDE_GUARD_TOKENFACTORY_HPP)
23 #define XERCESC_INCLUDE_GUARD_TOKENFACTORY_HPP
24
25 // ---------------------------------------------------------------------------
26 // Includes
27 // ---------------------------------------------------------------------------
28 #include <xercesc/util/RefVectorOf.hpp>
29 #include <xercesc/util/regx/Token.hpp>
30 #include <xercesc/util/Mutexes.hpp>
31
32 XERCES_CPP_NAMESPACE_BEGIN
33
34 // ---------------------------------------------------------------------------
35 // Forward Declaration
36 // ---------------------------------------------------------------------------
37 class RangeToken;
38 class CharToken;
39 class ClosureToken;
40 class ConcatToken;
41 class ParenToken;
42 class StringToken;
43 class UnionToken;
44
45 class XMLUTIL_EXPORT TokenFactory : public XMemory
46 {
47
48 public:
49 // -----------------------------------------------------------------------
50 // Constructors and destructors
51 // -----------------------------------------------------------------------
52 TokenFactory(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
53 ~TokenFactory();
54
55 // -----------------------------------------------------------------------
56 // Factory methods
57 // -----------------------------------------------------------------------
58 Token* createToken(const Token::tokType tkType);
59
60 ParenToken* createParenthesis(Token* const token, const int noGroups);
61 ClosureToken* createClosure(Token* const token, bool isNonGreedy = false);
62 ConcatToken* createConcat(Token* const token1, Token* const token2);
63 UnionToken* createUnion(const bool isConcat = false);
64 RangeToken* createRange(const bool isNegRange = false);
65 CharToken* createChar(const XMLUInt32 ch, const bool isAnchor = false);
66 StringToken* createBackReference(const int refNo);
67 StringToken* createString(const XMLCh* const literal);
68
69
70 //static void printUnicode();
71
72 // -----------------------------------------------------------------------
73 // Getter methods
74 // -----------------------------------------------------------------------
75 /*
76 * Gets a commonly used RangeToken from the token registry based on the
77 * range name.
78 */
79 RangeToken* getRange(const XMLCh* const name,const bool complement=false);
80 Token* getLineBegin();
81 Token* getLineEnd();
82 Token* getDot();
83 MemoryManager* getMemoryManager() const;
84
85 static RangeToken* staticGetRange(const XMLCh* const name,const bool complement=false);
86
87 // -----------------------------------------------------------------------
88 // Notification that lazy data has been deleted
89 // -----------------------------------------------------------------------
90 static void reinitTokenFactoryMutex();
91
92 private:
93 // -----------------------------------------------------------------------
94 // Unimplemented constructors and operators
95 // -----------------------------------------------------------------------
96 TokenFactory(const TokenFactory&);
97 TokenFactory& operator=(const TokenFactory&);
98
99 // -----------------------------------------------------------------------
100 // Private data members
101 //
102 // fRangeInitialized
103 // Indicates whether we have initialized the RangeFactory instance or
104 // not
105 //
106 // fToken
107 // Contains user created Token objects. Used for memory cleanup.
108 // -----------------------------------------------------------------------
109 RefVectorOf<Token>* fTokens;
110 Token* fEmpty;
111 Token* fLineBegin;
112 Token* fLineEnd;
113 Token* fDot;
114 MemoryManager* fMemoryManager;
115 };
116
getRange(const XMLCh * const name,const bool complement)117 inline RangeToken* TokenFactory::getRange(const XMLCh* const name,const bool complement)
118 {
119 return staticGetRange(name, complement);
120 }
121
getMemoryManager() const122 inline MemoryManager* TokenFactory::getMemoryManager() const
123 {
124 return fMemoryManager;
125 }
126
127 XERCES_CPP_NAMESPACE_END
128
129 #endif
130
131 /**
132 * End file TokenFactory
133 */
134
135