[core] Make ActorRef methods const

So that the lambdas calling these methods do not have to be mutable.
This commit is contained in:
Mikhail Pozdnyakov
2019-05-10 11:10:23 +03:00
parent 9fb41a74bc
commit b41f39d545
5 changed files with 8 additions and 8 deletions

View File

@@ -29,14 +29,14 @@ public:
}
template <typename Fn, class... Args>
void invoke(Fn fn, Args&&... args) {
void invoke(Fn fn, Args&&... args) const {
if (auto mailbox = weakMailbox.lock()) {
mailbox->push(actor::makeMessage(*object, fn, std::forward<Args>(args)...));
}
}
template <typename Fn, class... Args>
auto ask(Fn fn, Args&&... args) {
auto ask(Fn fn, Args&&... args) const {
// Result type is deduced from the function's return type
using ResultType = typename std::result_of<decltype(fn)(Object, Args...)>::type;

View File

@@ -81,7 +81,7 @@ MapSnapshotter::Impl::Impl(std::shared_ptr<Scheduler> scheduler_,
}
void MapSnapshotter::Impl::snapshot(ActorRef<MapSnapshotter::Callback> callback) {
map.renderStill([this, callback = std::move(callback)] (std::exception_ptr error) mutable {
map.renderStill([this, callback = std::move(callback)] (std::exception_ptr error) {
// Create lambda that captures the current transform state
// and can be used to translate for geographic to screen

View File

@@ -97,7 +97,7 @@ public:
}
void request(AsyncRequest* req, Resource resource, ActorRef<FileSourceRequest> ref) {
auto callback = [ref] (const Response& res) mutable {
auto callback = [ref] (const Response& res) {
ref.invoke(&FileSourceRequest::setResponse, res);
};
@@ -145,7 +145,7 @@ public:
// Get from the online file source
if (resource.hasLoadingMethod(Resource::LoadingMethod::Network)) {
MBGL_TIMING_START(watch);
tasks[req] = onlineFileSource.request(resource, [=] (Response onlineResponse) mutable {
tasks[req] = onlineFileSource.request(resource, [=] (Response onlineResponse) {
this->offlineDatabase->put(resource, onlineResponse);
if (resource.kind == Resource::Kind::Tile) {
// onlineResponse.data will be null if data not modified
@@ -259,7 +259,7 @@ void DefaultFileSource::setResourceCachePath(const std::string& path) {
std::unique_ptr<AsyncRequest> DefaultFileSource::request(const Resource& resource, Callback callback) {
auto req = std::make_unique<FileSourceRequest>(std::move(callback));
req->onCancel([fs = impl->actor(), req = req.get()] () mutable { fs.invoke(&Impl::cancel, req); });
req->onCancel([fs = impl->actor(), req = req.get()] () { fs.invoke(&Impl::cancel, req); });
impl->actor().invoke(&Impl::request, req.get(), resource, req->actor());

View File

@@ -79,7 +79,7 @@ public:
// Request the ResourceTransform actor a new url and replace the resource url with the
// transformed one before proceeding to schedule the request.
resourceTransform->invoke(&ResourceTransform::transform, request->resource.kind,
std::move(request->resource.url), [ref = request->actor()](const std::string&& url) mutable {
std::move(request->resource.url), [ref = request->actor()](const std::string&& url) {
ref.invoke(&OnlineFileRequest::setTransformedURL, std::move(url));
});
} else {

View File

@@ -183,7 +183,7 @@ void ImageManager::checkMissingAndNotify(ImageRequestor& requestor, const ImageR
auto actorRef = callback->self();
emplaced.first->second.callbacks.emplace(dependency.first, std::move(callback));
observer->onStyleImageMissing(dependency.first, [actorRef]() mutable {
observer->onStyleImageMissing(dependency.first, [actorRef]() {
actorRef.invoke(&Callback::operator());
});