changeset 13:85801331454c

* Make static adapter map a pointer to avoid any confusion about static destructor ordering
author cannam
date Thu, 06 Apr 2006 16:35:49 +0000
parents a3d35e11c3fe
children b63909cbbf57
files COPYING examples/SpectralCentroid.cpp vamp-sdk/PluginAdapter.cpp vamp-sdk/PluginAdapter.h
diffstat 4 files changed, 35 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/COPYING	Thu Apr 06 15:12:25 2006 +0000
+++ b/COPYING	Thu Apr 06 16:35:49 2006 +0000
@@ -1,5 +1,3 @@
-
-    Copyright 2006 Chris Cannam.
   
     Permission is hereby granted, free of charge, to any person
     obtaining a copy of this software and associated documentation
--- a/examples/SpectralCentroid.cpp	Thu Apr 06 15:12:25 2006 +0000
+++ b/examples/SpectralCentroid.cpp	Thu Apr 06 16:35:49 2006 +0000
@@ -156,7 +156,7 @@
 
     FeatureSet returnFeatures;
 
-    std::cerr << "power " << denom << ", block size " << m_blockSize << std::endl;
+//    std::cerr << "power " << denom << ", block size " << m_blockSize << std::endl;
 
     if (denom != 0.0) {
 	float centroidLin = float(numLin / denom);
--- a/vamp-sdk/PluginAdapter.cpp	Thu Apr 06 15:12:25 2006 +0000
+++ b/vamp-sdk/PluginAdapter.cpp	Thu Apr 06 16:35:49 2006 +0000
@@ -121,7 +121,10 @@
     m_descriptor.getRemainingFeatures = vampGetRemainingFeatures;
     m_descriptor.releaseFeatureSet = vampReleaseFeatureSet;
     
-    m_adapterMap[&m_descriptor] = this;
+    if (!m_adapterMap) {
+        m_adapterMap = new AdapterMap;
+        (*m_adapterMap)[&m_descriptor] = this;
+    }
 
     delete plugin;
 
@@ -157,14 +160,23 @@
     }
     free((void *)m_descriptor.programs);
 
-    m_adapterMap.erase(&m_descriptor);
+    if (m_adapterMap) {
+        
+        m_adapterMap->erase(&m_descriptor);
+
+        if (m_adapterMap->empty()) {
+            delete m_adapterMap;
+            m_adapterMap = 0;
+        }
+    }
 }
 
 PluginAdapterBase *
 PluginAdapterBase::lookupAdapter(VampPluginHandle handle)
 {
-    AdapterMap::const_iterator i = m_adapterMap.find(handle);
-    if (i == m_adapterMap.end()) return 0;
+    if (!m_adapterMap) return 0;
+    AdapterMap::const_iterator i = m_adapterMap->find(handle);
+    if (i == m_adapterMap->end()) return 0;
     return i->second;
 }
 
@@ -172,13 +184,14 @@
 PluginAdapterBase::vampInstantiate(const VampPluginDescriptor *desc,
                                    float inputSampleRate)
 {
-    if (m_adapterMap.find(desc) == m_adapterMap.end()) return 0;
-    PluginAdapterBase *adapter = m_adapterMap[desc];
+    if (!m_adapterMap) return 0;
+    if (m_adapterMap->find(desc) == m_adapterMap->end()) return 0;
+    PluginAdapterBase *adapter = (*m_adapterMap)[desc];
     if (desc != &adapter->m_descriptor) return 0;
 
     Plugin *plugin = adapter->createPlugin(inputSampleRate);
     if (plugin) {
-        m_adapterMap[plugin] = adapter;
+        (*m_adapterMap)[plugin] = adapter;
     }
 
     return plugin;
@@ -363,7 +376,16 @@
         delete m_pluginOutputs[plugin];
         m_pluginOutputs.erase(plugin);
     }
-    m_adapterMap.erase(plugin);
+
+    if (m_adapterMap) {
+        m_adapterMap->erase(plugin);
+
+        if (m_adapterMap->empty()) {
+            delete m_adapterMap;
+            m_adapterMap = 0;
+        }
+    }
+
     delete ((Plugin *)plugin);
 }
 
@@ -596,8 +618,8 @@
     m_fvsizes[plugin][n][j] = sz;
 }
   
-PluginAdapterBase::AdapterMap 
-PluginAdapterBase::m_adapterMap;
+PluginAdapterBase::AdapterMap *
+PluginAdapterBase::m_adapterMap = 0;
 
 }
 
--- a/vamp-sdk/PluginAdapter.h	Thu Apr 06 15:12:25 2006 +0000
+++ b/vamp-sdk/PluginAdapter.h	Thu Apr 06 16:35:49 2006 +0000
@@ -105,8 +105,9 @@
     VampFeatureList *convertFeatures(Plugin *plugin,
                                      const Plugin::FeatureSet &features);
     
+    // maps both plugins and descriptors to adapters
     typedef std::map<const void *, PluginAdapterBase *> AdapterMap;
-    static AdapterMap m_adapterMap;
+    static AdapterMap *m_adapterMap;
     static PluginAdapterBase *lookupAdapter(VampPluginHandle);
 
     bool m_populated;