Change PBD::PathScanner API to return results by value to avoid inadvertent memory...
authorTim Mayberry <mojofunk@gmail.com>
Mon, 16 Jun 2014 10:39:45 +0000 (20:39 +1000)
committerTim Mayberry <mojofunk@gmail.com>
Tue, 17 Jun 2014 11:13:05 +0000 (21:13 +1000)
14 files changed:
gtk2_ardour/ardour_ui.cc
gtk2_ardour/session_dialog.cc
libs/ardour/ardour/session.h
libs/ardour/lv2_plugin.cc
libs/ardour/panner_manager.cc
libs/ardour/plugin_manager.cc
libs/ardour/session_state.cc
libs/ardour/template_utils.cc
libs/pbd/file_utils.cc
libs/pbd/pathscanner.cc
libs/pbd/pbd/pathscanner.h
libs/surfaces/generic_midi/generic_midi_control_protocol.cc
libs/surfaces/mackie/device_info.cc
libs/surfaces/mackie/device_profile.cc

index 3ad33b5c8c668ab5e73d8767c5b2bb32f6683d4b..d9ac37e36f5c94b038def8a136da7cfaa70746d4 100644 (file)
@@ -1416,7 +1416,7 @@ ARDOUR_UI::redisplay_recent_sessions ()
 
                get_state_files_in_directory (*i, state_file_paths);
 
-               vector<string*>* states;
+               vector<string> states;
                vector<const gchar*> item;
                string fullpath = *i;
 
@@ -1433,13 +1433,12 @@ ARDOUR_UI::redisplay_recent_sessions ()
                }
 
                /* now get available states for this session */
+               states = Session::possible_states (fullpath);
 
-               if ((states = Session::possible_states (fullpath)) == 0) {
+               if (states.empty()) {
                        /* no state file? */
                        continue;
                }
-               vector_delete(states);
-               delete(states);
 
                std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
 
index 178fcb835c8c5cc6038c64c55b19c0777acf98e2..7fb765e2bc82d4381db216d352db5b844bfcbb29 100644 (file)
@@ -621,7 +621,7 @@ SessionDialog::redisplay_recent_sessions ()
 
                get_state_files_in_directory (*i, state_file_paths);
 
-               vector<string*>* states;
+               vector<string> states;
                vector<const gchar*> item;
                string dirname = *i;
 
@@ -639,12 +639,12 @@ SessionDialog::redisplay_recent_sessions ()
 
                /* now get available states for this session */
 
-               if ((states = Session::possible_states (dirname)) == 0) {
+               states = Session::possible_states (dirname);
+
+               if (states.empty()) {
                        /* no state file? */
                        continue;
                }
-               vector_delete (states);
-               delete (states);
 
                std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths));
 
index 08d0ec1e4e12cbbc91ad373242550ab45bed06cb..0dd986226b2c2766f72bab5e2f5a05ce9e58e4f6 100644 (file)
@@ -402,8 +402,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        PBD::Signal0<void> StateReady;
        PBD::Signal0<void> SaveSession;
 
-       std::vector<std::string*>* possible_states() const;
-       static std::vector<std::string*>* possible_states (std::string path);
+       std::vector<std::string> possible_states() const;
+       static std::vector<std::string> possible_states (std::string path);
 
        XMLNode& get_state();
        int      set_state(const XMLNode& node, int version); // not idempotent
