Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

STLHelper.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 1999-2004 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #if !defined(STLHELPERS_HEADER_GUARD_1357924680)
00017 #define STLHELPERS_HEADER_GUARD_1357924680
00018 
00019 
00020 
00021 // Base include file.  Must be first.
00022 #include <xalanc/Include/PlatformDefinitions.hpp>
00023 
00024 
00025 
00026 #include <algorithm>
00027 #include <functional>
00028 
00029 
00030 
00031 #include <xalanc/Include/XalanMap.hpp>
00032 
00033 
00034 
00035 XALAN_CPP_NAMESPACE_BEGIN
00036 
00037 
00038 
00039 template<class Type>
00040 struct
00041 XalanDestroyFunctor
00042 {
00043     void
00044     operator()(Type&  theArg)
00045     {
00046         theArg.~Type();
00047     }
00048 
00049     void
00050     operator()(Type*  theArg)
00051     {
00052         theArg->~Type();
00053     }
00054 
00055     void
00056     operator()(const Type*    theArg)
00057     {
00058         (*this)(const_cast<Type*>(theArg));
00059     }
00060 
00061     void
00062     operator()(
00063                 Type*               theArg,
00064                 MemoryManagerType&  theMemoryManager)
00065     {
00066         if (theArg != 0)
00067         {
00068             (*this)(*theArg);
00069 
00070             theMemoryManager.deallocate(theArg);
00071         }
00072     }
00073 
00074     void
00075     operator()(
00076                 const Type*         theArg,
00077                 MemoryManagerType&  theMemoryManager)
00078     {
00079         (*this)(const_cast<Type*>(theArg), theMemoryManager);
00080     }
00081 };
00082 
00083 
00084 
00085 template<class Type>
00086 XalanDestroyFunctor<Type>
00087 makeXalanDestroyFunctor(const Type*     /* theType */)
00088 {
00089     return XalanDestroyFunctor<Type>();
00090 }
00091 
00092 
00093 
00097 template <class Type>
00098 #if defined(XALAN_NO_STD_NAMESPACE)
00099 struct DeleteFunctor : public unary_function<const Type*, void>
00100 #else
00101 struct DeleteFunctor : public std::unary_function<const Type*, void>
00102 #endif
00103 {
00104 #if defined(XALAN_NO_STD_NAMESPACE)
00105     typedef unary_function<const Type*, void>       BaseClassType;
00106 #else
00107     typedef std::unary_function<const Type*, void>  BaseClassType;
00108 #endif
00109 
00110     typedef typename BaseClassType::result_type     result_type;
00111     typedef typename BaseClassType::argument_type   argument_type;
00112 
00113     DeleteFunctor(MemoryManagerType&    theManager) :
00114         m_memoryManager(theManager)
00115     {
00116     }
00117 
00123     result_type
00124     operator()(argument_type    thePointer) const
00125     {
00126         makeXalanDestroyFunctor(thePointer)(thePointer, m_memoryManager);
00127     }
00128 
00129 private:
00130 
00131    MemoryManagerType&   m_memoryManager;
00132 };
00133 
00134 
00135 
00136 #if !defined(XALAN_SGI_BASED_STL)
00137 
00142 template <class PairType>
00143 #if defined(XALAN_NO_STD_NAMESPACE)
00144 struct select1st : public unary_function<PairType, PairType::first_type>
00145 #else
00146 struct select1st : public std::unary_function<PairType, typename PairType::first_type>
00147 #endif
00148 {
00149 #if defined(XALAN_NO_STD_NAMESPACE)
00150     typedef unary_function<PairType, PairType::first_type>  BaseClassType;
00151 #else
00152     typedef std::unary_function<PairType, typename PairType::first_type>    BaseClassType;
00153 #endif
00154 
00155     typedef typename BaseClassType::result_type     result_type;
00156     typedef typename BaseClassType::argument_type   argument_type;
00157 
00158     typedef PairType                                value_type;
00159 
00166     result_type
00167     operator()(const argument_type&     thePair) const
00168     {
00169         return thePair.first;
00170     }
00171 };
00172 
00173 
00174 
00179 template <class PairType>
00180 #if defined(XALAN_NO_STD_NAMESPACE)
00181 struct select2nd : public unary_function<PairType, PairType::second_type>
00182 #else
00183 struct select2nd : public std::unary_function<PairType, typename PairType::second_type>
00184 #endif
00185 {
00186 #if defined(XALAN_NO_STD_NAMESPACE)
00187     typedef unary_function<PairType, PairType::second_type> BaseClassType;
00188 #else
00189     typedef std::unary_function<PairType, typename PairType::second_type>   BaseClassType;
00190 #endif
00191 
00192     typedef typename BaseClassType::result_type     result_type;
00193     typedef typename BaseClassType::argument_type   argument_type;
00194 
00195     typedef PairType                                value_type;
00196 
00203     result_type
00204     operator()(const argument_type&     thePair) const
00205     {
00206         return thePair.second;
00207     }
00208 };
00209 
00210 #endif
00211 
00212 
00213 
00217 template <class Type>
00218 #if defined(XALAN_NO_STD_NAMESPACE)
00219 struct ClearFunctor : public unary_function<Type, void>
00220 #else
00221 struct ClearFunctor : public std::unary_function<Type, void>
00222 #endif
00223 {
00224 #if defined(XALAN_NO_STD_NAMESPACE)
00225     typedef unary_function<Type, void>      BaseClassType;
00226 #else
00227     typedef std::unary_function<Type, void> BaseClassType;
00228 #endif
00229 
00230     typedef typename BaseClassType::result_type     result_type;
00231     typedef typename BaseClassType::argument_type   argument_type;
00232 
00233     typedef Type                                    value_type;
00234 
00241     result_type
00242     operator()(argument_type&   theArg) const
00243     {
00244         theArg.clear();
00245     }
00246 };
00247 
00248 
00249 
00253 template <class T>
00254 #if defined(XALAN_NO_STD_NAMESPACE)
00255 struct MapValueDeleteFunctor : public unary_function<const typename T::value_type&, void>
00256 #else
00257 struct MapValueDeleteFunctor : public std::unary_function<const typename T::value_type&, void>
00258 #endif
00259 {
00260 #if defined(XALAN_NO_STD_NAMESPACE)
00261     typedef unary_function<const typename T::value_type&, void>         BaseClassType;
00262 #else
00263     typedef std::unary_function<const typename T::value_type&, void>    BaseClassType;
00264 #endif
00265 
00266     typedef typename BaseClassType::result_type     result_type;
00267     typedef typename BaseClassType::argument_type   argument_type;
00268 
00269     MapValueDeleteFunctor(MemoryManagerType&    theManager) :
00270         m_memoryManager(theManager)
00271     {
00272     }
00273 
00280     result_type
00281     operator()(argument_type    thePair) const
00282     {
00283         makeXalanDestroyFunctor(thePair.second)(thePair.second, m_memoryManager);
00284     }
00285 
00286 private:
00287 
00288     MemoryManagerType&  m_memoryManager;
00289 };
00290 
00291 
00292 
00293 template<class MapType>
00294 MapValueDeleteFunctor<MapType>
00295 makeMapValueDeleteFunctor(MapType&   theMap)
00296 {
00297     return MapValueDeleteFunctor<MapType>(theMap.getMemoryManager());
00298 }
00299 
00300 
00301 
00311 template<class T>
00312 #if defined(XALAN_NO_STD_NAMESPACE)
00313 struct less_null_terminated_arrays : public binary_function<const T*, const T*, bool>
00314 #else
00315 struct less_null_terminated_arrays : public std::binary_function<const T*, const T*, bool>
00316 #endif
00317 {
00318 #if defined(XALAN_NO_STD_NAMESPACE)
00319     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00320 #else
00321     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00322 #endif
00323 
00324     typedef typename BaseClassType::result_type             result_type;
00325     typedef typename BaseClassType::first_argument_type     first_argument_type;
00326     typedef typename BaseClassType::second_argument_type    second_argument_type;
00327 
00336     result_type
00337     operator()(
00338             first_argument_type     theLHS,
00339             second_argument_type    theRHS) const
00340     {
00341         while(*theLHS && *theRHS)
00342         {
00343             if (*theLHS != *theRHS)
00344             {
00345                 break;
00346             }
00347             else
00348             {
00349                 theLHS++;
00350                 theRHS++;
00351             }
00352         }
00353 
00354         return *theLHS < *theRHS ? true : false;
00355     }
00356 };
00357 
00358 
00359 
00360 template<class T>
00361 struct equal_null_terminated_arrays : public XALAN_STD_QUALIFIER binary_function<const T*, const T*, bool>
00362 {
00363     typedef XALAN_STD_QUALIFIER binary_function<const T*, const T*, bool>       BaseClassType;
00364 
00365     typedef typename BaseClassType::result_type             result_type;
00366     typedef typename BaseClassType::first_argument_type     first_argument_type;
00367     typedef typename BaseClassType::second_argument_type    second_argument_type;
00376     result_type
00377     operator()(
00378             first_argument_type     theLHS,
00379             second_argument_type    theRHS) const
00380     {
00381         while(*theLHS && *theRHS)
00382         {
00383             if (*theLHS != *theRHS)
00384             {
00385                 return false;
00386             }
00387             else
00388             {
00389                 ++theLHS;
00390                 ++theRHS;
00391             }
00392         }
00393 
00394         if (*theLHS || *theRHS)
00395         {
00396             return false;
00397         }
00398         else
00399         {
00400             return true;
00401         }
00402     }
00403 };
00404 
00405 
00406 
00407 template <class T>
00408 struct hash_null_terminated_arrays : public XALAN_STD_QUALIFIER unary_function<const T*, size_t>
00409 {
00410     typedef XALAN_STD_QUALIFIER unary_function<const T*, size_t>        BaseClassType;
00411 
00412     typedef typename BaseClassType::result_type             result_type;
00413     typedef typename BaseClassType::argument_type       argument_type;
00414 
00415     result_type
00416     operator() (argument_type   theKey) const
00417     {
00418         const T*        theRawBuffer = theKey;
00419 
00420         result_type     theHashValue = 0; 
00421 
00422         while (*theRawBuffer)
00423         {
00424             theHashValue = 5 * theHashValue + *theRawBuffer;
00425             ++theRawBuffer;
00426         }
00427 
00428         return ++theHashValue;
00429     }
00430 };
00431 
00432 
00433 
00434 template<>
00435 struct XalanMapKeyTraits<const XalanDOMChar*>
00436 {
00437     typedef hash_null_terminated_arrays<XalanDOMChar>   Hasher;
00438     typedef equal_null_terminated_arrays<XalanDOMChar>  Comparator;
00439 };
00440 
00441 
00442 
00443 template<class CollectionType>
00444 class CollectionClearGuard
00445 {
00446 public:
00447 
00448     CollectionClearGuard(CollectionType&    theCollection) :
00449         m_collection(&theCollection)
00450     {
00451     }
00452 
00453     ~CollectionClearGuard()
00454     {
00455         if (m_collection != 0)
00456         {
00457             m_collection->clear();
00458         }
00459     }
00460 
00461     void
00462     release()
00463     {
00464         m_collection = 0;
00465     }
00466 
00467 private:
00468 
00469     // Not implemented...
00470     CollectionClearGuard(const CollectionClearGuard<CollectionType>&);
00471 
00472     CollectionClearGuard<CollectionType>&
00473     operator=(const CollectionClearGuard<CollectionType>&);
00474 
00475     // Data members...
00476     CollectionType*     m_collection;
00477 };
00478 
00479 
00480 
00481 template<class CollectionType, class DeleteFunctorType>
00482 class CollectionDeleteGuard
00483 {
00484 public:
00485 
00486     CollectionDeleteGuard(CollectionType&   theCollection) :
00487         m_collection(&theCollection)
00488     {
00489     }
00490 
00491     ~CollectionDeleteGuard()
00492     {
00493         if (m_collection != 0)
00494         {
00495 #if !defined(XALAN_NO_STD_NAMESPACE)
00496             using std::for_each;
00497 #endif
00498 
00499             // Delete all of the objects in the temp vector.
00500             for_each(m_collection->begin(),
00501                      m_collection->end(),
00502                      DeleteFunctorType(m_collection->getMemoryManager()));
00503         }
00504     }
00505 
00506     void
00507     release()
00508     {
00509         m_collection = 0;
00510     }
00511 
00512 private:
00513 
00514     // Not implemented...
00515     CollectionDeleteGuard(const CollectionDeleteGuard<CollectionType, DeleteFunctorType>&);
00516 
00517     CollectionDeleteGuard<CollectionType, DeleteFunctorType>&
00518     operator=(const CollectionDeleteGuard<CollectionType, DeleteFunctorType>&);
00519 
00520     // Data members...
00521     CollectionType*     m_collection;
00522 };
00523 
00524 
00525 
00526 template<class T>
00527 #if defined(XALAN_NO_STD_NAMESPACE)
00528 struct pointer_equals : public binary_function<const T*, const T*, bool>
00529 #else
00530 struct pointer_equals : public std::binary_function<const T*, const T*, bool>
00531 #endif
00532 {
00533 #if defined(XALAN_NO_STD_NAMESPACE)
00534     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00535 #else
00536     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00537 #endif
00538 
00539     typedef typename BaseClassType::result_type             result_type;
00540     typedef typename BaseClassType::first_argument_type     first_argument_type;
00541     typedef typename BaseClassType::second_argument_type    second_argument_type;
00542 
00543     result_type
00544     operator()(
00545         first_argument_type     theLHS,
00546         second_argument_type    theRHS) const
00547     {
00548         assert(theLHS != 0 && theRHS != 0);
00549 
00550         return *theLHS == *theRHS;
00551     }
00552 };
00553 
00554 
00555 
00556 template<class T>
00557 #if defined(XALAN_NO_STD_NAMESPACE)
00558 struct pointer_equals_predicate : public unary_function<const T*, bool>
00559 #else
00560 struct pointer_equals_predicate : public std::unary_function<const T*, bool>
00561 #endif
00562 {
00563 #if defined(XALAN_NO_STD_NAMESPACE)
00564     typedef unary_function<const T*, bool>          BaseClassType;
00565 #else
00566     typedef std::unary_function<const T*, bool>     BaseClassType;
00567 #endif
00568 
00569     typedef typename BaseClassType::result_type     result_type;
00570     typedef typename BaseClassType::argument_type   argument_type;
00571 
00572     pointer_equals_predicate(argument_type  theArg) :
00573         m_arg(theArg)
00574     {
00575     }
00576 
00577     result_type
00578     operator()(
00579         argument_type   theOther) const
00580     {
00581         assert(theOther != 0);
00582 
00583         return *theOther == *m_arg;
00584     }
00585 
00586 private:
00587 
00588     const argument_type     m_arg;
00589 };
00590 
00591 
00592 
00593 template<class T>
00594 #if defined(XALAN_NO_STD_NAMESPACE)
00595 struct pointer_less : public binary_function<const T*, const T*, bool>
00596 #else
00597 struct pointer_less : public std::binary_function<const T*, const T*, bool>
00598 #endif
00599 {
00600 #if defined(XALAN_NO_STD_NAMESPACE)
00601     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00602 #else
00603     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00604 #endif
00605 
00606     typedef typename BaseClassType::result_type             result_type;
00607     typedef typename BaseClassType::first_argument_type     first_argument_type;
00608     typedef typename BaseClassType::second_argument_type    second_argument_type;
00609 
00610     result_type
00611     operator()(
00612         first_argument_type     theLHS,
00613         second_argument_type    theRHS) const
00614     {
00615         assert(theLHS != 0 && theRHS != 0);
00616 
00617 #if !defined(XALAN_NO_STD_NAMESPACE)
00618         using std::less;
00619 #endif
00620 
00621         return less<T>()(*theLHS, *theRHS);
00622     }
00623 };
00624 
00625 
00626 
00627 template<class T>
00628 struct pointer_equal : public XALAN_STD_QUALIFIER binary_function<const T*, const T*, bool>
00629 {
00630     typedef XALAN_STD_QUALIFIER binary_function<const T*, const T*, bool> BaseClassType;
00631 
00632     typedef typename BaseClassType::result_type             result_type;
00633     typedef typename BaseClassType::first_argument_type     first_argument_type;
00634     typedef typename BaseClassType::second_argument_type    second_argument_type;
00635 
00636     result_type
00637     operator()(
00638         first_argument_type     theLHS,
00639         second_argument_type    theRHS) const
00640     {
00641         assert(theLHS != 0 && theRHS != 0);
00642         return XALAN_STD_QUALIFIER equal_to<T>()(*theLHS, *theRHS);
00643     }
00644 };
00645 
00646 
00647 
00648 
00649 XALAN_CPP_NAMESPACE_END
00650 
00651 
00652 
00653 #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