Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


XObjectFactory.hpp
Go to the documentation of this file.
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(XOBJECTFACTORY_HEADER_GUARD_1357924680)
19 #define XOBJECTFACTORY_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
26 
27 
28 #include <algorithm>
29 #include <cassert>
30 
31 
32 #include <xalanc/XPath/XObject.hpp>
34 
35 
36 
37 XALAN_CPP_NAMESPACE_BEGIN
38 
39 
40 
41 class XalanNode;
42 class MutableNodeRefList;
43 class NodeRefListBase;
44 class XObject;
45 class XObjectPtr;
46 class XToken;
47 
48 
49 
50 /**
51  * This class handles the creation of XObjects and manages their lifetime.
52  */
54 {
55 public:
56 
60 
61 
62  XObjectFactory(MemoryManager& theManager);
63 
64  virtual
65  ~XObjectFactory();
66 
67 
68  MemoryManager&
70  {
71  return m_memoryManager;
72  }
73 
74  /**
75  * Return an XObject to the factory.
76  *
77  * @param theXObject The XObject to be returned
78  * @return true if the object belongs to the factory, false if not.
79  */
80  bool
81  returnObject(XObject* theXObject)
82  {
83  return doReturnObject(theXObject);
84  }
85 
86  /**
87  * Reset the instance. This invalidates all existing instances created
88  * with this XObjectFactory.
89  */
90  virtual void
91  reset() = 0;
92 
93  /**
94  * Create a boolean XObject from a boolean value.
95  *
96  * @param theValue value used to create object
97  * @return pointer to new object
98  */
99  virtual const XObjectPtr
100  createBoolean(bool theValue) = 0;
101 
102  /**
103  * Create a node set XObject from a node list.
104  *
105  * @param theValue value used to create object. theValue will be owned by the new XObject.
106  * @return pointer to new object
107  */
108  virtual const XObjectPtr
109  createNodeSet(BorrowReturnMutableNodeRefList& theValue) = 0;
110 
111  /**
112  * Create a node set XObject from a node.
113  *
114  * @param theNOde value used to create object.
115  * @return pointer to new object
116  */
117  virtual const XObjectPtr
118  createNodeSet(XalanNode* theValue) = 0;
119 
120  /**
121  * Create a numeric XObject from a number.
122  *
123  * @param theValue value used to create object
124  * @return pointer to new object
125  */
126  virtual const XObjectPtr
127  createNumber(double theValue) = 0;
128 
129  /**
130  * Create a numeric XObject from an XToken. The XToken
131  * instance must be inexistence for the lifetime of the
132  * object.
133  *
134  * @param theValue value used to create object
135  * @return pointer to new object
136  */
137  virtual const XObjectPtr
138  createNumber(const XToken& theValue) = 0;
139 
140  /**
141  * Create a string XObject from a string.
142  *
143  * @param theValue value used to create object
144  * @return pointer to new object
145  */
146  virtual const XObjectPtr
147  createString(const XalanDOMString& theValue) = 0;
148 
149  /**
150  * Create a string XObject from a null-terminated array of characters.
151  *
152  * @param theValue a pointer to the array
153  * @return pointer to new object
154  */
155  virtual const XObjectPtr
156  createString(const XalanDOMChar* theValue) = 0;
157 
158  /**
159  * Create a string XObject from an array of characters.
160  *
161  * @param theValue a pointer to the array
162  * @paran theLength the length of the array
163  * @return pointer to new object
164  */
165  virtual const XObjectPtr
166  createString(
167  const XalanDOMChar* theValue,
168  XalanSize_t theLength) = 0;
169 
170  /**
171  * Create a string XObject from an XToken. The XToken
172  * instance must be inexistence for the lifetime of the
173  * object.
174  *
175  * @param theValue value used to create object
176  * @return pointer to new object
177  */
178  virtual const XObjectPtr
179  createString(const XToken& theValue) = 0;
180 
181  /**
182  * Create a string XObject from a string. The XObject
183  * will hold a reference to the supplied string, so
184  * the string must be in scope for the lifetime of
185  * the instance
186  *
187  * @param theValue value used to create object
188  * @return pointer to new object
189  */
190  virtual const XObjectPtr
191  createStringReference(const XalanDOMString& theValue) = 0;
192 
193  /**
194  * Create a string XObject that will adapt another XObject to
195  * behave like a string. The XObject holds a reference to the
196  * other XObject.
197  *
198  * @param theValue value used to create object
199  * @paran theExecutionContext The current execution context
200  * @return pointer to new object
201  */
202  virtual const XObjectPtr
203  createStringAdapter(
204  const XObjectPtr& theValue,
205  XPathExecutionContext& theExecutionContext) = 0;
206 
207  /**
208  * Create a string XObject from a cached XalanDOMString,
209  *
210  * @param theValue value used to create object
211  * @return pointer to new object
212  */
213  virtual const XObjectPtr
214  createString(GetCachedString& theValue) = 0;
215 
216  /**
217  * Create an "unknown" XObject from a string.
218  *
219  * @param theValue value used to create object
220  * @return pointer to new object
221  */
222  virtual const XObjectPtr
223  createUnknown(const XalanDOMString& theValue) = 0;
224 
225  /**
226  * Hold a reference to an XObject instance until the
227  * factory is reset. This is needed in a very few cases
228  * when the object lifetime needs to extend after the
229  * execution of an XPath expression.
230  *
231  * @param theValue The XObjectPtr instance.
232  */
233  virtual void
234  holdReference(XObjectPtr theValue) = 0;
235 
236  /**
237  *
238  * A public functor for use with stl algorithms.
239  *
240  */
241 #if defined(XALAN_NO_STD_NAMESPACE)
242  struct DeleteXObjectFunctor : public unary_function<XObject*, void>
243 #else
244  struct DeleteXObjectFunctor : public std::unary_function<XObject*, bool>
245 #endif
246  {
247  public:
248 
250  XObjectFactory& theFactoryInstance,
251  bool fInReset = false) :
252  m_factoryInstance(theFactoryInstance),
253  m_fInReset(fInReset)
254  {
255  }
256 
257  result_type
258  operator()(argument_type theXObject) const
259  {
260  if (m_fInReset == true)
261  {
262  return m_factoryInstance.doReturnObject(
263  theXObject,
264  true);
265  }
266  else
267  {
268  return m_factoryInstance.returnObject(theXObject);
269  }
270  }
271 
272  private:
273 
274  XObjectFactory& m_factoryInstance;
275 
276  const bool m_fInReset;
277  };
278 
279  friend struct DeleteXObjectFunctor;
280 
281 protected:
282 
283  /**
284  * Return the actual implementation type of an XObject.
285  *
286  * @param theXObject the XObject
287  */
289  getRealType(const XObject& theXObject) const
290  {
291  return theXObject.getRealType();
292  }
293 
294  /**
295  * Delete a FactoryObject instance.
296  *
297  * @param theXObject the XObject instance to delete.
298  */
299  void
300  deleteObject(const XObject* theXObject) const
301  {
302  if( theXObject!= 0)
303  {
304  XObject* const nonConst =
305  const_cast<XObject*>(theXObject);
306 
307  nonConst->~XObject();
308 
309  m_memoryManager.deallocate(nonConst);
310  }
311  }
312 
313  /**
314  * Return an XObject to the factory.
315  *
316  * @param theXObject XObject to be returned
317  * @param fInReset true when called during reset().
318  */
319 
320  virtual bool
321  doReturnObject(
322  XObject* theXObject,
323  bool fInReset = false) = 0;
324 
325 private:
326 
327  // Not implemented...
329 
331  operator=(const XObjectFactory&);
332 
333  bool
334  operator==(const XObjectFactory&) const;
335 
336  MemoryManager& m_memoryManager;
337 };
338 
339 
340 
341 XALAN_CPP_NAMESPACE_END
342 
343 
344 
345 #endif // XOBJECTFACTORY_HEADER_GUARD_1357924680
Local implementation of MutableNodeRefList.
void deleteObject(const XObject *theXObject) const
Delete a FactoryObject instance.
eObjectType
Enumeration of possible object types.
Definition: XObject.hpp:74
Class to hold XObjectPtr return types.
Definition: XObject.hpp:883
bool returnObject(XObject *theXObject)
Return an XObject to the factory.
result_type operator()(argument_type theXObject) const
Local implementation of NodeRefList.
A public functor for use with stl algorithms.
DeleteXObjectFunctor(XObjectFactory &theFactoryInstance, bool fInReset=false)
Class to hold XPath return types.
Definition: XObject.hpp:63
MemoryManager & getMemoryManager()
XPathExecutionContext::GetCachedString GetAndReleaseCachedString
XPathExecutionContext::GetCachedString GetCachedString
virtual ~XObject()
bool operator==(const ElemAttributeSet &theLHS, const ElemAttributeSet &theRHS)
#define XALAN_XPATH_EXPORT
XObject::eObjectType getRealType(const XObject &theXObject) const
Return the actual implementation type of an XObject.
This class handles the creation of XObjects and manages their lifetime.
XPathExecutionContext::BorrowReturnMutableNodeRefList BorrowReturnMutableNodeRefList
virtual eObjectType getRealType() const
Tell what kind of class this is.

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSLT Processor Version 1.11
Copyright © 1999-2012 The Apache Software Foundation.
All Rights Reserved.

Apache Logo