index 8fac9369b00ecdf99e51c2b22b49f69eeca12f27..d68c4e50779649fc36733d0fac08935ad2d527bf 100644 (file)
@@ -2013,23 +2013,20 @@ void
 LV2World::load_bundled_plugins()
 {
        if (!_bundle_checked) {
-               cout << "Scanning folders for bundled LV2s: " << ARDOUR::lv2_bundled_search_path().to_string() << endl;
                PathScanner scanner;
-               vector<string *> *plugin_objects = scanner (ARDOUR::lv2_bundled_search_path().to_string(), lv2_filter, 0, true, true);
-               if (plugin_objects) {
-                       for ( vector<string *>::iterator x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
+               cout << "Scanning folders for bundled LV2s: " << ARDOUR::lv2_bundled_search_path().to_string() << endl;
+
+               vector<string> plugin_objects = scanner (ARDOUR::lv2_bundled_search_path().to_string(), lv2_filter, 0, true, true);
+               for ( vector<string>::iterator x = plugin_objects.begin(); x != plugin_objects.end (); ++x) {
 #ifdef PLATFORM_WINDOWS
-                               string uri = "file:///" + **x + "/";
+                       string uri = "file:///" + *x + "/";
 #else
-                               string uri = "file://" + **x + "/";
+                       string uri = "file://" + *x + "/";
 #endif
-                               LilvNode *node = lilv_new_uri(world, uri.c_str());
-                               lilv_world_load_bundle(world, node);
-                               lilv_node_free(node);
-                       }
+                       LilvNode *node = lilv_new_uri(world, uri.c_str());
+                       lilv_world_load_bundle(world, node);
+                       lilv_node_free(node);
                }
-               vector_delete (plugin_objects);
-               delete (plugin_objects);
 
                _bundle_checked = true;
        }
index 95136c29518ceeb0663b6826c30544c550e46df6..2988a8ab467ed459c1e87db284c3123083454435 100644 (file)
@@ -91,19 +91,16 @@ void
 PannerManager::discover_panners ()
 {
        PathScanner scanner;
-       std::vector<std::string *> *panner_modules;
+       std::vector<std::stringpanner_modules;
        std::string search_path = panner_search_path().to_string();
 
        DEBUG_TRACE (DEBUG::Panning, string_compose (_("looking for panners in %1\n"), search_path));
 
        panner_modules = scanner (search_path, panner_filter, 0, false, true, 1, true);
 
-       for (vector<std::string *>::iterator i = panner_modules->begin(); i != panner_modules->end(); ++i) {
-               panner_discover (**i);
+       for (vector<std::string>::iterator i = panner_modules.begin(); i != panner_modules.end(); ++i) {
+               panner_discover (*i);
        }
-
-       vector_delete (panner_modules);
-       delete (panner_modules);
 }
 
 int
index c638ff2e86c8f8ca0b6eac2b962a94bad58b8ed5..c1e596ff3d6692560c263fcdcf96cd74d6677331 100644 (file)
@@ -243,31 +243,23 @@ PluginManager::clear_vst_cache ()
 #ifdef WINDOWS_VST_SUPPORT
        {
                PathScanner scanner;
-               vector<string *> *fsi_files;
+               vector<stringfsi_files;
 
                fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsi$", true, true, -1, false);
-               if (fsi_files) {
-                       for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
-                               ::g_unlink((*i)->c_str());
-                       }
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
                }
-               vector_delete(fsi_files);
-               delete(fsi_files);
        }
 #endif
 
 #ifdef LXVST_SUPPORT
        {
                PathScanner scanner;
-               vector<string *> *fsi_files;
+               vector<stringfsi_files;
                fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsi$", true, true, -1, false);
-               if (fsi_files) {
-                       for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
-                               ::g_unlink((*i)->c_str());
-                       }
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
                }
-               vector_delete(fsi_files);
-               delete(fsi_files);
        }
 #endif
 
@@ -275,15 +267,11 @@ PluginManager::clear_vst_cache ()
        {
                string personal = get_personal_vst_info_cache_dir();
                PathScanner scanner;
-               vector<string *> *fsi_files;
+               vector<stringfsi_files;
                fsi_files = scanner (personal, "\\.fsi$", true, true, -1, false);
-               if (fsi_files) {
-                       for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
-                               ::g_unlink((*i)->c_str());
-                       }
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
                }
-               vector_delete(fsi_files);
-               delete(fsi_files);
        }
 #endif
 }
@@ -294,31 +282,23 @@ PluginManager::clear_vst_blacklist ()
 #ifdef WINDOWS_VST_SUPPORT
        {
                PathScanner scanner;
-               vector<string *> *fsi_files;
+               vector<stringfsi_files;
 
                fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsb$", true, true, -1, false);
-               if (fsi_files) {
-                       for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
-                               ::g_unlink((*i)->c_str());
-                       }
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
                }
-               vector_delete(fsi_files);
-               delete(fsi_files);
        }
 #endif
 
 #ifdef LXVST_SUPPORT
        {
                PathScanner scanner;
-               vector<string *> *fsi_files;
+               vector<stringfsi_files;
                fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsb$", true, true, -1, false);
-               if (fsi_files) {
-                       for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
-                               ::g_unlink((*i)->c_str());
-                       }
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
                }
-               vector_delete(fsi_files);
-               delete(fsi_files);
        }
 #endif
 
@@ -327,15 +307,11 @@ PluginManager::clear_vst_blacklist ()
                string personal = get_personal_vst_blacklist_dir();
 
                PathScanner scanner;
-               vector<string *> *fsi_files;
+               vector<stringfsi_files;
                fsi_files = scanner (personal, "\\.fsb$", true, true, -1, false);
-               if (fsi_files) {
-                       for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
-                               ::g_unlink((*i)->c_str());
-                       }
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
                }
