Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

STLHelper.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 1999-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 #if !defined(STLHELPERS_HEADER_GUARD_1357924680)
17 #define STLHELPERS_HEADER_GUARD_1357924680
18 
19 
20 
21 // Base include file. Must be first.
23 
24 
25 
26 #include <algorithm>
27 #include <functional>
28 
29 
30 
32 
33 
34 
35 XALAN_CPP_NAMESPACE_BEGIN
36 
37 
38 
39 template<class Type>
40 struct
42 {
43  void
44  operator()(Type& theArg)
45  {
46  theArg.~Type();
47  }
48 
49  void
50  operator()(Type* theArg)
51  {
52  theArg->~Type();
53  }
54 
55  void
56  operator()(const Type* theArg)
57  {
58  (*this)(const_cast<Type*>(theArg));
59  }
60 
61  void
62  operator()(
63  Type* theArg,
64  MemoryManagerType& theMemoryManager)
65  {
66  if (theArg != 0)
67  {
68  (*this)(*theArg);
69 
70  theMemoryManager.deallocate(theArg);
71  }
72  }
73 
74  void
75  operator()(
76  const Type* theArg,
77  MemoryManagerType& theMemoryManager)
78  {
79  (*this)(const_cast<Type*>(theArg), theMemoryManager);
80  }
81 };
82 
83 
84 
85 template<class Type>
87 makeXalanDestroyFunctor(const Type* /* theType */)
88 {
90 }
91 
92 
93 
97 template <class Type>
98 #if defined(XALAN_NO_STD_NAMESPACE)
99 struct DeleteFunctor : public unary_function<const Type*, void>
100 #else
101 struct DeleteFunctor : public std::unary_function<const Type*, void>
102 #endif
103 {
104 #if defined(XALAN_NO_STD_NAMESPACE)
106 #else
107  typedef std::unary_function<const Type*, void> BaseClassType;
108 #endif
109 
110  typedef typename BaseClassType::result_type result_type;
111  typedef typename BaseClassType::argument_type argument_type;
112 
114  m_memoryManager(theManager)
115  {
116  }
117 
124  operator()(argument_type thePointer) const
125  {
126  makeXalanDestroyFunctor(thePointer)(thePointer, m_memoryManager);
127  }
128 
129 private:
130 
131  MemoryManagerType& m_memoryManager;
132 };
133 
134 
135 
136 #if !defined(XALAN_SGI_BASED_STL)
137 
142 template <class PairType>
143 #if defined(XALAN_NO_STD_NAMESPACE)
144 struct select1st : public unary_function<PairType, PairType::first_type>
145 #else
146 struct select1st : public std::unary_function<PairType, typename PairType::first_type>
147 #endif
148 {
149 #if defined(XALAN_NO_STD_NAMESPACE)
151 #else
152  typedef std::unary_function<PairType, typename PairType::first_type> BaseClassType;
153 #endif
154 
155  typedef typename BaseClassType::result_type result_type;
156  typedef typename BaseClassType::argument_type argument_type;
157 
158  typedef PairType value_type;
159 
167  operator()(const argument_type& thePair) const
168  {
169  return thePair.first;
170  }
171 };
172 
173 
174 
179 template <class PairType>
180 #if defined(XALAN_NO_STD_NAMESPACE)
181 struct select2nd : public unary_function<PairType, PairType::second_type>
182 #else
183 struct select2nd : public std::unary_function<PairType, typename PairType::second_type>
184 #endif
185 {
186 #if defined(XALAN_NO_STD_NAMESPACE)
188 #else
189  typedef std::unary_function<PairType, typename PairType::second_type> BaseClassType;
190 #endif
191 
192  typedef typename BaseClassType::result_type result_type;
193  typedef typename BaseClassType::argument_type argument_type;
194 
195  typedef PairType value_type;
196 
204  operator()(const argument_type& thePair) const
205  {
206  return thePair.second;
207  }
208 };
209 
210 #endif
211 
212 
213 
217 template <class Type>
218 #if defined(XALAN_NO_STD_NAMESPACE)
219 struct ClearFunctor : public unary_function<Type, void>
220 #else
221 struct ClearFunctor : public std::unary_function<Type, void>
222 #endif
223 {
224 #if defined(XALAN_NO_STD_NAMESPACE)
226 #else
227  typedef std::unary_function<Type, void> BaseClassType;
228 #endif
229 
230  typedef typename BaseClassType::result_type result_type;
231  typedef typename BaseClassType::argument_type argument_type;
232 
233  typedef Type value_type;
234 
242  operator()(argument_type& theArg) const
243  {
244  theArg.clear();
245  }
246 };
247 
248 
249 
253 template <class T>
254 #if defined(XALAN_NO_STD_NAMESPACE)
255 struct MapValueDeleteFunctor : public unary_function<const typename T::value_type&, void>
256 #else
257 struct MapValueDeleteFunctor : public std::unary_function<const typename T::value_type&, void>
258 #endif
259 {
260 #if defined(XALAN_NO_STD_NAMESPACE)
262 #else
263  typedef std::unary_function<const typename T::value_type&, void> BaseClassType;
264 #endif
265 
266  typedef typename BaseClassType::result_type result_type;
267  typedef typename BaseClassType::argument_type argument_type;
268 
270  m_memoryManager(theManager)
271  {
272  }
273 
281  operator()(argument_type thePair) const
282  {
283  makeXalanDestroyFunctor(thePair.second)(thePair.second, m_memoryManager);
284  }
285 
286 private:
287 
288  MemoryManagerType& m_memoryManager;
289 };
290 
291 
292 
293 template<class MapType>
296 {
297  return MapValueDeleteFunctor<MapType>(theMap.getMemoryManager());
298 }
299 
300 
301 
311 template<class T>
312 #if defined(XALAN_NO_STD_NAMESPACE)
313 struct less_null_terminated_arrays : public binary_function<const T*, const T*, bool>
314 #else
315 struct less_null_terminated_arrays : public std::binary_function<const T*, const T*, bool>
316 #endif
317 {
318 #if defined(XALAN_NO_STD_NAMESPACE)
319  typedef binary_function<const T*, const T*, bool> BaseClassType;
320 #else
321  typedef std::binary_function<const T*, const T*, bool> BaseClassType;
322 #endif
323 
324  typedef typename BaseClassType::result_type result_type;
325  typedef typename BaseClassType::first_argument_type first_argument_type;
326  typedef typename BaseClassType::second_argument_type second_argument_type;
327 
338  first_argument_type theLHS,
339  second_argument_type theRHS) const
340  {
341  while(*theLHS && *theRHS)
342  {
343  if (*theLHS != *theRHS)
344  {
345  break;
346  }
347  else
348  {
349  theLHS++;
350  theRHS++;
351  }
352  }
353 
354  return *theLHS < *theRHS ? true : false;
355  }
356 };
357 
358 
359 
360 template<class T>
361 struct equal_null_terminated_arrays : public XALAN_STD_QUALIFIER binary_function<const T*, const T*, bool>
362 {
363  typedef XALAN_STD_QUALIFIER binary_function<const T*, const T*, bool> BaseClassType;
364 
365  typedef typename BaseClassType::result_type result_type;
366  typedef typename BaseClassType::first_argument_type first_argument_type;
367  typedef typename BaseClassType::second_argument_type second_argument_type;
378  first_argument_type theLHS,
379  second_argument_type theRHS) const
380  {
381  while(*theLHS && *theRHS)
382  {
383  if (*theLHS != *theRHS)
384  {
385  return false;
386  }
387  else
388  {
389  ++theLHS;
390  ++theRHS;
391  }
392  }
393 
394  if (*theLHS || *theRHS)
395  {
396  return false;
397  }
398  else
399  {
400  return true;
401  }
402  }
403 };
404 
405 
406 
407 template <class T>
408 struct hash_null_terminated_arrays : public XALAN_STD_QUALIFIER unary_function<const T*, size_t>
409 {
410  typedef XALAN_STD_QUALIFIER unary_function<const T*, size_t> BaseClassType;
411 
412  typedef typename BaseClassType::result_type result_type;
413  typedef typename BaseClassType::argument_type argument_type;
414 
417  {
418  const T* theRawBuffer = theKey;
419 
420  result_type theHashValue = 0;
421 
422  while (*theRawBuffer)
423  {
424  theHashValue = 5 * theHashValue + *theRawBuffer;
425  ++theRawBuffer;
426  }
427 
428  return ++theHashValue;
429  }
430 };
431 
432 
433 
434 template<>
435 struct XalanMapKeyTraits<const XalanDOMChar*>
436 {
439 };
440 
441 
442 
443 template<class CollectionType>
445 {
446 public:
447 
448  CollectionClearGuard(CollectionType& theCollection) :
449  m_collection(&theCollection)
450  {
451  }
452 
454  {
455  if (m_collection != 0)
456  {
457  m_collection->clear();
458  }
459  }
460 
461  void
463  {
464  m_collection = 0;
465  }
466 
467 private:
468 
469  // Not implemented...
471 
473  operator=(const CollectionClearGuard<CollectionType>&);
474 
475  // Data members...
476  CollectionType* m_collection;
477 };
478 
479 
480 
481 template<class CollectionType, class DeleteFunctorType>
483 {
484 public:
485 
486  CollectionDeleteGuard(CollectionType& theCollection) :
487  m_collection(&theCollection)
488  {
489  }
490 
492  {
493  if (m_collection != 0)
494  {
495 #if !defined(XALAN_NO_STD_NAMESPACE)
496  using std::for_each;
497 #endif
498 
499  // Delete all of the objects in the temp vector.
500  for_each(m_collection->begin(),
501  m_collection->end(),
502  DeleteFunctorType(m_collection->getMemoryManager()));
503  }
504  }
505 
506  void
508  {
509  m_collection = 0;
510  }
511 
512 private:
513 
514  // Not implemented...
516 
519 
520  // Data members...
521  CollectionType* m_collection;
522 };
523 
524 
525 
526 template<class T>
527 #if defined(XALAN_NO_STD_NAMESPACE)
528 struct pointer_equals : public binary_function<const T*, const T*, bool>
529 #else
530 struct pointer_equals : public std::binary_function<const T*, const T*, bool>
531 #endif
532 {
533 #if defined(XALAN_NO_STD_NAMESPACE)
534  typedef binary_function<const T*, const T*, bool> BaseClassType;
535 #else
536  typedef std::binary_function<const T*, const T*, bool> BaseClassType;
537 #endif
538 
539  typedef typename BaseClassType::result_type result_type;
540  typedef typename BaseClassType::first_argument_type first_argument_type;
541  typedef typename BaseClassType::second_argument_type second_argument_type;
542 
545  first_argument_type theLHS,
546  second_argument_type theRHS) const
547  {
548  assert(theLHS != 0 && theRHS != 0);
549 
550  return *theLHS == *theRHS;
551  }
552 };
553 
554 
555 
556 template<class T>
557 #if defined(XALAN_NO_STD_NAMESPACE)
558 struct pointer_equals_predicate : public unary_function<const T*, bool>
559 #else
560 struct pointer_equals_predicate : public std::unary_function<const T*, bool>
561 #endif
562 {
563 #if defined(XALAN_NO_STD_NAMESPACE)
565 #else
566  typedef std::unary_function<const T*, bool> BaseClassType;
567 #endif
568 
569  typedef typename BaseClassType::result_type result_type;
570  typedef typename BaseClassType::argument_type argument_type;
571 
573  m_arg(theArg)
574  {
575  }
576 
579  argument_type theOther) const
580  {
581  assert(theOther != 0);
582 
583  return *theOther == *m_arg;
584  }
585 
586 private:
587 
588  const argument_type m_arg;
589 };
590 
591 
592 
593 template<class T>
594 #if defined(XALAN_NO_STD_NAMESPACE)
595 struct pointer_less : public binary_function<const T*, const T*, bool>
596 #else
597 struct pointer_less : public std::binary_function<const T*, const T*, bool>
598 #endif
599 {
600 #if defined(XALAN_NO_STD_NAMESPACE)
601  typedef binary_function<const T*, const T*, bool> BaseClassType;
602 #else
603  typedef std::binary_function<const T*, const T*, bool> BaseClassType;
604 #endif
605 
606  typedef typename BaseClassType::result_type result_type;
607  typedef typename BaseClassType::first_argument_type first_argument_type;
608  typedef typename BaseClassType::second_argument_type second_argument_type;
609 
612  first_argument_type theLHS,
613  second_argument_type theRHS) const
614  {
615  assert(theLHS != 0 && theRHS != 0);
616 
617 #if !defined(XALAN_NO_STD_NAMESPACE)
618  using std::less;
619 #endif
620 
621  return less<T>()(*theLHS, *theRHS);
622  }
623 };
624 
625 
626 
627 template<class T>
628 struct pointer_equal : public XALAN_STD_QUALIFIER binary_function<const T*, const T*, bool>
629 {
630  typedef XALAN_STD_QUALIFIER binary_function<const T*, const T*, bool> BaseClassType;
631 
632  typedef typename BaseClassType::result_type result_type;
633  typedef typename BaseClassType::first_argument_type first_argument_type;
634  typedef typename BaseClassType::second_argument_type second_argument_type;
635 
638  first_argument_type theLHS,
639  second_argument_type theRHS) const
640  {
641  assert(theLHS != 0 && theRHS != 0);
642  return XALAN_STD_QUALIFIER equal_to<T>()(*theLHS, *theRHS);
643  }
644 };
645 
646 
647 
648 
649 XALAN_CPP_NAMESPACE_END
650 
651 
652 
653 #endif // STLHELPERS_HEADER_GUARD_1357924680

Interpreting class diagrams

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

dot

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

Apache Logo