MustFind.h
Go to the documentation of this file.
1 #ifndef _utl_MustFind_h_
2 #define _utl_MustFind_h_
3 
4 #include <string>
5 #include <utl/AugerException.h>
6 
7 
8 namespace utl {
9 
10  template<class Map>
11  inline
12  typename Map::mapped_type&
13  MustFind(Map& map, const typename Map::key_type& key, const std::string& failMessage = "key not found")
14  {
15  const typename Map::iterator it = map.find(key);
16  if (it != map.end())
17  return it->second;
18  ERROR(failMessage);
19  throw NonExistentComponentException(failMessage);
20  }
21 
22 
23  template<class Map>
24  inline
25  const typename Map::mapped_type&
26  MustFind(const Map& map, const typename Map::key_type& key, const std::string& failMessage = "key not found")
27  {
28  const typename Map::const_iterator it = map.find(key);
29  if (it != map.end())
30  return it->second;
31  ERROR(failMessage);
32  throw NonExistentComponentException(failMessage);
33  }
34 
35 
36  template<class Map>
37  inline
38  typename Map::mapped_type&
39  MustFind(Map* const map, const typename Map::key_type& key, const std::string& failMessage = "key not found")
40  {
41  if (map) {
42  const typename Map::iterator it = map->find(key);
43  if (it != map->end())
44  return it->second;
45  }
46  ERROR(failMessage);
47  throw NonExistentComponentException(failMessage);
48  }
49 
50 
51  template<class Map>
52  inline
53  const typename Map::mapped_type&
54  MustFind(const Map* const map, const typename Map::key_type& key, const std::string& failMessage = "key not found")
55  {
56  if (map) {
57  const typename Map::const_iterator it = map->find(key);
58  if (it != map->end())
59  return it->second;
60  }
61  ERROR(failMessage);
62  throw NonExistentComponentException(failMessage);
63  }
64 
65 }
66 
67 
68 #endif
Map::mapped_type & MustFind(Map &map, const typename Map::key_type &key, const std::string &failMessage="key not found")
Definition: MustFind.h:13
Base class for exceptions trying to access non-existing components.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.