From 8ba559b7f7960c69b81e1aacc83c5f43c5eba916 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 28 Sep 2011 19:48:58 +0000 Subject: [PATCH] Clean up Automation4::ScriptManager Originally committed to SVN as r5642. --- aegisub/src/auto4_base.cpp | 80 +++++++------------------------------- aegisub/src/auto4_base.h | 40 +++++++------------ 2 files changed, 28 insertions(+), 92 deletions(-) diff --git a/aegisub/src/auto4_base.cpp b/aegisub/src/auto4_base.cpp index 3a6d6176e..8cb0f518e 100644 --- a/aegisub/src/auto4_base.cpp +++ b/aegisub/src/auto4_base.cpp @@ -355,76 +355,31 @@ namespace Automation4 { } // ScriptManager - - - /// @brief DOCME - /// - ScriptManager::ScriptManager() - { - // do nothing...? - } - - - /// @brief DOCME - /// ScriptManager::~ScriptManager() { RemoveAll(); } - - /// @brief DOCME - /// @param script - /// @return - /// void ScriptManager::Add(Script *script) { - for (std::vector::iterator i = scripts.begin(); i != scripts.end(); ++i) { - if (script == *i) return; - } - scripts.push_back(script); + if (find(scripts.begin(), scripts.end(), script) == scripts.end()) + scripts.push_back(script); } - - /// @brief DOCME - /// @param script - /// @return - /// void ScriptManager::Remove(Script *script) { - for (std::vector::iterator i = scripts.begin(); i != scripts.end(); ++i) { - if (script == *i) { - delete *i; - scripts.erase(i); - return; - } + std::vector::iterator i = find(scripts.begin(), scripts.end(), script); + if (i != scripts.end()) { + delete *i; + scripts.erase(i); } } - - /// @brief DOCME - /// void ScriptManager::RemoveAll() { - for (std::vector::iterator i = scripts.begin(); i != scripts.end(); ++i) { - delete *i; - } - scripts.clear(); + delete_clear(scripts); } - - /// @brief DOCME - /// @return - /// - const std::vector& ScriptManager::GetScripts() const - { - return scripts; - } - - - /// @brief DOCME - /// @return - /// const std::vector& ScriptManager::GetMacros() { macros.clear(); @@ -437,20 +392,12 @@ namespace Automation4 { // AutoloadScriptManager - - - /// @brief DOCME - /// @param _path - /// - AutoloadScriptManager::AutoloadScriptManager(const wxString &_path) - : path(_path) + AutoloadScriptManager::AutoloadScriptManager(wxString const& path) + : path(path) { Reload(); } - - /// @brief DOCME - /// void AutoloadScriptManager::Reload() { RemoveAll(); @@ -496,7 +443,8 @@ namespace Automation4 { slots.push_back(c->ass->AddFileOpenListener(&LocalScriptManager::Reload, this)); } - void LocalScriptManager::Reload() { + void LocalScriptManager::Reload() + { RemoveAll(); wxString local_scripts = context->ass->GetScriptInfo("Automation Scripts"); @@ -525,7 +473,6 @@ namespace Automation4 { wxFileName sfname(trimmed); sfname.MakeAbsolute(basepath); if (sfname.FileExists()) { - wxString err; Add(Automation4::ScriptFactory::CreateFromFile(sfname.GetFullPath(), true)); } else { wxLogWarning("Automation Script referenced could not be found.\nFilename specified: %c%s\nSearched relative to: %s\nResolved filename: %s", @@ -534,7 +481,8 @@ namespace Automation4 { } } - void LocalScriptManager::OnSubtitlesSave() { + void LocalScriptManager::OnSubtitlesSave() + { // Store Automation script data // Algorithm: // 1. If script filename has Automation Base Path as a prefix, the path is relative to that (ie. "$") @@ -614,6 +562,7 @@ namespace Automation4 { if (log_errors) wxLogError(_("The file was not recognised as an Automation script: %s"), filename); + return new UnknownScript(filename); } @@ -661,7 +610,6 @@ namespace Automation4 { return fnfilter; } - // UnknownScript UnknownScript::UnknownScript(wxString const& filename) : Script(filename) diff --git a/aegisub/src/auto4_base.h b/aegisub/src/auto4_base.h index beb416aec..96385d1a9 100644 --- a/aegisub/src/auto4_base.h +++ b/aegisub/src/auto4_base.h @@ -217,30 +217,25 @@ namespace Automation4 { virtual std::vector GetFormats() const=0; }; - /// DOCME - /// @class ScriptManager - /// @brief DOCME - /// - /// DOCME + /// A manager of loaded automation scripts class ScriptManager { - private: - - /// DOCME std::vector scripts; - - - /// DOCME std::vector macros; public: - ScriptManager(); - virtual ~ScriptManager(); // Deletes all scripts managed - void Add(Script *script); // Add a script to the manager. The ScriptManager takes owvership of the script and will automatically delete it. - void Remove(Script *script); // Remove a script from the manager, and delete the Script object. - void RemoveAll(); // Deletes all scripts managed + /// Deletes all scripts managed + virtual ~ScriptManager(); + /// Add a script to the manager. The ScriptManager takes ownership of the script and will automatically delete it. + void Add(Script *script); + /// Remove a script from the manager, and delete the Script object. + void Remove(Script *script); + /// Deletes all scripts managed + void RemoveAll(); + /// Reload all scripts mananaged virtual void Reload() = 0; - const std::vector& GetScripts() const; + /// Get all managed scripts (both loaded and invalid) + const std::vector& GetScripts() const { return scripts; } const std::vector& GetMacros(); // No need to have getters for the other kinds of features, I think. @@ -258,18 +253,11 @@ namespace Automation4 { void Reload(); }; - /// DOCME - /// @class AutoloadScriptManager - /// @brief DOCME - /// - /// DOCME + /// Manager for scripts in the autoload directory class AutoloadScriptManager : public ScriptManager { - private: - - /// DOCME wxString path; public: - AutoloadScriptManager(const wxString &_path); + AutoloadScriptManager(wxString const& path); void Reload(); };