diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-21 15:32:52 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-22 20:11:50 +0200 |
commit | 200ca388246e525f6e8f909766977f534c0c897e (patch) | |
tree | a1ddcd356bddada68d1510eb409721b6b2564562 /shell | |
parent | ac9db25da2d78f8ecc2ce68ad622cc6012972494 (diff) |
teach useuniqueptr loplugin about calling delete on a param
which is often a useful indicator that the callers can be made to use
std::unique_ptr
Change-Id: Idb1745d1f58dbcf389c9f60f1a5728d7d092ade5
Reviewed-on: https://gerrit.libreoffice.org/56238
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/source/unix/sysshell/recently_used_file_handler.cxx | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/shell/source/unix/sysshell/recently_used_file_handler.cxx b/shell/source/unix/sysshell/recently_used_file_handler.cxx index 6ca13932143c..ced51eda9787 100644 --- a/shell/source/unix/sysshell/recently_used_file_handler.cxx +++ b/shell/source/unix/sysshell/recently_used_file_handler.cxx @@ -32,6 +32,7 @@ #include <i_xml_parser_event_handler.hxx> #include <map> +#include <memory> #include <vector> #include <algorithm> #include <string.h> @@ -194,7 +195,7 @@ namespace /* private */ { string_container_t groups_; }; - typedef std::vector<recently_used_item*> recently_used_item_list_t; + typedef std::vector<std::unique_ptr<recently_used_item>> recently_used_item_list_t; typedef void (recently_used_item::* SET_COMMAND)(const string_t&); // thrown if we encounter xml tags that we do not know @@ -205,7 +206,6 @@ namespace /* private */ { { public: explicit recently_used_file_filter(recently_used_item_list_t& item_list) : - item_(nullptr), item_list_(item_list) { named_command_map_[TAG_RECENT_FILES] = &recently_used_item::set_nothing; @@ -227,7 +227,7 @@ namespace /* private */ { const xml_tag_attribute_container_t& /*attributes*/) override { if ((local_name == TAG_RECENT_ITEM) && (nullptr == item_)) - item_ = new recently_used_item; + item_.reset(new recently_used_item); } virtual void end_element(const string_t& /*raw_name*/, const string_t& local_name) override @@ -237,17 +237,16 @@ namespace /* private */ { return; // will result in an XML parser error anyway if (named_command_map_.find(local_name) != named_command_map_.end()) - (item_->*named_command_map_[local_name])(current_element_); + (item_.get()->*named_command_map_[local_name])(current_element_); else { - delete item_; + item_.reset(); throw unknown_xml_format_exception(); } if (local_name == TAG_RECENT_ITEM) { - item_list_.push_back(item_); - item_ = nullptr; + item_list_.push_back(std::move(item_)); } current_element_.clear(); } @@ -264,7 +263,7 @@ namespace /* private */ { virtual void comment(const string_t& /*comment*/) override {} private: - recently_used_item* item_; + std::unique_ptr<recently_used_item> item_; std::map<string_t, SET_COMMAND> named_command_map_; string_t current_element_; recently_used_item_list_t& item_list_; @@ -301,7 +300,7 @@ namespace /* private */ { items_written_(0) {} - void operator() (const recently_used_item* item) + void operator() (const std::unique_ptr<recently_used_item> & item) { if (items_written_++ < MAX_RECENTLY_USED_ITEMS) item->write_xml(file_); @@ -338,23 +337,6 @@ namespace /* private */ { } - struct delete_recently_used_item - { - void operator() (const recently_used_item* item) const - { delete item; } - }; - - - void recently_used_item_list_clear(recently_used_item_list_t& item_list) - { - std::for_each( - item_list.begin(), - item_list.end(), - delete_recently_used_item()); - item_list.clear(); - } - - class find_item_predicate { public: @@ -362,7 +344,7 @@ namespace /* private */ { uri_(uri) {} - bool operator() (const recently_used_item* item) const + bool operator() (const std::unique_ptr<recently_used_item> & item) const { return (item->uri_ == uri_); } private: string_t uri_; @@ -371,7 +353,7 @@ namespace /* private */ { struct greater_recently_used_item { - bool operator ()(const recently_used_item* lhs, const recently_used_item* rhs) const + bool operator ()(const std::unique_ptr<recently_used_item> & lhs, const std::unique_ptr<recently_used_item> & rhs) const { return (lhs->timestamp_ > rhs->timestamp_); } }; @@ -416,7 +398,7 @@ namespace /* private */ { if (mimetype.length() == 0) mimetype = "application/octet-stream"; - item_list.push_back(new recently_used_item(uri, mimetype, groups)); + item_list.emplace_back(new recently_used_item(uri, mimetype, groups)); } // sort decreasing after the timestamp @@ -434,7 +416,7 @@ namespace /* private */ { item_list_(item_list) {} ~cleanup_guard() - { recently_used_item_list_clear(item_list_); } + { item_list_.clear(); } recently_used_item_list_t& item_list_; }; |