From 1dc97055974a95245e17d14cf27e6376cb8ca416 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 23 Aug 2023 11:03:16 +0200 Subject: [PATCH] Introduce LibraryPtr and ConstLibraryPtr. As we enforce the use of Library through a shared_ptr, let's simplify user life (and code) with new "type". --- include/library.h | 8 ++++++-- include/manager.h | 8 ++++---- src/manager.cpp | 4 ++-- src/name_mapper.cpp | 2 +- src/server.cpp | 2 +- src/server/internalServer.cpp | 2 +- src/server/internalServer.h | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/library.h b/include/library.h index 795792b3..f1a58f6c 100644 --- a/include/library.h +++ b/include/library.h @@ -183,6 +183,9 @@ class ConcurrentCache; template class MultiKeyCache; +using LibraryPtr = std::shared_ptr; +using ConstLibraryPtr = std::shared_ptr; + /** * A Library store several books. */ @@ -198,8 +201,8 @@ class Library: public std::enable_shared_from_this Library(); public: - [[nodiscard]] static std::shared_ptr create() { - return std::shared_ptr(new Library()); + [[nodiscard]] static LibraryPtr create() { + return LibraryPtr(new Library()); } ~Library(); @@ -405,6 +408,7 @@ private: //data std::unique_ptr m_bookDB; }; + } #endif diff --git a/include/manager.h b/include/manager.h index 9b13da39..415db622 100644 --- a/include/manager.h +++ b/include/manager.h @@ -37,10 +37,10 @@ namespace kiwix class LibraryManipulator { public: // functions - explicit LibraryManipulator(std::shared_ptr library); + explicit LibraryManipulator(LibraryPtr library); virtual ~LibraryManipulator(); - std::shared_ptr getLibrary() const { return library; } + LibraryPtr getLibrary() const { return library; } bool addBookToLibrary(const Book& book); void addBookmarkToLibrary(const Bookmark& bookmark); @@ -52,7 +52,7 @@ class LibraryManipulator virtual void booksWereRemovedFromLibrary(); private: // data - std::shared_ptr library; + LibraryPtr library; }; /** @@ -65,7 +65,7 @@ class Manager public: // functions explicit Manager(LibraryManipulator manipulator); - explicit Manager(std::shared_ptr library); + explicit Manager(LibraryPtr library); /** * Read a `library.xml` and add book in the file to the library. diff --git a/src/manager.cpp b/src/manager.cpp index 9a4f9b28..ba4d0c75 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -31,7 +31,7 @@ namespace kiwix // LibraryManipulator //////////////////////////////////////////////////////////////////////////////// -LibraryManipulator::LibraryManipulator(std::shared_ptr library) +LibraryManipulator::LibraryManipulator(LibraryPtr library) : library(library) {} @@ -85,7 +85,7 @@ Manager::Manager(LibraryManipulator manipulator): { } -Manager::Manager(std::shared_ptr library) : +Manager::Manager(LibraryPtr library) : writableLibraryPath(""), manipulator(LibraryManipulator(library)) { diff --git a/src/name_mapper.cpp b/src/name_mapper.cpp index f4422704..bf2a2e4d 100644 --- a/src/name_mapper.cpp +++ b/src/name_mapper.cpp @@ -63,7 +63,7 @@ std::string HumanReadableNameMapper::getIdForName(const std::string& name) const // UpdatableNameMapper //////////////////////////////////////////////////////////////////////////////// -UpdatableNameMapper::UpdatableNameMapper(std::shared_ptr lib, bool withAlias) +UpdatableNameMapper::UpdatableNameMapper(LibraryPtr lib, bool withAlias) : library(lib) , withAlias(withAlias) { diff --git a/src/server.cpp b/src/server.cpp index 2e258245..1a4ecfa9 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -29,7 +29,7 @@ namespace kiwix { -Server::Server(std::shared_ptr library, std::shared_ptr nameMapper) : +Server::Server(LibraryPtr library, std::shared_ptr nameMapper) : mp_library(library), mp_nameMapper(nameMapper), mp_server(nullptr) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 11bdd097..08d35e70 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -411,7 +411,7 @@ public: }; -InternalServer::InternalServer(std::shared_ptr library, +InternalServer::InternalServer(LibraryPtr library, std::shared_ptr nameMapper, std::string addr, int port, diff --git a/src/server/internalServer.h b/src/server/internalServer.h index e11c690b..cdd7cebe 100644 --- a/src/server/internalServer.h +++ b/src/server/internalServer.h @@ -92,7 +92,7 @@ class OPDSDumper; class InternalServer { public: - InternalServer(std::shared_ptr library, + InternalServer(LibraryPtr library, std::shared_ptr nameMapper, std::string addr, int port, @@ -178,7 +178,7 @@ class InternalServer { int m_ipConnectionLimit; struct MHD_Daemon* mp_daemon; - std::shared_ptr mp_library; + LibraryPtr mp_library; std::shared_ptr mp_nameMapper; SearchCache searchCache;