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, 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, 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, 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, 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 00230 template <class T> 00231 #if defined(XALAN_NO_NAMESPACES) 00232 struct MapKeyDeleteFunctor : public unary_function<const typename T::value_type&, void> 00233 #else 00234 struct MapKeyDeleteFunctor : public std::unary_function<const typename T::value_type&, void> 00235 #endif 00236 { 00237 #if defined(XALAN_NO_NAMESPACES) 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) 00254 { 00255 delete thePair.first; 00256 } 00257 }; 00258 00259 00260 00261 template<class T> 00262 MapKeyDeleteFunctor<T> 00263 makeMapKeyDeleteFunctor(const T& /* theMap */) 00264 { 00265 return MapKeyDeleteFunctor<T>(); 00266 } 00267 00268 00269 00279 template<class T> 00280 #if defined(XALAN_NO_NAMESPACES) 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_NAMESPACES) 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_NAMESPACES) 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 #endif // STLHELPERS_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSL Transformer Version 1.1 |
|