Skip to content

Commit

Permalink
Make listener<>::instances inline
Browse files Browse the repository at this point in the history
This simplifies the user interface and removes a clang warning about it being
potentially uninitialized.

See #2139.
  • Loading branch information
lmoureaux committed Jan 20, 2024
1 parent 3f13180 commit af35774
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 19 deletions.
1 change: 0 additions & 1 deletion client/chatline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

static bool is_plain_public_message(const QString &s);

FC_CPP_DECLARE_LISTENER(chat_listener)
QStringList chat_listener::history = QStringList();

namespace {
Expand Down
17 changes: 1 addition & 16 deletions client/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
};
~~~~~
The listener needs some static data. Declaring it is as simple as putting
a macro in some source file:
~~~~~{.cpp}
FC_CPP_DECLARE_LISTENER(foo_listener)
~~~~~
Then, you call the listeners from the implementation of the C interface:
~~~~~{.cpp}
Expand Down Expand Up @@ -104,7 +97,7 @@ template <class _type_> class listener {

private:
// All instances of type_t that have called listen().
static std::set<listener<type_t> *> instances;
inline static std::set<listener<type_t> *> instances{};

protected:
explicit listener();
Expand All @@ -117,14 +110,6 @@ template <class _type_> class listener {
static void invoke(_member_fct_ function, _args_ &&...args);
};

/***************************************************************************
Macro to declare the static data needed by listener<> classes
***************************************************************************/
#define FC_CPP_DECLARE_LISTENER(_type_) \
template <> \
std::set<listener<_type_> *> listener<_type_>::instances = \
std::set<listener<_type_> *>();

/***************************************************************************
Constructor
***************************************************************************/
Expand Down
2 changes: 0 additions & 2 deletions client/map_updates_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include "options.h"
#include "tilespec.h"

FC_CPP_DECLARE_LISTENER(freeciv::map_updates_handler)

namespace freeciv {

/**
Expand Down

0 comments on commit af35774

Please sign in to comment.