Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.4

Main Page   Namespace List   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 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 <Include/PlatformDefinitions.hpp>
00064 
00065 
00066 
00067 #include <algorithm>
00068 #include <functional>
00069 
00070 
00071 
00075 template <class T>
00076 #if defined(XALAN_NO_NAMESPACES)
00077 struct DeleteFunctor : public unary_function<const T*, void>
00078 #else
00079 struct DeleteFunctor : public std::unary_function<const T*, void>
00080 #endif
00081 {
00082 #if defined(XALAN_NO_NAMESPACES)
00083     typedef unary_function<const T*, void>  BaseClassType;
00084 #else
00085     typedef std::unary_function<const T*, void> BaseClassType;
00086 #endif
00087 
00088     typedef typename BaseClassType::result_type     result_type;
00089     typedef typename BaseClassType::argument_type   argument_type;
00090 
00096     result_type
00097     operator()(argument_type    thePointer) const
00098     {
00099 #if defined(XALAN_CANNOT_DELETE_CONST)
00100         delete (T*)thePointer;
00101 #else
00102         delete thePointer;
00103 #endif
00104     }
00105 };
00106 
00107 
00108 
00109 #if !defined(XALAN_SGI_BASED_STL)
00110 
00115 template <class PairType>
00116 #if defined(XALAN_NO_NAMESPACES)
00117 struct select1st : public unary_function<PairType, PairType::first_type>
00118 #else
00119 struct select1st : public std::unary_function<PairType, typename PairType::first_type>
00120 #endif
00121 {
00122 #if defined(XALAN_NO_NAMESPACES)
00123     typedef unary_function<PairType, PairType::first_type>  BaseClassType;
00124 #else
00125     typedef std::unary_function<PairType, typename PairType::first_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.first;
00143     }
00144 };
00145 
00146 
00147 
00152 template <class PairType>
00153 #if defined(XALAN_NO_NAMESPACES)
00154 struct select2nd : public unary_function<PairType, PairType::second_type>
00155 #else
00156 struct select2nd : public std::unary_function<PairType, typename PairType::second_type>
00157 #endif
00158 {
00159 #if defined(XALAN_NO_NAMESPACES)
00160     typedef unary_function<PairType, PairType::second_type> BaseClassType;
00161 #else
00162     typedef std::unary_function<PairType, typename PairType::second_type>   BaseClassType;
00163 #endif
00164 
00165     typedef typename BaseClassType::result_type     result_type;
00166     typedef typename BaseClassType::argument_type   argument_type;
00167 
00168     typedef PairType                                value_type;
00169 
00176     result_type
00177     operator()(const argument_type&     thePair) const
00178     {
00179         return thePair.second;
00180     }
00181 };
00182 
00183 #endif
00184 
00185 
00186 
00190 template <class T>
00191 #if defined(XALAN_NO_NAMESPACES)
00192 struct MapValueDeleteFunctor : public unary_function<const typename T::value_type&, void>
00193 #else
00194 struct MapValueDeleteFunctor : public std::unary_function<const typename T::value_type&, void>
00195 #endif
00196 {
00197 #if defined(XALAN_NO_NAMESPACES)
00198     typedef unary_function<const typename T::value_type&, void>     BaseClassType;
00199 #else
00200     typedef std::unary_function<const typename T::value_type&, void>    BaseClassType;
00201 #endif
00202 
00203     typedef typename BaseClassType::result_type     result_type;
00204     typedef typename BaseClassType::argument_type   argument_type;
00205 
00212     result_type
00213     operator()(argument_type    thePair) const
00214     {
00215         delete thePair.second;
00216     }
00217 };
00218 
00219 
00220 
00221 template<class T>
00222 MapValueDeleteFunctor<T>
00223 makeMapValueDeleteFunctor(const T&  /* theMap */)
00224 {
00225     return MapValueDeleteFunctor<T>();
00226 }
00227 
00228 
00229 
00239 template<class T>
00240 #if defined(XALAN_NO_NAMESPACES)
00241 struct less_null_terminated_arrays : public binary_function<const T*, const T*, bool>
00242 #else
00243 struct less_null_terminated_arrays : public std::binary_function<const T*, const T*, bool>
00244 #endif
00245 {
00246 #if defined(XALAN_NO_NAMESPACES)
00247     typedef binary_function<const T*, const T*, bool>           BaseClassType;
00248 #else
00249     typedef std::binary_function<const T*, const T*, bool>      BaseClassType;
00250 #endif
00251 
00252     typedef typename BaseClassType::result_type             result_type;
00253     typedef typename BaseClassType::first_argument_type     first_argument_type;
00254     typedef typename BaseClassType::second_argument_type    second_argument_type;
00255 
00264     result_type
00265     operator()(
00266             first_argument_type     theLHS,
00267             second_argument_type    theRHS) const
00268     {
00269         while(*theLHS && *theRHS)
00270         {
00271             if (*theLHS != *theRHS)
00272             {
00273                 break;
00274             }
00275             else
00276             {
00277                 theLHS++;
00278                 theRHS++;
00279             }
00280         }
00281 
00282         return *theLHS < *theRHS ? true : false;
00283     }
00284 };
00285 
00286 
00287 
00288 template<class CollectionType>
00289 class CollectionClearGuard
00290 {
00291 public:
00292 
00293     CollectionClearGuard(CollectionType&    theCollection) :
00294         m_collection(&theCollection)
00295     {
00296     }
00297 
00298     ~CollectionClearGuard()
00299     {
00300         if (m_collection != 0)
00301         {
00302             m_collection->clear();
00303         }
00304     }
00305 
00306     void
00307     release()
00308     {
00309         m_collection = 0;
00310     }
00311 
00312 private:
00313 
00314     // Not implemented...
00315     CollectionClearGuard(const CollectionClearGuard<CollectionType>&);
00316 
00317     CollectionClearGuard<CollectionType>&
00318     operator=(const CollectionClearGuard<CollectionType>&);
00319 
00320     // Data members...
00321     CollectionType*     m_collection;
00322 };
00323 
00324 
00325 
00326 template<class CollectionType, class DeleteFunctorType>
00327 class CollectionDeleteGuard
00328 {
00329 public:
00330 
00331     CollectionDeleteGuard(CollectionType&   theCollection) :
00332         m_collection(&theCollection)
00333     {
00334     }
00335 
00336     ~CollectionDeleteGuard()
00337     {
00338         if (m_collection != 0)
00339         {
00340 #if !defined(XALAN_NO_NAMESPACES)
00341             using std::for_each;
00342 #endif
00343 
00344             // Delete all of the objects in the temp vector.
00345             for_each(m_collection->begin(),
00346                      m_collection->end(),
00347                      DeleteFunctorType());
00348         }
00349     }
00350 
00351     void
00352     release()
00353     {
00354         m_collection = 0;
00355     }
00356 
00357 private:
00358 
00359     // Not implemented...
00360     CollectionDeleteGuard(const CollectionDeleteGuard<CollectionType, DeleteFunctorType>&);
00361 
00362     CollectionDeleteGuard<CollectionType, DeleteFunctorType>&
00363     operator=(const CollectionDeleteGuard<CollectionType, DeleteFunctorType>&);
00364 
00365     // Data members...
00366     CollectionType*     m_collection;
00367 };
00368 
00369 
00370 
00371 #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.4
Copyright © 2000, 2001, 2002 The Apache Software Foundation. All Rights Reserved.