OSVR-Core
AnyMap.h
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 #ifndef INCLUDED_AnyMap_h_GUID_794993EB_B778_4E88_16A7_3A047A615587
26 #define INCLUDED_AnyMap_h_GUID_794993EB_B778_4E88_16A7_3A047A615587
27 
28 // Internal Includes
29 #include <osvr/Util/Export.h>
30 #include <osvr/Util/AnyMap_fwd.h>
31 
32 // Library/third-party includes
33 #include <boost/any.hpp>
34 
35 // Standard includes
36 #include <string>
37 #include <map>
38 
39 namespace osvr {
40 namespace util {
42  class AnyMap {
43  public:
45  OSVR_UTIL_EXPORT bool contains(std::string const &key) const;
47  OSVR_UTIL_EXPORT bool contains(const char *key) const;
48 
53  OSVR_UTIL_EXPORT void set(std::string const &key,
54  boost::any const &value);
55  OSVR_UTIL_EXPORT void set(const char *key, boost::any const &value);
56 
57  template <typename T> void set(std::string const &key, T value) {
58  set(key, boost::any(value));
59  }
60 
61  template <typename T> void set(const char *key, T value) {
62  set(key, boost::any(value));
63  }
65 
69  OSVR_UTIL_EXPORT boost::any get(std::string const &key) const;
71  OSVR_UTIL_EXPORT boost::any get(const char *key) const;
72 
76  OSVR_UTIL_EXPORT void erase(std::string const &key);
78  OSVR_UTIL_EXPORT void erase(const char *key);
79 
80  private:
81  typedef std::map<std::string, boost::any> Contents;
82  Contents m_contents;
83  };
84 } // namespace util
85 } // namespace osvr
86 
87 #endif // INCLUDED_AnyMap_h_GUID_794993EB_B778_4E88_16A7_3A047A615587
Definition: RunLoopManager.h:42
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
OSVR_UTIL_EXPORT void erase(std::string const &key)
Clears the data for this key.
Definition: AnyMap.cpp:66
OSVR_UTIL_EXPORT bool contains(std::string const &key) const
Do we have data under this key?
Definition: AnyMap.cpp:38
A data structure storing "any" by name, to reduce coupling.
Definition: AnyMap.h:42
Header forward-declaring declaring osvr::util::AnyMap.