refactor: remove event.cpp, event code is just the header now

basedon: 6b7d45e9c4
This commit is contained in:
sithlord48 2025-11-12 20:37:54 -05:00 committed by Chris Rizzitello
parent ad33114e0c
commit e011351aad
3 changed files with 58 additions and 97 deletions

View file

@ -7,7 +7,6 @@ add_library(base STATIC
BaseException.cpp BaseException.cpp
BaseException.h BaseException.h
DirectionTypes.h DirectionTypes.h
Event.cpp
Event.h Event.h
EventQueue.cpp EventQueue.cpp
EventQueue.h EventQueue.h

View file

@ -1,81 +0,0 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#include "base/Event.h"
#include <assert.h>
#include <cstdlib>
//
// Event
//
Event::Event(EventTypes type, void *target, void *data, Flags flags)
: m_type(type),
m_target(target),
m_data(data),
m_flags(flags)
{
// do nothing
}
Event::Event(EventTypes type, void *target, EventData *dataObject)
: m_type(type),
m_target(target),
m_dataObject(dataObject)
{
// do nothing
}
EventTypes Event::getType() const
{
return m_type;
}
void *Event::getTarget() const
{
return m_target;
}
void *Event::getData() const
{
return m_data;
}
EventData *Event::getDataObject() const
{
return m_dataObject;
}
Event::Flags Event::getFlags() const
{
return m_flags;
}
void Event::deleteData(const Event &event)
{
switch (event.getType()) {
using enum EventTypes;
case Unknown:
case Quit:
case System:
case Timer:
break;
default:
if ((event.getFlags() & EventFlags::DontFreeData) == 0) {
free(event.getData());
delete event.getDataObject();
}
break;
}
}
void Event::setDataObject(EventData *dataObject)
{
assert(m_dataObject == nullptr);
m_dataObject = dataObject;
}

View file

@ -9,6 +9,9 @@
#include "EventTypes.h" #include "EventTypes.h"
#include <assert.h>
#include <cstdlib>
using deskflow::EventTypes; using deskflow::EventTypes;
class EventData class EventData
@ -44,15 +47,19 @@ public:
\p target is the intended recipient of the event. \p target is the intended recipient of the event.
\p flags is any combination of \c Flags. \p flags is any combination of \c Flags.
*/ */
explicit Event(EventTypes type, void *target = nullptr, void *data = nullptr, Flags flags = EventFlags::NoFlags); explicit Event(EventTypes type, void *target = nullptr, void *data = nullptr, Flags flags = EventFlags::NoFlags)
: m_type(type),
m_target(target),
m_data(data),
m_flags(flags)
{
// do nothing
}
//! Create \c Event with non-POD data Event(EventTypes type, void *target, EventData *dataObject) : m_type(type), m_target(target), m_dataObject(dataObject)
/*! {
\p type of the event // do nothing
\p target is the intended recipient of the event. }
\p dataObject with event data
*/
explicit Event(EventTypes type, void *target, EventData *dataObject);
//! @name manipulators //! @name manipulators
//@{ //@{
@ -61,14 +68,35 @@ public:
/*! /*!
Deletes event data for the given event (using free()). Deletes event data for the given event (using free()).
*/ */
static void deleteData(const Event &); static void deleteData(const Event &event)
{
switch (event.getType()) {
using enum EventTypes;
case Unknown:
case Quit:
case System:
case Timer:
break;
default:
if ((event.getFlags() & EventFlags::DontFreeData) == 0) {
free(event.getData());
delete event.getDataObject();
}
break;
}
}
//! Set data (non-POD) //! Set data (non-POD)
/*! /*!
Set non-POD (non plain old data), where delete is called when the event Set non-POD (non plain old data), where delete is called when the event
is deleted, and the destructor is called. is deleted, and the destructor is called.
*/ */
void setDataObject(EventData *dataObject); void setDataObject(EventData *dataObject)
{
assert(m_dataObject == nullptr);
m_dataObject = dataObject;
};
//@} //@}
//! @name accessors //! @name accessors
@ -78,19 +106,28 @@ public:
/*! /*!
Returns the event type. Returns the event type.
*/ */
EventTypes getType() const; EventTypes getType() const
{
return m_type;
}
//! Get the event target //! Get the event target
/*! /*!
Returns the event target. Returns the event target.
*/ */
void *getTarget() const; void *getTarget() const
{
return m_target;
}
//! Get the event data (POD). //! Get the event data (POD).
/*! /*!
Returns the event data (POD). Returns the event data (POD).
*/ */
void *getData() const; void *getData() const
{
return m_data;
}
//! Get the event data (non-POD) //! Get the event data (non-POD)
/*! /*!
@ -98,13 +135,19 @@ public:
\c getData() is that when delete is called on this data, so non-POD \c getData() is that when delete is called on this data, so non-POD
(non plain old data) dtor is called. (non plain old data) dtor is called.
*/ */
EventData *getDataObject() const; EventData *getDataObject() const
{
return m_dataObject;
}
//! Get event flags //! Get event flags
/*! /*!
Returns the event flags. Returns the event flags.
*/ */
Flags getFlags() const; Flags getFlags() const
{
return m_flags;
}
//@} //@}