1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 #if !defined(XPATHCONSTRUCTIONCONTEXT_HEADER_GUARD_1357924680) 19 #define XPATHCONSTRUCTIONCONTEXT_HEADER_GUARD_1357924680 20 21 22 23 // Base include file. Must be first. 24 #include <xalanc/XPath/XPathDefinitions.hpp> 25 26 27 28 #include <xalanc/XalanDOM/XalanDOMString.hpp> 29 30 31 32 #include "xalanc/PlatformSupport/ProblemListenerBase.hpp" 33 34 35 36 namespace XERCES_CPP_NAMESPACE 37 { 38 class Locator; 39 } 40 41 42 43 namespace XALAN_CPP_NAMESPACE { 44 45 46 47 typedef xercesc::Locator LocatorType; 48 using xercesc::Locator; 49 50 51 52 class XalanNode; 53 54 55 56 // 57 // An abstract class which provides support for constructing the internal 58 // representation of a stylesheet. 59 // 60 class XALAN_XPATH_EXPORT XPathConstructionContext : public ProblemListenerBase 61 { 62 public: 63 64 XPathConstructionContext(MemoryManager& theManager); 65 66 virtual 67 ~XPathConstructionContext(); 68 69 70 // These interfaces are inherited from ProblemListenerBase... 71 virtual void 72 problem( 73 eSource source, 74 eClassification classification, 75 const XalanDOMString& msg, 76 const Locator* locator, 77 const XalanNode* sourceNode) = 0; 78 79 virtual void 80 problem( 81 eSource source, 82 eClassification classification, 83 const XalanDOMString& msg, 84 const XalanNode* sourceNode) = 0; 85 86 87 // These interfaces are new... 88 /** 89 * Reset the instance. Any existing objects 90 * created by the instance will be destroyed. 91 */ 92 virtual void 93 reset() = 0; 94 95 /** 96 * Get a pooled string given the source string. If 97 * the string already exists in the pool, no copy 98 * will be made. If not, a copy will be made and 99 * kept for later use. 100 * 101 * @param theString The source string 102 * @return a const reference to a pooled string. 103 */ 104 virtual const XalanDOMString& 105 getPooledString(const XalanDOMString& theString) = 0; 106 107 /** 108 * Get a pooled string given the source character 109 * array. If the string already exists in the pool, 110 * no copy will be made. If not, a copy will be made 111 * and kept for later use. 112 * 113 * @param theString The source character array 114 * @param theLength The length of the character array 115 * @return a const reference to a pooled string. 116 */ 117 virtual const XalanDOMString& 118 getPooledString( 119 const XalanDOMChar* theString, 120 XalanDOMString::size_type theLength = XalanDOMString::npos) = 0; 121 122 /** 123 * Get a cached string for temporary use. 124 * 125 * @return A reference to the string 126 */ 127 virtual XalanDOMString& 128 getCachedString() = 0; 129 130 /** 131 * Return a cached string. 132 * 133 * @param theString The string to release. 134 * 135 * @return true if the string was released successfully. 136 */ 137 virtual bool 138 releaseCachedString(XalanDOMString& theString) = 0; 139 140 class GetCachedString 141 { 142 public: 143 GetCachedString(XPathConstructionContext & theConstructionContext)144 GetCachedString(XPathConstructionContext& theConstructionContext) : 145 m_constructionContext(&theConstructionContext), 146 m_string(&theConstructionContext.getCachedString()) 147 { 148 } 149 ~GetCachedString()150 ~GetCachedString() 151 { 152 assert(m_string != 0); 153 154 m_constructionContext->releaseCachedString(*m_string); 155 } 156 157 XalanDOMString& get() const158 get() const 159 { 160 assert(m_string != 0); 161 162 return *m_string; 163 } 164 165 XPathConstructionContext& getConstructionContext() const166 getConstructionContext() const 167 { 168 assert(m_constructionContext != 0); 169 170 return *m_constructionContext; 171 } 172 173 private: 174 175 // Not implemented... 176 GetCachedString(); 177 178 GetCachedString(const GetCachedString&); 179 180 GetCachedString& 181 operator=(const GetCachedString&); 182 183 184 // Data members... 185 XPathConstructionContext* m_constructionContext; 186 187 XalanDOMString* m_string; 188 }; 189 190 typedef GetCachedString GetAndReleaseCachedString; 191 192 MemoryManager& getMemoryManager() const193 getMemoryManager() const 194 { 195 return m_memoryManager; 196 } 197 198 MemoryManager& getMemoryManager()199 getMemoryManager() 200 { 201 return m_memoryManager; 202 } 203 204 private: 205 206 MemoryManager& m_memoryManager; 207 }; 208 209 210 211 } 212 213 214 215 #endif // XPATHCONSTRUCTIONCONTEXT_HEADER_GUARD_1357924680 216