Xalan-C++ API Reference  1.12.0
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 namespace XALAN_CPP_NAMESPACE {
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
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
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
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
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
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  */
242  {
243  public:
244 
246  XObjectFactory& theFactoryInstance,
247  bool fInReset = false) :
248  m_factoryInstance(theFactoryInstance),
249  m_fInReset(fInReset)
250  {
251  }
252 
253  bool
254  operator()(XObject* theXObject) const
255  {
256  if (m_fInReset == true)
257  {
258  return m_factoryInstance.doReturnObject(
259  theXObject,
260  true);
261  }
262  else
263  {
264  return m_factoryInstance.returnObject(theXObject);
265  }
266  }
267 
268  private:
269 
270  XObjectFactory& m_factoryInstance;
271 
272  const bool m_fInReset;
273  };
274 
275  friend struct DeleteXObjectFunctor;
276 
277 protected:
278 
279  /**
280  * Return the actual implementation type of an XObject.
281  *
282  * @param theXObject the XObject
283  */
285  getRealType(const XObject& theXObject) const
286  {
287  return theXObject.getRealType();
288  }
289 
290  /**
291  * Delete a FactoryObject instance.
292  *
293  * @param theXObject the XObject instance to delete.
294  */
295  void
296  deleteObject(const XObject* theXObject) const
297  {
298  if( theXObject!= 0)
299  {
300  XObject* const nonConst =
301  const_cast<XObject*>(theXObject);
302 
303  nonConst->~XObject();
304 
305  m_memoryManager.deallocate(nonConst);
306  }
307  }
308 
309  /**
310  * Return an XObject to the factory.
311  *
312  * @param theXObject XObject to be returned
313  * @param fInReset true when called during reset().
314  */
315 
316  virtual bool
318  XObject* theXObject,
319  bool fInReset = false) = 0;
320 
321 private:
322 
323  // Not implemented...
325 
327  operator=(const XObjectFactory&);
328 
329  bool
330  operator==(const XObjectFactory&) const;
331 
332  MemoryManager& m_memoryManager;
333 };
334 
335 
336 
337 }
338 
339 
340 
341 #endif // XOBJECTFACTORY_HEADER_GUARD_1357924680
#define XALAN_XPATH_EXPORT
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
This class handles the creation of XObjects and manages their lifetime.
virtual const XObjectPtr createString(const XalanDOMChar *theValue, XalanSize_t theLength)=0
Create a string XObject from an array of characters.
virtual const XObjectPtr createNumber(const XToken &theValue)=0
Create a numeric XObject from an XToken.
bool returnObject(XObject *theXObject)
Return an XObject to the factory.
virtual const XObjectPtr createString(const XalanDOMString &theValue)=0
Create a string XObject from a string.
virtual const XObjectPtr createUnknown(const XalanDOMString &theValue)=0
Create an "unknown" XObject from a string.
virtual void holdReference(XObjectPtr theValue)=0
Hold a reference to an XObject instance until the factory is reset.
virtual const XObjectPtr createStringReference(const XalanDOMString &theValue)=0
Create a string XObject from a string.
XPathExecutionContext::GetCachedString GetCachedString
XObject::eObjectType getRealType(const XObject &theXObject) const
Return the actual implementation type of an XObject.
XObjectFactory(MemoryManager &theManager)
virtual const XObjectPtr createNumber(double theValue)=0
Create a numeric XObject from a number.
void deleteObject(const XObject *theXObject) const
Delete a FactoryObject instance.
virtual const XObjectPtr createStringAdapter(const XObjectPtr &theValue, XPathExecutionContext &theExecutionContext)=0
Create a string XObject that will adapt another XObject to behave like a string.
virtual void reset()=0
Reset the instance.
virtual const XObjectPtr createString(const XalanDOMChar *theValue)=0
Create a string XObject from a null-terminated array of characters.
virtual const XObjectPtr createString(GetCachedString &theValue)=0
Create a string XObject from a cached XalanDOMString,.
virtual bool doReturnObject(XObject *theXObject, bool fInReset=false)=0
Return an XObject to the factory.
XPathExecutionContext::BorrowReturnMutableNodeRefList BorrowReturnMutableNodeRefList
XPathExecutionContext::GetCachedString GetAndReleaseCachedString
virtual const XObjectPtr createNodeSet(BorrowReturnMutableNodeRefList &theValue)=0
Create a node set XObject from a node list.
MemoryManager & getMemoryManager()
virtual const XObjectPtr createString(const XToken &theValue)=0
Create a string XObject from an XToken.
virtual const XObjectPtr createBoolean(bool theValue)=0
Create a boolean XObject from a boolean value.
virtual const XObjectPtr createNodeSet(XalanNode *theValue)=0
Create a node set XObject from a node.
Class to hold XObjectPtr return types.
Definition: XObject.hpp:884
Class to hold XPath return types.
Definition: XObject.hpp:64
eObjectType
Enumeration of possible object types.
Definition: XObject.hpp:74
virtual ~XObject()
virtual eObjectType getRealType() const
Tell what kind of class this is.
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
A public functor for use with stl algorithms.
bool operator()(XObject *theXObject) const
DeleteXObjectFunctor(XObjectFactory &theFactoryInstance, bool fInReset=false)