NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
insensitive_map.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 
20 #ifndef JSONLOADER_INSENSITIVE_MAP_H_
21 #define JSONLOADER_INSENSITIVE_MAP_H_
22 
23 #include <cctype>
24 #include <string>
25 #include <unordered_map>
26 
27 namespace jsonloader {
28 
30  bool operator()(const std::string &rhs, const std::string &lhs) const {
31  if (rhs.size() != lhs.size())
32  return false;
33  for (std::string::size_type i = 0; i < rhs.size(); i++) {
34  if (std::tolower(rhs[i]) != std::tolower(lhs[i]))
35  return false;
36  }
37  return true;
38  }
39 };
40 
42  std::size_t operator()(const std::string &s) const {
43  std::string s_cpy(s);
44  for (std::string::size_type i = 0; i < s_cpy.size(); i++) {
45  s_cpy[i] = std::tolower(s_cpy[i]);
46  }
47  return std::hash<std::string>()(s_cpy);
48  }
49 };
50 
51 // aww yeah, templated 'using' declaration.
52 // what is this *madman* going to DO next?
53 template<class V>
54 using InsensitiveMap =
55  std::unordered_map<std::string, V,
57 
58 } // namespace jsonloader
59 
60 #endif // JSONLOADER_INSENSITIVE_MAP_H_
jsonloader::CaseInsensitiveHash::operator()
std::size_t operator()(const std::string &s) const
Definition: insensitive_map.h:42
jsonloader::InsensitiveMap
std::unordered_map< std::string, V, CaseInsensitiveHash, CaseInsensitiveEquals > InsensitiveMap
Definition: insensitive_map.h:56
jsonloader
Definition: command.h:28
jsonloader::CaseInsensitiveHash
Definition: insensitive_map.h:41
jsonloader::CaseInsensitiveEquals
Definition: insensitive_map.h:29
jsonloader::CaseInsensitiveEquals::operator()
bool operator()(const std::string &rhs, const std::string &lhs) const
Definition: insensitive_map.h:30