summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-01-21 00:41:34 +0100
committerDavid Robillard <d@drobilla.net>2018-01-21 00:56:50 +0100
commitfa2fd348491cddef0a356fb13a8dab0d2e91d5fb (patch)
tree3885d48c5f648c5e884133993d5056862e3babd0
parent001b459dfaf5d2ed53e4f7a5daea2a408aba1a2d (diff)
downloadingen-fa2fd348491cddef0a356fb13a8dab0d2e91d5fb.tar.gz
ingen-fa2fd348491cddef0a356fb13a8dab0d2e91d5fb.tar.bz2
ingen-fa2fd348491cddef0a356fb13a8dab0d2e91d5fb.zip
Replace glib quarks
-rw-r--r--ingen/URIMap.hpp12
-rw-r--r--src/URIMap.cpp28
2 files changed, 32 insertions, 8 deletions
diff --git a/ingen/URIMap.hpp b/ingen/URIMap.hpp
index 6ad8c684..fc402c2c 100644
--- a/ingen/URIMap.hpp
+++ b/ingen/URIMap.hpp
@@ -18,8 +18,11 @@
#define INGEN_URIMAP_HPP
#include <cstdint>
+#include <mutex>
#include <string>
+#include <unordered_map>
#include <utility>
+#include <vector>
#include "ingen/LV2Features.hpp"
#include "ingen/ingen.h"
@@ -65,7 +68,7 @@ public:
struct URIDMapFeature : public Feature {
URIDMapFeature(URIMap* map, LV2_URID_Map* impl, Log& log);
LV2_URID map(const char* uri);
- static LV2_URID default_map(LV2_URID_Map_Handle h, const char* uri);
+ static LV2_URID default_map(LV2_URID_Map_Handle h, const char* c_uri);
LV2_URID_Map urid_map;
Log& log;
};
@@ -81,8 +84,15 @@ public:
SPtr<URIDUnmapFeature> urid_unmap_feature() { return _urid_unmap_feature; }
private:
+ friend class URIDMapFeature;
+ friend class URIDUnMapFeature;
+
SPtr<URIDMapFeature> _urid_map_feature;
SPtr<URIDUnmapFeature> _urid_unmap_feature;
+
+ std::mutex _mutex;
+ std::unordered_map<std::string, LV2_URID> _map;
+ std::vector<std::string> _unmap;
};
} // namespace Ingen
diff --git a/src/URIMap.cpp b/src/URIMap.cpp
index 01d48c00..9ce1f178 100644
--- a/src/URIMap.cpp
+++ b/src/URIMap.cpp
@@ -16,8 +16,6 @@
#include <cstdint>
-#include <glib.h>
-
#include "ingen/Log.hpp"
#include "ingen/URI.hpp"
#include "ingen/URIMap.hpp"
@@ -40,15 +38,26 @@ URIMap::URIDMapFeature::URIDMapFeature(URIMap* map,
urid_map = *impl;
} else {
urid_map.map = default_map;
- urid_map.handle = nullptr;
+ urid_map.handle = map;
}
}
LV2_URID
URIMap::URIDMapFeature::default_map(LV2_URID_Map_Handle h,
- const char* uri)
+ const char* c_uri)
{
- return static_cast<LV2_URID>(g_quark_from_string(uri));
+ URIMap* const map((URIMap*)h);
+ std::string uri(c_uri);
+ std::lock_guard<std::mutex> lock(map->_mutex);
+
+ auto record = map->_map.emplace(uri, map->_map.size() + 1);
+ const auto id = record.first->second;
+ if (record.second) {
+ assert(id == map->_map.size());
+ assert(id == map->_unmap.size() + 1);
+ map->_unmap.emplace_back(std::move(uri));
+ }
+ return id;
}
LV2_URID
@@ -69,7 +78,7 @@ URIMap::URIDUnmapFeature::URIDUnmapFeature(URIMap* map,
urid_unmap = *impl;
} else {
urid_unmap.unmap = default_unmap;
- urid_unmap.handle = nullptr;
+ urid_unmap.handle = map;
}
}
@@ -77,7 +86,12 @@ const char*
URIMap::URIDUnmapFeature::default_unmap(LV2_URID_Unmap_Handle h,
LV2_URID urid)
{
- return g_quark_to_string(urid);
+ URIMap* const map((URIMap*)h);
+ std::lock_guard<std::mutex> lock(map->_mutex);
+
+ return (urid > 0 && urid <= map->_unmap.size()
+ ? map->_unmap[urid - 1].c_str()
+ : NULL);
}
const char*