VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
ControllerFactory.h
1 /*
2  * Copyright (C) 2014 Google Inc.
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 CONTROLLERFACTORY_H
18 #define CONTROLLERFACTORY_H
19 
20 #include <set>
21 #include "InputScheme.h"
22 #include "VirtualController.h"
23 
24 class ControllerEvent;
25 
35 public:
36  virtual ~ControllerFactory() { }
37 
42  virtual VirtualController* createNewController(int deviceId) const = 0;
43 
51  virtual bool intersects(const ControllerFactory& otherFactory) const = 0;
52 
57  virtual bool handlesControllerEvent(const ControllerEvent* event) const = 0;
58 
65  template <typename Input>
66  static bool isValidInputScheme(const InputScheme<Input>& scheme, std::set<Input>& validInputs) {
67  for (auto& inputActionPair : scheme) {
68  if (!validInputs.count(inputActionPair.first)) {
69  return false;
70  }
71  }
72  return true;
73  }
74 };
75 
76 #endif // CONTROLLERFACTORY_H
Software represention and state capable of describing almost all physical controllers.
Definition: VirtualController.h:36
Base interface for constructing virtual controllers from a deviceId.
Definition: ControllerFactory.h:34
virtual VirtualController * createNewController(int deviceId) const =0
Returns a new VirtualController for the specified deviceId.
A platform independent event generated by controller device.
Definition: ControllerEvent.h:34
virtual bool intersects(const ControllerFactory &otherFactory) const =0
Returns whether or not this ControllerFactory intersects (i.e. overlaps input schemes) with the speci...
static bool isValidInputScheme(const InputScheme< Input > &scheme, std::set< Input > &validInputs)
Returns whether or not the given InputScheme is valid (i.e. only contains input mappings which are va...
Definition: ControllerFactory.h:66
virtual bool handlesControllerEvent(const ControllerEvent *event) const =0
Returns whether or not this ControllerFactory can process the specified event.
Represents a scheme mapping generic input "events" to output "actions".
Definition: InputScheme.h:28