Added NameMapperProxy from kiwix/kiwix-desktop#714

The right place for NameMapperProxy introduced by kiwix/kiwix-desktop#714 is in
libkiwix (so that it can be reused in kiwix-serve).
This commit is contained in:
Veloman Yunkan
2021-11-22 21:08:01 +04:00
parent 4ccbdcb740
commit 8fffa59974
2 changed files with 62 additions and 0 deletions

View File

@ -22,6 +22,8 @@
#include <string>
#include <map>
#include <memory>
#include <mutex>
namespace kiwix
{
@ -54,6 +56,25 @@ class HumanReadableNameMapper : public NameMapper {
virtual std::string getIdForName(const std::string& name) const;
};
class NameMapperProxy : public NameMapper {
typedef std::shared_ptr<NameMapper> NameMapperHandle;
public:
explicit NameMapperProxy(Library& library);
virtual std::string getNameForId(const std::string& id) const;
virtual std::string getIdForName(const std::string& name) const;
void update();
private:
NameMapperHandle currentNameMapper() const;
private:
mutable std::mutex mutex;
Library& library;
NameMapperHandle nameMapper;
};
}
#endif