Skip to content

Commit

Permalink
refactor: force move only objects, proper use of destructor instead o…
Browse files Browse the repository at this point in the history
…f relying on shared_ptr
  • Loading branch information
ABeltramo committed Mar 11, 2024
1 parent 0d174f9 commit bb88575
Show file tree
Hide file tree
Showing 15 changed files with 518 additions and 446 deletions.
66 changes: 40 additions & 26 deletions include/inputtino/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class VirtualDevice {
*/
class Mouse : public VirtualDevice {
public:
static Result<std::shared_ptr<Mouse>> create();
static Result<Mouse> create();

Mouse(const Mouse &j) : _state(j._state) {}
Mouse(Mouse &&j) noexcept : _state(std::move(j._state)) {}
Mouse(Mouse &&j) noexcept : _state(nullptr) {
std::swap(j._state, _state);
}
~Mouse() override;
std::vector<std::string> get_nodes() const override;

void move(int delta_x, int delta_y);
Expand Down Expand Up @@ -99,9 +101,11 @@ class Mouse : public VirtualDevice {
*/
class Trackpad : public VirtualDevice {
public:
static Result<std::shared_ptr<Trackpad>> create();
Trackpad(const Trackpad &j) : _state(j._state) {}
Trackpad(Trackpad &&j) noexcept : _state(std::move(j._state)) {}
static Result<Trackpad> create();
Trackpad(Trackpad &&j) noexcept : _state(nullptr) {
std::swap(j._state, _state);
}
~Trackpad() override;
std::vector<std::string> get_nodes() const override;

/**
Expand Down Expand Up @@ -132,9 +136,11 @@ class Trackpad : public VirtualDevice {
class TouchScreen : public VirtualDevice {

public:
static Result<std::shared_ptr<TouchScreen>> create();
TouchScreen(const TouchScreen &j) : _state(j._state) {}
TouchScreen(TouchScreen &&j) noexcept : _state(std::move(j._state)) {}
static Result<TouchScreen> create();
TouchScreen(TouchScreen &&j) noexcept : _state(nullptr) {
std::swap(j._state, _state);
}
~TouchScreen() override;
std::vector<std::string> get_nodes() const override;

/**
Expand Down Expand Up @@ -164,10 +170,11 @@ class TouchScreen : public VirtualDevice {
*/
class PenTablet : public VirtualDevice {
public:
static Result<std::shared_ptr<PenTablet>> create();
PenTablet(const PenTablet &j) : _state(j._state) {}
PenTablet(PenTablet &&j) : _state(std::move(j._state)) {}

static Result<PenTablet> create();
PenTablet(PenTablet &&j) : _state(nullptr) {
std::swap(j._state, _state);
}
~PenTablet() override;
std::vector<std::string> get_nodes() const override;

enum TOOL_TYPE {
Expand Down Expand Up @@ -217,10 +224,11 @@ class PenTablet : public VirtualDevice {
*/
class Keyboard : public VirtualDevice {
public:
static Result<std::shared_ptr<Keyboard>> create(std::chrono::milliseconds timeout_repress_key = 50ms);
Keyboard(const Keyboard &j) : _state(j._state) {}
Keyboard(Keyboard &&j) noexcept : _state(std::move(j._state)) {}

static Result<Keyboard> create(std::chrono::milliseconds timeout_repress_key = 50ms);
Keyboard(Keyboard &&j) noexcept : _state(nullptr) {
std::swap(j._state, _state);
}
~Keyboard() override;
std::vector<std::string> get_nodes() const override;

void press(short key_code);
Expand Down Expand Up @@ -292,9 +300,11 @@ class Joypad : public VirtualDevice {

class XboxOneJoypad : public Joypad {
public:
static Result<std::shared_ptr<XboxOneJoypad>> create();
XboxOneJoypad(const XboxOneJoypad &j) : _state(j._state) {}
XboxOneJoypad(XboxOneJoypad &&j) noexcept : _state(std::move(j._state)) {}
static Result<XboxOneJoypad> create();
XboxOneJoypad(XboxOneJoypad &&j) noexcept : _state(nullptr) {
std::swap(j._state, _state);
}
~XboxOneJoypad() override;

std::vector<std::string> get_nodes() const override;

Expand All @@ -313,9 +323,11 @@ class XboxOneJoypad : public Joypad {

class SwitchJoypad : public Joypad {
public:
static Result<std::shared_ptr<SwitchJoypad>> create();
SwitchJoypad(const SwitchJoypad &j) : _state(j._state) {}
SwitchJoypad(SwitchJoypad &&j) : _state(std::move(j._state)) {}
static Result<SwitchJoypad> create();
SwitchJoypad(SwitchJoypad &&j) : _state(nullptr) {
std::swap(j._state, _state);
}
~SwitchJoypad() override;

std::vector<std::string> get_nodes() const override;

Expand All @@ -334,9 +346,11 @@ class SwitchJoypad : public Joypad {

class PS5Joypad : public Joypad {
public:
static Result<std::shared_ptr<PS5Joypad>> create();
PS5Joypad(const PS5Joypad &j) : _state(j._state) {}
PS5Joypad(PS5Joypad &&j) noexcept : _state(std::move(j._state)) {}
static Result<PS5Joypad> create();
PS5Joypad(PS5Joypad &&j) noexcept : _state(nullptr) {
std::swap(j._state, _state);
}
~PS5Joypad() override;

std::vector<std::string> get_nodes() const override;

Expand Down
Loading

0 comments on commit bb88575

Please sign in to comment.