All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
KeyEventHandler.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _KEY_EVENT_HANDLER_HH_
18 #define _KEY_EVENT_HANDLER_HH_
19 
20 #include <boost/function.hpp>
21 #include <string>
22 #include <list>
23 
26 #include "gazebo/util/system.hh"
27 
28 namespace gazebo
29 {
30  namespace gui
31  {
34  class GAZEBO_VISIBLE KeyEventHandler : public SingletonT<KeyEventHandler>
35  {
38  public: typedef boost::function<bool (const common::KeyEvent &_event)>
39  KeyEventFilter;
40 
43  private: class Filter
44  {
48  public: Filter(const std::string &_name,
49  KeyEventFilter _func)
50  : name(_name), func(_func) {}
51 
55  public: bool operator==(const Filter &_f) const
56  {
57  return this->name == _f.name;
58  }
59 
63  public: bool operator==(const std::string &_f) const
64  {
65  return this->name == _f;
66  }
67 
69  public: std::string name;
70 
72  public: KeyEventFilter func;
73  };
74 
76  private: KeyEventHandler();
77 
79  private: virtual ~KeyEventHandler();
80 
84  public: void AddPressFilter(const std::string &_name,
85  KeyEventFilter _filter);
86 
90  public: void AddReleaseFilter(const std::string &_name,
91  KeyEventFilter _filter);
92 
95  public: void RemovePressFilter(const std::string &_name);
96 
99  public: void RemoveReleaseFilter(const std::string &_name);
100 
103  public: void HandlePress(const common::KeyEvent &_event);
104 
107  public: void HandleRelease(const common::KeyEvent &_event);
108 
113  private: void Add(const std::string &_name, KeyEventFilter _filter,
114  std::list<Filter> &_list);
115 
119  private: void Remove(const std::string &_name, std::list<Filter> &_list);
120 
124  private: void Handle(const common::KeyEvent &_event,
125  std::list<Filter> &_list);
126 
128  private: std::list<Filter> pressFilters;
129 
131  private: std::list<Filter> releaseFilters;
132 
134  private: friend class SingletonT<KeyEventHandler>;
135  };
136  }
137 }
138 #endif
Singleton template class.
Definition: SingletonT.hh:33
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48