commit 906fd06eb2bbee2f736a83cc773423cc1c481cf9
parent 7b8d17c00e45957bbd8b8a4d9fd5d97bba3058e0
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Tue, 14 Sep 2021 21:33:16 +0200
Fix some mistake with emplace()
Diffstat:
5 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/examples/host/plugin-host.cc b/examples/host/plugin-host.cc
@@ -1,4 +1,4 @@
-#include <exception>
+#include <exception>
#include <iostream>
#include <memory>
#include <sstream>
@@ -437,7 +437,7 @@ bool PluginHost::clapRegisterTimer(const clap_host *host, uint32_t period_ms, cl
});
auto t = timer.get();
- h->_timers.emplace(*timer_id, std::move(timer));
+ h->_timers.insert_or_assign(*timer_id, std::move(timer));
t->start(period_ms);
return true;
}
@@ -473,7 +473,7 @@ bool PluginHost::clapRegisterFd(const clap_host *host, clap_fd fd, uint32_t flag
throw std::logic_error(
"Called register_fd() for a fd that was already registered, use modify_fd() instead.");
- h->_fds.emplace(fd, std::make_unique<Notifiers>());
+ h->_fds.insert_or_assign(fd, std::make_unique<Notifiers>());
h->eventLoopSetFdNotifierFlags(fd, flags);
return true;
}
@@ -491,7 +491,7 @@ bool PluginHost::clapModifyFd(const clap_host *host, clap_fd fd, uint32_t flags)
throw std::logic_error(
"Called modify_fd() for a fd that was not registered, use register_fd() instead.");
- h->_fds.emplace(fd, std::make_unique<Notifiers>());
+ h->_fds.insert_or_assign(fd, std::make_unique<Notifiers>());
h->eventLoopSetFdNotifierFlags(fd, flags);
return true;
}
@@ -880,7 +880,7 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) {
double value = h->getParamValue(info);
auto param = std::make_unique<PluginParam>(*h, info, value);
h->checkValidParamValue(*param, value);
- h->_params.emplace(info.id, std::move(param));
+ h->_params.insert_or_assign(info.id, std::move(param));
} else {
// update param info
if (!it->second->isInfoEqualTo(info)) {
@@ -1008,7 +1008,7 @@ void PluginHost::scanQuickControls() {
throw std::invalid_argument(msg.str());
}
- _quickControlsPages.emplace(page->id, std::move(page));
+ _quickControlsPages.insert_or_assign(page->id, std::move(page));
}
quickControlsPagesChanged();
diff --git a/examples/host/plugin-parameters-widget.cc b/examples/host/plugin-parameters-widget.cc
@@ -174,7 +174,7 @@ void PluginParametersWidget::computeDataModel() {
module = &module->subModule(m);
auto item = std::make_unique<ParamTreeItem>(module, param);
- _idToParamTreeItem.emplace(param.info().id, std::move(item));
+ _idToParamTreeItem.insert_or_assign(param.info().id, std::move(item));
}
_treeWidget->sortItems(0, Qt::AscendingOrder);
}
diff --git a/examples/plugins/gui/plugin-proxy.cc b/examples/plugins/gui/plugin-proxy.cc
@@ -8,7 +8,7 @@ ParameterProxy *PluginProxy::param(clap_id paramId) {
return it->second;
auto *p = new ParameterProxy(paramId, this);
- _parameters.emplace(paramId, p);
+ _parameters.insert_or_assign(paramId, p);
return p;
}
@@ -16,9 +16,7 @@ QString PluginProxy::toString() const { return "Plugin"; }
void PluginProxy::defineParameter(const clap_param_info &info)
{
- auto it = _parameters.find(info.id);
- if (it != _parameters.end())
- it->second->redefine(info);
- else
- _parameters.emplace(info.id, new ParameterProxy(info, this));
+ auto it = _parameters.emplace(info.id, new ParameterProxy(info, this));
+ if (it.second)
+ it.first->second->redefine(info);
}
\ No newline at end of file
diff --git a/examples/plugins/io/remote-channel.cc b/examples/plugins/io/remote-channel.cc
@@ -152,7 +152,10 @@ namespace clap {
bool RemoteChannel::sendMessageSync(const Message &msg, const MessageHandler &handler) {
sendMessageAsync(msg);
- _syncHandlers.emplace(msg.cookie, handler);
+ auto it = _syncHandlers.emplace(msg.cookie, handler);
+ assert(it.second);
+ if (!it.second)
+ return false;
while (_syncHandlers.count(msg.cookie) > 0)
runOnce();
diff --git a/examples/plugins/parameters.cc b/examples/plugins/parameters.cc
@@ -7,7 +7,7 @@ namespace clap {
assert(_id2param.find(info.id) == _id2param.end());
auto p = std::make_unique<Parameter>(info);
- _id2param.emplace(info.id, p.get());
+ _id2param.insert_or_assign(info.id, p.get());
_params.emplace_back(std::move(p));
}