create new singleton class

This commit is contained in:
RickyRister 2025-02-18 22:48:30 -08:00
parent 77a3515470
commit e9f8f4ef20
3 changed files with 41 additions and 0 deletions

View file

@ -31,6 +31,7 @@ set(cockatrice_SOURCES
src/server/chat_view/chat_view.cpp
src/game/board/counter_general.cpp
src/deck/custom_line_edit.cpp
src/deck/deck_edit_event_bus.cpp
src/deck/deck_loader.cpp
src/deck/deck_list_model.cpp
src/deck/deck_stats_interface.cpp

View file

@ -0,0 +1,14 @@
#include "deck_edit_event_bus.h"
DeckEditEventBus::DeckEditEventBus()
{
}
/**
* Gets the singleton instance of the event bus
*/
DeckEditEventBus *DeckEditEventBus::instance()
{
static DeckEditEventBus deckEditEventBus; // Created only once, on first access
return &deckEditEventBus;
}

View file

@ -0,0 +1,26 @@
#ifndef DECK_EDIT_EVENT_BUS_H
#define DECK_EDIT_EVENT_BUS_H
#include <QObject>
/**
* A singleton object that can be used to pass signals between objects that are far apart in the object tree.
* Contains signals that are related to deck editor and deck storage.
*/
class DeckEditEventBus : public QObject
{
Q_OBJECT
private:
// hide constructor
explicit DeckEditEventBus();
// Delete copy constructor and assignment operator to enforce singleton
DeckEditEventBus(const DeckEditEventBus &) = delete;
DeckEditEventBus &operator=(const DeckEditEventBus &) = delete;
public:
static DeckEditEventBus *instance();
};
#endif // DECK_EDIT_EVENT_BUS_H