[gnote] Remove std::list from directory APIs



commit 16bc8731d0f4bfc1aecb0a20e935af6f3d7e9e45
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Apr 13 16:25:27 2019 +0300

    Remove std::list from directory APIs

 src/addinmanager.cpp                               |  5 ++---
 src/addins/bugzilla/bugzillapreferences.cpp        |  5 ++---
 .../filesystemsyncserviceaddin.cpp                 |  5 ++---
 src/addins/tomboyimport/tomboyimportaddin.cpp      |  5 ++---
 src/notemanager.cpp                                | 10 +++------
 src/sharp/directory.cpp                            | 26 ++++++++++++----------
 src/sharp/directory.hpp                            | 11 +++------
 src/synchronization/filesystemsyncserver.cpp       |  3 +--
 src/synchronization/fusesyncserviceaddin.cpp       |  5 ++---
 src/test/unit/directorytests.cpp                   | 26 ++++++++--------------
 src/test/unit/syncmanagerutests.cpp                |  9 ++++----
 11 files changed, 44 insertions(+), 66 deletions(-)
---
diff --git a/src/addinmanager.cpp b/src/addinmanager.cpp
index 9a4f2f7e..565047c0 100644
--- a/src/addinmanager.cpp
+++ b/src/addinmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2017 Aurimas Cernius
+ * Copyright (C) 2010-2017,2019 Aurimas Cernius
  * Copyright (C) 2009, 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -206,8 +206,7 @@ namespace {
 
   void AddinManager::load_addin_infos(const Glib::ustring & path)
   {
-    std::list<Glib::ustring> files;
-    sharp::directory_get_files_with_ext(path, ".desktop", files);
+    std::vector<Glib::ustring> files = sharp::directory_get_files_with_ext(path, ".desktop");
     for(auto file : files) {
       try {
         AddinInfo addin_info(file);
diff --git a/src/addins/bugzilla/bugzillapreferences.cpp b/src/addins/bugzilla/bugzillapreferences.cpp
index b2ed0085..d23c1633 100644
--- a/src/addins/bugzilla/bugzillapreferences.cpp
+++ b/src/addins/bugzilla/bugzillapreferences.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011,2013-2014,2017 Aurimas Cernius
+ * Copyright (C) 2011,2013-2014,2017,2019 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -140,8 +140,7 @@ namespace bugzilla {
 
     icon_store->clear(); // clear out the old entries
 
-    std::list<Glib::ustring> icon_files;
-    sharp::directory_get_files (s_image_dir, icon_files);
+    std::vector<Glib::ustring> icon_files = sharp::directory_get_files (s_image_dir);
     for(auto icon_file : icon_files) {
       sharp::FileInfo file_info(icon_file);
 
diff --git a/src/addins/filesystemsyncservice/filesystemsyncserviceaddin.cpp 
b/src/addins/filesystemsyncservice/filesystemsyncserviceaddin.cpp
index 764d6ed4..9d0819f9 100644
--- a/src/addins/filesystemsyncservice/filesystemsyncserviceaddin.cpp
+++ b/src/addins/filesystemsyncservice/filesystemsyncserviceaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2013,2017-2018 Aurimas Cernius
+ * Copyright (C) 2012-2013,2017-2019 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -160,8 +160,7 @@ bool FileSystemSyncServiceAddin::save_configuration()
 
     // Test ability to read
     bool testFileFound = false;
-    std::list<Glib::ustring> files;
-    sharp::directory_get_files(syncPath, files);
+    std::vector<Glib::ustring> files = sharp::directory_get_files(syncPath);
     for(auto file : files) {
       if(file == testPath) {
         testFileFound = true;
diff --git a/src/addins/tomboyimport/tomboyimportaddin.cpp b/src/addins/tomboyimport/tomboyimportaddin.cpp
index e122c3bc..309d07fb 100644
--- a/src/addins/tomboyimport/tomboyimportaddin.cpp
+++ b/src/addins/tomboyimport/tomboyimportaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2011,2013-2014,2017 Aurimas Cernius
+ * Copyright (C) 2010-2011,2013-2014,2017,2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -71,8 +71,7 @@ bool TomboyImportAddin::first_run(gnote::NoteManager & manager)
   DBG_OUT("import path is %s", m_tomboy_path.c_str());
 
   if(sharp::directory_exists(m_tomboy_path)) {
-    std::list<Glib::ustring> files;
-    sharp::directory_get_files_with_ext(m_tomboy_path, ".note", files);
+    std::vector<Glib::ustring> files = sharp::directory_get_files_with_ext(m_tomboy_path, ".note");
 
     for(auto file_path : files) {
       to_import++;
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index 00071fb8..53b1d359 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -182,8 +182,7 @@ namespace gnote {
 
   void NoteManager::load_notes()
   {
-    std::list<Glib::ustring> files;
-    sharp::directory_get_files_with_ext(notes_dir(), ".note", files);
+    std::vector<Glib::ustring> files = sharp::directory_get_files_with_ext(notes_dir(), ".note");
 
     for(auto file_path : files) {
       try {
@@ -230,8 +229,7 @@ namespace gnote {
 
   void NoteManager::migrate_notes(const Glib::ustring & old_note_dir)
   {
-    std::list<Glib::ustring> files;
-    sharp::directory_get_files_with_ext(old_note_dir, ".note", files);
+    std::vector<Glib::ustring> files = sharp::directory_get_files_with_ext(old_note_dir, ".note");
 
     for(auto file : files) {
       const Glib::RefPtr<Gio::File> src = Gio::File::create_for_path(file);
@@ -243,12 +241,10 @@ namespace gnote {
       src->copy(dest, Gio::FILE_COPY_NONE);
     }
 
-    files.clear();
     const Glib::ustring old_backup_dir = Glib::build_filename(
                                          old_note_dir,
                                          "Backup");
-    sharp::directory_get_files_with_ext(old_backup_dir,
-                                        ".note", files);
+    files = sharp::directory_get_files_with_ext(old_backup_dir, ".note");
 
     for(auto file : files) {
       const Glib::RefPtr<Gio::File> src = Gio::File::create_for_path(file);
diff --git a/src/sharp/directory.cpp b/src/sharp/directory.cpp
index 32007a00..73da200b 100644
--- a/src/sharp/directory.cpp
+++ b/src/sharp/directory.cpp
@@ -39,15 +39,14 @@
 namespace sharp {
 
 
-  void directory_get_files_with_ext(const Glib::ustring & dir,
-                                    const Glib::ustring & ext,
-                                    std::list<Glib::ustring> & list)
+  std::vector<Glib::ustring> directory_get_files_with_ext(const Glib::ustring & dir, const Glib::ustring & 
ext)
   {
+    std::vector<Glib::ustring> list;
     if (!Glib::file_test(dir, Glib::FILE_TEST_EXISTS))
-      return;
+      return list;
 
     if (!Glib::file_test(dir, Glib::FILE_TEST_IS_DIR))
-      return;
+      return list;
 
     Glib::Dir d(dir);
 
@@ -61,6 +60,8 @@ namespace sharp {
         list.push_back(file);
       }
     }
+
+    return list;
   }
 
   std::vector<Glib::RefPtr<Gio::File>> directory_get_files_with_ext(const Glib::RefPtr<Gio::File> & dir,
@@ -96,11 +97,11 @@ namespace sharp {
     return files;
   }
 
-  void directory_get_directories(const Glib::ustring & dir,
-                                 std::list<Glib::ustring> & files)
+  std::vector<Glib::ustring> directory_get_directories(const Glib::ustring & dir)
   {
+    std::vector<Glib::ustring> files;
     if(!Glib::file_test(dir, Glib::FILE_TEST_IS_DIR)) {
-      return;
+      return files;
     }
 
     Glib::Dir d(dir);
@@ -112,6 +113,8 @@ namespace sharp {
         files.push_back(file);
       }
     }
+
+    return files;
   }
 
   std::vector<Glib::RefPtr<Gio::File>> directory_get_directories(const Glib::RefPtr<Gio::File> & dir)
@@ -136,9 +139,9 @@ namespace sharp {
     return files;
   }
 
-  void directory_get_files(const Glib::ustring & dir, std::list<Glib::ustring> & files)
+  std::vector<Glib::ustring> directory_get_files(const Glib::ustring & dir)
   {
-    directory_get_files_with_ext(dir, "", files);
+    return directory_get_files_with_ext(dir, "");
   }
 
   std::vector<Glib::RefPtr<Gio::File>> directory_get_files(const Glib::RefPtr<Gio::File> & dir)
@@ -214,8 +217,7 @@ namespace sharp {
   bool directory_delete(const Glib::ustring & dir, bool recursive)
   {
     if(!recursive) {
-      std::list<Glib::ustring> files;
-      directory_get_files(dir, files);
+      std::vector<Glib::ustring> files = directory_get_files(dir);
       if(files.size()) {
         return false;
       }
diff --git a/src/sharp/directory.hpp b/src/sharp/directory.hpp
index e4989d47..de50f377 100644
--- a/src/sharp/directory.hpp
+++ b/src/sharp/directory.hpp
@@ -29,7 +29,6 @@
 #ifndef __SHARP_DIRECTORY_HPP_
 #define __SHARP_DIRECTORY_HPP_
 
-#include <list>
 #include <vector>
 
 #include <giomm/file.h>
@@ -41,18 +40,14 @@ namespace sharp {
    * @param ext the extension. If empty, then all files are listed.
    * @retval files the list of files
    */
-  void directory_get_files_with_ext(const Glib::ustring & dir,
-                                    const Glib::ustring & ext,
-                                    std::list<Glib::ustring> & files);
+  std::vector<Glib::ustring> directory_get_files_with_ext(const Glib::ustring & dir, const Glib::ustring & 
ext);
   std::vector<Glib::RefPtr<Gio::File>> directory_get_files_with_ext(const Glib::RefPtr<Gio::File> & dir,
                                     const Glib::ustring & ext);
 
-  void directory_get_directories(const Glib::ustring & dir,
-                                 std::list<Glib::ustring> & files);
+  std::vector<Glib::ustring> directory_get_directories(const Glib::ustring & dir);
   std::vector<Glib::RefPtr<Gio::File>> directory_get_directories(const Glib::RefPtr<Gio::File> & dir);
 
-  void directory_get_files(const Glib::ustring & dir,
-                           std::list<Glib::ustring> & files);
+  std::vector<Glib::ustring> directory_get_files(const Glib::ustring & dir);
   std::vector<Glib::RefPtr<Gio::File>> directory_get_files(const Glib::RefPtr<Gio::File> & dir);
 
   bool directory_exists(const Glib::ustring & dir);
diff --git a/src/synchronization/filesystemsyncserver.cpp b/src/synchronization/filesystemsyncserver.cpp
index dfe89152..abe8510e 100644
--- a/src/synchronization/filesystemsyncserver.cpp
+++ b/src/synchronization/filesystemsyncserver.cpp
@@ -160,8 +160,7 @@ std::map<Glib::ustring, NoteUpdate> FileSystemSyncServer::get_note_updates_since
   else {
     // Empty the temp dir
     try {
-      std::list<Glib::ustring> files;
-      sharp::directory_get_files(tempPath, files);
+      std::vector<Glib::ustring> files = sharp::directory_get_files(tempPath);
       for(auto & iter : files) {
         sharp::file_delete(iter);
       }
diff --git a/src/synchronization/fusesyncserviceaddin.cpp b/src/synchronization/fusesyncserviceaddin.cpp
index 43e09b02..242fcc7d 100644
--- a/src/synchronization/fusesyncserviceaddin.cpp
+++ b/src/synchronization/fusesyncserviceaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2013,2017-2018 Aurimas Cernius
+ * Copyright (C) 2012-2013,2017-2019 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -140,8 +140,7 @@ bool FuseSyncServiceAddin::save_configuration()
 
       // Test ability to read
       bool testFileFound = false;
-      std::list<Glib::ustring> files;
-      sharp::directory_get_files(m_mount_path, files);
+      std::vector<Glib::ustring> files = sharp::directory_get_files(m_mount_path);
       for(auto file : files) {
         if(file == testPath) {
           testFileFound = true;
diff --git a/src/test/unit/directorytests.cpp b/src/test/unit/directorytests.cpp
index 08479e7b..50277e62 100644
--- a/src/test/unit/directorytests.cpp
+++ b/src/test/unit/directorytests.cpp
@@ -31,8 +31,7 @@ SUITE(directory)
   {
     Glib::ustring dir = Glib::build_filename(Glib::path_get_dirname(__FILE__), "nonexistent");
 
-    std::list<Glib::ustring> directories;
-    sharp::directory_get_directories(dir, directories);
+    std::vector<Glib::ustring> directories = sharp::directory_get_directories(dir);
     CHECK_EQUAL(0, directories.size());
   }
 
@@ -48,8 +47,7 @@ SUITE(directory)
   {
     Glib::ustring dir(__FILE__);
 
-    std::list<Glib::ustring> directories;
-    sharp::directory_get_directories(dir, directories);
+    std::vector<Glib::ustring> directories = sharp::directory_get_directories(dir);
     CHECK_EQUAL(0, directories.size());
   }
 
@@ -65,8 +63,7 @@ SUITE(directory)
   {
     Glib::ustring dir = Glib::build_filename(Glib::path_get_dirname(__FILE__), ".deps");
 
-    std::list<Glib::ustring> directories;
-    sharp::directory_get_directories(dir, directories);
+    std::vector<Glib::ustring> directories = sharp::directory_get_directories(dir);
     CHECK_EQUAL(0, directories.size());
   }
 
@@ -82,8 +79,7 @@ SUITE(directory)
   {
     Glib::ustring dir = Glib::path_get_dirname(__FILE__);
 
-    std::list<Glib::ustring> directories;
-    sharp::directory_get_directories(dir, directories);
+    std::vector<Glib::ustring> directories = sharp::directory_get_directories(dir);
     CHECK_EQUAL(1, directories.size());
   }
 
@@ -96,7 +92,7 @@ SUITE(directory)
   }
 
   void remove_matching_files(const std::vector<Glib::RefPtr<Gio::File>> & dirsf,
-      std::list<Glib::ustring> & dirss)
+      std::vector<Glib::ustring> & dirss)
   {
     for(auto f : dirsf) {
       auto name = Glib::path_get_basename(f->get_path());
@@ -113,8 +109,7 @@ SUITE(directory)
   {
     auto dir = Glib::path_get_dirname(Glib::path_get_dirname(__FILE__));
 
-    std::list<Glib::ustring> dirss;
-    sharp::directory_get_directories(dir, dirss);
+    std::vector<Glib::ustring> dirss = sharp::directory_get_directories(dir);
 
     auto file = Gio::File::create_for_path(dir);
 
@@ -130,8 +125,7 @@ SUITE(directory)
   {
     Glib::ustring dir = Glib::build_filename(Glib::path_get_dirname(__FILE__), "nonexistent");
 
-    std::list<Glib::ustring> files;
-    sharp::directory_get_files_with_ext(dir, "", files);
+    std::vector<Glib::ustring> files = sharp::directory_get_files_with_ext(dir, "");
     CHECK_EQUAL(0, files.size());
   }
 
@@ -147,8 +141,7 @@ SUITE(directory)
   {
     Glib::ustring dir(__FILE__);
 
-    std::list<Glib::ustring> files;
-    sharp::directory_get_files_with_ext(dir, "", files);
+    std::vector<Glib::ustring> files = sharp::directory_get_files_with_ext(dir, "");
     CHECK_EQUAL(0, files.size());
   }
 
@@ -164,8 +157,7 @@ SUITE(directory)
   {
     Glib::ustring dir = Glib::path_get_dirname(__FILE__);
 
-    std::list<Glib::ustring> filess;
-    sharp::directory_get_files_with_ext(dir, ext, filess);
+    std::vector<Glib::ustring> filess = sharp::directory_get_files_with_ext(dir, ext);
     CHECK(0 < filess.size());
     if(ext.size()) {
       for(auto f : filess) {
diff --git a/src/test/unit/syncmanagerutests.cpp b/src/test/unit/syncmanagerutests.cpp
index c305b40e..733994e0 100644
--- a/src/test/unit/syncmanagerutests.cpp
+++ b/src/test/unit/syncmanagerutests.cpp
@@ -49,7 +49,7 @@ SUITE(SyncManagerTests)
     test::NoteManager *manager2;
     test::SyncManager *sync_manager1;
     test::SyncManager *sync_manager2;
-    std::list<Glib::ustring> files;
+    std::vector<Glib::ustring> files;
 
     Fixture()
     {
@@ -114,8 +114,7 @@ SUITE(SyncManagerTests)
 
     void get_notes_in_dir(const Glib::ustring & dir)
     {
-      files.clear();
-      sharp::directory_get_files_with_ext(dir, ".note", files);
+      files = sharp::directory_get_files_with_ext(dir, ".note");
     }
   };
 
@@ -185,7 +184,7 @@ SUITE(SyncManagerTests)
     // check sync dir contents
     Glib::ustring syncednotesdir = syncdir + "/0";
     REQUIRE CHECK(sharp::directory_exists(syncednotesdir));
-    sharp::directory_get_directories(syncednotesdir, files);
+    files = sharp::directory_get_directories(syncednotesdir);
     CHECK_EQUAL(3, files.size());
 
     // sync to first client
@@ -207,7 +206,7 @@ SUITE(SyncManagerTests)
     // check sync dir contents
     Glib::ustring syncednotesdir = syncdir + "/0";
     REQUIRE CHECK(sharp::directory_exists(syncednotesdir));
-    sharp::directory_get_directories(syncednotesdir, files);
+    files = sharp::directory_get_directories(syncednotesdir);
     CHECK_EQUAL(2, files.size());
 
     FIRST_SYNC(sync_manager2, manager2, manifest2, sync_client2, sync_ui2)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]