Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
hugin_base/hugin_utils/stl_utils.h
Go to the documentation of this file.00001 // -*- c-basic-offset: 4 -*- 00002 00003 // taken from the GNU/sgi stl extensions 00004 00005 /* 00006 * 00007 * Copyright (c) 1994 00008 * Hewlett-Packard Company 00009 * 00010 * Permission to use, copy, modify, distribute and sell this software 00011 * and its documentation for any purpose is hereby granted without fee, 00012 * provided that the above copyright notice appear in all copies and 00013 * that both that copyright notice and this permission notice appear 00014 * in supporting documentation. Hewlett-Packard Company makes no 00015 * representations about the suitability of this software for any 00016 * purpose. It is provided "as is" without express or implied warranty. 00017 * 00018 * 00019 * Copyright (c) 1996 00020 * Silicon Graphics Computer Systems, Inc. 00021 * 00022 * Permission to use, copy, modify, distribute and sell this software 00023 * and its documentation for any purpose is hereby granted without fee, 00024 * provided that the above copyright notice appear in all copies and 00025 * that both that copyright notice and this permission notice appear 00026 * in supporting documentation. Silicon Graphics makes no 00027 * representations about the suitability of this software for any 00028 * purpose. It is provided "as is" without express or implied warranty. 00029 */ 00030 00031 00032 #ifndef _HUGIN_UTILS_STL_UTILS_H 00033 #define _HUGIN_UTILS_STL_UTILS_H 00034 00035 00036 #include <functional> 00037 #include <algorithm> 00038 #include <utility> 00039 #include <string> 00040 #include <string.h> 00041 #include <ctype.h> 00042 #include <stdexcept> 00043 00044 #include <hugin_utils/utils.h> 00045 00046 namespace hugin_utils { 00047 00049 inline std::string tolower(const std::string& s) 00050 { 00051 std::string result = s; 00052 std::transform<std::string::iterator, 00053 std::string::iterator, 00054 int (*)(int)>(result.begin(), result.end(), 00055 result.begin(), ::tolower); 00056 return result; 00057 } 00058 00059 } 00060 00061 00063 template<typename _Container> 00064 //inline bool set_contains(const _Container & c, const _Container::key_type & key) 00065 inline bool set_contains(const _Container & c, const typename _Container::key_type & key) 00066 { 00067 return c.find(key) != c.end(); 00068 } 00069 00071 template<typename _Container> 00072 inline void fill_set(_Container & c, typename _Container::key_type begin, 00073 typename _Container::key_type end) 00074 { 00075 for (typename _Container::key_type i=begin; i <= end; i++) { 00076 c.insert(i); 00077 } 00078 } 00079 00080 00081 00088 template<typename Map> 00089 typename Map::mapped_type & map_get(Map &m, const typename Map::key_type & key) 00090 { 00091 typename Map::iterator it = m.find(key); 00092 if (it != m.end()) { 00093 return (*it).second; 00094 } else { 00095 DEBUG_WARN("could not find " << key); 00096 throw std::out_of_range("No such element in vector"); 00097 } 00098 } 00099 00100 template<typename Map> 00101 const typename Map::mapped_type & const_map_get(const Map &m, const typename Map::key_type & key) 00102 { 00103 typename Map::const_iterator it = m.find(key); 00104 if (it != m.end()) { 00105 return (*it).second; 00106 } else { 00107 DEBUG_WARN("could not find " << key); 00108 throw std::out_of_range("No such element in vector"); 00109 } 00110 } 00111 00112 00113 template<typename Map> 00114 typename Map::mapped_type & map_get(Map &m, const char * key) 00115 { 00116 typename Map::iterator it = m.find(key); 00117 if (it != m.end()) { 00118 return (*it).second; 00119 } else { 00120 DEBUG_WARN("could not find " << key); 00121 throw std::out_of_range("No such element in vector"); 00122 } 00123 } 00124 00125 template<typename Map> 00126 const typename Map::mapped_type & const_map_get(const Map &m, const char * key) 00127 { 00128 typename Map::const_iterator it = m.find(key); 00129 if (it != m.end()) { 00130 return (*it).second; 00131 } else { 00132 DEBUG_WARN("could not find " << key); 00133 throw std::out_of_range("No such element in vector"); 00134 } 00135 } 00136 00137 #endif // _HUGIN_UTILS_STL_UTILS_H
1.3.9.1