[gnote] Make directory_get_files_with_ext return value



commit f12cffa2b8d78614444c481bb38c0cf5af71c460
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Apr 13 13:55:24 2019 +0300

    Make directory_get_files_with_ext return value

 src/sharp/directory.cpp          | 15 +++++++++------
 src/sharp/directory.hpp          |  7 +++----
 src/test/unit/directorytests.cpp | 11 ++++-------
 3 files changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/src/sharp/directory.cpp b/src/sharp/directory.cpp
index 980cebc0..78857a75 100644
--- a/src/sharp/directory.cpp
+++ b/src/sharp/directory.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2014,2017-2018 Aurimas Cernius
+ * Copyright (C) 2011-2014,2017-2019 Aurimas Cernius
  * Copyright (C) 2011 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  * 
@@ -63,12 +63,12 @@ namespace sharp {
     }
   }
 
-  void directory_get_files_with_ext(const Glib::RefPtr<Gio::File> & dir,
-                                    const Glib::ustring & ext,
-                                    std::vector<Glib::RefPtr<Gio::File>> & files)
+  std::vector<Glib::RefPtr<Gio::File>> directory_get_files_with_ext(const Glib::RefPtr<Gio::File> & dir,
+                                    const Glib::ustring & ext)
   {
+    std::vector<Glib::RefPtr<Gio::File>> files;
     if(!directory_exists(dir)) {
-      return;
+      return files;
     }
 
     auto children = dir->enumerate_children();
@@ -92,6 +92,8 @@ namespace sharp {
         }
       }
     }
+
+    return files;
   }
 
   void directory_get_directories(const Glib::ustring & dir,
@@ -140,7 +142,8 @@ namespace sharp {
   void directory_get_files(const Glib::RefPtr<Gio::File> & dir,
                            std::vector<Glib::RefPtr<Gio::File>> & files)
   {
-    directory_get_files_with_ext(dir, "", files);
+    auto ret = directory_get_files_with_ext(dir, "");
+    std::swap(files, ret);
   }
 
   bool directory_exists(const Glib::ustring & dir)
diff --git a/src/sharp/directory.hpp b/src/sharp/directory.hpp
index 6834b37e..26024a86 100644
--- a/src/sharp/directory.hpp
+++ b/src/sharp/directory.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012,2017-2018 Aurimas Cernius
+ * Copyright (C) 2012,2017-2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -44,9 +44,8 @@ namespace sharp {
   void directory_get_files_with_ext(const Glib::ustring & dir,
                                     const Glib::ustring & ext,
                                     std::list<Glib::ustring> & files);
-  void directory_get_files_with_ext(const Glib::RefPtr<Gio::File> & dir,
-                                    const Glib::ustring & ext,
-                                    std::vector<Glib::RefPtr<Gio::File>> & files);
+  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);
diff --git a/src/test/unit/directorytests.cpp b/src/test/unit/directorytests.cpp
index 01dce2a5..230e3418 100644
--- a/src/test/unit/directorytests.cpp
+++ b/src/test/unit/directorytests.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2018 Aurimas Cernius
+ * Copyright (C) 2018-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
@@ -144,8 +144,7 @@ SUITE(directory)
   {
     auto dir = Gio::File::create_for_path(Glib::build_filename(Glib::path_get_dirname(__FILE__), 
"nonexistent"));
 
-    std::vector<Glib::RefPtr<Gio::File>> files;
-    sharp::directory_get_files_with_ext(dir, "", files);
+    std::vector<Glib::RefPtr<Gio::File>> files = sharp::directory_get_files_with_ext(dir, "");
     CHECK_EQUAL(0, files.size());
   }
 
@@ -162,8 +161,7 @@ SUITE(directory)
   {
     auto dir = Gio::File::create_for_path(__FILE__);
 
-    std::vector<Glib::RefPtr<Gio::File>> files;
-    sharp::directory_get_files_with_ext(dir, "", files);
+    std::vector<Glib::RefPtr<Gio::File>> files = sharp::directory_get_files_with_ext(dir, "");
     CHECK_EQUAL(0, files.size());
   }
 
@@ -182,8 +180,7 @@ SUITE(directory)
     }
 
     auto file = Gio::File::create_for_path(dir);
-    std::vector<Glib::RefPtr<Gio::File>> filesf;
-    sharp::directory_get_files_with_ext(file, ext, filesf);
+    std::vector<Glib::RefPtr<Gio::File>> filesf = sharp::directory_get_files_with_ext(file, ext);
     CHECK_EQUAL(filess.size(), filesf.size());
     remove_matching_files(filesf, filess);
     CHECK_EQUAL(0, filess.size());


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