commit 760c37d12f25f42cf83841e41a2ec794100c1d8a
parent 4b15951a7631c2bdbe1b078ab84e22c7c3dc1101
Author: cfillion <cfillion@users.noreply.github.com>
Date: Tue, 4 Sep 2018 01:57:29 -0400
improve API registration code
Diffstat:
4 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/src/api.hpp b/src/api.hpp
@@ -32,6 +32,7 @@ struct APIFunc {
class APIDef {
public:
APIDef(const APIFunc *);
+ APIDef(const APIDef &) = delete;
~APIDef();
private:
diff --git a/src/main.cpp b/src/main.cpp
@@ -151,17 +151,17 @@ static void setupActions()
static void setupAPI()
{
- g_reapack->setupAPI(&API::AboutInstalledPackage);
- g_reapack->setupAPI(&API::AboutRepository);
- g_reapack->setupAPI(&API::AddSetRepository);
- g_reapack->setupAPI(&API::BrowsePackages);
- g_reapack->setupAPI(&API::CompareVersions);
- g_reapack->setupAPI(&API::EnumOwnedFiles);
- g_reapack->setupAPI(&API::FreeEntry);
- g_reapack->setupAPI(&API::GetEntryInfo);
- g_reapack->setupAPI(&API::GetOwner);
- g_reapack->setupAPI(&API::GetRepositoryInfo);
- g_reapack->setupAPI(&API::ProcessQueue);
+ g_reapack->addAPI(&API::AboutInstalledPackage);
+ g_reapack->addAPI(&API::AboutRepository);
+ g_reapack->addAPI(&API::AddSetRepository);
+ g_reapack->addAPI(&API::BrowsePackages);
+ g_reapack->addAPI(&API::CompareVersions);
+ g_reapack->addAPI(&API::EnumOwnedFiles);
+ g_reapack->addAPI(&API::FreeEntry);
+ g_reapack->addAPI(&API::GetEntryInfo);
+ g_reapack->addAPI(&API::GetOwner);
+ g_reapack->addAPI(&API::GetRepositoryInfo);
+ g_reapack->addAPI(&API::ProcessQueue);
}
extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -149,11 +149,6 @@ bool ReaPack::execActions(const int id, const int)
return true;
}
-void ReaPack::setupAPI(const APIFunc *func)
-{
- m_api.push_back(std::make_unique<APIDef>(func));
-}
-
void ReaPack::synchronizeAll()
{
const vector<Remote> &remotes = m_config->remotes.getEnabled();
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -18,24 +18,22 @@
#ifndef REAPACK_REAPACK_HPP
#define REAPACK_REAPACK_HPP
+#include "api.hpp"
#include "path.hpp"
#include <functional>
#include <map>
-#include <memory>
-#include <vector>
+#include <list>
#include <reaper_plugin.h>
class About;
-class APIDef;
class Browser;
class Config;
class Manager;
class Progress;
class Remote;
class Transaction;
-struct APIFunc;
#define g_reapack (ReaPack::instance())
@@ -62,7 +60,7 @@ public:
gaccel_register_t *action, const ActionCallback &);
bool execActions(int id, int);
- void setupAPI(const APIFunc *func);
+ void addAPI(const APIFunc *func) { m_api.emplace_back(func); }
void synchronizeAll();
void uninstall(const Remote &);
@@ -91,7 +89,7 @@ private:
void teardownTransaction();
std::map<int, ActionCallback> m_actions;
- std::vector<std::unique_ptr<APIDef> > m_api;
+ std::list<APIDef> m_api;
Config *m_config;
Transaction *m_tx;