OSVR-Core
HandlerContainer.h
Go to the documentation of this file.
1 
11 // Copyright 2015 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_HandlerContainer_h_GUID_EAD5E6BA_FEDA_428B_0F12_B30FBE4AD6DB
26 #define INCLUDED_HandlerContainer_h_GUID_EAD5E6BA_FEDA_428B_0F12_B30FBE4AD6DB
27 
28 // Internal Includes
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 #include <vector>
37 
38 namespace osvr {
39 namespace client {
42  public:
43  void update() {
44  // temp copy to avoid invalidated iterators
45  auto handlersTemp = m_handlers;
46  for (auto const &handler : handlersTemp) {
47  handler->update();
48  }
49  }
50 
51  void add(RemoteHandlerPtr const &handler) {
52  if (!handler) {
53  // Early out for null pointers.
54  return;
55  }
56  m_handlers.insert(handler);
57  }
58 
59  void remove(RemoteHandlerPtr const &handler) {
60  if (!handler) {
61  // Early out for null pointers.
62  return;
63  }
64  m_handlers.remove(handler);
65  }
66 
67  private:
68  typedef std::vector<RemoteHandlerPtr> BaseContainer;
70  typedef util::UniqueContainer<BaseContainer, UniquePolicy,
71  util::container_policies::iterators>
73  InternalHandlerContainer m_handlers;
74  };
75 } // namespace client
76 } // namespace osvr
77 
78 #endif // INCLUDED_HandlerContainer_h_GUID_EAD5E6BA_FEDA_428B_0F12_B30FBE4AD6DB
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
A basic policy for use with a vector or similar container, where you don&#39;t expect a lot of additions ...
Definition: UniqueContainer.h:48
Wrapper for a container of handlers.
Definition: HandlerContainer.h:41
A "Unique Container" designed for composition, not inheritance.
Definition: UniqueContainer.h:327