-               vector_delete(fsi_files);
-               delete(fsi_files);
        }
 #endif
 }
@@ -410,8 +386,8 @@ PluginManager::add_presets(string domain)
 {
 #ifdef HAVE_LRDF
        PathScanner scanner;
-       vector<string *> *presets;
-       vector<string *>::iterator x;
+       vector<stringpresets;
+       vector<string>::iterator x;
 
        char* envvar;
        if ((envvar = getenv ("HOME")) == 0) {
@@ -421,17 +397,13 @@ PluginManager::add_presets(string domain)
        string path = string_compose("%1/.%2/rdf", envvar, domain);
        presets = scanner (path, rdf_filter, 0, false, true);
 
-       if (presets) {
-               for (x = presets->begin(); x != presets->end (); ++x) {
-                       string file = "file:" + **x;
-                       if (lrdf_read_file(file.c_str())) {
-                               warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
-                       }
+       for (x = presets.begin(); x != presets.end (); ++x) {
+               string file = "file:" + *x;
+               if (lrdf_read_file(file.c_str())) {
+                       warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg;
                }
-
-               vector_delete (presets);
-               delete (presets);
        }
+
 #endif
 }
 
@@ -440,22 +412,17 @@ PluginManager::add_lrdf_data (const string &path)
 {
 #ifdef HAVE_LRDF
        PathScanner scanner;
-       vector<string *>* rdf_files;
-       vector<string *>::iterator x;
+       vector<string> rdf_files;
+       vector<string>::iterator x;
 
        rdf_files = scanner (path, rdf_filter, 0, false, true);
 
-       if (rdf_files) {
-               for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
-                       const string uri(string("file://") + **x);
+       for (x = rdf_files.begin(); x != rdf_files.end (); ++x) {
+               const string uri(string("file://") + *x);
 
-                       if (lrdf_read_file(uri.c_str())) {
-                               warning << "Could not parse rdf file: " << uri << endmsg;
-                       }
+               if (lrdf_read_file(uri.c_str())) {
+                       warning << "Could not parse rdf file: " << uri << endmsg;
                }
-
-               vector_delete (rdf_files);
-               delete (rdf_files);
        }
 #endif
 }
@@ -662,22 +629,17 @@ int
 PluginManager::windows_vst_discover_from_path (string path, bool cache_only)
 {
        PathScanner scanner;
-       vector<string *> *plugin_objects;
-       vector<string *>::iterator x;
+       vector<stringplugin_objects;
+       vector<string>::iterator x;
        int ret = 0;
 
        DEBUG_TRACE (DEBUG::PluginManager, string_compose ("detecting Windows VST plugins along %1\n", path));
 
        plugin_objects = scanner (Config->get_plugin_path_vst(), windows_vst_filter, 0, false, true);
 
-       if (plugin_objects) {
-               for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
-                       ARDOUR::PluginScanMessage(_("VST"), **x, !cache_only && !cancelled());
-                       windows_vst_discover (**x, cache_only || cancelled());
-               }
-
-               vector_delete (plugin_objects);
-               delete (plugin_objects);
+       for (x = plugin_objects.begin(); x != plugin_objects.end (); ++x) {
+               ARDOUR::PluginScanMessage(_("VST"), *x, !cache_only && !cancelled());
+               windows_vst_discover (*x, cache_only || cancelled());
        }
 
        return ret;
@@ -783,8 +745,8 @@ int
 PluginManager::lxvst_discover_from_path (string path, bool cache_only)
 {
        PathScanner scanner;
-       vector<string *> *plugin_objects;
-       vector<string *>::iterator x;
+       vector<stringplugin_objects;
+       vector<string>::iterator x;
        int ret = 0;
 
 #ifndef NDEBUG
@@ -795,14 +757,9 @@ PluginManager::lxvst_discover_from_path (string path, bool cache_only)
 
        plugin_objects = scanner (Config->get_plugin_path_lxvst(), lxvst_filter, 0, false, true);
 
-       if (plugin_objects) {
-               for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
-                       ARDOUR::PluginScanMessage(_("LXVST"), **x, !cache_only && !cancelled());
-                       lxvst_discover (**x, cache_only || cancelled());
-               }
-
-               vector_delete (plugin_objects);
-               delete (plugin_objects);
+       for (x = plugin_objects.begin(); x != plugin_objects.end (); ++x) {
+               ARDOUR::PluginScanMessage(_("LXVST"), *x, !cache_only && !cancelled());
+               lxvst_discover (*x, cache_only || cancelled());
        }
 
        return ret;
index 8999927729d744790717bb4834b768328f43596a..9151ebf5ebc5bfc2e52aadefbd62c3c9073d6f55 100644 (file)
@@ -2299,16 +2299,10 @@ state_file_filter (const string &str, void* /*arg*/)
                str.find (statefile_suffix) == (str.length() - strlen (statefile_suffix)));
 }
 
-struct string_cmp {
-       bool operator()(const string* a, const string* b) {
-               return *a < *b;
-       }
-};
-
-static string*
-remove_end(string* state)
+static string
+remove_end(string state)
 {
-       string statename(*state);
+       string statename(state);
 
        string::size_type start,end;
        if ((start = statename.find_last_of (G_DIR_SEPARATOR)) != string::npos) {
@@ -2319,24 +2313,23 @@ remove_end(string* state)
                end = statename.length();
        }
 
-       return new string(statename.substr (0, end));
+       return string(statename.substr (0, end));
 }
 
-vector<string *> *
+vector<string>
 Session::possible_states (string path)
 {
        PathScanner scanner;
-       vector<string*>* states = scanner (path, state_file_filter, 0, false, false);
+       vector<string> states = scanner (path, state_file_filter, 0, false, false);
 
-       transform(states->begin(), states->end(), states->begin(), remove_end);
+       transform(states.begin(), states.end(), states.begin(), remove_end);
 
-       string_cmp cmp;
-       sort (states->begin(), states->end(), cmp);
+       sort (states.begin(), states.end());
 
        return states;
 }
 
-vector<string *> *
+vector<string>
 Session::possible_states () const
 {
        return possible_states(_path);
@@ -2561,7 +2554,7 @@ int
 Session::find_all_sources_across_snapshots (set<string>& result, bool exclude_this_snapshot)
 {
        PathScanner scanner;
-       vector<string*>* state_files;
+       vector<string> state_files;
        string ripped;
        string this_snapshot_path;
 
@@ -2575,7 +2568,7 @@ Session::find_all_sources_across_snapshots (set<string>& result, bool exclude_th
 
        state_files = scanner (ripped, accept_all_state_files, (void *) 0, true, true);
 
-       if (state_files == 0) {
+       if (state_files.empty()) {
                /* impossible! */
                return 0;
        }
@@ -2584,13 +2577,13 @@ Session::find_all_sources_across_snapshots (set<string>& result, bool exclude_th
        this_snapshot_path += legalize_for_path (_current_snapshot_name);
        this_snapshot_path += statefile_suffix;
 
-       for (vector<string*>::iterator i = state_files->begin(); i != state_files->end(); ++i) {
+       for (vector<string>::iterator i = state_files.begin(); i != state_files.end(); ++i) {
 
-               if (exclude_this_snapshot && **i == this_snapshot_path) {
+               if (exclude_this_snapshot && *i == this_snapshot_path) {
                        continue;
                }
 
-               if (find_all_sources (**i, result) < 0) {
+               if (find_all_sources (*i, result) < 0) {
                        return -1;
                }
        }
@@ -2645,8 +2638,8 @@ Session::cleanup_sources (CleanupReport& rep)
        string midi_path;
        vector<space_and_path>::iterator i;
        vector<space_and_path>::iterator nexti;
-       vector<string*>* candidates;
-       vector<string*>* candidates2;
+       vector<string> candidates;
+       vector<string> candidates2;
        vector<string> unused;
        set<string> all_sources;
        bool used;
@@ -2733,16 +2726,9 @@ Session::cleanup_sources (CleanupReport& rep)
 
         /* merge them */
 
-        if (candidates) {
-                if (candidates2) {
-                        for (vector<string*>::iterator i = candidates2->begin(); i != candidates2->end(); ++i) {
-                                candidates->push_back (*i);
-                        }
-                        delete candidates2;
-                }
-        } else {
-                candidates = candidates2; // might still be null
-        }
+       for (vector<string>::iterator i = candidates2.begin(); i != candidates2.end(); ++i) {
+               candidates.push_back (*i);
+       }
 
        /* find all sources, but don't use this snapshot because the
           state file on disk still references sources we may have already
@@ -2782,32 +2768,26 @@ Session::cleanup_sources (CleanupReport& rep)
                 i = tmp;
        }
 
-        if (candidates) {
-                for (vector<string*>::iterator x = candidates->begin(); x != candidates->end(); ++x) {
+       for (vector<string>::iterator x = candidates.begin(); x != candidates.end(); ++x) {
 
-                        used = false;
-                        spath = **x;
+               used = false;
+               spath = *x;
 
-                        for (set<string>::iterator i = all_sources.begin(); i != all_sources.end(); ++i) {
+               for (set<string>::iterator i = all_sources.begin(); i != all_sources.end(); ++i) {
 
-                               tmppath1 = canonical_path (spath);
-                               tmppath2 = canonical_path ((*i));
-
-                               if (tmppath1 == tmppath2) {
-                                        used = true;
-                                        break;
-                                }
-                        }
+                       tmppath1 = canonical_path (spath);
+                       tmppath2 = canonical_path ((*i));
 
-                        if (!used) {
-                                unused.push_back (spath);
-                        }
-
-                        delete *x;
-                }
+                       if (tmppath1 == tmppath2) {
+                               used = true;
+                               break;
+                       }
+               }
 
-                delete candidates;
-        }
+               if (!used) {
+                       unused.push_back (spath);
+               }
+       }
 
        /* now try to move all unused files into the "dead" directory(ies) */
 
index 86881adfc3260ad16f4b3bc62615075425768aad..20530ca9cc37821ee07840eac7552c541891b3fd 100644 (file)
@@ -81,21 +81,21 @@ session_template_dir_to_file (string const & dir)
 void
 find_session_templates (vector<TemplateInfo>& template_names)
 {
-       vector<string *> *templates;
+       vector<stringtemplates;
        PathScanner scanner;
        Searchpath spath (template_search_path());
 
        templates = scanner (spath.to_string(), template_filter, 0, true, true);
 
-       if (!templates) {
+       if (templates.empty()) {
                cerr << "Found nothing along " << spath.to_string() << endl;
                return;
        }
 
-       cerr << "Found " << templates->size() << " along " << spath.to_string() << endl;
+       cerr << "Found " << templates.size() << " along " << spath.to_string() << endl;
 
-       for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
-               string file = session_template_dir_to_file (**i);
+       for (vector<string>::iterator i = templates.begin(); i != templates.end(); ++i) {
+               string file = session_template_dir_to_file (*i);
 
                XMLTree tree;
 
@@ -105,31 +105,28 @@ find_session_templates (vector<TemplateInfo>& template_names)
 
                TemplateInfo rti;
 
-               rti.name = basename_nosuffix (**i);
-               rti.path = **i;
+               rti.name = basename_nosuffix (*i);
+               rti.path = *i;
 
                template_names.push_back (rti);
        }
-
-       vector_delete (templates);
-       delete templates;
 }
 
 void
 find_route_templates (vector<TemplateInfo>& template_names)
 {
-       vector<string *> *templates;
+       vector<stringtemplates;
        PathScanner scanner;
        Searchpath spath (route_template_search_path());
 
        templates = scanner (spath.to_string(), route_template_filter, 0, false, true);
 
-       if (!templates) {
+       if (templates.empty()) {
                return;
        }
 
-       for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
-               string fullpath = *(*i);
+       for (vector<string>::iterator i = templates.begin(); i != templates.end(); ++i) {
+               string fullpath = *i;
 
                XMLTree tree;
 
@@ -146,9 +143,6 @@ find_route_templates (vector<TemplateInfo>& template_names)
 
                template_names.push_back (rti);
        }
-
-       vector_delete (templates);
-       delete templates;
 }
 
 }
index 756bd24fe4876238802a77cdf8ee2047a05ddc4d..552012d2274f84fdceb49f219712401b767ba923 100644 (file)
@@ -229,16 +229,12 @@ void
 copy_files(const std::string & from_path, const std::string & to_dir)
 {
        PathScanner scanner;
-       vector<string*>* files = scanner (from_path, accept_all_files, 0, true, false);
+       vector<string> files = scanner (from_path, accept_all_files, 0, true, false);
 
-       if (files) {
-               for (vector<string*>::iterator i = files->begin(); i != files->end(); ++i) {
-                       std::string from = Glib::build_filename (from_path, **i);
-                       std::string to = Glib::build_filename (to_dir, **i);
-                       copy_file (from, to);
-               }
-               vector_delete (files);
-               delete (files);
+       for (vector<string>::iterator i = files.begin(); i != files.end(); ++i) {
+               std::string from = Glib::build_filename (from_path, *i);
+               std::string to = Glib::build_filename (to_dir, *i);
+               copy_file (from, to);
        }
 }
 
index b60e1eee1ab95435b045cadfb9ff3454b83962dc..bd010e66c52bb44dde8f2ccac7e533acd47b4cf1 100644 (file)
@@ -40,12 +40,11 @@ using PBD::closedir;
 #include "pbd/error.h"
 #include "pbd/pathexpand.h"
 #include "pbd/pathscanner.h"
-#include "pbd/stl_delete.h"
 
 using namespace std;
 using namespace PBD;
 
-vector<string *> *
+vector<string>
 PathScanner::operator() (const string &dirpath, const string &regexp,
                         bool match_fullpath, bool return_fullpath, 
                         long limit, bool recurse)
@@ -65,7 +64,7 @@ PathScanner::operator() (const string &dirpath, const string &regexp,
                      << ")" 
                      << endmsg;
                
-               return 0;
+               return vector<string>();
        }
        
        return run_scan (dirpath, &PathScanner::regexp_filter, 
@@ -76,7 +75,7 @@ PathScanner::operator() (const string &dirpath, const string &regexp,
                         limit, recurse);
 }      
 
-vector<string *> *
+vector<string>
 PathScanner::run_scan (const string &dirpath, 
                       bool (PathScanner::*memberfilter)(const string &),
                       bool (*filter)(const string &, void *),
@@ -85,11 +84,13 @@ PathScanner::run_scan (const string &dirpath,
                       long limit,
                       bool recurse)
 {
-       return run_scan_internal ((vector<string*>*) 0, dirpath, memberfilter, filter, arg, match_fullpath, return_fullpath, limit, recurse);
+       vector<string> result;
+       run_scan_internal (result, dirpath, memberfilter, filter, arg, match_fullpath, return_fullpath, limit, recurse);
+       return result;
 }
        
-vector<string *> *
-PathScanner::run_scan_internal (vector<string *> *result,
+void
+PathScanner::run_scan_internal (vector<string>& result,
                                const string &dirpath, 
                                bool (PathScanner::*memberfilter)(const string &),
                                bool (*filter)(const string &, void *),
@@ -104,18 +105,13 @@ PathScanner::run_scan_internal (vector<string *> *result,
        char *thisdir;
        string fullpath;
        string search_str;
-       string *newstr;
        long nfound = 0;
        char *saveptr;
 
        if ((thisdir = strtok_r (pathcopy, G_SEARCHPATH_SEPARATOR_S, &saveptr)) == 0 ||
            strlen (thisdir) == 0) {
                free (pathcopy);
-               return 0;
-       }
-
-       if (result == 0) {
-               result = new vector<string *>;
+               return;
        }
 
        do {
@@ -161,12 +157,11 @@ PathScanner::run_scan_internal (vector<string *> *result,
                                }
 
                                if (return_fullpath) {
-                                       newstr = new string (fullpath);
+                                       result.push_back(fullpath);
                                } else {
-                                       newstr = new string (finfo->d_name);
+                                       result.push_back(finfo->d_name);
                                } 
                                
-                               result->push_back (newstr);
                                nfound++;
                        }
                }
@@ -175,17 +170,16 @@ PathScanner::run_scan_internal (vector<string *> *result,
        } while ((limit < 0 || (nfound < limit)) && (thisdir = strtok_r (0, G_SEARCHPATH_SEPARATOR_S, &saveptr)));
 
        free (pathcopy);
-       return result;
+       return;
 }
 
-string *
+string
 PathScanner::find_first (const string &dirpath,
                         const string &regexp,
                         bool match_fullpath,
                         bool return_fullpath)
 {
-       vector<string *> *res;
-       string *ret;
+       vector<string> res;
        int err;
        char msg[256];
 
@@ -197,51 +191,45 @@ PathScanner::find_first (const string &dirpath,
                
                error << "Cannot compile soundfile regexp for use (" << msg << ")" << endmsg;
 
-               
                return 0;
        }
        
-       res = run_scan (dirpath, 
-                       &PathScanner::regexp_filter,
-                       (bool (*)(const string &, void *)) 0,
-                       0,
-                       match_fullpath,
-                       return_fullpath, 
-                       1);
+       run_scan_internal (res, dirpath,
+                          &PathScanner::regexp_filter,
+                          (bool (*)(const string &, void *)) 0,
+                          0,
+                          match_fullpath,
+                          return_fullpath,
+                          1);
        
-       if (res->size() == 0) {
-               ret = 0;
-       } else {
-               ret = res->front();
+       if (res.size() == 0) {
+               return string();
        }
-       vector_delete (res);
-       delete res;
-       return ret;
+
+       return res.front();
 }
 
-string *
+string
 PathScanner::find_first (const string &dirpath,
                         bool (*filter)(const string &, void *),
                         void * /*arg*/,
                         bool match_fullpath,
                         bool return_fullpath)
 {
-       vector<string *> *res;
-       string *ret;
-
-       res = run_scan (dirpath, 
-                       (bool (PathScanner::*)(const string &)) 0,
-                       filter,
-                       0,
-                       match_fullpath,
-                       return_fullpath, 1);
+       vector<string> res;
+       string ret;
+
+       run_scan_internal (res,
+                          dirpath,
+                          (bool (PathScanner::*)(const string &)) 0,
+                          filter,
+                          0,
+                          match_fullpath,
+                          return_fullpath, 1);
        
-       if (res->size() == 0) {
-               ret = 0;
-       } else {
-               ret = res->front();
+       if (res.size() == 0) {
+               return string();
        }
-       vector_delete (res);
-       delete res;
-       return ret;
+
+       return res.front();
 }
index d62203c008c2c13c67d214f2eb82540fffc0548d..990aa44c77fa78d774870c4d3916c26156b191ee 100644 (file)
@@ -34,13 +34,13 @@ class LIBPBD_API PathScanner
 
 {
   public:
-       std::vector<std::string *> *operator() (const std::string &dirpath,
-                                               bool (*filter)(const std::string &, void *arg),
-                                               void *arg, 
-                                               bool match_fullpath = true,
-                                               bool return_fullpath = true,
-                                               long limit = -1,
-                                               bool recurse = false) {
+       std::vector<std::stringoperator() (const std::string &dirpath,
+                                            bool (*filter)(const std::string &, void *arg),
+                                            void *arg,
+                                            bool match_fullpath = true,
+                                            bool return_fullpath = true,
+                                            long limit = -1,
+                                            bool recurse = false) {
                return run_scan (dirpath,
                                 (bool (PathScanner::*)(const std::string &)) 0, 
                                 filter, 
@@ -50,23 +50,23 @@ class LIBPBD_API PathScanner
                                 limit, recurse);
        }
 
-       std::vector<std::string *> *operator() (const std::string &dirpath,
-                                               const std::string &regexp,
-                                               bool match_fullpath = true,
-                                               bool return_fullpath = true,
-                                               long limit = -1,
-                                               bool recurse = false);
+       std::vector<std::stringoperator() (const std::string &dirpath,
+                                            const std::string &regexp,
+                                            bool match_fullpath = true,
+                                            bool return_fullpath = true,
+                                            long limit = -1,
+                                            bool recurse = false);
        
-       std::string *find_first (const std::string &dirpath,
-                                const std::string &regexp,
-                                bool match_fullpath = true,
-                                bool return_fullpath = true);
+       std::string find_first (const std::string &dirpath,
+                               const std::string &regexp,
+                               bool match_fullpath = true,
+                               bool return_fullpath = true);
        
-       std::string *find_first (const std::string &dirpath,
-                                bool (*filter)(const std::string &, void *),
-                                void *arg,
-                                bool match_fullpath = true,
-                                bool return_fullpath = true);
+       std::string find_first (const std::string &dirpath,
+                               bool (*filter)(const std::string &, void *),
+                               void *arg,
+                               bool match_fullpath = true,
+                               bool return_fullpath = true);
        
   private:
        regex_t compiled_pattern;
@@ -75,24 +75,24 @@ class LIBPBD_API PathScanner
                return regexec (&compiled_pattern, str.c_str(), 0, 0, 0) == 0;
        }
        
-       std::vector<std::string *> *run_scan (const std::string &dirpath,
-                                             bool (PathScanner::*mfilter) (const std::string &),
-                                             bool (*filter)(const std::string &, void *),
-                                             void *arg,
-                                             bool match_fullpath,
-                                             bool return_fullpath,
-                                             long limit,
-                                             bool recurse = false);
+       std::vector<std::stringrun_scan (const std::string &dirpath,
+                                          bool (PathScanner::*mfilter) (const std::string &),
+                                          bool (*filter)(const std::string &, void *),
+                                          void *arg,
+                                          bool match_fullpath,
+                                          bool return_fullpath,
+                                          long limit,
+                                          bool recurse = false);
 
-       std::vector<std::string *> *run_scan_internal (std::vector<std::string*>*, 
-                                                      const std::string &dirpath,
-                                                      bool (PathScanner::*mfilter) (const std::string &),
-                                                      bool (*filter)(const std::string &, void *),
-                                                      void *arg,
-                                                      bool match_fullpath,
-                                                      bool return_fullpath,
-                                                      long limit,
-                                                      bool recurse = false);
+       void run_scan_internal (std::vector<std::string>&,
+                               const std::string &dirpath,
+                               bool (PathScanner::*mfilter) (const std::string &),
+                               bool (*filter)(const std::string &, void *),
+                               void *arg,
+                               bool match_fullpath,
+                               bool return_fullpath,
+                               long limit,
+                               bool recurse = false);
 };
 
 #endif // __libmisc_pathscanner_h__
index bae6a4883757ec9f89b8d679906332ce1b440ba4..7a9104cfdbc69f8ce148249e5b9642847a44e3ae 100644 (file)
@@ -136,20 +136,20 @@ midi_map_filter (const string &str, void* /*arg*/)
 void
 GenericMidiControlProtocol::reload_maps ()
 {
-       vector<string *> *midi_maps;
+       vector<stringmidi_maps;
        PathScanner scanner;
        Searchpath spath (system_midi_map_search_path());
        spath += user_midi_map_directory ();
 
        midi_maps = scanner (spath.to_string(), midi_map_filter, 0, false, true);
 
-       if (!midi_maps) {
+       if (midi_maps.empty()) {
                cerr << "No MIDI maps found using " << spath.to_string() << endl;
                return;
        }
 
-       for (vector<string*>::iterator i = midi_maps->begin(); i != midi_maps->end(); ++i) {
-               string fullpath = *(*i);
+       for (vector<string>::iterator i = midi_maps.begin(); i != midi_maps.end(); ++i) {
+               string fullpath = *i;
 
                XMLTree tree;
 
@@ -170,8 +170,6 @@ GenericMidiControlProtocol::reload_maps ()
                
                map_info.push_back (mi);
        }
-
-       delete midi_maps;
 }
        
 void
index a2aeaa08aa2a7ef199cc35d0acfa478011eedc71..672bb255113a20ecf8a22960f403964201ca0201 100644 (file)
@@ -471,31 +471,24 @@ DeviceInfo::reload_device_info ()
 {
        DeviceInfo di;
        vector<string> s;
-       vector<string *> *devinfos;
+       vector<stringdevinfos;
        PathScanner scanner;
        Searchpath spath (devinfo_search_path());
 
        devinfos = scanner (spath.to_string(), devinfo_filter, 0, false, true);
        device_info.clear ();
 
-       if (!devinfos) {
+       if (devinfos.empty()) {
                error << "No MCP device info files found using " << spath.to_string() << endmsg;
                std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl;
                return;
        }
 
-       if (devinfos->empty()) {
-               error << "No MCP device info files found using " << spath.to_string() << endmsg;
-               std::cerr << "No MCP device info files found using " << spath.to_string() << std::endl;
-               return;
-       }
-
-       for (vector<string*>::iterator i = devinfos->begin(); i != devinfos->end(); ++i) {
-               string fullpath = *(*i);
+       for (vector<string>::iterator i = devinfos.begin(); i != devinfos.end(); ++i) {
+               string fullpath = *i;
 
                XMLTree tree;
 
-
                if (!tree.read (fullpath.c_str())) {
                        continue;
                }
@@ -509,9 +502,6 @@ DeviceInfo::reload_device_info ()
                        device_info[di.name()] = di;
                }
        }
-
-       vector_delete (devinfos);
-       delete devinfos;
 }
 
 std::ostream& operator<< (std::ostream& os, const Mackie::DeviceInfo& di)
index 73e885d8c5e6a7cd1a14e7b1348e38c11a0a1ccf..42b70830cb85030213eabd7bb09695880918125b 100644 (file)
@@ -90,25 +90,20 @@ DeviceProfile::reload_device_profiles ()
 {
        DeviceProfile dp;
        vector<string> s;
-       vector<string *> *devprofiles;
+       vector<stringdevprofiles;
        PathScanner scanner;
        Searchpath spath (devprofile_search_path());
 
        devprofiles = scanner (spath.to_string(), devprofile_filter, 0, false, true);
        device_profiles.clear ();
 
-       if (!devprofiles) {
+       if (devprofiles.empty()) {
                error << "No MCP device info files found using " << spath.to_string() << endmsg;
                return;
        }
 
-       if (devprofiles->empty()) {
-               error << "No MCP device info files found using " << spath.to_string() << endmsg;
-               return;
-       }
-
-       for (vector<string*>::iterator i = devprofiles->begin(); i != devprofiles->end(); ++i) {
-               string fullpath = *(*i);
+       for (vector<string>::iterator i = devprofiles.begin(); i != devprofiles.end(); ++i) {
+               string fullpath = *i;
 
                XMLTree tree;
 
@@ -126,9 +121,6 @@ DeviceProfile::reload_device_profiles ()
                        device_profiles[dp.name()] = dp;
                }
        }
-
-       vector_delete (devprofiles);
-       delete devprofiles;
 }
 
 int