Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.6

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  * The Apache Software License, Version 1.1
00003  *
00004  *
00005  * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
00006  * reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer. 
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. The end-user documentation included with the redistribution,
00021  *    if any, must include the following acknowledgment:  
00022  *       "This product includes software developed by the
00023  *        Apache Software Foundation (http://www.apache.org/)."
00024  *    Alternately, this acknowledgment may appear in the software itself,
00025  *    if and wherever such third-party acknowledgments normally appear.
00026  *
00027  * 4. The names "Xalan" and "Apache Software Foundation" must
00028  *    not be used to endorse or promote products derived from this
00029  *    software without prior written permission. For written 
00030  *    permission, please contact apache@apache.org.
00031  *
00032  * 5. Products derived from this software may not be called "Apache",
00033  *    nor may "Apache" appear in their name, without prior written
00034  *    permission of the Apache Software Foundation.
00035  *
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00039  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00040  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00041  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00042  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00043  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00044  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00045  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00046  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00047  * SUCH DAMAGE.
00048  * ====================================================================
00049  *
00050  * This software consists of voluntary contributions made by many
00051  * individuals on behalf of the Apache Software Foundation and was
00052  * originally based on software copyright (c) 1999, International
00053  * Business Machines, Inc., http://www.ibm.com.  For more
00054  * information on the Apache Software Foundation, please see
00055  * <http://www.apache.org/>.
00056  */
00057 #if !defined(STLHELPERS_HEADER_GUARD_1357924680)
00058 #define STLHELPERS_HEADER_GUARD_1357924680
00059 
00060 
00061 
00062 // Base include file.  Must be first.
00063 #include <xalanc/Include/PlatformDefinitions.hpp>
00064 
00065 
00066 
00067 #include <algorithm>
00068 #include <functional>
00069 
00070 
00071 
00072 XALAN_CPP_NAMESPACE_BEGIN
00073 
00074 
00075 
00079 template <class T>
00080 #if defined(XALAN_NO_STD_NAMESPACE)
00081 struct DeleteFunctor : public unary_function<const T*, void>
00082 #else
00083 struct DeleteFunctor : public std::unary_function<const T*, void>
00084 #endif
00085 {
00086 #if defined(XALAN_NO_STD_NAMESPACE)
00087     typedef unary_function<const T*, void>  BaseClassType;
00088 #else
00089     typedef std::unary_function<const T*, void> BaseClassType;
00090 #endif
00091 
00092     typedef typename BaseClassType::result_type     result_type;
00093     typedef typename BaseClassType::argument_type   argument_type;
00094 
00100     result_type
00101 	operator()(argument_type   thePointer) const
00102     {
00103 #if defined(XALAN_CANNOT_DELETE_CONST)
00104         delete (T*)thePointer;
00105 #else
00106         delete thePointer;
00107 #endif
00108     }
00109 };
00110 
00111 
00112 
00113 #if !defined(XALAN_SGI_BASED_STL)
00114 
00119 template <class PairType>
00120 #if defined(XALAN_NO_STD_NAMESPACE)
00121 struct select1st : public unary_function<PairType, PairType::first_type>
00122 #else
00123 struct select1st : public std::unary_function<PairType, typename PairType::first_type>
00124 #endif
00125 {
00126 #if defined(XALAN_NO_STD_NAMESPACE)
00127     typedef unary_function<PairType, PairType::first_type>  BaseClassType;
00128 #else
00129     typedef std::unary_function<PairType, typename PairType::first_type>    BaseClassType;
00130 #endif
00131 
00132     typedef typename BaseClassType::result_type     result_type;
00133     typedef typename BaseClassType::argument_type   argument_type;
00134 
00135     typedef PairType                                value_type;
00136 
00143     result_type
00144 	operator()(const argument_type&        thePair) const
00145     {
00146         return thePair.first;
00147     }
00148 };
00149 
00150 
00151 
00156 template <class PairType>
00157 #if defined(XALAN_NO_STD_NAMESPACE)
00158 struct select2nd : public unary_function<PairType, PairType::second_type>
00159 #else
00160 struct select2nd : public std::unary_function<PairType, typename PairType::second_type>
00161 #endif
00162 {
00163 #if defined(XALAN_NO_STD_NAMESPACE)
00164     typedef unary_function<PairType, PairType::second_type> BaseClassType;
00165 #else
00166     typedef std::unary_function<PairType, typename PairType::second_type>   BaseClassType;
00167 #endif
00168 
00169     typedef typename BaseClassType::result_type     result_type;
00170     typedef typename BaseClassType::argument_type   argument_type;
00171 
00172     typedef PairType                                value_type;
00173 
00180     result_type
00181 	operator()(const argument_type&        thePair) const
00182     {
00183         return thePair.second;
00184     }
00185 };
00186 
00187 #endif
00188 
00189 
00190 
00194 template <class Type>
00195 #if defined(XALAN_NO_STD_NAMESPACE)
00196 struct ClearFunctor : public unary_function<Type, void>
00197 #else
00198 struct ClearFunctor : public std::unary_function<Type, void>
00199 #endif
00200 {
00201 #if defined(XALAN_NO_STD_NAMESPACE)
00202     typedef unary_function<Type, void>      BaseClassType;
00203 #else
00204     typedef std::unary_function<Type, void> BaseClassType;
00205 #endif
00206 
00207     typedef typename BaseClassType::result_type     result_type;
00208     typedef typename BaseClassType::argument_type   argument_type;
00209 
00210     typedef Type                                    value_type;
00211 
00218     result_type
00219 	operator()(argument_type&  theArg) const
00220     {
00221         theArg.clear();
00222     }
00223 };
00224 
00225 
00226 
00230 template <class T>
00231 #if defined(XALAN_NO_STD_NAMESPACE)
00232 struct MapValueDeleteFunctor : public unary_function<const typename T::value_type&, void>
00233 #else
00234 struct MapValueDeleteFunctor : public std::unary_function<const typename T::value_type&, void>
00235 #endif
00236 {
00237 #if defined(XALAN_NO_STD_NAMESPACE)
00238     typedef unary_function<const typename T::value_type&, void>     BaseClassType;
00239 #else
00240     typedef std::unary_function<const typename T::value_type&, void>    BaseClassType;
00241 #endif
00242 
00243     typedef typename BaseClassType::result_type     result_type;
00244     typedef typename BaseClassType::argument_type   argument_type;
00245 
00252     result_type
00253 	operator()(argument_type   thePair) const
00254     {
00255         delete thePair.second;
00256     }
00257 };
00258 
00259 
00260 
00261 template<class T>
00262 MapValueDeleteFunctor<T>
00263 makeMapValueDeleteFunctor(const T&  /* theMap */)
00264 {
00265     return MapValueDeleteFunctor<T>();
00266 }
00267 
00268 
00269 
00279 template<class T>
00280 #if defined(XALAN_NO_STD_NAMESPACE)
00281 struct less_null_terminated_arrays : public binary_function<const T*, const T*, bool>
00282 #else
00283 struct less_null_terminated_arrays : public std::binary_function<const T*, const T*, bool>
00284 #endif
00285 {
00286 #if defined(XALAN_NO_STD_NAMESPACE)
00287     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00288 #else
00289     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00290 #endif
00291 
00292     typedef typename BaseClassType::result_type             result_type;
00293     typedef typename BaseClassType::first_argument_type     first_argument_type;
00294     typedef typename BaseClassType::second_argument_type    second_argument_type;
00295 
00304     result_type
00305 	operator()(
00306             first_argument_type     theLHS,
00307             second_argument_type    theRHS) const
00308     {
00309         while(*theLHS && *theRHS)
00310         {
00311             if (*theLHS != *theRHS)
00312             {
00313                 break;
00314             }
00315             else
00316             {
00317                 theLHS++;
00318                 theRHS++;
00319             }
00320         }
00321 
00322         return *theLHS < *theRHS ? true : false;
00323     }
00324 };
00325 
00326 
00327 
00328 template<class CollectionType>
00329 class CollectionClearGuard
00330 {
00331 public:
00332 
00333     CollectionClearGuard(CollectionType&    theCollection) :
00334         m_collection(&theCollection)
00335     {
00336     }
00337 
00338     ~CollectionClearGuard()
00339     {
00340         if (m_collection != 0)
00341         {
00342             m_collection->clear();
00343         }
00344     }
00345 
00346     void
00347     release()
00348     {
00349         m_collection = 0;
00350     }
00351 
00352 private:
00353 
00354     // Not implemented...
00355     CollectionClearGuard(const CollectionClearGuard<CollectionType>&);
00356 
00357     CollectionClearGuard<CollectionType>&
00358     operator=(const CollectionClearGuard<CollectionType>&);
00359 
00360     // Data members...
00361     CollectionType*     m_collection;
00362 };
00363 
00364 
00365 
00366 template<class CollectionType, class DeleteFunctorType>
00367 class CollectionDeleteGuard
00368 {
00369 public:
00370 
00371     CollectionDeleteGuard(CollectionType&   theCollection) :
00372         m_collection(&theCollection)
00373     {
00374     }
00375 
00376     ~CollectionDeleteGuard()
00377     {
00378         if (m_collection != 0)
00379         {
00380 #if !defined(XALAN_NO_STD_NAMESPACE)
00381             using std::for_each;
00382 #endif
00383 
00384             // Delete all of the objects in the temp vector.
00385             for_each(m_collection->begin(),
00386                      m_collection->end(),
00387                      DeleteFunctorType());
00388         }
00389     }
00390 
00391     void
00392     release()
00393     {
00394         m_collection = 0;
00395     }
00396 
00397 private:
00398 
00399     // Not implemented...
00400     CollectionDeleteGuard(const CollectionDeleteGuard<CollectionType, DeleteFunctorType>&);
00401 
00402     CollectionDeleteGuard<CollectionType, DeleteFunctorType>&
00403     operator=(const CollectionDeleteGuard<CollectionType, DeleteFunctorType>&);
00404 
00405     // Data members...
00406     CollectionType*     m_collection;
00407 };
00408 
00409 
00410 
00411 template<class T>
00412 #if defined(XALAN_NO_STD_NAMESPACE)
00413 struct pointer_equals : public binary_function<const T*, const T*, bool>
00414 #else
00415 struct pointer_equals : public std::binary_function<const T*, const T*, bool>
00416 #endif
00417 {
00418 #if defined(XALAN_NO_STD_NAMESPACE)
00419     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00420 #else
00421     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00422 #endif
00423 
00424     typedef typename BaseClassType::result_type             result_type;
00425     typedef typename BaseClassType::first_argument_type     first_argument_type;
00426     typedef typename BaseClassType::second_argument_type    second_argument_type;
00427 
00428     result_type
00429 	operator()(
00430         first_argument_type     theLHS,
00431         second_argument_type    theRHS) const
00432     {
00433         assert(theLHS != 0 && theRHS != 0);
00434 
00435         return *theLHS == *theRHS;
00436     }
00437 };
00438 
00439 
00440 
00441 template<class T>
00442 #if defined(XALAN_NO_STD_NAMESPACE)
00443 struct pointer_equals_predicate : public unary_function<const T*, bool>
00444 #else
00445 struct pointer_equals_predicate : public std::unary_function<const T*, bool>
00446 #endif
00447 {
00448 #if defined(XALAN_NO_STD_NAMESPACE)
00449     typedef unary_function<const T*, bool>          BaseClassType;
00450 #else
00451     typedef std::unary_function<const T*, bool>     BaseClassType;
00452 #endif
00453 
00454     typedef typename BaseClassType::result_type     result_type;
00455     typedef typename BaseClassType::argument_type   argument_type;
00456 
00457     pointer_equals_predicate(argument_type  theArg) :
00458         m_arg(theArg)
00459     {
00460     }
00461 
00462     result_type
00463 	operator()(
00464         argument_type   theOther) const
00465     {
00466         assert(theOther != 0);
00467 
00468         return *theOther == *m_arg;
00469     }
00470 
00471 private:
00472 
00473     const argument_type     m_arg;
00474 };
00475 
00476 
00477 
00478 template<class T>
00479 #if defined(XALAN_NO_STD_NAMESPACE)
00480 struct pointer_less : public binary_function<const T*, const T*, bool>
00481 #else
00482 struct pointer_less : public std::binary_function<const T*, const T*, bool>
00483 #endif
00484 {
00485 #if defined(XALAN_NO_STD_NAMESPACE)
00486     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00487 #else
00488     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00489 #endif
00490 
00491     typedef typename BaseClassType::result_type             result_type;
00492     typedef typename BaseClassType::first_argument_type     first_argument_type;
00493     typedef typename BaseClassType::second_argument_type    second_argument_type;
00494 
00495     result_type
00496 	operator()(
00497         first_argument_type     theLHS,
00498         second_argument_type    theRHS) const
00499     {
00500         assert(theLHS != 0 && theRHS != 0);
00501 
00502 #if !defined(XALAN_NO_STD_NAMESPACE)
00503         using std::less;
00504 #endif
00505 
00506         return less<T>()(*theLHS, *theRHS);
00507     }
00508 };
00509 
00510 
00511 
00512 XALAN_CPP_NAMESPACE_END
00513 
00514 
00515 
00516 #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.6
Copyright © 2000, 2001, 2002, 2003 The Apache Software Foundation. All Rights Reserved.