OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
AnyMap.cpp
Go to the documentation of this file.
1 
11 // Copyright 2014 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
26 #include <osvr/Util/AnyMap.h>
27 
28 // Library/third-party includes
29 // - none
30 
31 // Standard includes
32 // - none
33 
34 namespace osvr {
35 namespace util {
38  bool AnyMap::contains(std::string const &key) const {
39  return (m_contents.count(key) == 1);
40  }
41 
42  bool AnyMap::contains(const char *key) const {
43  return contains(std::string(key));
44  }
45 
46  void AnyMap::set(std::string const &key, boost::any const &value) {
47  m_contents.insert(std::make_pair(key, value));
48  }
49 
50  void AnyMap::set(const char *key, boost::any const &value) {
51  set(std::string(key), value);
52  }
53 
54  boost::any AnyMap::get(std::string const &key) const {
55  Contents::const_iterator location = m_contents.find(key);
56  if (location == m_contents.end()) {
57  return boost::any();
58  }
59  return location->second;
60  }
61 
62  boost::any AnyMap::get(const char *key) const {
63  return get(std::string(key));
64  }
65 
66  void AnyMap::erase(std::string const &key) {
67  Contents::iterator location = m_contents.find(key);
68  if (location != m_contents.end()) {
69  m_contents.erase(location);
70  }
71  }
72 
73  void AnyMap::erase(const char *key) { erase(std::string(key)); }
74 } // namespace util
75 } // namespace osvr
void erase(std::string const &key)
Clears the data for this key.
Definition: AnyMap.cpp:66
void set(std::string const &key, boost::any const &value)
Set data for the given key.
Definition: AnyMap.cpp:46
Header declaring the osvr::util::AnyMap structure.
boost::any get(std::string const &key) const
Get the data for this key.
Definition: AnyMap.cpp:54
bool contains(std::string const &key) const
Do we have data under this key?
Definition: AnyMap.cpp:38