Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class InputController
- {
- class InputValidator
- {
- public:
- virtual bool Invoke() const = 0;
- };
- class GenericInputValidator : public InputValidator
- {
- public:
- virtual bool Invoke() const { return this->Invoke(); }
- private:
- char m_storage[32];
- };
- template<typename Device, typename Function, typename Button>
- class InputValidatorWrapper : public InputValidator
- {
- public:
- InputValidatorWrapper(Device * device, Function function, Button button)
- : m_device(device)
- , m_function(function)
- , m_button(button)
- {}
- virtual bool Invoke() const { return (m_device->*m_function)(m_button); };
- private:
- Device * m_device;
- Function m_function;
- Button m_button;
- };
- public:
- InputController()
- : m_index(0)
- {
- }
- template<typename Device, typename Function, typename Button>
- void AddInput(Device * device, Function funct, Button button)
- {
- new (&m_validators[m_index]) InputValidatorWrapper<Device, Function, Button>(device, funct, button);
- m_index++;
- }
- bool IsAnyTriggered()
- {
- bool result = NS_FALSE;
- for (size_t i = 0; i < m_index; ++i)
- {
- result |= m_validators[i].Invoke();
- }
- return result;
- }
- private:
- static constexpr size_t MAX_INPUTS = 16;
- GenericInputValidator m_validators[MAX_INPUTS];
- size_t m_index;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement