diff bits/CountingPluginHandleMapper.h @ 65:2d866edd79d5

Merge from noexcept branch
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 23 Sep 2016 14:23:10 +0100
parents 8a4bcb3dc3a6
children
line wrap: on
line diff
--- a/bits/CountingPluginHandleMapper.h	Fri Sep 23 14:20:29 2016 +0100
+++ b/bits/CountingPluginHandleMapper.h	Fri Sep 23 14:23:10 2016 +0100
@@ -44,13 +44,13 @@
 
 namespace vampipe {
 
-//!!! NB not thread-safe at present, should it be?
 class CountingPluginHandleMapper : public PluginHandleMapper
 {
 public:
     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;
@@ -61,9 +61,7 @@
     }
 
     void removePlugin(Handle h) {
-	if (m_plugins.find(h) == m_plugins.end()) {
-	    throw NotFound();
-	}
+	if (m_plugins.find(h) == m_plugins.end()) return;
 	Vamp::Plugin *p = m_plugins[h];
         m_outputMappers.erase(h);
 	m_plugins.erase(h);
@@ -74,54 +72,57 @@
 	m_rplugins.erase(p);
     }
     
-    Handle pluginToHandle(Vamp::Plugin *p) const {
+    Handle pluginToHandle(Vamp::Plugin *p) const noexcept {
 	if (m_rplugins.find(p) == m_rplugins.end()) {
-	    throw NotFound();
+            return INVALID_HANDLE;
 	}
 	return m_rplugins.at(p);
     }
     
-    Vamp::Plugin *handleToPlugin(Handle h) const {
+    Vamp::Plugin *handleToPlugin(Handle h) const noexcept {
 	if (m_plugins.find(h) == m_plugins.end()) {
-	    throw NotFound();
+            return nullptr;
 	}
 	return m_plugins.at(h);
     }
 
     const std::shared_ptr<PluginOutputIdMapper> pluginToOutputIdMapper
-    (Vamp::Plugin *p) const {
-        // pluginToHandle checks the plugin has been registered with us
-        return m_outputMappers.at(pluginToHandle(p));
+    (Vamp::Plugin *p) const noexcept {
+        return handleToOutputIdMapper(pluginToHandle(p));
     }
 
     const std::shared_ptr<PluginOutputIdMapper> handleToOutputIdMapper
-    (Handle h) const {
-	if (m_plugins.find(h) == m_plugins.end()) {
-	    throw NotFound();
+    (Handle h) const noexcept {
+	if (h != INVALID_HANDLE &&
+            m_outputMappers.find(h) != m_outputMappers.end()) {
+            return m_outputMappers.at(h);
+        } else {
+	    return {};
 	}
-        return m_outputMappers.at(h);
     }
 
-    bool isConfigured(Handle h) const {
+    bool isConfigured(Handle h) const noexcept {
+        if (h == INVALID_HANDLE) return false;
 	return m_configuredPlugins.find(h) != m_configuredPlugins.end();
     }
 
     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;
     }
 
-    int getChannelCount(Handle h) const {
+    int getChannelCount(Handle h) const noexcept {
 	if (m_channelCounts.find(h) == m_channelCounts.end()) {
-	    throw NotFound();
+	    return 0;
 	}
 	return m_channelCounts.at(h);
     }
 
-    int getBlockSize(Handle h) const {
+    int getBlockSize(Handle h) const noexcept {
 	if (m_blockSizes.find(h) == m_blockSizes.end()) {
-	    throw NotFound();
+            return 0;
 	}
 	return m_blockSizes.at(h);
     }