160 lines
2.8 KiB
C++
160 lines
2.8 KiB
C++
#include "io/hid/InputHandler.h"
|
|
|
|
namespace ehs
|
|
{
|
|
InputHandler::~InputHandler()
|
|
{
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
delete devices[i];
|
|
}
|
|
|
|
InputHandler::InputHandler()
|
|
: hashId(0)
|
|
{
|
|
}
|
|
|
|
InputHandler::InputHandler(Str_8 id)
|
|
: hashId(id.Hash_64()), id((Str_8&&)id)
|
|
{
|
|
}
|
|
|
|
InputHandler::InputHandler(InputHandler&& ih) noexcept
|
|
: hashId(ih.hashId), id((Str_8&&)ih.id), devices((Array<HID*>&&)ih.devices)
|
|
{
|
|
ih.hashId = 0;
|
|
}
|
|
|
|
InputHandler::InputHandler(const InputHandler& ih)
|
|
: hashId(ih.hashId), id(ih.id), devices(ih.devices.Size())
|
|
{
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
devices[i] = ih.devices[i]->Clone();
|
|
}
|
|
|
|
InputHandler& InputHandler::operator=(InputHandler&& ih) noexcept
|
|
{
|
|
if (this == &ih)
|
|
return *this;
|
|
|
|
hashId = ih.hashId;
|
|
id = (Str_8&&)ih.id;
|
|
devices = (Array<HID*>&&)ih.devices;
|
|
|
|
ih.hashId = 0;
|
|
|
|
return *this;
|
|
}
|
|
|
|
InputHandler& InputHandler::operator=(const InputHandler& ih)
|
|
{
|
|
if (this == &ih)
|
|
return *this;
|
|
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
delete devices[i];
|
|
|
|
hashId = ih.hashId;
|
|
id = ih.id;
|
|
devices = Array<HID*>(ih.devices.Size());
|
|
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
devices[i] = ih.devices[i]->Clone();
|
|
|
|
return *this;
|
|
}
|
|
|
|
bool InputHandler::operator==(const UInt_64 otherHashId)
|
|
{
|
|
return hashId == otherHashId;
|
|
}
|
|
|
|
bool InputHandler::operator!=(const UInt_64 otherHashId)
|
|
{
|
|
return hashId != otherHashId;
|
|
}
|
|
|
|
bool InputHandler::Initialize()
|
|
{
|
|
if (IsInitialized())
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool InputHandler::Release()
|
|
{
|
|
if (!IsInitialized())
|
|
return false;
|
|
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
delete devices[i];
|
|
|
|
devices.Clear();
|
|
|
|
return true;
|
|
}
|
|
|
|
void InputHandler::Poll()
|
|
{
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
devices[i]->Poll();
|
|
}
|
|
|
|
UInt_64 InputHandler::GetHashId() const
|
|
{
|
|
return hashId;
|
|
}
|
|
|
|
Str_8 InputHandler::GetId() const
|
|
{
|
|
return id;
|
|
}
|
|
|
|
void InputHandler::ResetAllStates()
|
|
{
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
devices[i]->ReleaseAll();
|
|
}
|
|
|
|
bool InputHandler::HasDevice(const UInt_64 id) const
|
|
{
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
if (*devices[i] == id)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool InputHandler::AddDevice(HID* device)
|
|
{
|
|
if (HasDevice(device->GetId()))
|
|
return false;
|
|
|
|
devices.Push(device);
|
|
|
|
return true;
|
|
}
|
|
|
|
HID* InputHandler::GetDevice(const UInt_64 id) const
|
|
{
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
if (*devices[i] == id)
|
|
return devices[i];
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
HID* InputHandler::GetDeviceByType(const UInt_8 type) const
|
|
{
|
|
for (UInt_64 i = 0; i < devices.Size(); i++)
|
|
if (devices[i]->GetType() == type)
|
|
return devices[i];
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
bool InputHandler::IsInitialized() const
|
|
{
|
|
return false;
|
|
}
|
|
} |