From 18b7b5f277a7734c024f7b36b5ad9e0584740b1c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 7 Feb 2023 11:00:27 +0100 Subject: [PATCH] Mark constant methods as const. --- include/downloader.h | 24 ++++++++++++------------ src/downloader.cpp | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/downloader.h b/include/downloader.h index d2cebe8e0..e5bcff7a1 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -58,15 +58,15 @@ class Download { void pauseDownload(); void resumeDownload(); void cancelDownload(); - StatusResult getStatus() { return m_status; } - std::string getDid() { return m_did; } - std::string getFollowedBy() { return m_followedBy; } - uint64_t getTotalLength() { return m_totalLength; } - uint64_t getCompletedLength() { return m_completedLength; } - uint64_t getDownloadSpeed() { return m_downloadSpeed; } - uint64_t getVerifiedLength() { return m_verifiedLength; } - std::string getPath() { return m_path; } - std::vector& getUris() { return m_uris; } + StatusResult getStatus() const { return m_status; } + const std::string& getDid() const { return m_did; } + const std::string& getFollowedBy() const { return m_followedBy; } + uint64_t getTotalLength() const { return m_totalLength; } + uint64_t getCompletedLength() const { return m_completedLength; } + uint64_t getDownloadSpeed() const { return m_downloadSpeed; } + uint64_t getVerifiedLength() const { return m_verifiedLength; } + const std::string& getPath() const { return m_path; } + const std::vector& getUris() const { return m_uris; } protected: std::shared_ptr mp_aria; @@ -96,11 +96,11 @@ class Downloader std::shared_ptr startDownload(const std::string& uri, const std::vector>& options = {}); std::shared_ptr getDownload(const std::string& did); - size_t getNbDownload(); - std::vector getDownloadIds(); + size_t getNbDownload() const; + std::vector getDownloadIds() const; private: - std::mutex m_lock; + mutable std::mutex m_lock; std::map> m_knownDownloads; std::shared_ptr mp_aria; }; diff --git a/src/downloader.cpp b/src/downloader.cpp index 02c75f6fb..1163f69dc 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -155,7 +155,7 @@ void Downloader::close() mp_aria->close(); } -std::vector Downloader::getDownloadIds() { +std::vector Downloader::getDownloadIds() const { std::unique_lock lock(m_lock); std::vector ret; for(auto& p:m_knownDownloads) { @@ -201,7 +201,7 @@ std::shared_ptr Downloader::getDownload(const std::string& did) } } -size_t Downloader::getNbDownload() { +size_t Downloader::getNbDownload() const { std::unique_lock lock(m_lock); return m_knownDownloads.size(); }