comparison bits/CountingPluginHandleMapper.h @ 58:c38e12d4bbdd

Merge from branch outputid-string-in-featureset
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 19 Sep 2016 14:48:43 +0100
parents 7aec704705c7
children 8a4bcb3dc3a6
comparison
equal deleted inserted replaced
48:ce6cb3308bd7 58:c38e12d4bbdd
34 34
35 #ifndef VAMPIPE_COUNTING_PLUGIN_HANDLE_MAPPER_H 35 #ifndef VAMPIPE_COUNTING_PLUGIN_HANDLE_MAPPER_H
36 #define VAMPIPE_COUNTING_PLUGIN_HANDLE_MAPPER_H 36 #define VAMPIPE_COUNTING_PLUGIN_HANDLE_MAPPER_H
37 37
38 #include "PluginHandleMapper.h" 38 #include "PluginHandleMapper.h"
39 #include "PluginOutputIdMapper.h"
40 #include "DefaultPluginOutputIdMapper.h"
39 41
40 #include <set> 42 #include <set>
41 #include <map> 43 #include <map>
42 44
43 namespace vampipe { 45 namespace vampipe {
48 public: 50 public:
49 CountingPluginHandleMapper() : m_nextHandle(1) { } 51 CountingPluginHandleMapper() : m_nextHandle(1) { }
50 52
51 void addPlugin(Vamp::Plugin *p) { 53 void addPlugin(Vamp::Plugin *p) {
52 if (m_rplugins.find(p) == m_rplugins.end()) { 54 if (m_rplugins.find(p) == m_rplugins.end()) {
53 int32_t h = m_nextHandle++; 55 Handle h = m_nextHandle++;
54 m_plugins[h] = p; 56 m_plugins[h] = p;
55 m_rplugins[p] = h; 57 m_rplugins[p] = h;
58 m_outputMappers[h] =
59 std::make_shared<DefaultPluginOutputIdMapper>(p);
56 } 60 }
57 } 61 }
58 62
59 void removePlugin(int32_t h) { 63 void removePlugin(Handle h) {
60 if (m_plugins.find(h) == m_plugins.end()) { 64 if (m_plugins.find(h) == m_plugins.end()) {
61 throw NotFound(); 65 throw NotFound();
62 } 66 }
63 Vamp::Plugin *p = m_plugins[h]; 67 Vamp::Plugin *p = m_plugins[h];
68 m_outputMappers.erase(h);
64 m_plugins.erase(h); 69 m_plugins.erase(h);
65 if (isConfigured(h)) { 70 if (isConfigured(h)) {
66 m_configuredPlugins.erase(h); 71 m_configuredPlugins.erase(h);
67 m_channelCounts.erase(h); 72 m_channelCounts.erase(h);
68 } 73 }
69 m_rplugins.erase(p); 74 m_rplugins.erase(p);
70 } 75 }
71 76
72 int32_t pluginToHandle(Vamp::Plugin *p) const { 77 Handle pluginToHandle(Vamp::Plugin *p) const {
73 if (m_rplugins.find(p) == m_rplugins.end()) { 78 if (m_rplugins.find(p) == m_rplugins.end()) {
74 throw NotFound(); 79 throw NotFound();
75 } 80 }
76 return m_rplugins.at(p); 81 return m_rplugins.at(p);
77 } 82 }
78 83
79 Vamp::Plugin *handleToPlugin(int32_t h) const { 84 Vamp::Plugin *handleToPlugin(Handle h) const {
80 if (m_plugins.find(h) == m_plugins.end()) { 85 if (m_plugins.find(h) == m_plugins.end()) {
81 throw NotFound(); 86 throw NotFound();
82 } 87 }
83 return m_plugins.at(h); 88 return m_plugins.at(h);
84 } 89 }
85 90
86 bool isConfigured(int32_t h) const { 91 const std::shared_ptr<PluginOutputIdMapper> pluginToOutputIdMapper
92 (Vamp::Plugin *p) const {
93 // pluginToHandle checks the plugin has been registered with us
94 return m_outputMappers.at(pluginToHandle(p));
95 }
96
97 const std::shared_ptr<PluginOutputIdMapper> handleToOutputIdMapper
98 (Handle h) const {
99 if (m_plugins.find(h) == m_plugins.end()) {
100 throw NotFound();
101 }
102 return m_outputMappers.at(h);
103 }
104
105 bool isConfigured(Handle h) const {
87 return m_configuredPlugins.find(h) != m_configuredPlugins.end(); 106 return m_configuredPlugins.find(h) != m_configuredPlugins.end();
88 } 107 }
89 108
90 void markConfigured(int32_t h, int channelCount, int blockSize) { 109 void markConfigured(Handle h, int channelCount, int blockSize) {
91 m_configuredPlugins.insert(h); 110 m_configuredPlugins.insert(h);
92 m_channelCounts[h] = channelCount; 111 m_channelCounts[h] = channelCount;
93 m_blockSizes[h] = blockSize; 112 m_blockSizes[h] = blockSize;
94 } 113 }
95 114
96 int getChannelCount(int32_t h) const { 115 int getChannelCount(Handle h) const {
97 if (m_channelCounts.find(h) == m_channelCounts.end()) { 116 if (m_channelCounts.find(h) == m_channelCounts.end()) {
98 throw NotFound(); 117 throw NotFound();
99 } 118 }
100 return m_channelCounts.at(h); 119 return m_channelCounts.at(h);
101 } 120 }
102 121
103 int getBlockSize(int32_t h) const { 122 int getBlockSize(Handle h) const {
104 if (m_blockSizes.find(h) == m_blockSizes.end()) { 123 if (m_blockSizes.find(h) == m_blockSizes.end()) {
105 throw NotFound(); 124 throw NotFound();
106 } 125 }
107 return m_blockSizes.at(h); 126 return m_blockSizes.at(h);
108 } 127 }
109 128
110 private: 129 private:
111 int32_t m_nextHandle; // NB plugin handle type must fit in JSON number 130 Handle m_nextHandle; // NB plugin handle type must fit in JSON number
112 std::map<uint32_t, Vamp::Plugin *> m_plugins; 131 std::map<Handle, Vamp::Plugin *> m_plugins;
113 std::map<Vamp::Plugin *, uint32_t> m_rplugins; 132 std::map<Vamp::Plugin *, Handle> m_rplugins;
114 std::set<uint32_t> m_configuredPlugins; 133 std::set<Handle> m_configuredPlugins;
115 std::map<uint32_t, int> m_channelCounts; 134 std::map<Handle, int> m_channelCounts;
116 std::map<uint32_t, int> m_blockSizes; 135 std::map<Handle, int> m_blockSizes;
136 std::map<Handle, std::shared_ptr<PluginOutputIdMapper>> m_outputMappers;
117 }; 137 };
118 138
119 } 139 }
120 140
121 #endif 141 #endif