Mercurial > hg > piper-cpp
diff vamp-support/CountingPluginHandleMapper.h @ 80:d9e85a65d45b
Inching toward a client
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Tue, 11 Oct 2016 15:49:28 +0100 |
parents | 81e1c48e97f9 |
children | db9a6ab618bc |
line wrap: on
line diff
--- a/vamp-support/CountingPluginHandleMapper.h Tue Oct 11 14:38:04 2016 +0100 +++ b/vamp-support/CountingPluginHandleMapper.h Tue Oct 11 15:49:28 2016 +0100 @@ -37,7 +37,7 @@ #include "PluginHandleMapper.h" #include "PluginOutputIdMapper.h" -#include "DefaultPluginOutputIdMapper.h" +#include "AssignedPluginHandleMapper.h" #include <set> #include <map> @@ -50,91 +50,51 @@ CountingPluginHandleMapper() : m_nextHandle(1) { } void addPlugin(Vamp::Plugin *p) { - if (!p) return; - if (m_rplugins.find(p) == m_rplugins.end()) { - Handle h = m_nextHandle++; - m_plugins[h] = p; - m_rplugins[p] = h; - m_outputMappers[h] = - std::make_shared<DefaultPluginOutputIdMapper>(p); - } + Handle h = m_nextHandle++; + m_sub.addPlugin(p, h); } void removePlugin(Handle h) { - if (m_plugins.find(h) == m_plugins.end()) return; - Vamp::Plugin *p = m_plugins[h]; - m_outputMappers.erase(h); - m_plugins.erase(h); - if (isConfigured(h)) { - m_configuredPlugins.erase(h); - m_channelCounts.erase(h); - } - m_rplugins.erase(p); + m_sub.removePlugin(h); } Handle pluginToHandle(Vamp::Plugin *p) const noexcept { - if (m_rplugins.find(p) == m_rplugins.end()) { - return INVALID_HANDLE; - } - return m_rplugins.at(p); + return m_sub.pluginToHandle(p); } Vamp::Plugin *handleToPlugin(Handle h) const noexcept { - if (m_plugins.find(h) == m_plugins.end()) { - return nullptr; - } - return m_plugins.at(h); + return m_sub.handleToPlugin(h); } const std::shared_ptr<PluginOutputIdMapper> pluginToOutputIdMapper (Vamp::Plugin *p) const noexcept { - return handleToOutputIdMapper(pluginToHandle(p)); + return m_sub.pluginToOutputIdMapper(p); } const std::shared_ptr<PluginOutputIdMapper> handleToOutputIdMapper (Handle h) const noexcept { - if (h != INVALID_HANDLE && - m_outputMappers.find(h) != m_outputMappers.end()) { - return m_outputMappers.at(h); - } else { - return {}; - } + return m_sub.handleToOutputIdMapper(h); } bool isConfigured(Handle h) const noexcept { - if (h == INVALID_HANDLE) return false; - return m_configuredPlugins.find(h) != m_configuredPlugins.end(); + return m_sub.isConfigured(h); } void markConfigured(Handle h, int channelCount, int blockSize) { - if (h == INVALID_HANDLE) return; - m_configuredPlugins.insert(h); - m_channelCounts[h] = channelCount; - m_blockSizes[h] = blockSize; + m_sub.markConfigured(h, channelCount, blockSize); } int getChannelCount(Handle h) const noexcept { - if (m_channelCounts.find(h) == m_channelCounts.end()) { - return 0; - } - return m_channelCounts.at(h); + return m_sub.getChannelCount(h); } int getBlockSize(Handle h) const noexcept { - if (m_blockSizes.find(h) == m_blockSizes.end()) { - return 0; - } - return m_blockSizes.at(h); + return m_sub.getBlockSize(h); } private: Handle m_nextHandle; // NB plugin handle type must fit in JSON number - std::map<Handle, Vamp::Plugin *> m_plugins; - std::map<Vamp::Plugin *, Handle> m_rplugins; - std::set<Handle> m_configuredPlugins; - std::map<Handle, int> m_channelCounts; - std::map<Handle, int> m_blockSizes; - std::map<Handle, std::shared_ptr<PluginOutputIdMapper>> m_outputMappers; + AssignedPluginHandleMapper m_sub; }; }