From 5f3c34ed93d6d14a08c701e2c4a2feedb0670414 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Mon, 22 Nov 2021 21:06:27 +0400 Subject: [PATCH] NameMapper's API is now const --- include/name_mapper.h | 14 ++++++-------- src/name_mapper.cpp | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/name_mapper.h b/include/name_mapper.h index 3df594c12..247a19b9f 100644 --- a/include/name_mapper.h +++ b/include/name_mapper.h @@ -31,15 +31,15 @@ class Library; class NameMapper { public: virtual ~NameMapper() = default; - virtual std::string getNameForId(const std::string& id) = 0; - virtual std::string getIdForName(const std::string& name) = 0; + virtual std::string getNameForId(const std::string& id) const = 0; + virtual std::string getIdForName(const std::string& name) const = 0; }; class IdNameMapper : public NameMapper { public: - virtual std::string getNameForId(const std::string& id) { return id; }; - virtual std::string getIdForName(const std::string& name) { return name; }; + virtual std::string getNameForId(const std::string& id) const { return id; }; + virtual std::string getIdForName(const std::string& name) const { return name; }; }; class HumanReadableNameMapper : public NameMapper { @@ -50,12 +50,10 @@ class HumanReadableNameMapper : public NameMapper { public: HumanReadableNameMapper(kiwix::Library& library, bool withAlias); virtual ~HumanReadableNameMapper() = default; - virtual std::string getNameForId(const std::string& id); - virtual std::string getIdForName(const std::string& name); + virtual std::string getNameForId(const std::string& id) const; + virtual std::string getIdForName(const std::string& name) const; }; - - } #endif diff --git a/src/name_mapper.cpp b/src/name_mapper.cpp index 394e329d0..d700f4310 100644 --- a/src/name_mapper.cpp +++ b/src/name_mapper.cpp @@ -51,11 +51,11 @@ HumanReadableNameMapper::HumanReadableNameMapper(kiwix::Library& library, bool w } } -std::string HumanReadableNameMapper::getNameForId(const std::string& id) { +std::string HumanReadableNameMapper::getNameForId(const std::string& id) const { return m_idToName.at(id); } -std::string HumanReadableNameMapper::getIdForName(const std::string& name) { +std::string HumanReadableNameMapper::getIdForName(const std::string& name) const { return m_nameToId.at(name); }