@@ -29,10 +29,10 @@ using namespace std;
2929
3030enum supportedAction { NONE, ADD, SHOW, REMOVE };
3131
32- void show (kiwix::Library* library, const std::string& bookId)
32+ void show (const kiwix::Library& library, const std::string& bookId)
3333{
3434 try {
35- auto & book = library-> getBookById (bookId);
35+ auto & book = library. getBookById (bookId);
3636 std::cout << " id:\t\t " << book.getId () << std::endl
3737 << " path:\t\t " << book.getPath () << std::endl
3838 << " url:\t\t " << book.getUrl () << std::endl
@@ -96,7 +96,7 @@ void usage()
9696 << std::endl;
9797}
9898
99- int handle_show (kiwix::Library* library, const std::string& libraryPath,
99+ int handle_show (const kiwix::Library& library, const std::string& libraryPath,
100100 int argc, char * argv[])
101101{
102102 if (argc > 3 ) {
@@ -105,15 +105,15 @@ int handle_show(kiwix::Library* library, const std::string& libraryPath,
105105 show (library, bookId);
106106 }
107107 } else {
108- auto booksIds = library-> getBooksIds ();
108+ auto booksIds = library. getBooksIds ();
109109 for (auto & bookId: booksIds) {
110110 show (library, bookId);
111111 }
112112 }
113113 return (0 );
114114}
115115
116- int handle_add (kiwix::Library* library, const std::string& libraryPath,
116+ int handle_add (std::shared_ptr< kiwix::Library> library, const std::string& libraryPath,
117117 int argc, char * argv[])
118118{
119119 string zimPath;
@@ -182,7 +182,7 @@ int handle_add(kiwix::Library* library, const std::string& libraryPath,
182182 return (resultCode);
183183}
184184
185- int handle_remove (kiwix::Library* library, const std::string& libraryPath,
185+ int handle_remove (std::shared_ptr< kiwix::Library> library, const std::string& libraryPath,
186186 int argc, char * argv[])
187187{
188188 std::string bookId;
@@ -216,7 +216,7 @@ int main(int argc, char** argv)
216216{
217217 string libraryPath = " " ;
218218 supportedAction action = NONE;
219- kiwix::Library library ;
219+ auto library = std::make_shared< kiwix::Library>() ;
220220
221221 /* General argument parsing */
222222 static struct option long_options[] = {
@@ -261,7 +261,7 @@ int main(int argc, char** argv)
261261 libraryPath = kiwix::isRelativePath (libraryPath)
262262 ? kiwix::computeAbsolutePath (kiwix::getCurrentDirectory (), libraryPath)
263263 : libraryPath;
264- kiwix::Manager manager (& library);
264+ kiwix::Manager manager (library);
265265 if (!manager.readFile (libraryPath, false )) {
266266 if (kiwix::fileExists (libraryPath) || action!=ADD) {
267267 std::cerr << " Cannot read the library " << libraryPath << std::endl;
@@ -273,13 +273,13 @@ int main(int argc, char** argv)
273273 int exitCode = 0 ;
274274 switch (action) {
275275 case SHOW:
276- exitCode = handle_show (& library, libraryPath, argc, argv);
276+ exitCode = handle_show (* library, libraryPath, argc, argv);
277277 break ;
278278 case ADD:
279- exitCode = handle_add (& library, libraryPath, argc, argv);
279+ exitCode = handle_add (library, libraryPath, argc, argv);
280280 break ;
281281 case REMOVE:
282- exitCode = handle_remove (& library, libraryPath, argc, argv);
282+ exitCode = handle_remove (library, libraryPath, argc, argv);
283283 break ;
284284 case NONE:
285285 break ;
@@ -292,7 +292,7 @@ int main(int argc, char** argv)
292292 /* Rewrite the library file */
293293 if (action == REMOVE || action == ADD) {
294294 // writeToFile return true (1) if everything is ok => exitCode is 0
295- if (!library. writeToFile (libraryPath)) {
295+ if (!library-> writeToFile (libraryPath)) {
296296 std::cerr << " Cannot write the library " << libraryPath << std::endl;
297297 return 1 ;
298298 }
0 commit comments