Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.8

Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

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 XALAN_CPP_NAMESPACE_BEGIN
00032 
00033 
00034 
00038 template <class T>
00039 #if defined(XALAN_NO_STD_NAMESPACE)
00040 struct DeleteFunctor : public unary_function<const T*, void>
00041 #else
00042 struct DeleteFunctor : public std::unary_function<const T*, void>
00043 #endif
00044 {
00045 #if defined(XALAN_NO_STD_NAMESPACE)
00046     typedef unary_function<const T*, void>  BaseClassType;
00047 #else
00048     typedef std::unary_function<const T*, void> BaseClassType;
00049 #endif
00050 
00051     typedef typename BaseClassType::result_type     result_type;
00052     typedef typename BaseClassType::argument_type   argument_type;
00053 
00059     result_type
00060     operator()(argument_type    thePointer) const
00061     {
00062 #if defined(XALAN_CANNOT_DELETE_CONST)
00063         delete (T*)thePointer;
00064 #else
00065         delete thePointer;
00066 #endif
00067     }
00068 };
00069 
00070 
00071 
00072 #if !defined(XALAN_SGI_BASED_STL)
00073 
00078 template <class PairType>
00079 #if defined(XALAN_NO_STD_NAMESPACE)
00080 struct select1st : public unary_function<PairType, PairType::first_type>
00081 #else
00082 struct select1st : public std::unary_function<PairType, typename PairType::first_type>
00083 #endif
00084 {
00085 #if defined(XALAN_NO_STD_NAMESPACE)
00086     typedef unary_function<PairType, PairType::first_type>  BaseClassType;
00087 #else
00088     typedef std::unary_function<PairType, typename PairType::first_type>    BaseClassType;
00089 #endif
00090 
00091     typedef typename BaseClassType::result_type     result_type;
00092     typedef typename BaseClassType::argument_type   argument_type;
00093 
00094     typedef PairType                                value_type;
00095 
00102     result_type
00103     operator()(const argument_type&     thePair) const
00104     {
00105         return thePair.first;
00106     }
00107 };
00108 
00109 
00110 
00115 template <class PairType>
00116 #if defined(XALAN_NO_STD_NAMESPACE)
00117 struct select2nd : public unary_function<PairType, PairType::second_type>
00118 #else
00119 struct select2nd : public std::unary_function<PairType, typename PairType::second_type>
00120 #endif
00121 {
00122 #if defined(XALAN_NO_STD_NAMESPACE)
00123     typedef unary_function<PairType, PairType::second_type> BaseClassType;
00124 #else
00125     typedef std::unary_function<PairType, typename PairType::second_type>   BaseClassType;
00126 #endif
00127 
00128     typedef typename BaseClassType::result_type     result_type;
00129     typedef typename BaseClassType::argument_type   argument_type;
00130 
00131     typedef PairType                                value_type;
00132 
00139     result_type
00140     operator()(const argument_type&     thePair) const
00141     {
00142         return thePair.second;
00143     }
00144 };
00145 
00146 #endif
00147 
00148 
00149 
00153 template <class Type>
00154 #if defined(XALAN_NO_STD_NAMESPACE)
00155 struct ClearFunctor : public unary_function<Type, void>
00156 #else
00157 struct ClearFunctor : public std::unary_function<Type, void>
00158 #endif
00159 {
00160 #if defined(XALAN_NO_STD_NAMESPACE)
00161     typedef unary_function<Type, void>      BaseClassType;
00162 #else
00163     typedef std::unary_function<Type, void> BaseClassType;
00164 #endif
00165 
00166     typedef typename BaseClassType::result_type     result_type;
00167     typedef typename BaseClassType::argument_type   argument_type;
00168 
00169     typedef Type                                    value_type;
00170 
00177     result_type
00178     operator()(argument_type&   theArg) const
00179     {
00180         theArg.clear();
00181     }
00182 };
00183 
00184 
00185 
00189 template <class T>
00190 #if defined(XALAN_NO_STD_NAMESPACE)
00191 struct MapValueDeleteFunctor : public unary_function<const typename T::value_type&, void>
00192 #else
00193 struct MapValueDeleteFunctor : public std::unary_function<const typename T::value_type&, void>
00194 #endif
00195 {
00196 #if defined(XALAN_NO_STD_NAMESPACE)
00197     typedef unary_function<const typename T::value_type&, void>     BaseClassType;
00198 #else
00199     typedef std::unary_function<const typename T::value_type&, void>    BaseClassType;
00200 #endif
00201 
00202     typedef typename BaseClassType::result_type     result_type;
00203     typedef typename BaseClassType::argument_type   argument_type;
00204 
00211     result_type
00212     operator()(argument_type    thePair) const
00213     {
00214         delete thePair.second;
00215     }
00216 };
00217 
00218 
00219 
00220 template<class T>
00221 MapValueDeleteFunctor<T>
00222 makeMapValueDeleteFunctor(const T&  /* theMap */)
00223 {
00224     return MapValueDeleteFunctor<T>();
00225 }
00226 
00227 
00228 
00238 template<class T>
00239 #if defined(XALAN_NO_STD_NAMESPACE)
00240 struct less_null_terminated_arrays : public binary_function<const T*, const T*, bool>
00241 #else
00242 struct less_null_terminated_arrays : public std::binary_function<const T*, const T*, bool>
00243 #endif
00244 {
00245 #if defined(XALAN_NO_STD_NAMESPACE)
00246     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00247 #else
00248     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00249 #endif
00250 
00251     typedef typename BaseClassType::result_type             result_type;
00252     typedef typename BaseClassType::first_argument_type     first_argument_type;
00253     typedef typename BaseClassType::second_argument_type    second_argument_type;
00254 
00263     result_type
00264     operator()(
00265             first_argument_type     theLHS,
00266             second_argument_type    theRHS) const
00267     {
00268         while(*theLHS && *theRHS)
00269         {
00270             if (*theLHS != *theRHS)
00271             {
00272                 break;
00273             }
00274             else
00275             {
00276                 theLHS++;
00277                 theRHS++;
00278             }
00279         }
00280 
00281         return *theLHS < *theRHS ? true : false;
00282     }
00283 };
00284 
00285 
00286 
00287 template<class CollectionType>
00288 class CollectionClearGuard
00289 {
00290 public:
00291 
00292     CollectionClearGuard(CollectionType&    theCollection) :
00293         m_collection(&theCollection)
00294     {
00295     }
00296 
00297     ~CollectionClearGuard()
00298     {
00299         if (m_collection != 0)
00300         {
00301             m_collection->clear();
00302         }
00303     }
00304 
00305     void
00306     release()
00307     {
00308         m_collection = 0;
00309     }
00310 
00311 private:
00312 
00313     // Not implemented...
00314     CollectionClearGuard(const CollectionClearGuard<CollectionType>&);
00315 
00316     CollectionClearGuard<CollectionType>&
00317     operator=(const CollectionClearGuard<CollectionType>&);
00318 
00319     // Data members...
00320     CollectionType*     m_collection;
00321 };
00322 
00323 
00324 
00325 template<class CollectionType, class DeleteFunctorType>
00326 class CollectionDeleteGuard
00327 {
00328 public:
00329 
00330     CollectionDeleteGuard(CollectionType&   theCollection) :
00331         m_collection(&theCollection)
00332     {
00333     }
00334 
00335     ~CollectionDeleteGuard()
00336     {
00337         if (m_collection != 0)
00338         {
00339 #if !defined(XALAN_NO_STD_NAMESPACE)
00340             using std::for_each;
00341 #endif
00342 
00343             // Delete all of the objects in the temp vector.
00344             for_each(m_collection->begin(),
00345                      m_collection->end(),
00346                      DeleteFunctorType());
00347         }
00348     }
00349 
00350     void
00351     release()
00352     {
00353         m_collection = 0;
00354     }
00355 
00356 private:
00357 
00358     // Not implemented...
00359     CollectionDeleteGuard(const CollectionDeleteGuard<CollectionType, DeleteFunctorType>&);
00360 
00361     CollectionDeleteGuard<CollectionType, DeleteFunctorType>&
00362     operator=(const CollectionDeleteGuard<CollectionType, DeleteFunctorType>&);
00363 
00364     // Data members...
00365     CollectionType*     m_collection;
00366 };
00367 
00368 
00369 
00370 template<class T>
00371 #if defined(XALAN_NO_STD_NAMESPACE)
00372 struct pointer_equals : public binary_function<const T*, const T*, bool>
00373 #else
00374 struct pointer_equals : public std::binary_function<const T*, const T*, bool>
00375 #endif
00376 {
00377 #if defined(XALAN_NO_STD_NAMESPACE)
00378     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00379 #else
00380     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00381 #endif
00382 
00383     typedef typename BaseClassType::result_type             result_type;
00384     typedef typename BaseClassType::first_argument_type     first_argument_type;
00385     typedef typename BaseClassType::second_argument_type    second_argument_type;
00386 
00387     result_type
00388     operator()(
00389         first_argument_type     theLHS,
00390         second_argument_type    theRHS) const
00391     {
00392         assert(theLHS != 0 && theRHS != 0);
00393 
00394         return *theLHS == *theRHS;
00395     }
00396 };
00397 
00398 
00399 
00400 template<class T>
00401 #if defined(XALAN_NO_STD_NAMESPACE)
00402 struct pointer_equals_predicate : public unary_function<const T*, bool>
00403 #else
00404 struct pointer_equals_predicate : public std::unary_function<const T*, bool>
00405 #endif
00406 {
00407 #if defined(XALAN_NO_STD_NAMESPACE)
00408     typedef unary_function<const T*, bool>          BaseClassType;
00409 #else
00410     typedef std::unary_function<const T*, bool>     BaseClassType;
00411 #endif
00412 
00413     typedef typename BaseClassType::result_type     result_type;
00414     typedef typename BaseClassType::argument_type   argument_type;
00415 
00416     pointer_equals_predicate(argument_type  theArg) :
00417         m_arg(theArg)
00418     {
00419     }
00420 
00421     result_type
00422     operator()(
00423         argument_type   theOther) const
00424     {
00425         assert(theOther != 0);
00426 
00427         return *theOther == *m_arg;
00428     }
00429 
00430 private:
00431 
00432     const argument_type     m_arg;
00433 };
00434 
00435 
00436 
00437 template<class T>
00438 #if defined(XALAN_NO_STD_NAMESPACE)
00439 struct pointer_less : public binary_function<const T*, const T*, bool>
00440 #else
00441 struct pointer_less : public std::binary_function<const T*, const T*, bool>
00442 #endif
00443 {
00444 #if defined(XALAN_NO_STD_NAMESPACE)
00445     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00446 #else
00447     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00448 #endif
00449 
00450     typedef typename BaseClassType::result_type             result_type;
00451     typedef typename BaseClassType::first_argument_type     first_argument_type;
00452     typedef typename BaseClassType::second_argument_type    second_argument_type;
00453 
00454     result_type
00455     operator()(
00456         first_argument_type     theLHS,
00457         second_argument_type    theRHS) const
00458     {
00459         assert(theLHS != 0 && theRHS != 0);
00460 
00461 #if !defined(XALAN_NO_STD_NAMESPACE)
00462         using std::less;
00463 #endif
00464 
00465         return less<T>()(*theLHS, *theRHS);
00466     }
00467 };
00468 
00469 
00470 
00471 XALAN_CPP_NAMESPACE_END
00472 
00473 
00474 
00475 #endif  // STLHELPERS_HEADER_GUARD_1357924680

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.8
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.