Mercurial > hg > piper-cpp
comparison 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 |
comparison
equal
deleted
inserted
replaced
64:85ec33975434 | 65:2d866edd79d5 |
---|---|
42 #include <set> | 42 #include <set> |
43 #include <map> | 43 #include <map> |
44 | 44 |
45 namespace vampipe { | 45 namespace vampipe { |
46 | 46 |
47 //!!! NB not thread-safe at present, should it be? | |
48 class CountingPluginHandleMapper : public PluginHandleMapper | 47 class CountingPluginHandleMapper : public PluginHandleMapper |
49 { | 48 { |
50 public: | 49 public: |
51 CountingPluginHandleMapper() : m_nextHandle(1) { } | 50 CountingPluginHandleMapper() : m_nextHandle(1) { } |
52 | 51 |
53 void addPlugin(Vamp::Plugin *p) { | 52 void addPlugin(Vamp::Plugin *p) { |
53 if (!p) return; | |
54 if (m_rplugins.find(p) == m_rplugins.end()) { | 54 if (m_rplugins.find(p) == m_rplugins.end()) { |
55 Handle h = m_nextHandle++; | 55 Handle h = m_nextHandle++; |
56 m_plugins[h] = p; | 56 m_plugins[h] = p; |
57 m_rplugins[p] = h; | 57 m_rplugins[p] = h; |
58 m_outputMappers[h] = | 58 m_outputMappers[h] = |
59 std::make_shared<DefaultPluginOutputIdMapper>(p); | 59 std::make_shared<DefaultPluginOutputIdMapper>(p); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 void removePlugin(Handle h) { | 63 void removePlugin(Handle h) { |
64 if (m_plugins.find(h) == m_plugins.end()) { | 64 if (m_plugins.find(h) == m_plugins.end()) return; |
65 throw NotFound(); | |
66 } | |
67 Vamp::Plugin *p = m_plugins[h]; | 65 Vamp::Plugin *p = m_plugins[h]; |
68 m_outputMappers.erase(h); | 66 m_outputMappers.erase(h); |
69 m_plugins.erase(h); | 67 m_plugins.erase(h); |
70 if (isConfigured(h)) { | 68 if (isConfigured(h)) { |
71 m_configuredPlugins.erase(h); | 69 m_configuredPlugins.erase(h); |
72 m_channelCounts.erase(h); | 70 m_channelCounts.erase(h); |
73 } | 71 } |
74 m_rplugins.erase(p); | 72 m_rplugins.erase(p); |
75 } | 73 } |
76 | 74 |
77 Handle pluginToHandle(Vamp::Plugin *p) const { | 75 Handle pluginToHandle(Vamp::Plugin *p) const noexcept { |
78 if (m_rplugins.find(p) == m_rplugins.end()) { | 76 if (m_rplugins.find(p) == m_rplugins.end()) { |
79 throw NotFound(); | 77 return INVALID_HANDLE; |
80 } | 78 } |
81 return m_rplugins.at(p); | 79 return m_rplugins.at(p); |
82 } | 80 } |
83 | 81 |
84 Vamp::Plugin *handleToPlugin(Handle h) const { | 82 Vamp::Plugin *handleToPlugin(Handle h) const noexcept { |
85 if (m_plugins.find(h) == m_plugins.end()) { | 83 if (m_plugins.find(h) == m_plugins.end()) { |
86 throw NotFound(); | 84 return nullptr; |
87 } | 85 } |
88 return m_plugins.at(h); | 86 return m_plugins.at(h); |
89 } | 87 } |
90 | 88 |
91 const std::shared_ptr<PluginOutputIdMapper> pluginToOutputIdMapper | 89 const std::shared_ptr<PluginOutputIdMapper> pluginToOutputIdMapper |
92 (Vamp::Plugin *p) const { | 90 (Vamp::Plugin *p) const noexcept { |
93 // pluginToHandle checks the plugin has been registered with us | 91 return handleToOutputIdMapper(pluginToHandle(p)); |
94 return m_outputMappers.at(pluginToHandle(p)); | |
95 } | 92 } |
96 | 93 |
97 const std::shared_ptr<PluginOutputIdMapper> handleToOutputIdMapper | 94 const std::shared_ptr<PluginOutputIdMapper> handleToOutputIdMapper |
98 (Handle h) const { | 95 (Handle h) const noexcept { |
99 if (m_plugins.find(h) == m_plugins.end()) { | 96 if (h != INVALID_HANDLE && |
100 throw NotFound(); | 97 m_outputMappers.find(h) != m_outputMappers.end()) { |
98 return m_outputMappers.at(h); | |
99 } else { | |
100 return {}; | |
101 } | 101 } |
102 return m_outputMappers.at(h); | |
103 } | 102 } |
104 | 103 |
105 bool isConfigured(Handle h) const { | 104 bool isConfigured(Handle h) const noexcept { |
105 if (h == INVALID_HANDLE) return false; | |
106 return m_configuredPlugins.find(h) != m_configuredPlugins.end(); | 106 return m_configuredPlugins.find(h) != m_configuredPlugins.end(); |
107 } | 107 } |
108 | 108 |
109 void markConfigured(Handle h, int channelCount, int blockSize) { | 109 void markConfigured(Handle h, int channelCount, int blockSize) { |
110 if (h == INVALID_HANDLE) return; | |
110 m_configuredPlugins.insert(h); | 111 m_configuredPlugins.insert(h); |
111 m_channelCounts[h] = channelCount; | 112 m_channelCounts[h] = channelCount; |
112 m_blockSizes[h] = blockSize; | 113 m_blockSizes[h] = blockSize; |
113 } | 114 } |
114 | 115 |
115 int getChannelCount(Handle h) const { | 116 int getChannelCount(Handle h) const noexcept { |
116 if (m_channelCounts.find(h) == m_channelCounts.end()) { | 117 if (m_channelCounts.find(h) == m_channelCounts.end()) { |
117 throw NotFound(); | 118 return 0; |
118 } | 119 } |
119 return m_channelCounts.at(h); | 120 return m_channelCounts.at(h); |
120 } | 121 } |
121 | 122 |
122 int getBlockSize(Handle h) const { | 123 int getBlockSize(Handle h) const noexcept { |
123 if (m_blockSizes.find(h) == m_blockSizes.end()) { | 124 if (m_blockSizes.find(h) == m_blockSizes.end()) { |
124 throw NotFound(); | 125 return 0; |
125 } | 126 } |
126 return m_blockSizes.at(h); | 127 return m_blockSizes.at(h); |
127 } | 128 } |
128 | 129 |
129 private: | 130 private: |