File indexing completed on 2024-06-02 04:48:49

0001 /*
0002 Copyright (C) 1999-2007 The Botan Project. All rights reserved.
0003 
0004 Redistribution and use in source and binary forms, for any use, with or without
0005 modification, is permitted provided that the following conditions are met:
0006 
0007 1. Redistributions of source code must retain the above copyright notice, this
0008 list of conditions, and the following disclaimer.
0009 
0010 2. Redistributions in binary form must reproduce the above copyright notice,
0011 this list of conditions, and the following disclaimer in the documentation
0012 and/or other materials provided with the distribution.
0013 
0014 THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED
0015 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
0016 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
0017 
0018 IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT,
0019 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
0020 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0021 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0022 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
0023 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
0024 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0025 */
0026 // LICENSEHEADER_END
0027 namespace QCA { // WRAPNS_LINE
0028 /*************************************************
0029  * STL Utility Functions Header File              *
0030  * (C) 1999-2007 The Botan Project                *
0031  *************************************************/
0032 
0033 #ifndef BOTAN_STL_UTIL_H__
0034 #define BOTAN_STL_UTIL_H__
0035 
0036 } // WRAPNS_LINE
0037 #include <map>
0038 namespace QCA { // WRAPNS_LINE
0039 
0040 namespace Botan {
0041 
0042 /*************************************************
0043  * Copy-on-Predicate Algorithm                    *
0044  *************************************************/
0045 template<typename InputIterator, typename OutputIterator, typename Predicate>
0046 OutputIterator copy_if(InputIterator current, InputIterator end, OutputIterator dest, Predicate copy_p)
0047 {
0048     while (current != end) {
0049         if (copy_p(*current))
0050             *dest++ = *current;
0051         ++current;
0052     }
0053     return dest;
0054 }
0055 
0056 /*************************************************
0057  * Searching through a std::map                   *
0058  *************************************************/
0059 template<typename K, typename V>
0060 inline V search_map(const std::map<K, V> &mapping, const K &key, const V &null_result = V())
0061 {
0062     typename std::map<K, V>::const_iterator i = mapping.find(key);
0063     if (i == mapping.end())
0064         return null_result;
0065     return i->second;
0066 }
0067 
0068 template<typename K, typename V, typename R>
0069 inline R search_map(const std::map<K, V> &mapping, const K &key, const R &null_result, const R &found_result)
0070 {
0071     typename std::map<K, V>::const_iterator i = mapping.find(key);
0072     if (i == mapping.end())
0073         return null_result;
0074     return found_result;
0075 }
0076 
0077 /*************************************************
0078  * Function adaptor for delete operation          *
0079  *************************************************/
0080 template<class T> class del_fun
0081 {
0082 public:
0083     void operator()(T *ptr)
0084     {
0085         delete ptr;
0086     }
0087 };
0088 
0089 /*************************************************
0090  * Delete the second half of a pair of objects    *
0091  *************************************************/
0092 template<typename Pair> void delete2nd(Pair &pair)
0093 {
0094     delete pair.second;
0095 }
0096 
0097 /*************************************************
0098  * Insert a key/value pair into a multimap        *
0099  *************************************************/
0100 template<typename K, typename V> void multimap_insert(std::multimap<K, V> &multimap, const K &key, const V &value)
0101 {
0102     multimap.insert(std::make_pair(key, value));
0103 }
0104 
0105 }
0106 
0107 #endif
0108 } // WRAPNS_LINE