Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stl_utils.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
3 // taken from the GNU/sgi stl extensions
4 
5 /*
6  *
7  * Copyright (c) 1994
8  * Hewlett-Packard Company
9  *
10  * Permission to use, copy, modify, distribute and sell this software
11  * and its documentation for any purpose is hereby granted without fee,
12  * provided that the above copyright notice appear in all copies and
13  * that both that copyright notice and this permission notice appear
14  * in supporting documentation. Hewlett-Packard Company makes no
15  * representations about the suitability of this software for any
16  * purpose. It is provided "as is" without express or implied warranty.
17  *
18  *
19  * Copyright (c) 1996
20  * Silicon Graphics Computer Systems, Inc.
21  *
22  * Permission to use, copy, modify, distribute and sell this software
23  * and its documentation for any purpose is hereby granted without fee,
24  * provided that the above copyright notice appear in all copies and
25  * that both that copyright notice and this permission notice appear
26  * in supporting documentation. Silicon Graphics makes no
27  * representations about the suitability of this software for any
28  * purpose. It is provided "as is" without express or implied warranty.
29  */
30 
31 
32 #ifndef _HUGIN_UTILS_STL_UTILS_H
33 #define _HUGIN_UTILS_STL_UTILS_H
34 
35 
36 #include <functional>
37 #include <algorithm>
38 #include <utility>
39 #include <string>
40 #include <string.h>
41 #include <ctype.h>
42 #include <stdexcept>
43 
44 #include <hugin_utils/utils.h>
45 
46 namespace hugin_utils {
47 
49  inline std::string tolower(const std::string& s)
50  {
51  std::string result = s;
52  std::transform<std::string::iterator,
53  std::string::iterator,
54  int (*)(int)>(result.begin(), result.end(),
55  result.begin(), ::tolower);
56  return result;
57  }
58 
59  inline std::string toupper(const std::string& s)
60  {
61  std::string result = s;
62  std::transform<std::string::iterator,
63  std::string::iterator,
64  int (*)(int)>(result.begin(), result.end(),
65  result.begin(), ::toupper);
66  return result;
67  }
68 }
69 
70 
72 template<typename _Container>
73 //inline bool set_contains(const _Container & c, const _Container::key_type & key)
74 inline bool set_contains(const _Container & c, const typename _Container::key_type & key)
75 {
76  return c.find(key) != c.end();
77 }
78 
80 template<typename _Container>
81 inline void fill_set(_Container & c, typename _Container::key_type begin,
82  typename _Container::key_type end)
83 {
84  for (typename _Container::key_type i=begin; i <= end; i++) {
85  c.insert(i);
86  }
87 }
88 
89 
90 
97 template<typename Map>
98 typename Map::mapped_type & map_get(Map &m, const typename Map::key_type & key)
99 {
100  typename Map::iterator it = m.find(key);
101  if (it != m.end()) {
102  return (*it).second;
103  } else {
104  DEBUG_WARN("could not find " << key);
105  throw std::out_of_range("No such element in vector");
106  }
107 }
108 
109 template<typename Map>
110 const typename Map::mapped_type & const_map_get(const Map &m, const typename Map::key_type & key)
111 {
112  typename Map::const_iterator it = m.find(key);
113  if (it != m.end()) {
114  return (*it).second;
115  } else {
116  DEBUG_WARN("could not find " << key);
117  throw std::out_of_range("No such element in vector");
118  }
119 }
120 
121 
122 template<typename Map>
123 typename Map::mapped_type & map_get(Map &m, const char * key)
124 {
125  typename Map::iterator it = m.find(key);
126  if (it != m.end()) {
127  return (*it).second;
128  } else {
129  DEBUG_WARN("could not find " << key);
130  throw std::out_of_range("No such element in vector");
131  }
132 }
133 
134 template<typename Map>
135 const typename Map::mapped_type & const_map_get(const Map &m, const char * key)
136 {
137  typename Map::const_iterator it = m.find(key);
138  if (it != m.end()) {
139  return (*it).second;
140  } else {
141  DEBUG_WARN("could not find " << key);
142  throw std::out_of_range("No such element in vector");
143  }
144 }
145 
146 #endif // _HUGIN_UTILS_STL_UTILS_H
bool set_contains(const _Container &c, const typename _Container::key_type &key)
Definition: stl_utils.h:74
std::string toupper(const std::string &s)
Definition: stl_utils.h:59
const Map::mapped_type & const_map_get(const Map &m, const typename Map::key_type &key)
Definition: stl_utils.h:110
#define DEBUG_WARN(msg)
Definition: utils.h:74
Map::mapped_type & map_get(Map &m, const typename Map::key_type &key)
get a map element.
Definition: stl_utils.h:98
void fill_set(_Container &c, typename _Container::key_type begin, typename _Container::key_type end)
Definition: stl_utils.h:81
std::string tolower(const std::string &s)
convert a string to lowercase
Definition: stl_utils.h:49