diff --git a/.travis.yml b/.travis.yml index 0e597205..3d4cba7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ before_install: - - sudo apt-add-repository -y ppa:llxdev/pandora + - sudo apt-add-repository -y ppa:ondrej/php5-experimental + - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo apt-get update - - sudo apt-get install -qq libsqlite3-dev libcurl4-openssl-dev libxml2-dev libstfl-dev libjson-c-dev libncursesw5-dev bc + - sudo apt-get install -qq libsqlite3-dev libcurl4-openssl-dev libxml2-dev libstfl-dev libjson-c-dev libncursesw5-dev bc gcc-4.8 + - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50 language: cpp compiler: - gcc diff --git a/Makefile b/Makefile index 82d24f8e..f4608485 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ CXX?=c++ # compiler and linker flags DEFINES=-DLOCALEDIR=\"$(localedir)\" WARNFLAGS=-Wall -Wextra -Wunreachable-code -CXXFLAGS+=-ggdb -Iinclude -Istfl -Ifilter -I. -Irss $(WARNFLAGS) $(DEFINES) +CXXFLAGS+=-std=c++11 -ggdb -Iinclude -Istfl -Ifilter -I. -Irss $(WARNFLAGS) $(DEFINES) LDFLAGS+=-L. PACKAGE=newsbeuter diff --git a/include/cache.h b/include/cache.h index 760b6799..2ea5b331 100644 --- a/include/cache.h +++ b/include/cache.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace newsbeuter { @@ -15,15 +15,15 @@ class cache { public: cache(const std::string& cachefile, configcontainer * c); ~cache(); - void externalize_rssfeed(std::tr1::shared_ptr feed, bool reset_unread); - std::tr1::shared_ptr internalize_rssfeed(std::string rssurl, rss_ignores * ign); - void update_rssitem_unread_and_enqueued(std::tr1::shared_ptr item, const std::string& feedurl); + void externalize_rssfeed(std::shared_ptr feed, bool reset_unread); + std::shared_ptr internalize_rssfeed(std::string rssurl, rss_ignores * ign); + void update_rssitem_unread_and_enqueued(std::shared_ptr item, const std::string& feedurl); void update_rssitem_unread_and_enqueued(rss_item* item, const std::string& feedurl); - void cleanup_cache(std::vector >& feeds); + void cleanup_cache(std::vector>& feeds); void do_vacuum(); - std::vector > search_for_items(const std::string& querystr, const std::string& feedurl); + std::vector> search_for_items(const std::string& querystr, const std::string& feedurl); void catchup_all(const std::string& feedurl = ""); - void catchup_all(std::tr1::shared_ptr feed); + void catchup_all(std::shared_ptr feed); void update_rssitem_flags(rss_item* item); std::vector get_feed_urls(); void fetch_lastmodified(const std::string& uri, time_t& t, std::string& etag); @@ -40,15 +40,15 @@ class cache { private: void populate_tables(); void set_pragmas(); - void delete_item(const std::tr1::shared_ptr item); + void delete_item(const std::shared_ptr item); void clean_old_articles(); - void update_rssitem_unlocked(std::tr1::shared_ptr item, const std::string& feedurl, bool reset_unread); + void update_rssitem_unlocked(std::shared_ptr item, const std::string& feedurl, bool reset_unread); std::string prepare_query(const char * format, ...); sqlite3 * db; configcontainer * cfg; - mutex mtx; + std::mutex mtx; }; } diff --git a/include/colormanager.h b/include/colormanager.h index b632df72..e1644731 100644 --- a/include/colormanager.h +++ b/include/colormanager.h @@ -26,13 +26,13 @@ class colormanager : public config_action_handler { void set_pb_colors(podbeuter::pb_view * v); inline std::map& get_fgcolors() { return fg_colors; } inline std::map& get_bgcolors() { return bg_colors; } - inline std::map >& get_attributes() { return attributes; } + inline std::map>& get_attributes() { return attributes; } private: bool colors_loaded_; std::map fg_colors; std::map bg_colors; - std::map > attributes; + std::map> attributes; }; } diff --git a/include/configcontainer.h b/include/configcontainer.h index 612c1694..4d6e27b8 100644 --- a/include/configcontainer.h +++ b/include/configcontainer.h @@ -10,8 +10,8 @@ namespace newsbeuter struct configdata { enum configdata_type { INVALID, BOOL, INT, STR, PATH, ALIAS, ENUM }; - configdata(const std::string& v = "", configdata_type t = INVALID, bool m = false) : value(v), default_value(v), type(t), multi_option(m) { } - configdata(const std::string& v, ...); + configdata(std::string v = "", configdata_type t = INVALID, bool m = false) : value(v), default_value(v), type(t), multi_option(m) { } + configdata(std::string v, ...); std::string value; std::string default_value; configdata_type type; diff --git a/include/configparser.h b/include/configparser.h index 2fc7cf38..bbf03aea 100644 --- a/include/configparser.h +++ b/include/configparser.h @@ -30,7 +30,7 @@ namespace newsbeuter { private: void evaluate_backticks(std::vector& tokens); static std::string evaluate_cmd(const std::string& cmd); - std::vector > parsed_content; + std::vector> parsed_content; std::map action_handlers; std::set included_files; }; diff --git a/include/controller.h b/include/controller.h index 6a42faea..7b5ef477 100644 --- a/include/controller.h +++ b/include/controller.h @@ -35,9 +35,9 @@ namespace newsbeuter { void reload_range(unsigned int start, unsigned int end, unsigned int size, bool unattended = false); void start_reload_all_thread(std::vector * indexes = 0); - std::tr1::shared_ptr get_feed(unsigned int pos); - std::tr1::shared_ptr get_feed_by_url(const std::string& feedurl); - std::vector > search_for_items(const std::string& query, const std::string& feedurl); + std::shared_ptr get_feed(unsigned int pos); + std::shared_ptr get_feed_by_url(const std::string& feedurl); + std::vector> search_for_items(const std::string& query, const std::string& feedurl); inline unsigned int get_feedcount() { return feeds.size(); } inline void unlock_reload_mutex() { reload_mutex.unlock(); } @@ -49,18 +49,18 @@ namespace newsbeuter { void mark_article_read(const std::string& guid, bool read); void record_google_replay(const std::string& guid, bool read); void catchup_all(); - inline void catchup_all(std::tr1::shared_ptr feed) { rsscache->catchup_all(feed); } + inline void catchup_all(std::shared_ptr feed) { rsscache->catchup_all(feed); } inline bool get_refresh_on_start() const { return refresh_on_start; } bool is_valid_podcast_type(const std::string& mimetype); - void enqueue_url(const std::string& url, std::tr1::shared_ptr feed); + void enqueue_url(const std::string& url, std::shared_ptr feed); void notify(const std::string& msg); unsigned int get_pos_of_next_unread(unsigned int pos); void reload_urls_file(); void edit_urls_file(); - std::vector > get_all_feeds(); - std::vector > get_all_feeds_unlocked(); + std::vector> get_all_feeds(); + std::vector> get_all_feeds_unlocked(); inline filtercontainer& get_filters() { return filters; } @@ -70,9 +70,9 @@ namespace newsbeuter { inline configcontainer * get_cfg() { return &cfg; } - void write_item(std::tr1::shared_ptr item, const std::string& filename); - void write_item(std::tr1::shared_ptr item, std::ostream& ostr); - std::string write_temporary_item(std::tr1::shared_ptr item); + void write_item(std::shared_ptr item, const std::string& filename); + void write_item(std::shared_ptr item, std::ostream& ostr); + std::string write_temporary_item(std::shared_ptr item); void mark_deleted(const std::string& guid, bool b); @@ -84,7 +84,7 @@ namespace newsbeuter { void sort_feeds(); - void update_flags(std::tr1::shared_ptr item); + void update_flags(std::shared_ptr item); unsigned int get_feed_count_per_tag(const std::string& tag); private: @@ -99,9 +99,10 @@ namespace newsbeuter { void execute_commands(char ** argv, unsigned int i); std::string prepare_message(unsigned int pos, unsigned int max); - void enqueue_items(std::tr1::shared_ptr feed); + void save_feed(std::shared_ptr feed, unsigned int pos); + void enqueue_items(std::shared_ptr feed); - std::string generate_enqueue_filename(const std::string& url, std::tr1::shared_ptr feed); + std::string generate_enqueue_filename(const std::string& url, std::shared_ptr feed); std::string get_hostname_from_url(const std::string& url); void import_read_information(const std::string& readinfofile); @@ -110,7 +111,7 @@ namespace newsbeuter { view * v; urlreader * urlcfg; cache * rsscache; - std::vector > feeds; + std::vector> feeds; std::string config_dir; std::string url_file; std::string cache_file; @@ -123,12 +124,12 @@ namespace newsbeuter { rss_ignores ign; filtercontainer filters; - mutex reload_mutex; + std::mutex reload_mutex; configparser cfgparser; colormanager colorman; regexmanager rxman; remote_api * api; - mutex feeds_mutex; + std::mutex feeds_mutex; bool offline_mode; }; diff --git a/include/downloadthread.h b/include/downloadthread.h index f4be616e..b1201caf 100644 --- a/include/downloadthread.h +++ b/include/downloadthread.h @@ -1,7 +1,7 @@ #ifndef DOWNLOADTHREAD_H_ #define DOWNLOADTHREAD_H_ -#include +#include #include namespace newsbeuter @@ -9,24 +9,22 @@ namespace newsbeuter class controller; -class downloadthread : public thread +class downloadthread { public: downloadthread(controller * c, std::vector * idxs = 0); virtual ~downloadthread(); -protected: - virtual void run(); + void operator()(); private: controller * ctrl; std::vector indexes; }; -class reloadrangethread : public thread +class reloadrangethread { public: reloadrangethread(controller * c, unsigned int start, unsigned int end, unsigned int size, bool unattended); -protected: - virtual void run(); + void operator()(); private: controller * ctrl; unsigned int s, e, ss; diff --git a/include/feedlist_formaction.h b/include/feedlist_formaction.h index 88bb9e00..2478afd8 100644 --- a/include/feedlist_formaction.h +++ b/include/feedlist_formaction.h @@ -9,7 +9,7 @@ namespace newsbeuter { -typedef std::pair, unsigned int> feedptr_pos_pair; +typedef std::pair, unsigned int> feedptr_pos_pair; class feedlist_formaction : public formaction { public: @@ -17,11 +17,11 @@ class feedlist_formaction : public formaction { virtual ~feedlist_formaction(); virtual void prepare(); virtual void init(); - void set_feedlist(std::vector >& feeds); - void update_visible_feeds(std::vector >& feeds); + void set_feedlist(std::vector>& feeds); + void update_visible_feeds(std::vector>& feeds); void set_tags(const std::vector& t); virtual keymap_hint_entry * get_keymap_hint(); - std::tr1::shared_ptr get_feed(); + std::shared_ptr get_feed(); virtual void set_redraw(bool b) { formaction::set_redraw(b); @@ -61,9 +61,9 @@ class feedlist_formaction : public formaction { void set_pos(); - std::string get_title(std::tr1::shared_ptr feed); + std::string get_title(std::shared_ptr feed); - std::string format_line(const std::string& feedlist_format, std::tr1::shared_ptr feed, unsigned int pos, unsigned int width); + std::string format_line(const std::string& feedlist_format, std::shared_ptr feed, unsigned int pos, unsigned int width); bool zero_feedpos; unsigned int feeds_shown; @@ -77,7 +77,7 @@ class feedlist_formaction : public formaction { history filterhistory; - std::tr1::shared_ptr search_dummy_feed; + std::shared_ptr search_dummy_feed; unsigned int filterpos; bool set_filterpos; diff --git a/include/formaction.h b/include/formaction.h index 9d5aeb64..6e2cb1ba 100644 --- a/include/formaction.h +++ b/include/formaction.h @@ -26,7 +26,7 @@ class formaction { virtual ~formaction(); virtual void prepare() = 0; virtual void init() = 0; - std::tr1::shared_ptr get_form(); + std::shared_ptr get_form(); virtual void set_redraw(bool b) { do_redraw = b; } virtual keymap_hint_entry * get_keymap_hint() = 0; @@ -48,8 +48,8 @@ class formaction { inline std::string get_qna_response(unsigned int i) { return (qna_responses.size() >= (i + 1)) ? qna_responses[i] : ""; } void start_qna(const std::vector& prompts, operation finish_op, history * h = NULL); - inline void set_parent_formaction(std::tr1::shared_ptr fa) { parent_formaction = fa; } - inline std::tr1::shared_ptr get_parent_formaction() const { return parent_formaction; } + inline void set_parent_formaction(std::shared_ptr fa) { parent_formaction = fa; } + inline std::shared_ptr get_parent_formaction() const { return parent_formaction; } virtual std::string title() = 0; @@ -66,7 +66,7 @@ class formaction { void start_bookmark_qna(const std::string& default_title, const std::string& default_url, const std::string& default_desc); view * v; - std::tr1::shared_ptr f; + std::shared_ptr f; bool do_redraw; std::vector qna_responses; @@ -84,7 +84,7 @@ class formaction { std::vector qna_prompts; operation finish_operation; history * qna_history; - std::tr1::shared_ptr parent_formaction; + std::shared_ptr parent_formaction; }; diff --git a/include/itemlist_formaction.h b/include/itemlist_formaction.h index d35381d3..7f55c40d 100644 --- a/include/itemlist_formaction.h +++ b/include/itemlist_formaction.h @@ -3,13 +3,12 @@ #include #include -#include #include #include namespace newsbeuter { -typedef std::pair, unsigned int> itemptr_pos_pair; +typedef std::pair, unsigned int> itemptr_pos_pair; class itemlist_formaction : public formaction { public: @@ -24,12 +23,12 @@ class itemlist_formaction : public formaction { update_visible_items = true; } - void set_feed(std::tr1::shared_ptr fd); + void set_feed(std::shared_ptr fd); virtual std::string id() const { return "articlelist"; } virtual std::string title(); - inline std::tr1::shared_ptr get_feed() { return feed; } + inline std::shared_ptr get_feed() { return feed; } inline void set_pos(unsigned int p) { pos = p; } std::string get_guid(); virtual keymap_hint_entry * get_keymap_hint(); @@ -60,7 +59,7 @@ class itemlist_formaction : public formaction { void set_head(const std::string& s, unsigned int unread, unsigned int total, const std::string &url); int get_pos(unsigned int idx); - void save_article(const std::string& filename, std::tr1::shared_ptr item); + void save_article(const std::string& filename, std::shared_ptr item); void save_filterpos(); @@ -70,13 +69,13 @@ class itemlist_formaction : public formaction { void handle_cmdline_num(unsigned int idx); - std::string gen_flags(std::tr1::shared_ptr item); + std::string gen_flags(std::shared_ptr item); std::string gen_datestr(time_t t, const char * datetimeformat); void prepare_set_filterpos(); unsigned int pos; - std::tr1::shared_ptr feed; + std::shared_ptr feed; bool apply_filter; matcher m; std::vector visible_items; @@ -86,9 +85,9 @@ class itemlist_formaction : public formaction { history filterhistory; - std::tr1::shared_ptr search_dummy_feed; + std::shared_ptr search_dummy_feed; - mutex redraw_mtx; + std::mutex redraw_mtx; bool set_filterpos; unsigned int filterpos; diff --git a/include/itemview_formaction.h b/include/itemview_formaction.h index b845d152..ebb82d79 100644 --- a/include/itemview_formaction.h +++ b/include/itemview_formaction.h @@ -12,15 +12,12 @@ class itemlist_formaction; class itemview_formaction : public formaction { public: - itemview_formaction(view *, std::tr1::shared_ptr il, std::string formstr); + itemview_formaction(view *, std::shared_ptr il, std::string formstr); virtual ~itemview_formaction(); virtual void prepare(); virtual void init(); - inline void set_guid(const std::string& guid_) { - LOG(LOG_DEBUG, "itemview_formaction::set_guid: new guid = %s", guid_.c_str()); - guid = guid_; - } - inline void set_feed(std::tr1::shared_ptr fd) { feed = fd; } + inline void set_guid(const std::string& guid_) { guid = guid_; } + inline void set_feed(std::shared_ptr fd) { feed = fd; } void set_highlightphrase(const std::string& text); keymap_hint_entry * get_keymap_hint(); virtual void handle_cmdline(const std::string& cmd); @@ -46,13 +43,13 @@ class itemview_formaction : public formaction { void do_search(); std::string guid; - std::tr1::shared_ptr feed; + std::shared_ptr feed; bool show_source; std::vector links; bool quit; regexmanager * rxman; unsigned int num_lines; - std::tr1::shared_ptr itemlist; + std::shared_ptr itemlist; bool in_search; }; diff --git a/include/keymap.h b/include/keymap.h index 653a9fdb..558e0dd8 100644 --- a/include/keymap.h +++ b/include/keymap.h @@ -169,8 +169,8 @@ namespace newsbeuter { private: bool is_valid_context(const std::string& context); std::string getopname(operation op); - std::map > keymap_; - std::map > macros_; + std::map> keymap_; + std::map> macros_; }; } diff --git a/include/logger.h b/include/logger.h index b7815d63..97dbd55f 100644 --- a/include/logger.h +++ b/include/logger.h @@ -2,7 +2,7 @@ #define LOGGER__H #include -#include +#include #include namespace newsbeuter { @@ -26,8 +26,8 @@ class logger { ~logger() { } loglevel curlevel; - mutex logMutex; - static mutex instanceMutex; + std::mutex logMutex; + static std::mutex instanceMutex; std::fstream f; std::fstream ef; }; diff --git a/include/markreadthread.h b/include/markreadthread.h index f7aba2e0..e7130b5c 100644 --- a/include/markreadthread.h +++ b/include/markreadthread.h @@ -1,7 +1,7 @@ #ifndef MARKREADTHREAD_H_ #define MARKREADTHREAD_H_ -#include +#include #include namespace newsbeuter @@ -9,13 +9,12 @@ namespace newsbeuter class controller; -class markreadthread : public thread +class markreadthread { public: markreadthread( ttrss_api* r_api, const std::string& guid, bool read ); virtual ~markreadthread(); -protected: - virtual void run(); + void operator()(); private: ttrss_api* _r_api; const std::string& _guid; diff --git a/include/mutex.h b/include/mutex.h deleted file mode 100644 index 5cf2578d..00000000 --- a/include/mutex.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef AK_MUTEX__H -#define AK_MUTEX__H - -#include - -namespace newsbeuter { - -class mutex { - public: - mutex(); - ~mutex(); - void lock(); - void unlock(); - bool trylock(); - - private: - pthread_mutex_t mtx; - pthread_mutexattr_t attr; - - friend class condition; -}; - -class scope_mutex { - public: - scope_mutex(mutex * m); - ~scope_mutex(); - private: - mutex * mtx; -}; - -} - -#endif diff --git a/include/poddlthread.h b/include/poddlthread.h index 8a42b165..a10b9e73 100644 --- a/include/poddlthread.h +++ b/include/poddlthread.h @@ -1,7 +1,7 @@ #ifndef PODBEUTER_PODDLTHREAD__H #define PODBEUTER_PODDLTHREAD__H -#include +#include #include #include @@ -12,19 +12,19 @@ namespace podbeuter { -class poddlthread : public newsbeuter::thread { +class poddlthread { public: poddlthread(download * dl_, newsbeuter::configcontainer *); virtual ~poddlthread(); size_t write_data(void * buffer, size_t size, size_t nmemb); int progress(double dlnow, double dltotal); + void operator()(); protected: - virtual void run(); double compute_kbps(); private: void mkdir_p(const char * file); download * dl; - std::ofstream f; + std::ofstream *f; timeval tv1; timeval tv2; size_t bytecount; diff --git a/include/regexmanager.h b/include/regexmanager.h index e7354fc6..da0193d6 100644 --- a/include/regexmanager.h +++ b/include/regexmanager.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include namespace newsbeuter { @@ -21,10 +21,10 @@ class regexmanager : public config_action_handler { void remove_last_regex(const std::string& location); int article_matches(matchable * item); private: - typedef std::pair, std::vector > rc_pair; + typedef std::pair, std::vector> rc_pair; std::map locations; std::vector cheat_store_for_dump_config; - std::vector, int> > matchers; + std::vector, int>> matchers; std::string extract_initial_marker(const std::string& str); public: inline std::vector& get_attrs(const std::string& loc) { return locations[loc].second; } diff --git a/include/reloadthread.h b/include/reloadthread.h index 7537af2b..48c39bf6 100644 --- a/include/reloadthread.h +++ b/include/reloadthread.h @@ -1,20 +1,19 @@ #ifndef RELOADTHREAD_H_ #define RELOADTHREAD_H_ -#include +#include #include #include namespace newsbeuter { -class reloadthread : public thread +class reloadthread { public: reloadthread(controller * c, configcontainer * cf); virtual ~reloadthread(); -protected: - virtual void run(); + void operator()(); private: controller * ctrl; time_t oldtime; diff --git a/include/remote_api.h b/include/remote_api.h index 7a068c0a..15f5a561 100644 --- a/include/remote_api.h +++ b/include/remote_api.h @@ -9,7 +9,7 @@ namespace newsbeuter { -typedef std::pair > tagged_feedurl; +typedef std::pair> tagged_feedurl; class remote_api { public: diff --git a/include/rss.h b/include/rss.h index 29a86a11..2a2ad1ac 100644 --- a/include/rss.h +++ b/include/rss.h @@ -6,11 +6,11 @@ #include #include -#include +#include #include -#include -#include +#include +#include namespace newsbeuter { @@ -83,8 +83,8 @@ namespace newsbeuter { virtual bool has_attribute(const std::string& attribname); virtual std::string get_attribute(const std::string& attribname); - void set_feedptr(std::tr1::shared_ptr ptr); - inline std::tr1::shared_ptr get_feedptr() { return feedptr; } + void set_feedptr(std::shared_ptr ptr); + inline std::shared_ptr get_feedptr() { return feedptr; } inline bool deleted() const { return deleted_; } inline void set_deleted(bool b) { deleted_ = b; } @@ -115,7 +115,7 @@ namespace newsbeuter { bool enqueued_; std::string flags_; std::string oldflags_; - std::tr1::shared_ptr feedptr; + std::shared_ptr feedptr; bool deleted_; unsigned int idx; std::string base; @@ -144,8 +144,8 @@ namespace newsbeuter { bool hidden() const; - inline std::vector >& items() { return items_; } - inline void add_item(std::tr1::shared_ptr item) { + inline std::vector>& items() { return items_; } + inline void add_item(std::shared_ptr item) { items_.push_back(item); items_guid_map[item->guid()] = item; } @@ -156,19 +156,19 @@ namespace newsbeuter { items_guid_map.clear(); } - inline void erase_items(std::vector >::iterator begin, std::vector >::iterator end) { - for (std::vector >::const_iterator it=begin;it!=end;++it) { + inline void erase_items(std::vector>::iterator begin, std::vector>::iterator end) { + for (auto it=begin;it!=end;++it) { items_guid_map.erase((*it)->guid()); } items_.erase(begin, end); } - inline void erase_item(std::vector >::iterator pos) { + inline void erase_item(std::vector>::iterator pos) { items_guid_map.erase((*pos)->guid()); items_.erase(pos); } - std::tr1::shared_ptr get_item_by_guid(const std::string& guid); - std::tr1::shared_ptr get_item_by_guid_unlocked(const std::string& guid); + std::shared_ptr get_item_by_guid(const std::string& guid); + std::shared_ptr get_item_by_guid_unlocked(const std::string& guid); inline const std::string& rssurl() const { return rssurl_; } void set_rssurl(const std::string& u); @@ -184,7 +184,7 @@ namespace newsbeuter { virtual bool has_attribute(const std::string& attribname); virtual std::string get_attribute(const std::string& attribname); - void update_items(std::vector > feeds); + void update_items(std::vector> feeds); inline void set_query(const std::string& s) { query = s; } @@ -207,7 +207,7 @@ namespace newsbeuter { inline void set_order(unsigned int x) { order = x; } inline unsigned int get_order() { return order; } - void set_feedptrs(std::tr1::shared_ptr self); + void set_feedptrs(std::shared_ptr self); std::string get_status(); @@ -217,15 +217,15 @@ namespace newsbeuter { void unload(); void load(); - mutex item_mutex; // this is ugly, but makes it possible to lock items use e.g. from the cache class + std::mutex item_mutex; // this is ugly, but makes it possible to lock items use e.g. from the cache class private: std::string title_; std::string description_; std::string link_; time_t pubDate_; std::string rssurl_; - std::vector > items_; - std::tr1::unordered_map > items_guid_map; + std::vector> items_; + std::unordered_map> items_guid_map; std::vector tags_; std::string query; @@ -236,7 +236,7 @@ namespace newsbeuter { unsigned int idx; unsigned int order; dl_status status_; - mutex items_guid_map_mutex; + std::mutex items_guid_map_mutex; }; class rss_ignores : public config_action_handler { diff --git a/include/rss_parser.h b/include/rss_parser.h index 2c6ae261..b7e6584c 100644 --- a/include/rss_parser.h +++ b/include/rss_parser.h @@ -16,7 +16,7 @@ namespace newsbeuter { public: rss_parser(const std::string& uri, cache * c, configcontainer *, rss_ignores * ii, remote_api * a = 0); ~rss_parser(); - std::tr1::shared_ptr parse(); + std::shared_ptr parse(); bool check_and_update_lastmodified(); void set_easyhandle(curl_handle *h) { easyhandle = h; } @@ -24,7 +24,7 @@ namespace newsbeuter { void replace_newline_characters(std::string& str); std::string render_xhtml_title(const std::string& title, const std::string& link); time_t parse_date(const std::string& datestr); - void set_rtl(std::tr1::shared_ptr feed, const char * lang); + void set_rtl(std::shared_ptr feed, const char * lang); void retrieve_uri(const std::string& uri); void download_http(const std::string& uri); @@ -32,19 +32,19 @@ namespace newsbeuter { void download_filterplugin(const std::string& filter, const std::string& uri); void parse_file(const std::string& file); - void fill_feed_fields(std::tr1::shared_ptr feed); - void fill_feed_items(std::tr1::shared_ptr feed); + void fill_feed_fields(std::shared_ptr feed); + void fill_feed_items(std::shared_ptr feed); - void set_item_title(std::tr1::shared_ptr feed, std::tr1::shared_ptr x, rsspp::item& item); - void set_item_author(std::tr1::shared_ptr x, rsspp::item& item); - void set_item_content(std::tr1::shared_ptr x, rsspp::item& item); - void set_item_enclosure(std::tr1::shared_ptr x, rsspp::item& item); + void set_item_title(std::shared_ptr feed, std::shared_ptr x, rsspp::item& item); + void set_item_author(std::shared_ptr x, rsspp::item& item); + void set_item_content(std::shared_ptr x, rsspp::item& item); + void set_item_enclosure(std::shared_ptr x, rsspp::item& item); std::string get_guid(rsspp::item& item); - void add_item_to_feed(std::tr1::shared_ptr feed, std::tr1::shared_ptr item); + void add_item_to_feed(std::shared_ptr feed, std::shared_ptr item); - void handle_content_encoded(std::tr1::shared_ptr x, rsspp::item& item); - void handle_itunes_summary(std::tr1::shared_ptr x, rsspp::item& item); + void handle_content_encoded(std::shared_ptr x, rsspp::item& item); + void handle_itunes_summary(std::shared_ptr x, rsspp::item& item); bool is_html_type(const std::string& type); void fetch_ttrss(const std::string& feed_id); void fetch_newsblur(const std::string& feed_id); diff --git a/include/thread.h b/include/thread.h deleted file mode 100644 index 68c8a9ba..00000000 --- a/include/thread.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef AK_THREAD__H -#define AK_THREAD__H - -#include - - -namespace newsbeuter { - - class thread; - - void * run_thread(void * p); - - // TODO: implement an option to provide attributes - - class thread { - public: - thread(); - virtual ~thread(); - pthread_t start(); - void join(); - - protected: - virtual void run() = 0; - void detach(); - - friend void * run_thread(void * p); - - private: - static void cleanup(thread * p); - pthread_t pt; - }; - -} - - -#endif diff --git a/include/ttrss_api.h b/include/ttrss_api.h index c1d1da33..2f71e283 100644 --- a/include/ttrss_api.h +++ b/include/ttrss_api.h @@ -32,7 +32,7 @@ class ttrss_api : public remote_api { std::string auth_info; const char * auth_info_ptr; bool single; - mutex auth_lock; + std::mutex auth_lock; }; class ttrss_urlreader : public urlreader { diff --git a/include/urlreader.h b/include/urlreader.h index 8ff58589..6e7ca9a0 100644 --- a/include/urlreader.h +++ b/include/urlreader.h @@ -25,7 +25,7 @@ namespace newsbeuter { inline void set_offline(bool off) { offline = off; } protected: std::vector urls; - std::map > tags; + std::map> tags; std::set alltags; bool offline; }; diff --git a/include/utils.h b/include/utils.h index d9fe41fd..992e962f 100644 --- a/include/utils.h +++ b/include/utils.h @@ -84,7 +84,7 @@ class utils { static bool is_valid_color(const std::string& color); static bool is_valid_attribute(const std::string& attrib); - static std::vector > partition_indexes(unsigned int start, unsigned int end, unsigned int parts); + static std::vector> partition_indexes(unsigned int start, unsigned int end, unsigned int parts); static std::string join(const std::vector& strings, const std::string& separator); diff --git a/include/view.h b/include/view.h index 7b164386..ddf3b652 100644 --- a/include/view.h +++ b/include/view.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include @@ -27,10 +27,10 @@ namespace newsbeuter { view(controller *); ~view(); void run(); - std::string run_modal(std::tr1::shared_ptr f, const std::string& value = ""); + std::string run_modal(std::shared_ptr f, const std::string& value = ""); - void set_feedlist(std::vector > feeds); - void update_visible_feeds(std::vector > feeds); + void set_feedlist(std::vector> feeds); + void update_visible_feeds(std::vector> feeds); void set_keymap(keymap * k); void set_config_container(configcontainer * cfgcontainer); void show_error(const std::string& msg); @@ -48,11 +48,11 @@ namespace newsbeuter { char confirm(const std::string& prompt, const std::string& charset); void push_itemlist(unsigned int pos); - void push_itemlist(std::tr1::shared_ptr feed); - void push_itemview(std::tr1::shared_ptr f, const std::string& guid, const std::string& searchphrase = ""); + void push_itemlist(std::shared_ptr feed); + void push_itemview(std::shared_ptr f, const std::string& guid, const std::string& searchphrase = ""); void push_help(); void push_urlview(const std::vector& links); - void push_searchresult(std::tr1::shared_ptr feed, const std::string& phrase = ""); + void push_searchresult(std::shared_ptr feed, const std::string& phrase = ""); void view_dialogs(); std::string run_filebrowser(const std::string& default_filename = "", const std::string& dir = ""); @@ -75,23 +75,23 @@ namespace newsbeuter { bool get_next_feed(itemlist_formaction * itemlist); bool get_prev_feed(itemlist_formaction * itemlist); - void prepare_query_feed(std::tr1::shared_ptr feed); + void prepare_query_feed(std::shared_ptr feed); void force_redraw(); - void set_colors(std::map& fg_colors, std::map& bg_colors, std::map >& attributes); + void set_colors(std::map& fg_colors, std::map& bg_colors, std::map>& attributes); - void notify_itemlist_change(std::tr1::shared_ptr feed); + void notify_itemlist_change(std::shared_ptr feed); void feedlist_mark_pos_if_visible(unsigned int pos); void set_regexmanager(regexmanager * r); - std::vector > get_formaction_names(); + std::vector> get_formaction_names(); - std::tr1::shared_ptr get_current_formaction(); + std::shared_ptr get_current_formaction(); - std::tr1::shared_ptr get_formaction(unsigned int idx) const { return formaction_stack[idx]; } + std::shared_ptr get_formaction(unsigned int idx) const { return formaction_stack[idx]; } void goto_next_dialog(); void goto_prev_dialog(); @@ -106,24 +106,24 @@ namespace newsbeuter { void dump_current_form(); protected: - void set_bindings(std::tr1::shared_ptr fa); - void apply_colors(std::tr1::shared_ptr fa); + void set_bindings(std::shared_ptr fa); + void apply_colors(std::shared_ptr fa); - void handle_cmdline_completion(std::tr1::shared_ptr fa); - void clear_line(std::tr1::shared_ptr fa); - void clear_eol(std::tr1::shared_ptr fa); - void cancel_input(std::tr1::shared_ptr fa); - void delete_word(std::tr1::shared_ptr fa); + void handle_cmdline_completion(std::shared_ptr fa); + void clear_line(std::shared_ptr fa); + void clear_eol(std::shared_ptr fa); + void cancel_input(std::shared_ptr fa); + void delete_word(std::shared_ptr fa); controller * ctrl; configcontainer * cfg; keymap * keys; - mutex * mtx; + std::mutex mtx; friend class colormanager; - std::vector > formaction_stack; + std::vector> formaction_stack; unsigned int current_formaction; std::vector tags; @@ -133,7 +133,7 @@ namespace newsbeuter { std::map fg_colors; std::map bg_colors; - std::map > attributes; + std::map> attributes; bool is_inside_qna; bool is_inside_cmdline; diff --git a/mk/libbeuter.deps b/mk/libbeuter.deps index 0555b7f5..fa9d769d 100644 --- a/mk/libbeuter.deps +++ b/mk/libbeuter.deps @@ -1 +1 @@ -src/configcontainer.cpp src/configparser.cpp src/colormanager.cpp src/keymap.cpp src/stflpp.cpp src/logger.cpp src/exception.cpp src/mutex.cpp src/utils.cpp src/thread.cpp src/matcher.cpp src/formatstring.cpp +src/configcontainer.cpp src/configparser.cpp src/colormanager.cpp src/keymap.cpp src/stflpp.cpp src/logger.cpp src/exception.cpp src/utils.cpp src/matcher.cpp src/formatstring.cpp diff --git a/mk/mk.deps b/mk/mk.deps index 74afcfbb..b159d432 100644 --- a/mk/mk.deps +++ b/mk/mk.deps @@ -55,8 +55,6 @@ src/logger.o: include/logger.h include/exception.h src/matcher.o: include/matcher.h include/logger.h include/utils.h include/exceptions.h -src/mutex.o: include/mutex.h - src/pb_controller.o: include/pb_controller.h include/pb_view.h include/poddlthread.h \ include/utils.h config.h include/keymap.h include/configcontainer.h include/colormanager.h \ include/exceptions.h include/queueloader.h include/logger.h @@ -77,8 +75,6 @@ src/select_formaction.o: include/select_formaction.h include/view.h config.h inc src/stflpp.o: include/stflpp.h include/logger.h include/exception.h -src/thread.o: include/thread.h include/exception.h include/logger.h - src/urlreader.o: include/urlreader.h include/utils.h include/logger.h config.h src/urlview_formaction.o: include/urlview_formaction.h include/view.h config.h include/listformatter.h diff --git a/rss/parser.cpp b/rss/parser.cpp index 468f7546..c7a9ca49 100644 --- a/rss/parser.cpp +++ b/rss/parser.cpp @@ -257,7 +257,7 @@ feed parser::parse_xmlnode(xmlNode* node) { } } - std::tr1::shared_ptr parser = rss_parser_factory::get_object(f, doc); + std::shared_ptr parser = rss_parser_factory::get_object(f, doc); try { parser->parse_feed(f, node); diff --git a/rss/parser_factory.cpp b/rss/parser_factory.cpp index 00ed69cf..1d1a4784 100644 --- a/rss/parser_factory.cpp +++ b/rss/parser_factory.cpp @@ -8,20 +8,20 @@ namespace rsspp { -std::tr1::shared_ptr rss_parser_factory::get_object(feed& f, xmlDocPtr doc) { +std::shared_ptr rss_parser_factory::get_object(feed& f, xmlDocPtr doc) { switch (f.rss_version) { case RSS_0_91: case RSS_0_92: case RSS_0_94: - return std::tr1::shared_ptr(new rss_09x_parser(doc)); + return std::shared_ptr(new rss_09x_parser(doc)); case RSS_2_0: - return std::tr1::shared_ptr(new rss_20_parser(doc)); + return std::shared_ptr(new rss_20_parser(doc)); case RSS_1_0: - return std::tr1::shared_ptr(new rss_10_parser(doc)); + return std::shared_ptr(new rss_10_parser(doc)); case ATOM_0_3: case ATOM_0_3_NONS: case ATOM_1_0: - return std::tr1::shared_ptr(new atom_parser(doc)); + return std::shared_ptr(new atom_parser(doc)); case UNKNOWN: default: throw exception(_("unsupported feed format")); diff --git a/rss/rsspp_internal.h b/rss/rsspp_internal.h index 7bfed506..fb654a74 100644 --- a/rss/rsspp_internal.h +++ b/rss/rsspp_internal.h @@ -7,7 +7,7 @@ #define RSSPP_INTERNAL__H #include -#include +#include #define CONTENT_URI "http://purl.org/rss/1.0/modules/content/" #define RDF_URI "http://www.w3.org/1999/02/22-rdf-syntax-ns#" @@ -69,7 +69,7 @@ struct atom_parser : public rss_parser { }; struct rss_parser_factory { - static std::tr1::shared_ptr get_object(feed& f, xmlDocPtr doc); + static std::shared_ptr get_object(feed& f, xmlDocPtr doc); }; } diff --git a/src/cache.cpp b/src/cache.cpp index 68173acc..ed98bfef 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -52,7 +52,7 @@ static int single_string_callback(void * handler, int argc, char ** argv, char * } static int rssfeed_callback(void * myfeed, int argc, char ** argv, char ** /* azColName */) { - std::tr1::shared_ptr* feed = static_cast* >(myfeed); + std::shared_ptr* feed = static_cast* >(myfeed); // normaly, this shouldn't happen, but we keep the assert()s here nevertheless assert(argc == 3); assert(argv[0] != NULL); @@ -94,9 +94,9 @@ static int vectorofstring_callback(void * vp, int argc, char ** argv, char ** /* } static int rssitem_callback(void * myfeed, int argc, char ** argv, char ** /* azColName */) { - std::tr1::shared_ptr* feed = static_cast* >(myfeed); + std::shared_ptr* feed = static_cast* >(myfeed); assert (argc == 13); - std::tr1::shared_ptr item(new rss_item(NULL)); + std::shared_ptr item(new rss_item(NULL)); item->set_guid(argv[0]); item->set_title(argv[1]); item->set_author(argv[2]); @@ -127,16 +127,16 @@ static int fill_content_callback(void * myfeed, int argc, char ** argv, char ** rss_feed * feed = static_cast(myfeed); assert(argc == 2); if (argv[0]) { - std::tr1::shared_ptr item = feed->get_item_by_guid_unlocked(argv[0]); + std::shared_ptr item = feed->get_item_by_guid_unlocked(argv[0]); item->set_description(argv[1] ? argv[1] : ""); } return 0; } static int search_item_callback(void * myfeed, int argc, char ** argv, char ** /* azColName */) { - std::vector > * items = static_cast > *>(myfeed); + std::vector> * items = static_cast> *>(myfeed); assert (argc == 13); - std::tr1::shared_ptr item(new rss_item(NULL)); + std::shared_ptr item(new rss_item(NULL)); item->set_guid(argv[0]); item->set_title(argv[1]); item->set_author(argv[2]); @@ -284,7 +284,7 @@ void cache::populate_tables() { void cache::fetch_lastmodified(const std::string& feedurl, time_t& t, std::string& etag) { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); std::string query = prepare_query("SELECT lastmodified, etag FROM rss_feed WHERE rssurl = '%q';", feedurl.c_str()); LOG(LOG_DEBUG, "running: query: %s", query.c_str()); header_values result = { 0, "" }; @@ -303,7 +303,7 @@ void cache::update_lastmodified(const std::string& feedurl, time_t t, const std: LOG(LOG_INFO, "cache::update_lastmodified: both time and etag are empty, not updating anything"); return; } - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); std::string query = "UPDATE rss_feed SET "; if (t > 0) query.append(utils::strprintf("lastmodified = '%d'", t)); @@ -316,7 +316,7 @@ void cache::update_lastmodified(const std::string& feedurl, time_t t, const std: } void cache::mark_item_deleted(const std::string& guid, bool b) { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); std::string query = prepare_query("UPDATE rss_item SET deleted = %u WHERE guid = '%q'", b ? 1 : 0, guid.c_str()); int rc = sqlite3_exec(db, query.c_str(), NULL, NULL, NULL); LOG(LOG_DEBUG, "cache::mark_item_deleted ran SQL statement: %s result = %d", query.c_str(), rc); @@ -324,7 +324,7 @@ void cache::mark_item_deleted(const std::string& guid, bool b) { std::vector cache::get_feed_urls() { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); std::string query = "SELECT rssurl FROM rss_feed;"; std::vector urls; @@ -337,13 +337,13 @@ std::vector cache::get_feed_urls() { // this function writes an rss_feed including all rss_items to the database -void cache::externalize_rssfeed(std::tr1::shared_ptr feed, bool reset_unread) { +void cache::externalize_rssfeed(std::shared_ptr feed, bool reset_unread) { scope_measure m1("cache::externalize_feed"); if (feed->rssurl().substr(0,6) == "query:") return; - scope_mutex lock(&mtx); - scope_mutex feedlock(&feed->item_mutex); + std::lock_guard lock(mtx); + std::lock_guard feedlock(feed->item_mutex); //scope_transaction dbtrans(db); cb_handler count_cbh; @@ -380,7 +380,7 @@ void cache::externalize_rssfeed(std::tr1::shared_ptr feed, bool reset_ LOG(LOG_INFO, "cache::externalize_feed: max_items = %u feed.items().size() = %u", max_items, feed->total_item_count()); if (max_items > 0 && feed->items().size() > max_items) { - std::vector >::iterator it=feed->items().begin(); + auto it=feed->items().begin(); for (unsigned int i=0;iitems().end()) @@ -391,7 +391,7 @@ void cache::externalize_rssfeed(std::tr1::shared_ptr feed, bool reset_ time_t old_time = time(NULL) - days * 24*60*60; // the reverse iterator is there for the sorting foo below (think about it) - for (std::vector >::reverse_iterator it=feed->items().rbegin(); it != feed->items().rend(); ++it) { + for (auto it=feed->items().rbegin(); it != feed->items().rend(); ++it) { if (days == 0 || (*it)->pubDate_timestamp() >= old_time) update_rssitem_unlocked(*it, feed->rssurl(), reset_unread); } @@ -399,15 +399,17 @@ void cache::externalize_rssfeed(std::tr1::shared_ptr feed, bool reset_ // this function reads an rss_feed including all of its rss_items. // the feed parameter needs to have the rssurl member set. -std::tr1::shared_ptr cache::internalize_rssfeed(std::string rssurl, rss_ignores * ign) { - std::tr1::shared_ptr feed(new rss_feed(this)); +std::shared_ptr cache::internalize_rssfeed(std::string rssurl, rss_ignores * ign) { + scope_measure m1("cache::internalize_rssfeed"); + + std::shared_ptr feed(new rss_feed(this)); feed->set_rssurl(rssurl); - scope_measure m1("cache::internalize_rssfeed"); if (rssurl.substr(0,6) == "query:") return feed; - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); + std::lock_guard feedlock(feed->item_mutex); /* first, we check whether the feed is there at all */ std::string query = prepare_query("SELECT count(*) FROM rss_feed WHERE rssurl = '%q';",rssurl.c_str()); @@ -442,7 +444,7 @@ std::tr1::shared_ptr cache::internalize_rssfeed(std::string rssurl, rs } unsigned int i=0; - for (std::vector >::iterator it=feed->items().begin(); it != feed->items().end(); ++it,++i) { + for (auto it=feed->items().begin(); it != feed->items().end(); ++it,++i) { (*it)->set_cache(this); (*it)->set_feedptr(feed); (*it)->set_feedurl(feed->rssurl()); @@ -468,8 +470,8 @@ std::tr1::shared_ptr cache::internalize_rssfeed(std::string rssurl, rs unsigned int max_items = cfg->get_configvalue_as_int("max-items"); if (max_items > 0 && feed->items().size() > max_items) { - std::vector > flagged_items; - std::vector >::iterator it=feed->items().begin(); + std::vector> flagged_items; + auto it=feed->items().begin(); for (unsigned int i=0;iitems().size();++i) { @@ -482,8 +484,8 @@ std::tr1::shared_ptr cache::internalize_rssfeed(std::string rssurl, rs feed->erase_items(it, feed->items().end()); // delete old entries if (flagged_items.size() > 0) { // if some flagged articles were saved, append them - for (std::vector >::iterator jt=flagged_items.begin();jt!=flagged_items.end();++jt) { - feed->add_item(*jt); + for (auto item : flagged_items) { + feed->add_item(item); } } } @@ -491,12 +493,12 @@ std::tr1::shared_ptr cache::internalize_rssfeed(std::string rssurl, rs return feed; } -std::vector > cache::search_for_items(const std::string& querystr, const std::string& feedurl) { +std::vector> cache::search_for_items(const std::string& querystr, const std::string& feedurl) { std::string query; - std::vector > items; + std::vector> items; int rc; - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); if (feedurl.length() > 0) { query = prepare_query("SELECT guid,title,author,url,pubDate,length(content),unread,feedurl,enclosure_url,enclosure_type,enqueued,flags,base FROM rss_item WHERE (title LIKE '%%%q%%' OR content LIKE '%%%q%%') AND feedurl = '%q' AND deleted = 0 ORDER BY pubDate DESC, id DESC;",querystr.c_str(), querystr.c_str(), feedurl.c_str()); } else { @@ -514,7 +516,7 @@ std::vector > cache::search_for_items(const std:: return items; } -void cache::delete_item(const std::tr1::shared_ptr item) { +void cache::delete_item(const std::shared_ptr item) { std::string query = prepare_query("DELETE FROM rss_item WHERE guid = '%q';",item->guid().c_str()); LOG(LOG_DEBUG,"running query: %s",query.c_str()); int rc = sqlite3_exec(db,query.c_str(),NULL,NULL,NULL); @@ -525,7 +527,7 @@ void cache::delete_item(const std::tr1::shared_ptr item) { } void cache::do_vacuum() { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); const char * vacuum_query = "VACUUM;"; int rc = sqlite3_exec(db,vacuum_query,NULL,NULL,NULL); if (rc != SQLITE_OK) { @@ -533,8 +535,8 @@ void cache::do_vacuum() { } } -void cache::cleanup_cache(std::vector >& feeds) { - mtx.lock(); // we don't use the scope_mutex here... see comments below +void cache::cleanup_cache(std::vector>& feeds) { + mtx.lock(); // we don't use the std::lock_guard<> here... see comments below /* * cache cleanup means that all entries in both the rss_feed and rss_item tables that are associated with @@ -552,14 +554,14 @@ void cache::cleanup_cache(std::vector >& feeds) { unsigned int i = 0; unsigned int feed_size = feeds.size(); - for (std::vector >::iterator it=feeds.begin();it!=feeds.end();++it,++i) { - std::string name = prepare_query("'%q'",(*it)->rssurl().c_str()); + for (auto feed : feeds) { + std::string name = prepare_query("'%q'",feed->rssurl().c_str()); list.append(name); if (i < feed_size-1) { list.append(", "); } } - list.append(")"); + list.append("'')"); std::string cleanup_rss_feeds_statement("DELETE FROM rss_feed WHERE rssurl NOT IN "); cleanup_rss_feeds_statement.append(list); @@ -604,7 +606,7 @@ void cache::cleanup_cache(std::vector >& feeds) { } } -void cache::update_rssitem_unlocked(std::tr1::shared_ptr item, const std::string& feedurl, bool reset_unread) { +void cache::update_rssitem_unlocked(std::shared_ptr item, const std::string& feedurl, bool reset_unread) { std::string query = prepare_query("SELECT count(*) FROM rss_item WHERE guid = '%q';",item->guid().c_str()); cb_handler count_cbh; LOG(LOG_DEBUG,"running query: %s", query.c_str()); @@ -668,13 +670,13 @@ void cache::update_rssitem_unlocked(std::tr1::shared_ptr item, const s } } -void cache::catchup_all(std::tr1::shared_ptr feed) { - scope_mutex lock(&mtx); - scope_mutex feedlock(&feed->item_mutex); +void cache::catchup_all(std::shared_ptr feed) { + std::lock_guard lock(mtx); + std::lock_guard itemlock(feed->item_mutex); std::string query = "UPDATE rss_item SET unread = '0' WHERE unread != '0' AND guid IN ("; - for (std::vector >::iterator it=feed->items().begin();it!=feed->items().end();++it) { - query.append(prepare_query("'%q',", (*it)->guid().c_str())); + for (auto item : feed->items()) { + query.append(prepare_query("'%q',", item->guid().c_str())); } query.append("'');"); @@ -688,7 +690,7 @@ void cache::catchup_all(std::tr1::shared_ptr feed) { /* this function marks all rss_items (optionally of a certain feed url) as read */ void cache::catchup_all(const std::string& feedurl) { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); std::string query; if (feedurl.length() > 0) { @@ -705,7 +707,7 @@ void cache::catchup_all(const std::string& feedurl) { } void cache::update_rssitem_unread_and_enqueued(rss_item* item, const std::string& feedurl) { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); std::string query = prepare_query("SELECT count(*) FROM rss_item WHERE guid = '%q';",item->guid().c_str()); cb_handler count_cbh; @@ -742,8 +744,8 @@ void cache::update_rssitem_unread_and_enqueued(rss_item* item, const std::string } /* this function updates the unread and enqueued flags */ -void cache::update_rssitem_unread_and_enqueued(std::tr1::shared_ptr item, const std::string& feedurl) { - scope_mutex lock(&mtx); +void cache::update_rssitem_unread_and_enqueued(std::shared_ptr item, const std::string& feedurl) { + std::lock_guard lock(mtx); std::string query = prepare_query("SELECT count(*) FROM rss_item WHERE guid = '%q';",item->guid().c_str()); cb_handler count_cbh; @@ -794,7 +796,7 @@ std::string cache::prepare_query(const char * format, ...) { } void cache::update_rssitem_flags(rss_item* item) { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); std::string update = prepare_query("UPDATE rss_item SET flags = '%q' WHERE guid = '%q';", item->flags().c_str(), item->guid().c_str()); LOG(LOG_DEBUG,"running query: %s", update.c_str()); @@ -812,12 +814,12 @@ void cache::remove_old_deleted_items(const std::string& rssurl, const std::vecto return; } std::string guidset = "("; - for (std::vector::const_iterator it=guids.begin();it!=guids.end();++it) { - guidset.append(prepare_query("'%q', ", it->c_str())); + for (auto guid : guids) { + guidset.append(prepare_query("'%q', ", guid.c_str())); } guidset.append("'')"); std::string query = prepare_query("DELETE FROM rss_item WHERE feedurl = '%q' AND deleted = 1 AND guid NOT IN %s;", rssurl.c_str(), guidset.c_str()); - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); int rc = sqlite3_exec(db, query.c_str(), NULL, NULL, NULL); if (rc != SQLITE_OK) { LOG(LOG_CRITICAL, "query \"%s\" failed: error = %d", query.c_str(), rc); @@ -828,7 +830,7 @@ void cache::remove_old_deleted_items(const std::string& rssurl, const std::vecto } unsigned int cache::get_unread_count() { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); std::string countquery = "SELECT count(id) FROM rss_item WHERE unread = 1;"; cb_handler count_cbh; @@ -841,8 +843,8 @@ unsigned int cache::get_unread_count() { void cache::mark_items_read_by_guid(const std::vector& guids) { scope_measure m1("cache::mark_items_read_by_guid"); std::string guidset("("); - for (std::vector::const_iterator it=guids.begin();it!=guids.end();++it) { - guidset.append(prepare_query("'%q', ", it->c_str())); + for (auto guid : guids) { + guidset.append(prepare_query("'%q', ", guid.c_str())); } guidset.append("'')"); @@ -850,7 +852,7 @@ void cache::mark_items_read_by_guid(const std::vector& guids) { int rc; { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); rc = sqlite3_exec(db, updatequery.c_str(), NULL, NULL, NULL); } @@ -868,7 +870,7 @@ std::vector cache::get_read_item_guids() { int rc; { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); rc = sqlite3_exec(db, query.c_str(), vectorofstring_callback, &guids, NULL); } @@ -882,7 +884,7 @@ std::vector cache::get_read_item_guids() { } void cache::clean_old_articles() { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); unsigned int days = cfg->get_configvalue_as_int("keep-articles-days"); if (days > 0) { @@ -898,10 +900,9 @@ void cache::clean_old_articles() { } void cache::fetch_descriptions(rss_feed * feed) { - std::vector >& items = feed->items(); std::vector guids; - for (std::vector >::iterator it=items.begin();it!=items.end();++it) { - guids.push_back(prepare_query("'%q'", (*it)->guid().c_str())); + for (auto item : feed->items()) { + guids.push_back(prepare_query("'%q'", item->guid().c_str())); } std::string in_clause = utils::join(guids, ", "); @@ -917,7 +918,7 @@ void cache::fetch_descriptions(rss_feed * feed) { } void cache::record_google_replay(const std::string& guid, unsigned int state) { - scope_mutex lock(&mtx); + std::lock_guard lock(mtx); std::string query = prepare_query("INSERT INTO google_replay ( guid, state, ts ) VALUES ( '%q', %u, %u );", guid.c_str(), state, (unsigned int)time(NULL)); @@ -928,8 +929,8 @@ void cache::record_google_replay(const std::string& guid, unsigned int state) { void cache::delete_google_replay_by_guid(const std::vector& guids) { std::vector escaped_guids; - for (std::vector::const_iterator it=guids.begin();it!=guids.end();++it) { - escaped_guids.push_back(prepare_query("'%q'", it->c_str())); + for (auto guid : guids) { + escaped_guids.push_back(prepare_query("'%q'", guid.c_str())); } std::string query = prepare_query("DELETE FROM google_replay WHERE guid IN ( %s );", utils::join(escaped_guids, ", ").c_str()); diff --git a/src/colormanager.cpp b/src/colormanager.cpp index 0f94567f..eb21d87c 100644 --- a/src/colormanager.cpp +++ b/src/colormanager.cpp @@ -67,12 +67,11 @@ void colormanager::handle_action(const std::string& action, const std::vector& config_output) { - for (std::map::iterator it=fg_colors.begin();it!=fg_colors.end();++it) { - std::string configline = utils::strprintf("color %s %s %s", it->first.c_str(), it->second.c_str(), bg_colors[it->first].c_str()); - std::vector attribs = attributes[it->first]; - for (std::vector::iterator jt=attribs.begin();jt!=attribs.end();++jt) { + for (auto color : fg_colors) { + std::string configline = utils::strprintf("color %s %s %s", color.first.c_str(), color.second.c_str(), bg_colors[color.first].c_str()); + for (auto attrib : attributes[color.first]) { configline.append(" "); - configline.append(*jt); + configline.append(attrib); } config_output.push_back(configline); } @@ -83,9 +82,9 @@ void colormanager::dump_config(std::vector& config_output) { * TODO: refactor this */ void colormanager::set_pb_colors(podbeuter::pb_view * v) { - std::map::iterator fgcit = fg_colors.begin(); - std::map::iterator bgcit = bg_colors.begin(); - std::map >::iterator attit = attributes.begin(); + auto fgcit = fg_colors.begin(); + auto bgcit = bg_colors.begin(); + auto attit = attributes.begin(); for (;fgcit != fg_colors.end(); ++fgcit, ++bgcit, ++attit) { std::string colorattr; @@ -99,11 +98,11 @@ void colormanager::set_pb_colors(podbeuter::pb_view * v) { colorattr.append("bg="); colorattr.append(bgcit->second); } - for (std::vector::iterator it=attit->second.begin(); it!= attit->second.end(); ++it) { + for (auto attr : attit->second) { if (colorattr.length() > 0) colorattr.append(","); colorattr.append("attr="); - colorattr.append(*it); + colorattr.append(attr); } LOG(LOG_DEBUG,"colormanager::set_pb_colors: %s %s\n",fgcit->first.c_str(), colorattr.c_str()); diff --git a/src/configcontainer.cpp b/src/configcontainer.cpp index 50a65f9a..892175d5 100644 --- a/src/configcontainer.cpp +++ b/src/configcontainer.cpp @@ -16,7 +16,7 @@ namespace newsbeuter { -configdata::configdata(const std::string& v, ...) : value(v), default_value(v), type(ENUM) { +configdata::configdata(std::string v, ...) : value(v), default_value(v), type(ENUM) { va_list ap; va_start(ap, v); @@ -149,8 +149,8 @@ void configcontainer::register_commands(configparser& cfgparser) { // this registers the config options defined above in the configuration parser // -> if the resp. config option is encountered, it is passed to the configcontainer - for (std::map::iterator it=config_data.begin();it!=config_data.end();++it) { - cfgparser.register_handler(it->first, this); + for (auto cfg : config_data) { + cfgparser.register_handler(cfg.first, this); } } @@ -270,31 +270,28 @@ void configcontainer::toggle(const std::string& key) { } void configcontainer::dump_config(std::vector& config_output) { - for (std::map::iterator it=config_data.begin();it!=config_data.end();++it) { - std::string configline = it->first + " "; - assert(it->second.type != configdata::INVALID); - switch (it->second.type) { + for (auto cfg : config_data) { + std::string configline = cfg.first + " "; + assert(cfg.second.type != configdata::INVALID); + switch (cfg.second.type) { case configdata::BOOL: case configdata::INT: - configline.append(it->second.value); - if (it->second.value != it->second.default_value) - configline.append(utils::strprintf(" # default: %s", it->second.default_value.c_str())); + configline.append(cfg.second.value); + if (cfg.second.value != cfg.second.default_value) + configline.append(utils::strprintf(" # default: %s", cfg.second.default_value.c_str())); break; case configdata::ENUM: case configdata::STR: case configdata::PATH: - if (it->second.multi_option) { - std::vector tokens = utils::tokenize(it->second.value, " "); - if (tokens.size() == 0) { - goto ignore_entry; - } - for (std::vector::iterator it=tokens.begin();it!=tokens.end();++it) { - configline.append(utils::quote(*it) + " "); + if (cfg.second.multi_option) { + std::vector tokens = utils::tokenize(cfg.second.value, " "); + for (auto token : tokens) { + configline.append(utils::quote(token) + " "); } } else { - configline.append(utils::quote(it->second.value)); - if (it->second.value != it->second.default_value) { - configline.append(utils::strprintf(" # default: %s", it->second.default_value.c_str())); + configline.append(utils::quote(cfg.second.value)); + if (cfg.second.value != cfg.second.default_value) { + configline.append(utils::strprintf(" # default: %s", cfg.second.default_value.c_str())); } } break; @@ -313,9 +310,9 @@ ignore_entry: ; std::vector configcontainer::get_suggestions(const std::string& fragment) { std::vector result; - for (std::map::iterator it=config_data.begin();it!=config_data.end();++it) { - if (it->first.substr(0, fragment.length()) == fragment) - result.push_back(it->first); + for (auto cfg : config_data) { + if (cfg.first.substr(0, fragment.length()) == fragment) + result.push_back(cfg.first); } std::sort(result.begin(), result.end()); return result; diff --git a/src/configparser.cpp b/src/configparser.cpp index f93421fd..ee25da18 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -98,8 +98,8 @@ void configparser::unregister_handler(const std::string& cmd) { } void configparser::evaluate_backticks(std::vector& tokens) { - for (std::vector::iterator it=tokens.begin();it!=tokens.end();++it) { - *it = evaluate_backticks(*it); + for (auto& token : tokens) { + token = evaluate_backticks(token); } } diff --git a/src/controller.cpp b/src/controller.cpp index e7d083aa..dacbdb13 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -190,10 +191,10 @@ controller::~controller() { delete urlcfg; delete api; - scope_mutex feedslock(&feeds_mutex); - for (std::vector >::iterator it=feeds.begin();it!=feeds.end();++it) { - scope_mutex lock(&((*it)->item_mutex)); - (*it)->clear_items(); + std::lock_guard feedslock(feeds_mutex); + for (auto feed : feeds) { + std::lock_guard lock(feed->item_mutex); + feed->clear_items(); } feeds.clear(); } @@ -522,23 +523,27 @@ void controller::run(int argc, char * argv[]) { } unsigned int i=0; - for (std::vector::const_iterator it=urlcfg->get_urls().begin(); it != urlcfg->get_urls().end(); ++it, ++i) { + for (auto url : urlcfg->get_urls()) { + std::shared_ptr feed(new rss_feed(rsscache)); try { + feed->set_rssurl(url); + feed->set_tags(urlcfg->get_tags(url)); bool ignore_disp = (cfg.get_configvalue("ignore-mode") == "display"); - std::tr1::shared_ptr feed = rsscache->internalize_rssfeed(*it, ignore_disp ? &ign : NULL); - feed->set_tags(urlcfg->get_tags(*it)); - feed->set_order(i); - scope_mutex feedslock(&feeds_mutex); - feeds.push_back(feed); + std::shared_ptr feed = rsscache->internalize_rssfeed(url, ignore_disp ? &ign : NULL); + feed->set_tags(urlcfg->get_tags(url)); } catch(const dbexception& e) { std::cout << _("Error while loading feeds from database: ") << e.what() << std::endl; utils::remove_fs_lock(lock_file); return; } catch(const std::string& str) { - std::cout << utils::strprintf(_("Error while loading feed '%s': %s"), it->c_str(), str.c_str()) << std::endl; + std::cout << utils::strprintf(_("Error while loading feed '%s': %s"), url.c_str(), str.c_str()) << std::endl; utils::remove_fs_lock(lock_file); return; } + feed->set_order(i); + std::lock_guard feedslock(feeds_mutex); + feeds.push_back(feed); + i++; } sort_feeds(); @@ -552,10 +557,10 @@ void controller::run(int argc, char * argv[]) { if (cfg.get_configvalue_as_bool("prepopulate-query-feeds")) { std::cout << _("Prepopulating query feeds..."); std::cout.flush(); - scope_mutex feedslock(&feeds_mutex); - for (std::vector >::iterator it=feeds.begin();it!=feeds.end();++it) { - if ((*it)->rssurl().substr(0,6) == "query:") { - (*it)->update_items(get_all_feeds_unlocked()); + std::lock_guard feedslock(feeds_mutex); + for (auto feed : feeds) { + if (feed->rssurl().substr(0,6) == "query:") { + feed->update_items(get_all_feeds_unlocked()); } } std::cout << _("done.") << std::endl; @@ -616,7 +621,7 @@ void controller::run(int argc, char * argv[]) { std::cout.flush(); } try { - scope_mutex feedslock(&feeds_mutex); + std::lock_guard feedslock(feeds_mutex); rsscache->cleanup_cache(feeds); if (!silent) { std::cout << _("done.") << std::endl; @@ -632,12 +637,12 @@ void controller::run(int argc, char * argv[]) { } void controller::update_feedlist() { - scope_mutex feedslock(&feeds_mutex); + std::lock_guard feedslock(feeds_mutex); v->set_feedlist(feeds); } void controller::update_visible_feeds() { - scope_mutex feedslock(&feeds_mutex); + std::lock_guard feedslock(feeds_mutex); v->update_visible_feeds(feeds); } @@ -648,15 +653,15 @@ void controller::catchup_all() { v->show_error(utils::strprintf(_("Error: couldn't mark all feeds read: %s"), e.what())); return; } - scope_mutex feedslock(&feeds_mutex); - for (std::vector >::iterator it=feeds.begin();it!=feeds.end();++it) { - scope_mutex lock(&(*it)->item_mutex); - if ((*it)->items().size() > 0) { + std::lock_guard feedslock(feeds_mutex); + for (auto feed : feeds) { + std::lock_guard lock(feed->item_mutex); + if (feed->items().size() > 0) { if (api) { - api->mark_all_read((*it)->rssurl()); + api->mark_all_read(feed->rssurl()); } - for (std::vector >::iterator jt=(*it)->items().begin();jt!=(*it)->items().end();++jt) { - (*jt)->set_unread_nowrite(false); + for (auto item : feed->items()) { + item->set_unread_nowrite(false); } } } @@ -680,8 +685,8 @@ void controller::record_google_replay(const std::string& guid, bool read) { void controller::mark_all_read(unsigned int pos) { if (pos < feeds.size()) { scope_measure m("controller::mark_all_read"); - scope_mutex feedslock(&feeds_mutex); - std::tr1::shared_ptr feed = feeds[pos]; + std::lock_guard feedslock(feeds_mutex); + std::shared_ptr feed = feeds[pos]; if (feed->rssurl().substr(0,6) == "query:") { rsscache->catchup_all(feed); } else { @@ -691,14 +696,13 @@ void controller::mark_all_read(unsigned int pos) { } } m.stopover("after rsscache->catchup_all, before iteration over items"); - scope_mutex lock(&feed->item_mutex); - std::vector >& items = feed->items(); - std::vector >::iterator begin = items.begin(), end = items.end(); + std::lock_guard lock(feed->item_mutex); + std::vector>& items = feed->items(); if (items.size() > 0) { bool notify = items[0]->feedurl() != feed->rssurl(); LOG(LOG_DEBUG, "controller::mark_all_read: notify = %s", notify ? "yes" : "no"); - for (std::vector >::iterator it=begin;it!=end;++it) { - (*it)->set_unread_nowrite_notify(false, notify); + for (auto item : items) { + item->set_unread_nowrite_notify(false, notify); } } } @@ -707,7 +711,7 @@ void controller::mark_all_read(unsigned int pos) { void controller::reload(unsigned int pos, unsigned int max, bool unattended, curl_handle *easyhandle) { LOG(LOG_DEBUG, "controller::reload: pos = %u max = %u", pos, max); if (pos < feeds.size()) { - std::tr1::shared_ptr oldfeed = feeds[pos]; + std::shared_ptr oldfeed = feeds[pos]; std::string errmsg; if (!unattended) v->set_status(utils::strprintf(_("%sLoading %s..."), prepare_message(pos+1, max).c_str(), utils::censor_url(oldfeed->rssurl()).c_str())); @@ -719,16 +723,16 @@ void controller::reload(unsigned int pos, unsigned int max, bool unattended, cur LOG(LOG_DEBUG, "controller::reload: created parser"); try { oldfeed->set_status(DURING_DOWNLOAD); - std::tr1::shared_ptr newfeed = parser.parse(); + std::shared_ptr newfeed = parser.parse(); if (newfeed->items().size() > 0) { - scope_mutex feedslock(&feeds_mutex); - rsscache->externalize_rssfeed(newfeed, ign.matches_resetunread(newfeed->rssurl())); + std::lock_guard feedslock(feeds_mutex); + save_feed(newfeed, pos); enqueue_items(newfeed); newfeed->clear_items(); bool ignore_disp = (cfg.get_configvalue("ignore-mode") == "display"); - std::tr1::shared_ptr feed = rsscache->internalize_rssfeed(oldfeed->rssurl(), ignore_disp ? &ign : NULL); + std::shared_ptr feed = rsscache->internalize_rssfeed(oldfeed->rssurl(), ignore_disp ? &ign : NULL); feed->set_tags(urlcfg->get_tags(oldfeed->rssurl())); feed->set_order(oldfeed->get_order()); feeds[pos] = feed; @@ -761,12 +765,12 @@ void controller::reload(unsigned int pos, unsigned int max, bool unattended, cur } } -std::tr1::shared_ptr controller::get_feed(unsigned int pos) { - scope_mutex feedslock(&feeds_mutex); +std::shared_ptr controller::get_feed(unsigned int pos) { + std::lock_guard feedslock(feeds_mutex); if (pos >= feeds.size()) { throw std::out_of_range(_("invalid feed index (bug)")); } - std::tr1::shared_ptr feed = feeds[pos]; + std::shared_ptr feed = feeds[pos]; return feed; } @@ -777,12 +781,12 @@ void controller::reload_indexes(const std::vector& indexes, bool unattended unsigned long size; { - scope_mutex feedslock(&feeds_mutex); + std::lock_guard feedslock(feeds_mutex); size = feeds.size(); } - for (std::vector::const_iterator it=indexes.begin();it!=indexes.end();++it) { - this->reload(*it, size, unattended); + for (auto idx : indexes) { + this->reload(idx, size, unattended); } unsigned int unread_feeds2, unread_articles2; @@ -800,48 +804,34 @@ void controller::reload_indexes(const std::vector& indexes, bool unattended v->set_status(""); } -struct feed_cmp { - const std::vector > &feeds; - feed_cmp(const std::vector > &f) - : feeds(f) - { - } - void extract(std::string &s, const std::string &url) const - { +void controller::reload_range(unsigned int start, unsigned int end, unsigned int size, bool unattended) { + + std::vector v; + for (unsigned int i=start;i<=end;++i) + v.push_back(i); + + auto extract = [](std::string& s, const std::string& url) { size_t p = url.find("//"); p = (p == std::string::npos) ? 0 : p+2; std::string suff(url.substr(p)); p = suff.find('/'); s = suff.substr(0, p); - } - bool operator()(unsigned a, unsigned b) const - { - std::tr1::shared_ptr x = feeds[a]; - std::tr1::shared_ptr y = feeds[b]; - const std::string &u = x->rssurl(); - const std::string &v = y->rssurl(); - + }; + + std::sort(v.begin(), v.end(), [&](unsigned int a, unsigned int b) { std::string domain1, domain2; - extract(domain1, u); - extract(domain2, v); + extract(domain1, feeds[a]->rssurl()); + extract(domain2, feeds[b]->rssurl()); std::reverse(domain1.begin(), domain1.end()); std::reverse(domain2.begin(), domain2.end()); return domain1 < domain2; - } -}; - -void controller::reload_range(unsigned int start, unsigned int end, unsigned int size, bool unattended) { - - std::vector v; - for (unsigned i=start;i<=end;++i) - v.push_back(i); - std::sort(v.begin(), v.end(), feed_cmp(feeds)); + }); curl_handle easyhandle; - for (std::vector::iterator i = v.begin(); i!= v.end(); ++i) { - LOG(LOG_DEBUG, "controller::reload_range: reloading feed #%u", *i); - this->reload(*i, size, unattended, &easyhandle); + for (auto i : v) { + LOG(LOG_DEBUG, "controller::reload_range: reloading feed #%u", i); + this->reload(i, size, unattended, &easyhandle); } } @@ -854,9 +844,9 @@ void controller::reload_all(bool unattended) { unsigned int size; { - scope_mutex feedlock(&feeds_mutex); - for (std::vector >::iterator it=feeds.begin();it!=feeds.end();++it) { - (*it)->reset_status(); + std::lock_guard feedlock(feeds_mutex); + for (auto feed : feeds) { + feed->reset_status(); } size = feeds.size(); } @@ -875,25 +865,24 @@ void controller::reload_all(bool unattended) { if (num_threads <= 1) { this->reload_range(0, size-1, size, unattended); } else { - std::vector > partitions = utils::partition_indexes(0, size-1, num_threads); - std::vector threads; + std::vector> partitions = utils::partition_indexes(0, size-1, num_threads); + std::vector threads; LOG(LOG_DEBUG, "controller::reload_all: starting reload threads..."); for (unsigned int i=0;istart()); + threads.push_back(std::thread(reloadrangethread(this, partitions[i].first, partitions[i].second, size, unattended))); } LOG(LOG_DEBUG, "controller::reload_all: starting my own reload..."); this->reload_range(partitions[num_threads-1].first, partitions[num_threads-1].second, size, unattended); LOG(LOG_DEBUG, "controller::reload_all: joining other threads..."); - for (std::vector::iterator it=threads.begin();it!=threads.end();++it) { - ::pthread_join(*it, NULL); + for (size_t i=0;i >::iterator it=feeds.begin();it!=feeds.end();++it) { - v->prepare_query_feed(*it); + for (auto feed : feeds) { + v->prepare_query_feed(feed); } v->force_redraw(); @@ -948,8 +937,8 @@ void controller::notify(const std::string& msg) { void controller::compute_unread_numbers(unsigned int& unread_feeds, unsigned int& unread_articles) { unread_feeds = 0; unread_articles = 0; - for (std::vector >::iterator it=feeds.begin();it!=feeds.end();++it) { - unsigned int items = (*it)->unread_item_count(); + for (auto feed : feeds) { + unsigned int items = feed->unread_item_count(); if (items > 0) { ++unread_feeds; unread_articles += items; @@ -958,7 +947,7 @@ void controller::compute_unread_numbers(unsigned int& unread_feeds, unsigned int } bool controller::trylock_reload_mutex() { - if (reload_mutex.trylock()) { + if (reload_mutex.try_lock()) { LOG(LOG_DEBUG, "controller::trylock_reload_mutex succeeded"); return true; } @@ -968,8 +957,8 @@ bool controller::trylock_reload_mutex() { void controller::start_reload_all_thread(std::vector * indexes) { LOG(LOG_INFO,"starting reload all thread"); - thread * dlt = new downloadthread(this, indexes); - dlt->start(); + std::thread t(downloadthread(this, indexes)); + t.detach(); } void controller::version_information(const char * argv0, unsigned int level) { @@ -1075,11 +1064,11 @@ void controller::export_opml() { xmlNewTextChild(head, NULL, (const xmlChar *)"title", (const xmlChar *)PROGRAM_NAME " - Exported Feeds"); xmlNodePtr body = xmlNewTextChild(opml_node, NULL, (const xmlChar *)"body", NULL); - for (std::vector >::iterator it=feeds.begin(); it != feeds.end(); ++it) { - if (!utils::is_special_url((*it)->rssurl())) { - std::string rssurl = (*it)->rssurl(); - std::string link = (*it)->link(); - std::string title = (*it)->title(); + for (auto feed : feeds) { + if (!utils::is_special_url(feed->rssurl())) { + std::string rssurl = feed->rssurl(); + std::string link = feed->link(); + std::string title = feed->title(); xmlNodePtr outline = xmlNewTextChild(body, NULL, (const xmlChar *)"outline", NULL); xmlSetProp(outline, (const xmlChar *)"type", (const xmlChar *)"rss"); @@ -1136,8 +1125,8 @@ void controller::rec_find_rss_outlines(xmlNode * node, std::string tag) { LOG(LOG_DEBUG, "OPML import: size = %u", urlcfg->get_urls().size()); if (urlcfg->get_urls().size() > 0) { - for (std::vector::iterator it = urlcfg->get_urls().begin(); it != urlcfg->get_urls().end(); ++it) { - if (*it == url) { + for (auto u : urlcfg->get_urls()) { + if (u == url) { found = true; } } @@ -1175,28 +1164,29 @@ void controller::rec_find_rss_outlines(xmlNode * node, std::string tag) { -std::vector > controller::search_for_items(const std::string& query, const std::string& feedurl) { - std::vector > items = rsscache->search_for_items(query, feedurl); +std::vector> controller::search_for_items(const std::string& query, const std::string& feedurl) { + std::vector> items = rsscache->search_for_items(query, feedurl); LOG(LOG_DEBUG, "controller::search_for_items: setting feed pointers"); - for (std::vector >::iterator it=items.begin();it!=items.end();++it) { - (*it)->set_feedptr(get_feed_by_url((*it)->feedurl())); + for (auto item : items) { + item->set_feedptr(get_feed_by_url(item->feedurl())); } return items; } -std::tr1::shared_ptr controller::get_feed_by_url(const std::string& feedurl) { - for (std::vector >::iterator it=feeds.begin();it!=feeds.end();++it) { - if (feedurl == (*it)->rssurl()) - return *it; +std::shared_ptr controller::get_feed_by_url(const std::string& feedurl) { + for (auto feed : feeds) { + if (feedurl == feed->rssurl()) + return feed; } - return std::tr1::shared_ptr(); + LOG(LOG_ERROR, "controller:get_feed_by_url failed for %s", feedurl.c_str()); + return std::shared_ptr(); } bool controller::is_valid_podcast_type(const std::string& /* mimetype */) { return true; } -void controller::enqueue_url(const std::string& url, std::tr1::shared_ptr feed) { +void controller::enqueue_url(const std::string& url, std::shared_ptr feed) { bool url_found = false; std::fstream f; f.open(queue_file.c_str(), std::fstream::in); @@ -1224,25 +1214,34 @@ void controller::enqueue_url(const std::string& url, std::tr1::shared_ptrreload(); - std::vector > new_feeds; + std::vector> new_feeds; unsigned int i = 0; - for (std::vector::const_iterator it=urlcfg->get_urls().begin();it!=urlcfg->get_urls().end();++it,++i) { + for (auto url : urlcfg->get_urls()) { bool found = false; - for (std::vector >::iterator jt=feeds.begin();jt!=feeds.end();++jt) { - if (*it == (*jt)->rssurl()) { + for (auto feed : feeds) { + if (url == feed->rssurl()) { found = true; - (*jt)->set_tags(urlcfg->get_tags(*it)); - (*jt)->set_order(i); - new_feeds.push_back(*jt); + feed->set_tags(urlcfg->get_tags(url)); + feed->set_order(i); + new_feeds.push_back(feed); break; } } if (!found) { + std::shared_ptr new_feed(new rss_feed(rsscache)); + try { + new_feed->set_rssurl(url); + } catch (const std::string& str) { + LOG(LOG_USERERROR, "ignored invalid RSS URL '%s'", url.c_str()); + continue; + } + new_feed->set_tags(urlcfg->get_tags(url)); + new_feed->set_order(i); try { bool ignore_disp = (cfg.get_configvalue("ignore-mode") == "display"); - std::tr1::shared_ptr new_feed = rsscache->internalize_rssfeed(*it, ignore_disp ? &ign : NULL); - new_feed->set_tags(urlcfg->get_tags(*it)); + std::shared_ptr new_feed = rsscache->internalize_rssfeed(url, ignore_disp ? &ign : NULL); + new_feed->set_tags(urlcfg->get_tags(url)); new_feed->set_order(i); new_feeds.push_back(new_feed); } catch(const dbexception& e) { @@ -1250,12 +1249,13 @@ void controller::reload_urls_file() { throw; } } + i++; } v->set_tags(urlcfg->get_alltags()); { - scope_mutex feedslock(&feeds_mutex); + std::lock_guard feedslock(feeds_mutex); feeds = new_feeds; } @@ -1332,7 +1332,7 @@ void controller::execute_commands(char ** argv, unsigned int i) { } } -std::string controller::write_temporary_item(std::tr1::shared_ptr item) { +std::string controller::write_temporary_item(std::shared_ptr item) { char filename[1024]; snprintf(filename, sizeof(filename), "/tmp/newsbeuter-article.XXXXXX"); int fd = mkstemp(filename); @@ -1345,7 +1345,7 @@ std::string controller::write_temporary_item(std::tr1::shared_ptr item } } -void controller::write_item(std::tr1::shared_ptr item, const std::string& filename) { +void controller::write_item(std::shared_ptr item, const std::string& filename) { std::fstream f; f.open(filename.c_str(),std::fstream::out); if (!f.is_open()) @@ -1354,7 +1354,7 @@ void controller::write_item(std::tr1::shared_ptr item, const std::stri write_item(item, f); } -void controller::write_item(std::tr1::shared_ptr item, std::ostream& ostr) { +void controller::write_item(std::shared_ptr item, std::ostream& ostr) { std::vector lines; std::vector links; // not used @@ -1388,8 +1388,8 @@ void controller::write_item(std::tr1::shared_ptr item, std::ostream& o htmlrenderer rnd(width, true); rnd.render(item->description(), lines, links, item->feedurl()); - for (std::vector::iterator it=lines.begin();it!=lines.end();++it) { - ostr << *it << std::endl; + for (auto l : lines) { + ostr << l << std::endl; } } @@ -1404,24 +1404,47 @@ std::string controller::prepare_message(unsigned int pos, unsigned int max) { return ""; } -void controller::enqueue_items(std::tr1::shared_ptr feed) { +void controller::save_feed(std::shared_ptr feed, unsigned int pos) { + if (!feed->is_empty()) { + LOG(LOG_DEBUG, "controller::save_feed: feed is nonempty, saving"); + rsscache->externalize_rssfeed(feed, ign.matches_resetunread(feed->rssurl())); + LOG(LOG_DEBUG, "controller::save_feed: after externalize_rssfeed"); + + bool ignore_disp = (cfg.get_configvalue("ignore-mode") == "display"); + feed = rsscache->internalize_rssfeed(feed->rssurl(), ignore_disp ? &ign : NULL); + LOG(LOG_DEBUG, "controller::save_feed: after internalize_rssfeed"); + feed->set_tags(urlcfg->get_tags(feed->rssurl())); + { + unsigned int order = feeds[pos]->get_order(); + std::lock_guard itemlock(feeds[pos]->item_mutex); + feeds[pos]->clear_items(); + feed->set_order(order); + } + feeds[pos] = feed; + v->notify_itemlist_change(feeds[pos]); + } else { + LOG(LOG_DEBUG, "controller::save_feed: feed is empty, not saving"); + } +} + +void controller::enqueue_items(std::shared_ptr feed) { if (!cfg.get_configvalue_as_bool("podcast-auto-enqueue")) return; - scope_mutex lock(&feed->item_mutex); - for (std::vector >::iterator it=feed->items().begin();it!=feed->items().end();++it) { - if (!(*it)->enqueued() && (*it)->enclosure_url().length() > 0) { - LOG(LOG_DEBUG, "controller::enqueue_items: enclosure_url = `%s' enclosure_type = `%s'", (*it)->enclosure_url().c_str(), (*it)->enclosure_type().c_str()); - if (is_valid_podcast_type((*it)->enclosure_type()) && utils::is_http_url((*it)->enclosure_url())) { - LOG(LOG_INFO, "controller::enqueue_items: enqueuing `%s'", (*it)->enclosure_url().c_str()); - enqueue_url((*it)->enclosure_url(), feed); - (*it)->set_enqueued(true); - rsscache->update_rssitem_unread_and_enqueued(*it, feed->rssurl()); + std::lock_guard lock(feed->item_mutex); + for (auto item : feed->items()) { + if (!item->enqueued() && item->enclosure_url().length() > 0) { + LOG(LOG_DEBUG, "controller::enqueue_items: enclosure_url = `%s' enclosure_type = `%s'", item->enclosure_url().c_str(), item->enclosure_type().c_str()); + if (is_valid_podcast_type(item->enclosure_type()) && utils::is_http_url(item->enclosure_url())) { + LOG(LOG_INFO, "controller::enqueue_items: enqueuing `%s'", item->enclosure_url().c_str()); + enqueue_url(item->enclosure_url(), feed); + item->set_enqueued(true); + rsscache->update_rssitem_unread_and_enqueued(item, feed->rssurl()); } } } } -std::string controller::generate_enqueue_filename(const std::string& url, std::tr1::shared_ptr feed) { +std::string controller::generate_enqueue_filename(const std::string& url, std::shared_ptr feed) { std::string dlformat = cfg.get_configvalue("download-path"); if (dlformat[dlformat.length()-1] != NEWSBEUTER_PATH_SEP[0]) dlformat.append(NEWSBEUTER_PATH_SEP); @@ -1478,68 +1501,42 @@ void controller::export_read_information(const std::string& readinfofile) { std::fstream f; f.open(readinfofile.c_str(), std::fstream::out); if (f.is_open()) { - for (std::vector::iterator it=guids.begin();it!=guids.end();++it) { - f << *it << std::endl; + for (auto guid : guids) { + f << guid << std::endl; } } } -struct sort_feeds_by_firsttag : public std::binary_function, std::tr1::shared_ptr, bool> { - sort_feeds_by_firsttag() { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - if (a->get_firsttag().length() == 0 || b->get_firsttag().length() == 0) { - return a->get_firsttag().length() > b->get_firsttag().length(); - } - return strcasecmp(a->get_firsttag().c_str(), b->get_firsttag().c_str()) < 0; - } -}; - -struct sort_feeds_by_title : public std::binary_function, std::tr1::shared_ptr, bool> { - sort_feeds_by_title() { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return strcasecmp(a->title().c_str(), b->title().c_str()) < 0; - } -}; - -struct sort_feeds_by_articles : public std::binary_function, std::tr1::shared_ptr, bool> { - sort_feeds_by_articles() { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return a->total_item_count() < b->total_item_count(); - } -}; - -struct sort_feeds_by_unread_articles : public std::binary_function, std::tr1::shared_ptr, bool> { - sort_feeds_by_unread_articles() { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return a->unread_item_count() < b->unread_item_count(); - } -}; - -struct sort_feeds_by_order : public std::binary_function, std::tr1::shared_ptr, bool> { - sort_feeds_by_order() { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return a->get_order() < b->get_order(); - } -}; - - void controller::sort_feeds() { - scope_mutex feedslock(&feeds_mutex); + std::lock_guard feedslock(feeds_mutex); std::vector sortmethod_info = utils::tokenize(cfg.get_configvalue("feed-sort-order"), "-"); std::string sortmethod = sortmethod_info[0]; std::string direction = "desc"; if (sortmethod_info.size() > 1) direction = sortmethod_info[1]; if (sortmethod == "none") { - std::stable_sort(feeds.begin(), feeds.end(), sort_feeds_by_order()); + std::stable_sort(feeds.begin(), feeds.end(), [](std::shared_ptr a, std::shared_ptr b) { + return a->get_order() < b->get_order(); + }); } else if (sortmethod == "firsttag") { - std::stable_sort(feeds.begin(), feeds.end(), sort_feeds_by_firsttag()); + std::stable_sort(feeds.begin(), feeds.end(), [](std::shared_ptr a, std::shared_ptr b) { + if (a->get_firsttag().length() == 0 || b->get_firsttag().length() == 0) { + return a->get_firsttag().length() > b->get_firsttag().length(); + } + return strcasecmp(a->get_firsttag().c_str(), b->get_firsttag().c_str()) < 0; + }); } else if (sortmethod == "title") { - std::stable_sort(feeds.begin(), feeds.end(), sort_feeds_by_title()); + std::stable_sort(feeds.begin(), feeds.end(), [](std::shared_ptr a, std::shared_ptr b) { + return strcasecmp(a->title().c_str(), b->title().c_str()) < 0; + }); } else if (sortmethod == "articlecount") { - std::stable_sort(feeds.begin(), feeds.end(), sort_feeds_by_articles()); + std::stable_sort(feeds.begin(), feeds.end(), [](std::shared_ptr a, std::shared_ptr b) { + return a->total_item_count() < b->total_item_count(); + }); } else if (sortmethod == "unreadarticlecount") { - std::stable_sort(feeds.begin(), feeds.end(), sort_feeds_by_unread_articles()); + std::stable_sort(feeds.begin(), feeds.end(), [](std::shared_ptr a, std::shared_ptr b) { + return a->unread_item_count() < b->unread_item_count(); + }); } if (direction == "asc") { std::reverse(feeds.begin(), feeds.end()); @@ -1582,14 +1579,14 @@ void controller::dump_config(const std::string& filename) { std::fstream f; f.open(filename.c_str(), std::fstream::out); if (f.is_open()) { - for (std::vector::iterator it=configlines.begin();it!=configlines.end();++it) { - f << *it << std::endl; + for (auto line : configlines) { + f << line << std::endl; } } } unsigned int controller::get_pos_of_next_unread(unsigned int pos) { - scope_mutex feedslock(&feeds_mutex); + std::lock_guard feedslock(feeds_mutex); for (pos++;pos < feeds.size();pos++) { if (feeds[pos]->unread_item_count() > 0) break; @@ -1597,33 +1594,33 @@ unsigned int controller::get_pos_of_next_unread(unsigned int pos) { return pos; } -void controller::update_flags(std::tr1::shared_ptr item) { +void controller::update_flags(std::shared_ptr item) { if (api) { api->update_article_flags(item->oldflags(), item->flags(), item->guid()); } item->update_flags(); } -std::vector > controller::get_all_feeds() { - std::vector > tmpfeeds; +std::vector> controller::get_all_feeds() { + std::vector> tmpfeeds; { - scope_mutex feedslock(&feeds_mutex); + std::lock_guard feedslock(feeds_mutex); tmpfeeds = feeds; } return tmpfeeds; } -std::vector > controller::get_all_feeds_unlocked() { +std::vector> controller::get_all_feeds_unlocked() { return feeds; } unsigned int controller::get_feed_count_per_tag(const std::string& tag) { unsigned int count = 0; - scope_mutex feedslock(&feeds_mutex); + std::lock_guard feedslock(feeds_mutex); - for (std::vector >::const_iterator it=feeds.begin();it!=feeds.end();it++) { - if ((*it)->matches_tag(tag)) { + for (auto feed : feeds) { + if (feed->matches_tag(tag)) { count++; } } diff --git a/src/dialogs_formaction.cpp b/src/dialogs_formaction.cpp index fb23f76c..9db23d9b 100644 --- a/src/dialogs_formaction.cpp +++ b/src/dialogs_formaction.cpp @@ -27,12 +27,12 @@ void dialogs_formaction::init() { void dialogs_formaction::prepare() { if (update_list) { listformatter listfmt; - std::vector > formaction_names = v->get_formaction_names(); unsigned int i = 1; - for (std::vector >::iterator it=formaction_names.begin();it!=formaction_names.end();++it,i++) { - LOG(LOG_DEBUG, "dialogs_formaction::prepare: p1 = %p p2 = %p", v->get_current_formaction().get(), get_parent_formaction().get()); - listfmt.add_line(utils::strprintf("%4u %s %s", i, (v->get_formaction(it->first).get() == get_parent_formaction().get()) ? "*" : " ", it->second.c_str()), it->first); + for (auto fa : v->get_formaction_names()) { + LOG(LOG_DEBUG, "dialogs_formaction::prepare: p1 = %p p2 = %p", v->get_formaction(fa.first).get(), get_parent_formaction().get()); + listfmt.add_line(utils::strprintf("%4u %s %s", i, (v->get_formaction(fa.first).get() == get_parent_formaction().get()) ? "*" : " ", fa.second.c_str()), fa.first); + i++; } f->modify("dialogs", "replace_inner", listfmt.format_list()); diff --git a/src/downloadthread.cpp b/src/downloadthread.cpp index b1321d58..ef802955 100644 --- a/src/downloadthread.cpp +++ b/src/downloadthread.cpp @@ -12,7 +12,7 @@ downloadthread::downloadthread(controller * c, std::vector * idxs) : ctrl(c downloadthread::~downloadthread() { } -void downloadthread::run() { +void downloadthread::operator()() { /* * the downloadthread class drives the reload-all process. * A downloadthread is spawned whenever "reload all" is invoked, and whenever an auto-reload @@ -27,14 +27,13 @@ void downloadthread::run() { } ctrl->unlock_reload_mutex(); } - this->detach(); } reloadrangethread::reloadrangethread(controller * c, unsigned int start, unsigned int end, unsigned int size, bool unattended) : ctrl(c), s(start), e(end), ss(size), u(unattended) { } -void reloadrangethread::run() { +void reloadrangethread::operator()() { ctrl->reload_range(s, e, ss, u); } diff --git a/src/feedlist_formaction.cpp b/src/feedlist_formaction.cpp index 4a70e3b3..00c8ad1e 100644 --- a/src/feedlist_formaction.cpp +++ b/src/feedlist_formaction.cpp @@ -48,8 +48,8 @@ void feedlist_formaction::init() { * The feedlist_formaction is responsible for starting up the reloadthread, which is responsible * for regularly spawning downloadthreads. */ - reloadthread * rt = new reloadthread(v->get_ctrl(), v->get_cfg()); - rt->start(); + std::thread t{reloadthread(v->get_ctrl(), v->get_cfg())}; + t.detach(); apply_filter = !(v->get_cfg()->get_configvalue_as_bool("show-read-feeds")); } @@ -159,7 +159,7 @@ void feedlist_formaction::process_operation(operation op, bool automatic, std::v break; case OP_OPENINBROWSER: if (feeds_shown > 0 && feedpos.length() > 0) { - std::tr1::shared_ptr feed = v->get_ctrl()->get_feed(pos); + std::shared_ptr feed = v->get_ctrl()->get_feed(pos); if (feed) { LOG(LOG_INFO, "feedlist_formaction: opening feed at position `%s': %s", feedpos.c_str(), feed->link().c_str()); v->open_in_browser(feed->link()); @@ -173,8 +173,8 @@ void feedlist_formaction::process_operation(operation op, bool automatic, std::v { bool reload_only_visible_feeds = v->get_cfg()->get_configvalue_as_bool("reload-only-visible-feeds"); std::vector idxs; - for (std::vector::iterator it=visible_feeds.begin();it!=visible_feeds.end();++it) { - idxs.push_back(it->second); + for (auto feed : visible_feeds) { + idxs.push_back(feed.second); } v->get_ctrl()->start_reload_all_thread(reload_only_visible_feeds ? &idxs : NULL); } @@ -362,24 +362,25 @@ void feedlist_formaction::process_operation(operation op, bool automatic, std::v } } -void feedlist_formaction::update_visible_feeds(std::vector >& feeds) { +void feedlist_formaction::update_visible_feeds(std::vector>& feeds) { assert(v->get_cfg() != NULL); // must not happen visible_feeds.clear(); unsigned int i = 0; - for (std::vector >::iterator it = feeds.begin(); it != feeds.end(); ++it, ++i) { - (*it)->set_index(i+1); - if ((tag == "" || (*it)->matches_tag(tag)) && (!apply_filter || m.matches(it->get())) && !(*it)->hidden()) { - visible_feeds.push_back(feedptr_pos_pair(*it,i)); + for (auto feed : feeds) { + feed->set_index(i+1); + if ((tag == "" || feed->matches_tag(tag)) && (!apply_filter || m.matches(feed.get())) && !feed->hidden()) { + visible_feeds.push_back(feedptr_pos_pair(feed,i)); } + i++; } feeds_shown = visible_feeds.size(); } -void feedlist_formaction::set_feedlist(std::vector >& feeds) { +void feedlist_formaction::set_feedlist(std::vector>& feeds) { assert(v->get_cfg() != NULL); // must not happen unsigned int width = utils::to_u(f->get("feeds:w")); @@ -393,13 +394,14 @@ void feedlist_formaction::set_feedlist(std::vector::iterator it = visible_feeds.begin(); it != visible_feeds.end(); ++it, ++i) { - std::string title = get_title(it->first); + for (auto feed : visible_feeds) { + std::string title = get_title(feed.first); - if (it->first->unread_item_count() > 0) + if (feed.first->unread_item_count() > 0) ++unread_feeds; - listfmt.add_line(format_line(feedlist_format, it->first, it->second, width), it->second); + listfmt.add_line(format_line(feedlist_format, feed.first, feed.second, width), feed.second); + i++; } total_feeds = i; @@ -562,7 +564,7 @@ bool feedlist_formaction::jump_to_next_feed(unsigned int& feedpos) { return false; } -std::tr1::shared_ptr feedlist_formaction::get_feed() { +std::shared_ptr feedlist_formaction::get_feed() { unsigned int curpos; std::istringstream is(f->get("feedpos")); is >> curpos; @@ -628,21 +630,23 @@ void feedlist_formaction::mark_pos_if_visible(unsigned int pos) { scope_measure m1("feedlist_formaction::mark_pos_if_visible"); unsigned int vpos = 0; v->get_ctrl()->update_visible_feeds(); - for (std::vector::iterator it=visible_feeds.begin();it!=visible_feeds.end();++it, ++vpos) { - if (it->second == pos) { + for (auto feed : visible_feeds) { + if (feed.second == pos) { LOG(LOG_DEBUG, "feedlist_formaction::mark_pos_if_visible: match, setting position to %u", vpos); f->set("feedpos", utils::to_string(vpos)); return; } + vpos++; } vpos = 0; pos = v->get_ctrl()->get_pos_of_next_unread(pos); - for (std::vector::iterator it=visible_feeds.begin();it!=visible_feeds.end();++it, ++vpos) { - if (it->second == pos) { + for (auto feed : visible_feeds) { + if (feed.second == pos) { LOG(LOG_DEBUG, "feedlist_formaction::mark_pos_if_visible: match in 2nd try, setting position to %u", vpos); f->set("feedpos", utils::to_string(vpos)); return; } + vpos++; } } @@ -661,9 +665,9 @@ void feedlist_formaction::set_regexmanager(regexmanager * r) { std::vector& attrs = r->get_attrs("feedlist"); unsigned int i=0; std::string attrstr; - for (std::vector::iterator it=attrs.begin();it!=attrs.end();++it,++i) { - attrstr.append(utils::strprintf("@style_%u_normal:%s ", i, it->c_str())); - attrstr.append(utils::strprintf("@style_%u_focus:%s ", i, it->c_str())); + for (auto attribute : attrs) { + attrstr.append(utils::strprintf("@style_%u_normal:%s ", i, attribute.c_str())); + attrstr.append(utils::strprintf("@style_%u_focus:%s ", i, attribute.c_str())); } std::string textview = utils::strprintf("{!list[feeds] .expand:vh style_normal[listnormal]: style_focus[listfocus]:fg=yellow,bg=blue,attr=bold pos_name[feedposname]: pos[feedpos]:0 %s richtext:1}", attrstr.c_str()); f->modify("feeds", "replace", textview); @@ -692,7 +696,7 @@ void feedlist_formaction::op_start_search() { if (searchphrase.length() > 0) { v->set_status(_("Searching...")); searchhistory.add_line(searchphrase); - std::vector > items; + std::vector> items; try { std::string utf8searchphrase = utils::convert_text(searchphrase, "utf-8", nl_langinfo(CODESET)); items = v->get_ctrl()->search_for_items(utf8searchphrase, ""); @@ -703,8 +707,8 @@ void feedlist_formaction::op_start_search() { if (!items.empty()) { search_dummy_feed->item_mutex.lock(); search_dummy_feed->clear_items(); - for (std::vector >::iterator it=items.begin();it!=items.end();++it) { - search_dummy_feed->add_item(*it); + for (auto item : items) { + search_dummy_feed->add_item(item); } search_dummy_feed->item_mutex.unlock(); v->push_searchresult(search_dummy_feed, searchphrase); @@ -731,11 +735,12 @@ void feedlist_formaction::set_pos() { if (set_filterpos) { set_filterpos = false; unsigned int i = 0; - for (std::vector::iterator it=visible_feeds.begin();it!=visible_feeds.end();++it, ++i) { - if (it->second == filterpos) { + for (auto feed : visible_feeds) { + if (feed.second == filterpos) { f->set("feedpos", utils::to_string(i)); return; } + i++; } f->set("feedpos", "0"); } else if (zero_feedpos) { @@ -744,7 +749,7 @@ void feedlist_formaction::set_pos() { } } -std::string feedlist_formaction::get_title(std::tr1::shared_ptr feed) { +std::string feedlist_formaction::get_title(std::shared_ptr feed) { std::string title = feed->title(); if (title.length()==0) title = utils::censor_url(feed->rssurl()); @@ -753,7 +758,7 @@ std::string feedlist_formaction::get_title(std::tr1::shared_ptr feed) return title; } -std::string feedlist_formaction::format_line(const std::string& feedlist_format, std::tr1::shared_ptr feed, unsigned int pos, unsigned int width) { +std::string feedlist_formaction::format_line(const std::string& feedlist_format, std::shared_ptr feed, unsigned int pos, unsigned int width) { fmtstr_formatter fmt; unsigned int unread_count = feed->unread_item_count(); diff --git a/src/filtercontainer.cpp b/src/filtercontainer.cpp index 3e25dd87..a92a6f84 100644 --- a/src/filtercontainer.cpp +++ b/src/filtercontainer.cpp @@ -26,8 +26,8 @@ void filtercontainer::handle_action(const std::string& action, const std::vector } void filtercontainer::dump_config(std::vector& config_output) { - for (std::vector::iterator it=filters.begin();it!=filters.end();++it) { - config_output.push_back(utils::strprintf("define-filter %s %s", utils::quote(it->first).c_str(), utils::quote(it->second).c_str())); + for (auto filter : filters) { + config_output.push_back(utils::strprintf("define-filter %s %s", utils::quote(filter.first).c_str(), utils::quote(filter.second).c_str())); } } diff --git a/src/formaction.cpp b/src/formaction.cpp index 8f3ba5d9..ebb05bb4 100644 --- a/src/formaction.cpp +++ b/src/formaction.cpp @@ -43,7 +43,7 @@ void formaction::recalculate_form() { formaction::~formaction() { } -std::tr1::shared_ptr formaction::get_form() { +std::shared_ptr formaction::get_form() { return f; } @@ -90,8 +90,8 @@ void formaction::process_op(operation op, bool automatic, std::vector::iterator it=args->begin();it!=args->end();++it) { - cmdline.append(utils::strprintf("%s ", stfl::quote(*it).c_str())); + for (auto arg : *args) { + cmdline.append(utils::strprintf("%s ", stfl::quote(arg).c_str())); } } LOG(LOG_DEBUG, "formaction::process_op: running commandline `%s'", cmdline.c_str()); @@ -144,11 +144,11 @@ std::vector formaction::get_suggestions(const std::string& fragment LOG(LOG_DEBUG, "formaction::get_suggestions: fragment = %s", fragment.c_str()); std::vector result; // first check all formaction command suggestions - for (std::vector::iterator it=valid_cmds.begin();it!=valid_cmds.end();++it) { - LOG(LOG_DEBUG, "formaction::get_suggestions: extracted part: %s", it->substr(0, fragment.length()).c_str()); - if (it->substr(0, fragment.length()) == fragment) { + for (auto cmd : valid_cmds) { + LOG(LOG_DEBUG, "formaction::get_suggestions: extracted part: %s", cmd.substr(0, fragment.length()).c_str()); + if (cmd.substr(0, fragment.length()) == fragment) { LOG(LOG_DEBUG, "...and it matches."); - result.push_back(*it); + result.push_back(cmd); } } if (result.empty()) { @@ -161,8 +161,8 @@ std::vector formaction::get_suggestions(const std::string& fragment if (tokens.size() > 1) variable_fragment = tokens[1]; variable_suggestions = v->get_cfg()->get_suggestions(variable_fragment); - for (std::vector::iterator it=variable_suggestions.begin();it!=variable_suggestions.end();++it) { - std::string line = fragment + it->substr(variable_fragment.length(), it->length()-variable_fragment.length()); + for (auto suggestion : variable_suggestions) { + std::string line = fragment + suggestion.substr(variable_fragment.length(), suggestion.length()-variable_fragment.length()); result.push_back(line); LOG(LOG_DEBUG, "formaction::get_suggestions: suggested %s", line.c_str()); } @@ -223,9 +223,9 @@ void formaction::handle_cmdline(const std::string& cmdline) { if (tokens.empty()) { v->show_error(_("usage: source [...]")); } else { - for (std::vector::iterator it=tokens.begin();it!=tokens.end();++it) { + for (auto token : tokens) { try { - v->get_ctrl()->load_configfile(utils::resolve_tilde(*it)); + v->get_ctrl()->load_configfile(utils::resolve_tilde(token)); } catch (const configexception& ex) { v->show_error(ex.what()); break; diff --git a/src/help_formaction.cpp b/src/help_formaction.cpp index a6d70a2f..fdba0ab3 100644 --- a/src/help_formaction.cpp +++ b/src/help_formaction.cpp @@ -71,33 +71,33 @@ void help_formaction::prepare() { unsigned int syskey_count = 0; for (unsigned int i=0;i<3;i++) { - for (std::vector::iterator it=descs.begin();it!=descs.end();++it) { + for (auto desc : descs) { bool condition; switch (i) { case 0: - condition = (it->key.length() == 0 || it->flags & KM_SYSKEYS); - if (it->key.length() == 0) + condition = (desc.key.length() == 0 || desc.flags & KM_SYSKEYS); + if (desc.key.length() == 0) unbound_count++; - if (it->flags & KM_SYSKEYS) + if (desc.flags & KM_SYSKEYS) syskey_count++; break; case 1: - condition = !(it->flags & KM_SYSKEYS); + condition = !(desc.flags & KM_SYSKEYS); break; case 2: - condition = (it->key.length() > 0 || it->flags & KM_SYSKEYS); + condition = (desc.key.length() > 0 || desc.flags & KM_SYSKEYS); break; default: condition = true; break; } - if (context.length() > 0 && (it->ctx != context || condition)) + if (context.length() > 0 && (desc.ctx != context || condition)) continue; - if (!apply_search || strcasestr(it->key.c_str(), searchphrase.c_str())!=NULL || - strcasestr(it->cmd.c_str(), searchphrase.c_str())!=NULL || - strcasestr(it->desc.c_str(), searchphrase.c_str())!=NULL) { + if (!apply_search || strcasestr(desc.key.c_str(), searchphrase.c_str())!=NULL || + strcasestr(desc.cmd.c_str(), searchphrase.c_str())!=NULL || + strcasestr(desc.desc.c_str(), searchphrase.c_str())!=NULL) { char tabs_1[] = " "; char tabs_2[] = " "; - int how_often_1 = strlen(tabs_1) - it->key.length(); - int how_often_2 = strlen(tabs_2) - it->cmd.length(); + int how_often_1 = strlen(tabs_1) - desc.key.length(); + int how_often_2 = strlen(tabs_2) - desc.cmd.length(); if (how_often_1 <= 0) how_often_1 = 1; if (how_often_2 <= 0) @@ -107,8 +107,8 @@ void help_formaction::prepare() { std::string line; switch (i) { case 0: - case 1: line = utils::strprintf("%s%s%s%s%s", it->key.c_str(), tabs_1, it->cmd.c_str(), tabs_2, it->desc.c_str()); break; - case 2: line = utils::strprintf("%s%s%s%s", it->cmd.c_str(), tabs_1, tabs_2, it->desc.c_str()); break; + case 1: line = utils::strprintf("%s%s%s%s%s", desc.key.c_str(), tabs_1, desc.cmd.c_str(), tabs_2, desc.desc.c_str()); break; + case 2: line = utils::strprintf("%s%s%s%s", desc.cmd.c_str(), tabs_1, tabs_2, desc.desc.c_str()); break; } LOG(LOG_DEBUG, "help_formaction::prepare: step 1 - line = %s", line.c_str()); line = utils::quote_for_stfl(line); diff --git a/src/htmlrenderer.cpp b/src/htmlrenderer.cpp index 1c671be4..cdce67f1 100644 --- a/src/htmlrenderer.cpp +++ b/src/htmlrenderer.cpp @@ -57,11 +57,12 @@ void htmlrenderer::render(const std::string& source, std::vector& l unsigned int htmlrenderer::add_link(std::vector& links, const std::string& link, link_type type) { bool found = false; unsigned int i=1; - for (std::vector::iterator it=links.begin();it!=links.end();++it, ++i) { - if (it->first == link) { + for (auto l : links) { + if (l.first == link) { found = true; break; } + i++; } if (!found) links.push_back(linkpair(link,type)); @@ -542,38 +543,39 @@ void htmlrenderer::render(std::istream& input, std::vector& lines, { if (itunes_hack) { std::vector words = utils::tokenize_nl(utils::quote_for_stfl(xpp.getText())); - for (std::vector::iterator it=words.begin();it!=words.end();++it) { - if (*it == "\n") { + for (auto word : words) { + if (word == "\n") { add_line(curline, tables, lines); prepare_newline(curline, tables.size() ? 0 : indent_level); } else { - std::vector words2 = utils::tokenize_spaced(*it); + std::vector words2 = utils::tokenize_spaced(word); unsigned int i=0; bool new_line = false; - for (std::vector::iterator it2=words2.begin();it2!=words2.end();++it2,++i) { - if ((utils::strwidth_stfl(curline) + utils::strwidth_stfl(*it2)) >= w) { + for (auto word2 : words2) { + if ((utils::strwidth_stfl(curline) + utils::strwidth_stfl(word2)) >= w) { add_nonempty_line(curline, tables, lines); prepare_newline(curline, tables.size() ? 0 : indent_level); new_line = true; } if (new_line) { - if (*it2 != " ") - curline.append(*it2); + if (word2 != " ") + curline.append(word2); new_line = false; } else { - curline.append(*it2); + curline.append(word2); } + i++; } } } } else if (inside_pre) { std::vector words = utils::tokenize_nl(utils::quote_for_stfl(xpp.getText())); - for (std::vector::iterator it=words.begin();it!=words.end();++it) { - if (*it == "\n") { + for (auto word : words) { + if (word == "\n") { add_line(curline, tables, lines); prepare_newline(curline, tables.size() ? 0 : indent_level); } else { - curline.append(*it); + curline.append(word); } } } else if (inside_script || inside_style) { @@ -584,25 +586,24 @@ void htmlrenderer::render(std::istream& input, std::vector& lines, s.erase(0, 1); std::vector words = utils::tokenize_spaced(s); - unsigned int i=0; bool new_line = false; if (!line_is_nonempty(curline) && !words.empty() && words[0] == " ") { words.erase(words.begin()); } - for (std::vector::iterator it=words.begin();it!=words.end();++it,++i) { - if ((utils::strwidth_stfl(curline) + utils::strwidth_stfl(*it)) >= w) { + for (auto word : words) { + if ((utils::strwidth_stfl(curline) + utils::strwidth_stfl(word)) >= w) { add_nonempty_line(curline, tables, lines); prepare_newline(curline, tables.size() ? 0 : indent_level); new_line = true; } if (new_line) { - if (*it != " ") - curline.append(*it); + if (word != " ") + curline.append(word); new_line = false; } else { - curline.append(*it); + curline.append(word); } } } diff --git a/src/itemlist_formaction.cpp b/src/itemlist_formaction.cpp index 1178b6af..96ac0850 100644 --- a/src/itemlist_formaction.cpp +++ b/src/itemlist_formaction.cpp @@ -318,10 +318,10 @@ void itemlist_formaction::process_operation(operation op, bool automatic, std::v v->get_ctrl()->mark_all_read(pos); } else { { - scope_mutex lock(&feed->item_mutex); + std::lock_guard lock(feed->item_mutex); LOG(LOG_DEBUG, "itemlist_formaction: oh, it looks like I'm in a pseudo-feed (search result, query feed)"); - for (std::vector >::iterator it=feed->items().begin();it!=feed->items().end();++it) { - (*it)->set_unread_nowrite_notify(false, true); // TODO: do we need to call mark_article_read here, too? + for (auto item : feed->items()) { + item->set_unread_nowrite_notify(false, true); // TODO: do we need to call mark_article_read here, too? } } v->get_ctrl()->catchup_all(feed); @@ -574,7 +574,7 @@ void itemlist_formaction::qna_start_search() { v->set_status(_("Searching...")); searchhistory.add_line(searchphrase); - std::vector > items; + std::vector> items; try { std::string utf8searchphrase = utils::convert_text(searchphrase, "utf-8", nl_langinfo(CODESET)); if (show_searchresult) { @@ -593,10 +593,10 @@ void itemlist_formaction::qna_start_search() { } { - scope_mutex lock(&search_dummy_feed->item_mutex); + std::lock_guard lock(search_dummy_feed->item_mutex); search_dummy_feed->clear_items(); - for (std::vector >::iterator it=items.begin();it!=items.end();++it) { - search_dummy_feed->add_item(*it); + for (auto item : items) { + search_dummy_feed->add_item(item); } } @@ -612,8 +612,8 @@ void itemlist_formaction::do_update_visible_items() { update_visible_items = false; - scope_mutex lock(&feed->item_mutex); - std::vector >& items = feed->items(); + std::lock_guard lock(feed->item_mutex); + std::vector>& items = feed->items(); std::vector new_visible_items; @@ -624,10 +624,10 @@ void itemlist_formaction::do_update_visible_items() { */ unsigned int i=0; - for (std::vector >::iterator it = items.begin(); it != items.end(); ++it, ++i) { - (*it)->set_index(i+1); - if (!apply_filter || m.matches(it->get())) { - new_visible_items.push_back(itemptr_pos_pair(*it, i)); + for (auto item : items) { + item->set_index(i+1); + if (!apply_filter || m.matches(item.get())) { + new_visible_items.push_back(itemptr_pos_pair(item, i)); } } @@ -639,7 +639,7 @@ void itemlist_formaction::do_update_visible_items() { } void itemlist_formaction::prepare() { - scope_mutex mtx(&redraw_mtx); + std::lock_guard mtx(redraw_mtx); std::string sort_order = v->get_cfg()->get_configvalue("article-sort-order"); if (sort_order != old_sort_order) { @@ -685,32 +685,32 @@ void itemlist_formaction::prepare() { std::string itemlist_format = v->get_cfg()->get_configvalue("articlelist-format"); - for (std::vector::iterator it = visible_items.begin(); it != visible_items.end(); ++it) { + for (auto item : visible_items) { std::string tmp_itemlist_format = itemlist_format; fmtstr_formatter fmt; - fmt.register_fmt('i', utils::strprintf("%u",it->second + 1)); - fmt.register_fmt('f', gen_flags(it->first)); - fmt.register_fmt('D', gen_datestr(it->first->pubDate_timestamp(), datetimeformat.c_str())); - if (feed->rssurl() != it->first->feedurl() && it->first->get_feedptr() != NULL) { - fmt.register_fmt('T', utils::replace_all(it->first->get_feedptr()->title(), "<", "<>")); + fmt.register_fmt('i', utils::strprintf("%u",item.second + 1)); + fmt.register_fmt('f', gen_flags(item.first)); + fmt.register_fmt('D', gen_datestr(item.first->pubDate_timestamp(), datetimeformat.c_str())); + if (feed->rssurl() != item.first->feedurl() && item.first->get_feedptr() != NULL) { + fmt.register_fmt('T', utils::replace_all(item.first->get_feedptr()->title(), "<", "<>")); } - fmt.register_fmt('t', utils::replace_all(it->first->title(), "<", "<>")); - fmt.register_fmt('a', utils::replace_all(it->first->author(), "<", "<>")); - fmt.register_fmt('L', it->first->length()); + fmt.register_fmt('t', utils::replace_all(item.first->title(), "<", "<>")); + fmt.register_fmt('a', utils::replace_all(item.first->author(), "<", "<>")); + fmt.register_fmt('L', item.first->length()); if (rxman) { int id; - if ((id = rxman->article_matches(it->first.get())) != -1) { + if ((id = rxman->article_matches(item.first.get())) != -1) { tmp_itemlist_format = utils::strprintf("<%d>%s", id, itemlist_format.c_str()); } } - if (it->first->unread()) { + if (item.first->unread()) { tmp_itemlist_format = utils::strprintf("%s", itemlist_format.c_str()); } - listfmt.add_line(fmt.do_format(tmp_itemlist_format, width), it->second); + listfmt.add_line(fmt.do_format(tmp_itemlist_format, width), item.second); } f->modify("items","replace_inner", listfmt.format_list(rxman, "articlelist")); @@ -942,7 +942,7 @@ void itemlist_formaction::recalculate_form() { } } -void itemlist_formaction::save_article(const std::string& filename, std::tr1::shared_ptr item) { +void itemlist_formaction::save_article(const std::string& filename, std::shared_ptr item) { if (filename == "") { v->show_error(_("Aborted saving.")); } else { @@ -970,15 +970,15 @@ void itemlist_formaction::set_regexmanager(regexmanager * r) { std::vector& attrs = r->get_attrs("articlelist"); unsigned int i=0; std::string attrstr; - for (std::vector::iterator it=attrs.begin();it!=attrs.end();++it,++i) { - attrstr.append(utils::strprintf("@style_%u_normal:%s ", i, it->c_str())); - attrstr.append(utils::strprintf("@style_%u_focus:%s ", i, it->c_str())); + for (auto attribute : attrs) { + attrstr.append(utils::strprintf("@style_%u_normal:%s ", i, attribute.c_str())); + attrstr.append(utils::strprintf("@style_%u_focus:%s ", i, attribute.c_str())); } std::string textview = utils::strprintf("{list[items] .expand:vh style_normal[listnormal]: style_focus[listfocus]:fg=yellow,bg=blue,attr=bold pos_name[itemposname]: pos[itempos]:0 %s richtext:1}", attrstr.c_str()); f->modify("items", "replace", textview); } -std::string itemlist_formaction::gen_flags(std::tr1::shared_ptr item) { +std::string itemlist_formaction::gen_flags(std::shared_ptr item) { std::string flags; if (item->deleted()) { flags.append("D"); @@ -1006,17 +1006,18 @@ void itemlist_formaction::prepare_set_filterpos() { if (set_filterpos) { set_filterpos = false; unsigned int i=0; - for (std::vector::iterator it=visible_items.begin();it!=visible_items.end();++it, ++i) { - if (it->second == filterpos) { + for (auto item : visible_items) { + if (item.second == filterpos) { f->set("itempos", utils::to_string(i)); return; } + i++; } f->set("itempos", "0"); } } -void itemlist_formaction::set_feed(std::tr1::shared_ptr fd) { +void itemlist_formaction::set_feed(std::shared_ptr fd) { LOG(LOG_DEBUG, "itemlist_formaction::set_feed: fd pointer = %p title = `%s'", fd.get(), fd->title().c_str()); feed = fd; feed->load(); diff --git a/src/itemview_formaction.cpp b/src/itemview_formaction.cpp index 7d4818c6..e1c0625d 100644 --- a/src/itemview_formaction.cpp +++ b/src/itemview_formaction.cpp @@ -13,7 +13,7 @@ namespace newsbeuter { -itemview_formaction::itemview_formaction(view * vv, std::tr1::shared_ptr il, std::string formstr) +itemview_formaction::itemview_formaction(view * vv, std::shared_ptr il, std::string formstr) : formaction(vv,formstr), show_source(false), quit(false), rxman(0), num_lines(0), itemlist(il), in_search(false) { valid_cmds.push_back("save"); std::sort(valid_cmds.begin(), valid_cmds.end()); @@ -61,11 +61,10 @@ void itemview_formaction::prepare() { render_width -= 5; } - LOG(LOG_DEBUG, "itemview_formaction::prepare: guid = %s", guid.c_str()); - std::tr1::shared_ptr item = feed->get_item_by_guid(guid); + std::shared_ptr item = feed->get_item_by_guid(guid); listformatter listfmt; - std::tr1::shared_ptr feedptr = item->get_feedptr(); + std::shared_ptr feedptr = item->get_feedptr(); std::string title, feedtitle; if (feedptr.get() != NULL) { @@ -151,7 +150,7 @@ void itemview_formaction::prepare() { } void itemview_formaction::process_operation(operation op, bool automatic, std::vector * args) { - std::tr1::shared_ptr item = feed->get_item_by_guid(guid); + std::shared_ptr item = feed->get_item_by_guid(guid); bool hardquit = false; /* @@ -469,7 +468,7 @@ void itemview_formaction::handle_cmdline(const std::string& cmd) { if (!tokens.empty()) { if (tokens[0] == "save" && tokens.size() >= 2) { std::string filename = utils::resolve_tilde(tokens[1]); - std::tr1::shared_ptr item = feed->get_item_by_guid(guid); + std::shared_ptr item = feed->get_item_by_guid(guid); if (filename == "") { v->show_error(_("Aborted saving.")); @@ -491,7 +490,7 @@ void itemview_formaction::handle_cmdline(const std::string& cmd) { void itemview_formaction::finished_qna(operation op) { formaction::finished_qna(op); // important! - std::tr1::shared_ptr item = feed->get_item_by_guid(guid); + std::shared_ptr item = feed->get_item_by_guid(guid); switch (op) { case OP_INT_EDITFLAGS_END: @@ -565,8 +564,8 @@ void itemview_formaction::set_regexmanager(regexmanager * r) { std::vector& attrs = r->get_attrs("article"); unsigned int i=0; std::string attrstr; - for (std::vector::iterator it=attrs.begin();it!=attrs.end();++it,++i) { - attrstr.append(utils::strprintf("@style_%u_normal:%s ", i, it->c_str())); + for (auto attribute : attrs) { + attrstr.append(utils::strprintf("@style_%u_normal:%s ", i, attribute.c_str())); } attrstr.append("@style_b_normal[color_bold]:attr=bold @style_u_normal[color_underline]:attr=underline "); std::string textview = utils::strprintf("{textview[article] style_normal[article]: style_end[styleend]:fg=blue,attr=bold %s .expand:vh offset[articleoffset]:0 richtext:1}", attrstr.c_str()); @@ -598,7 +597,7 @@ void itemview_formaction::update_percent() { } std::string itemview_formaction::title() { - std::tr1::shared_ptr item = feed->get_item_by_guid(guid); + std::shared_ptr item = feed->get_item_by_guid(guid); return utils::strprintf(_("Article - %s"), item->title().c_str()); } diff --git a/src/keymap.cpp b/src/keymap.cpp index 3b958cff..0847c725 100644 --- a/src/keymap.cpp +++ b/src/keymap.cpp @@ -145,12 +145,12 @@ void keymap::get_keymap_descriptions(std::vector& descs, unsigned s for (unsigned int j=0;opdescs[j].op != OP_NIL;++j) { bool already_added = false; - for (std::map::iterator it=keymap_[ctx].begin();it!=keymap_[ctx].end();++it) { - operation op = it->second; + for (auto keymap : keymap_[ctx]) { + operation op = keymap.second; if (op != OP_NIL) { if (opdescs[j].op == op && opdescs[j].flags & flags) { keymap_desc desc; - desc.key = it->first; + desc.key = keymap.first; desc.ctx = ctx; if (!already_added) { desc.cmd = opdescs[j].opstr; @@ -241,30 +241,30 @@ operation keymap::get_operation(const std::string& keycode, const std::string& c void keymap::dump_config(std::vector& config_output) { for (unsigned int i=1;contexts[i]!=NULL;i++) { // TODO: optimize std::map& x = keymap_[contexts[i]]; - for (std::map::iterator it = x.begin();it!=x.end();++it) { - if (it->second < OP_INT_MIN) { + for (auto keymap : x) { + if (keymap.second < OP_INT_MIN) { std::string configline = "bind-key "; - configline.append(utils::quote(it->first)); + configline.append(utils::quote(keymap.first)); configline.append(" "); - configline.append(getopname(it->second)); + configline.append(getopname(keymap.second)); configline.append(" "); configline.append(contexts[i]); config_output.push_back(configline); } } } - for (std::map >::iterator it=macros_.begin();it!=macros_.end();++it) { + for (auto macro : macros_) { std::string configline = "macro "; - configline.append(it->first); + configline.append(macro.first); configline.append(" "); unsigned int i=0; - for (std::vector::iterator jt=it->second.begin();jt!=it->second.end();++jt,i++) { - configline.append(getopname(jt->op)); - for (std::vector::iterator kt=jt->args.begin();kt!=jt->args.end();++kt) { + for (auto cmd : macro.second) { + configline.append(getopname(cmd.op)); + for (auto arg : cmd.args) { configline.append(" "); - configline.append(utils::quote(*kt)); + configline.append(utils::quote(arg)); } - if (i < (it->second.size()-1)) + if (i < (macro.second.size()-1)) configline.append(" ; "); } config_output.push_back(configline); @@ -307,7 +307,7 @@ void keymap::handle_action(const std::string& action, const std::vector::const_iterator it = params.begin(); + auto it = params.begin(); std::string macrokey = *it; std::vector cmds; macrocmd tmpcmd; @@ -348,24 +348,24 @@ std::string keymap::getkey(operation op, const std::string& context) { if (context == "all") { for (unsigned int i=0;contexts[i]!=NULL;i++) { std::string ctx(contexts[i]); - for (std::map::iterator it=keymap_[ctx].begin(); it!=keymap_[ctx].end(); ++it) { - if (it->second == op) - return it->first; + for (auto keymap : keymap_[ctx]) { + if (keymap.second == op) + return keymap.first; } } } else { - for (std::map::iterator it=keymap_[context].begin(); it!=keymap_[context].end(); ++it) { - if (it->second == op) - return it->first; + for (auto keymap : keymap_[context]) { + if (keymap.second == op) + return keymap.first; } } return ""; } std::vector keymap::get_macro(const std::string& key) { - for (std::map >::iterator it=macros_.begin(); it!=macros_.end(); ++it) { - if (it->first == key) { - return it->second; + for (auto macro : macros_) { + if (macro.first == key) { + return macro.second; } } std::vector dummyvector; diff --git a/src/listformatter.cpp b/src/listformatter.cpp index 35519387..a00f6bca 100644 --- a/src/listformatter.cpp +++ b/src/listformatter.cpp @@ -31,21 +31,21 @@ void listformatter::add_line(const std::string& text, unsigned int id, unsigned } void listformatter::add_lines(const std::vector& thelines, unsigned int width) { - for (std::vector::const_iterator it=thelines.begin();it!=thelines.end();++it) { - add_line(utils::replace_all(*it, "\t", " "), UINT_MAX, width); + for (auto line : thelines) { + add_line(utils::replace_all(line, "\t", " "), UINT_MAX, width); } } std::string listformatter::format_list(regexmanager * rxman, const std::string& location) { format_cache = "{list"; - for (std::vector::iterator it=lines.begin();it!=lines.end();++it) { - std::string str = it->first; + for (auto line : lines) { + std::string str = line.first; if (rxman) rxman->quote_and_highlight(str, location); - if (it->second == UINT_MAX) { + if (line.second == UINT_MAX) { format_cache.append(utils::strprintf("{listitem text:%s}", stfl::quote(str).c_str())); } else { - format_cache.append(utils::strprintf("{listitem[%u] text:%s}", it->second, stfl::quote(str).c_str())); + format_cache.append(utils::strprintf("{listitem[%u] text:%s}", line.second, stfl::quote(str).c_str())); } } format_cache.append(1, '}'); diff --git a/src/logger.cpp b/src/logger.cpp index 946c8edf..21702129 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -4,7 +4,7 @@ #include namespace newsbeuter { -mutex logger::instanceMutex; +std::mutex logger::instanceMutex; logger::logger() : curlevel(LOG_NONE) { } @@ -12,7 +12,7 @@ void logger::set_logfile(const char * logfile) { /* * This sets the filename of the debug logfile */ - scope_mutex lock(&logMutex); + std::lock_guard lock(logMutex); if (f.is_open()) f.close(); f.open(logfile, std::fstream::out); @@ -25,7 +25,7 @@ void logger::set_errorlogfile(const char * logfile) { /* * This sets the filename of the error logfile, i.e. the one that can be configured to be generated. */ - scope_mutex lock(&logMutex); + std::lock_guard lock(logMutex); if (ef.is_open()) ef.close(); ef.open(logfile, std::fstream::out); @@ -38,7 +38,7 @@ void logger::set_errorlogfile(const char * logfile) { } void logger::set_loglevel(loglevel level) { - scope_mutex lock(&logMutex); + std::lock_guard lock(logMutex); curlevel = level; if (curlevel == LOG_NONE) f.close(); @@ -51,7 +51,7 @@ void logger::log(loglevel level, const char * format, ...) { * This function checks the loglevel, creates the error message, and then * writes it to the debug logfile and to the error logfile (if applicable). */ - scope_mutex lock(&logMutex); + std::lock_guard lock(logMutex); if (level <= curlevel && curlevel > LOG_NONE && (f.is_open() || ef.is_open())) { char * buf, * logmsgbuf; char date[128]; @@ -94,7 +94,7 @@ logger &logger::getInstance() { /* * This is the global logger that everyone uses */ - scope_mutex lock(&instanceMutex); + std::lock_guard lock(instanceMutex); static logger theLogger; return theLogger; } diff --git a/src/markreadthread.cpp b/src/markreadthread.cpp index 8983bdff..986b64d4 100644 --- a/src/markreadthread.cpp +++ b/src/markreadthread.cpp @@ -13,7 +13,7 @@ markreadthread::markreadthread( ttrss_api* r_api, const std::string& guid, bool markreadthread::~markreadthread() { } -void markreadthread::run() { +void markreadthread::operator()() { /* * the markreadthread class handles marking a thread as read in a way that * doesn't halt the presentation of the content. this is for remote sources, diff --git a/src/matcher.cpp b/src/matcher.cpp index 796d32ef..4fef2141 100644 --- a/src/matcher.cpp +++ b/src/matcher.cpp @@ -132,8 +132,8 @@ bool matcher::matchop_cont(expression * e, matchable * item) { throw matcherexception(matcherexception::ATTRIB_UNAVAIL, e->name); std::vector elements = utils::tokenize(item->get_attribute(e->name), " "); std::string literal = e->literal; - for (std::vector::iterator it=elements.begin();it!=elements.end();++it) { - if (literal == *it) { + for (auto elem : elements) { + if (literal == elem) { return true; } } diff --git a/src/mutex.cpp b/src/mutex.cpp deleted file mode 100644 index 2f15c807..00000000 --- a/src/mutex.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -#include - -namespace newsbeuter { - -mutex::mutex() { - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); - pthread_mutex_init(&mtx, &attr); -} - -mutex::~mutex() { - pthread_mutex_destroy(&mtx); - pthread_mutexattr_destroy(&attr); -} - -void mutex::lock() { - pthread_mutex_lock(&mtx); -} - -void mutex::unlock() { - pthread_mutex_unlock(&mtx); -} - -bool mutex::trylock() { - int rc = pthread_mutex_trylock(&mtx); - if (rc != 0) { - if (EBUSY == rc) { - return false; - } else { - throw exception(rc); - } - } else { - return true; - } -} - -scope_mutex::scope_mutex(mutex * m) : mtx(m) { - if (mtx) { - mtx->lock(); - } -} - -scope_mutex::~scope_mutex() { - if (mtx) { - mtx->unlock(); - } -} - -} diff --git a/src/newsblur_api.cpp b/src/newsblur_api.cpp index 437aea5f..7ee5e52a 100644 --- a/src/newsblur_api.cpp +++ b/src/newsblur_api.cpp @@ -110,10 +110,6 @@ bool newsblur_api::update_article_flags(const std::string& oldflags, const std:: return false; } -static bool sort_by_pubdate(const rsspp::item& a, const rsspp::item& b) { - return a.pubDate_ts > b.pubDate_ts; -} - time_t parse_date(const char * raw) { struct tm tm; memset(&tm, 0, sizeof(tm)); @@ -189,7 +185,9 @@ rsspp::feed newsblur_api::fetch_feed(const std::string& id) { } } - std::sort(f.items.begin(), f.items.end(), sort_by_pubdate); + std::sort(f.items.begin(), f.items.end(), [](const rsspp::item& a, const rsspp::item& b) { + return a.pubDate_ts > b.pubDate_ts; + }); return f; } diff --git a/src/newsblur_urlreader.cpp b/src/newsblur_urlreader.cpp index c2641e74..b259f228 100644 --- a/src/newsblur_urlreader.cpp +++ b/src/newsblur_urlreader.cpp @@ -20,17 +20,17 @@ void newsblur_urlreader::reload() { ur.reload(); std::vector& file_urls(ur.get_urls()); - for(std::vector::iterator it=file_urls.begin();it!=file_urls.end();++it) { - if (it->substr(0,6) == "query:") { - urls.push_back(*it); + for (auto url : file_urls) { + if (url.substr(0,6) == "query:") { + urls.push_back(url); } } std::vector feedurls = api->get_subscribed_urls(); - for (std::vector::iterator it=feedurls.begin();it!=feedurls.end();++it) { - LOG(LOG_INFO, "added %s to URL list", it->first.c_str()); - urls.push_back(it->first); + for (auto url : feedurls) { + LOG(LOG_INFO, "added %s to URL list", url.first.c_str()); + urls.push_back(url.first); } } diff --git a/src/oldreader_api.cpp b/src/oldreader_api.cpp index 9951809f..5903f387 100644 --- a/src/oldreader_api.cpp +++ b/src/oldreader_api.cpp @@ -104,10 +104,10 @@ std::string oldreader_api::retrieve_auth() { curl_easy_cleanup(handle); std::vector lines = utils::tokenize(result); - for (std::vector::iterator it=lines.begin();it!=lines.end();++it) { - LOG(LOG_DEBUG, "oldreader_api::retrieve_auth: line = %s", it->c_str()); - if (it->substr(0,5)=="Auth=") { - std::string auth = it->substr(5, it->length()-5); + for (auto line : lines) { + LOG(LOG_DEBUG, "oldreader_api::retrieve_auth: line = %s", line.c_str()); + if (line.substr(0,5)=="Auth=") { + std::string auth = line.substr(5, line.length()-5); return auth; } } @@ -185,17 +185,17 @@ bool oldreader_api::mark_all_read(const std::string& feedurl) { std::vector oldreader_api::bulk_mark_articles_read(const std::vector& actions) { std::vector successful_tokens; std::string token = get_new_token(); - for (std::vector::const_iterator it=actions.begin();it!=actions.end();++it) { + for (auto action : actions) { bool read; - if (it->second == GOOGLE_MARK_READ) { + if (action.second == GOOGLE_MARK_READ) { read = true; - } else if (it->second == GOOGLE_MARK_UNREAD) { + } else if (action.second == GOOGLE_MARK_UNREAD) { read = false; } else { continue; } - if (mark_article_read_with_token(it->first, read, token)) { - successful_tokens.push_back(it->first); + if (mark_article_read_with_token(action.first, read, token)) { + successful_tokens.push_back(action.first); } } return successful_tokens; diff --git a/src/oldreader_urlreader.cpp b/src/oldreader_urlreader.cpp index 915db414..e69ea0e8 100644 --- a/src/oldreader_urlreader.cpp +++ b/src/oldreader_urlreader.cpp @@ -39,25 +39,25 @@ void oldreader_urlreader::reload() { ur.reload(); std::vector& file_urls(ur.get_urls()); - for(std::vector::iterator it=file_urls.begin();it!=file_urls.end();++it) { - if (it->substr(0,6) == "query:") { - urls.push_back(*it); - std::vector& file_tags(ur.get_tags(*it)); - tags[*it] = ur.get_tags(*it); - for (std::vector::iterator jt=file_tags.begin();jt!=file_tags.end();++jt) { - alltags.insert(*jt); + for (auto url : file_urls) { + if (url.substr(0,6) == "query:") { + urls.push_back(url); + std::vector& file_tags(ur.get_tags(url)); + tags[url] = ur.get_tags(url); + for (auto tag : file_tags) { + alltags.insert(tag); } } } std::vector feedurls = api->get_subscribed_urls(); - for (std::vector::iterator it=feedurls.begin();it!=feedurls.end();++it) { - LOG(LOG_DEBUG, "added %s to URL list", it->first.c_str()); - urls.push_back(it->first); - tags[it->first] = it->second; - for (std::vector::iterator jt=it->second.begin();jt!=it->second.end();++jt) { - LOG(LOG_DEBUG, "%s: added tag %s", it->first.c_str(), jt->c_str()); - alltags.insert(*jt); + for (auto url : feedurls) { + LOG(LOG_DEBUG, "added %s to URL list", url.first.c_str()); + urls.push_back(url.first); + tags[url.first] = url.second; + for (auto tag : url.second) { + LOG(LOG_DEBUG, "%s: added tag %s", url.first.c_str(), tag.c_str()); + alltags.insert(tag); } } } diff --git a/src/pb_controller.cpp b/src/pb_controller.cpp index 1b9986c4..9d84ed9c 100644 --- a/src/pb_controller.cpp +++ b/src/pb_controller.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -256,11 +257,9 @@ std::string pb_controller::get_dlpath() { unsigned int pb_controller::downloads_in_progress() { unsigned int count = 0; - if (downloads_.size() > 0) { - for (std::vector::iterator it=downloads_.begin();it!=downloads_.end();++it) { - if (it->status() == DL_DOWNLOADING) - ++count; - } + for (auto dl : downloads_) { + if (dl.status() == DL_DOWNLOADING) + ++count; } return count; } @@ -277,11 +276,9 @@ void pb_controller::reload_queue(bool remove_unplayed) { double pb_controller::get_total_kbps() { double result = 0.0; - if (downloads_.size() > 0) { - for (std::vector::iterator it=downloads_.begin();it!=downloads_.end();++it) { - if (it->status() == DL_DOWNLOADING) { - result += it->kbps(); - } + for (auto dl : downloads_) { + if (dl.status() == DL_DOWNLOADING) { + result += dl.kbps(); } } return result; @@ -289,10 +286,9 @@ double pb_controller::get_total_kbps() { void pb_controller::start_downloads() { int dl2start = get_maxdownloads() - downloads_in_progress(); - for (std::vector::iterator it=downloads_.begin();dl2start > 0 && it!=downloads_.end();++it) { + for (auto it=downloads_.begin();dl2start > 0 && it!=downloads_.end();++it) { if (it->status() == DL_QUEUED) { - poddlthread * thread = new poddlthread(&(*it), cfg); - thread->start(); + std::thread t{poddlthread(&(*it), cfg)}; --dl2start; } } diff --git a/src/pb_view.cpp b/src/pb_view.cpp index 2fa5909a..de8faa34 100644 --- a/src/pb_view.cpp +++ b/src/pb_view.cpp @@ -50,14 +50,14 @@ void pb_view::run(bool auto_download) { LOG(LOG_DEBUG, "pb_view::run: updating view... downloads().size() = %u", ctrl->downloads().size()); if (ctrl->downloads().size() > 0) { - std::string code = "{list"; unsigned int i = 0; - for (std::vector::iterator it=ctrl->downloads().begin();it!=ctrl->downloads().end();++it,++i) { + for (auto dl : ctrl->downloads()) { char lbuf[1024]; - snprintf(lbuf, sizeof(lbuf), " %4u [%6.1fMB/%6.1fMB] [%5.1f %%] [%7.2f kb/s] %-20s %s -> %s", i+1, it->current_size()/(1024*1024), it->total_size()/(1024*1024), it->percents_finished(), it->kbps(), it->status_text(), it->url(), it->filename()); + snprintf(lbuf, sizeof(lbuf), " %4u [%6.1fMB/%6.1fMB] [%5.1f %%] [%7.2f kb/s] %-20s %s -> %s", i+1, dl.current_size()/(1024*1024), dl.total_size()/(1024*1024), dl.percents_finished(), dl.kbps(), dl.status_text(), dl.url(), dl.filename()); code.append(utils::strprintf("{listitem[%u] text:%s}", i, stfl::quote(lbuf).c_str())); + i++; } code.append("}"); @@ -110,8 +110,7 @@ void pb_view::run(bool auto_download) { os >> idx; if (idx != -1) { if (ctrl->downloads()[idx].status() != DL_DOWNLOADING) { - poddlthread * thread = new poddlthread(&ctrl->downloads()[idx], ctrl->get_cfgcont()); - thread->start(); + std::thread t{poddlthread(&ctrl->downloads()[idx], ctrl->get_cfgcont())}; } } } @@ -224,16 +223,17 @@ void pb_view::run_help() { std::string code = "{list"; - for (std::vector::iterator it=descs.begin();it!=descs.end();++it) { + for (auto desc : descs) { std::string line = "{listitem text:"; std::string descline; - descline.append(it->key); - descline.append(8-it->key.length(),' '); - descline.append(it->cmd); - descline.append(24-it->cmd.length(),' '); - descline.append(it->desc); + descline.append(desc.key); + descline.append(8-desc.key.length(),' '); + descline.append(desc.cmd); + descline.append(24-desc.cmd.length(),' '); + descline.append(desc.desc); line.append(stfl::quote(descline)); + line.append("}"); code.append(line); diff --git a/src/poddlthread.cpp b/src/poddlthread.cpp index d531b510..966506ce 100644 --- a/src/poddlthread.cpp +++ b/src/poddlthread.cpp @@ -18,13 +18,14 @@ namespace podbeuter { static size_t my_write_data(void *buffer, size_t size, size_t nmemb, void *userp); static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); -poddlthread::poddlthread(download * dl_, newsbeuter::configcontainer * c) : dl(dl_), cfg(c) { +poddlthread::poddlthread(download * dl_, newsbeuter::configcontainer * c) : dl(dl_), f(new std::ofstream()), cfg(c) { } poddlthread::~poddlthread() { + delete f; } -void poddlthread::run() { +void poddlthread::operator()() { gettimeofday(&tv1, NULL); ++bytecount; @@ -53,22 +54,22 @@ void poddlthread::run() { if (stat(dl->filename(), &sb) == -1) { LOG(LOG_INFO, "poddlthread::run: stat failed: starting normal download"); mkdir_p(dl->filename()); - f.open(dl->filename(), std::fstream::out); + f->open(dl->filename(), std::fstream::out); dl->set_offset(0); } else { LOG(LOG_INFO, "poddlthread::run: stat ok: starting download from %u", sb.st_size); curl_easy_setopt(easyhandle, CURLOPT_RESUME_FROM, sb.st_size); dl->set_offset(sb.st_size); - f.open(dl->filename(), std::fstream::out | std::fstream::app); + f->open(dl->filename(), std::fstream::out | std::fstream::app); } - if (f.is_open()) { + if (f->is_open()) { dl->set_status(DL_DOWNLOADING); CURLcode success = curl_easy_perform(easyhandle); - f.close(); + f->close(); LOG(LOG_INFO,"poddlthread::run: curl_easy_perform rc = %u (%s)", success, curl_easy_strerror(success)); @@ -98,10 +99,10 @@ static int progress_callback(void *clientp, double dltotal, double dlnow, double size_t poddlthread::write_data(void * buffer, size_t size, size_t nmemb) { if (dl->status() == DL_CANCELLED) return 0; - f.write(static_cast(buffer), size * nmemb); + f->write(static_cast(buffer), size * nmemb); bytecount += (size * nmemb); - LOG(LOG_DEBUG, "poddlthread::write_data: bad = %u size = %u", f.bad(), size * nmemb); - return f.bad() ? 0 : size * nmemb; + LOG(LOG_DEBUG, "poddlthread::write_data: bad = %u size = %u", f->bad(), size * nmemb); + return f->bad() ? 0 : size * nmemb; } int poddlthread::progress(double dlnow, double dltotal) { diff --git a/src/queueloader.cpp b/src/queueloader.cpp index 9878c423..348370b5 100644 --- a/src/queueloader.cpp +++ b/src/queueloader.cpp @@ -21,31 +21,29 @@ void queueloader::reload(std::vector& downloads, bool remove_unplayed) std::vector dltemp; std::fstream f; - if (downloads.size() > 0) { - for (std::vector::iterator it=downloads.begin();it!=downloads.end();++it) { - if (it->status() == DL_DOWNLOADING) { // we are not allowed to reload if a download is in progress! - LOG(LOG_INFO, "queueloader::reload: aborting reload due to DL_DOWNLOADING status"); - return; - } - switch (it->status()) { - case DL_QUEUED: - case DL_CANCELLED: - case DL_FAILED: - case DL_ALREADY_DOWNLOADED: - case DL_READY: - LOG(LOG_DEBUG, "queueloader::reload: storing %s to new vector", it->url()); - dltemp.push_back(*it); - break; - case DL_PLAYED: - case DL_FINISHED: - if (!remove_unplayed) { - LOG(LOG_DEBUG, "queueloader::reload: storing %s to new vector", it->url()); - dltemp.push_back(*it); - } - break; - default: - break; - } + for (auto dl : downloads) { + if (dl.status() == DL_DOWNLOADING) { // we are not allowed to reload if a download is in progress! + LOG(LOG_INFO, "queueloader::reload: aborting reload due to DL_DOWNLOADING status"); + return; + } + switch (dl.status()) { + case DL_QUEUED: + case DL_CANCELLED: + case DL_FAILED: + case DL_ALREADY_DOWNLOADED: + case DL_READY: + LOG(LOG_DEBUG, "queueloader::reload: storing %s to new vector", dl.url()); + dltemp.push_back(dl); + break; + case DL_PLAYED: + case DL_FINISHED: + if (!remove_unplayed) { + LOG(LOG_DEBUG, "queueloader::reload: storing %s to new vector", dl.url()); + dltemp.push_back(dl); + } + break; + default: + break; } } @@ -58,24 +56,23 @@ void queueloader::reload(std::vector& downloads, bool remove_unplayed) LOG(LOG_DEBUG, "queueloader::reload: loaded `%s' from queue file", line.c_str()); std::vector fields = utils::tokenize_quoted(line); bool url_found = false; - if (!dltemp.empty()) { - for (std::vector::iterator it=dltemp.begin();it!=dltemp.end();++it) { - if (fields[0] == it->url()) { - LOG(LOG_INFO, "queueloader::reload: found `%s' in old vector", fields[0].c_str()); - url_found = true; - break; - } + + for (auto dl : dltemp) { + if (fields[0] == dl.url()) { + LOG(LOG_INFO, "queueloader::reload: found `%s' in old vector", fields[0].c_str()); + url_found = true; + break; } } - if (!downloads.empty()) { - for (std::vector::iterator it=downloads.begin();it!=downloads.end();++it) { - if (fields[0] == it->url()) { - LOG(LOG_INFO, "queueloader::reload: found `%s' in new vector", line.c_str()); - url_found = true; - break; - } + + for (auto dl : downloads) { + if (fields[0] == dl.url()) { + LOG(LOG_INFO, "queueloader::reload: found `%s' in new vector", line.c_str()); + url_found = true; + break; } } + if (!url_found) { LOG(LOG_INFO, "queueloader::reload: found `%s' nowhere -> storing to new vector", line.c_str()); download d(ctrl); @@ -106,11 +103,11 @@ void queueloader::reload(std::vector& downloads, bool remove_unplayed) f.open(queuefile.c_str(), std::fstream::out); if (f.is_open()) { - for (std::vector::iterator it=dltemp.begin();it!=dltemp.end();++it) { - f << it->url() << " " << stfl::quote(it->filename()); - if (it->status() == DL_READY) + for (auto dl : dltemp) { + f << dl.url() << " " << stfl::quote(dl.filename()); + if (dl.status() == DL_READY) f << " downloaded"; - if (it->status() == DL_PLAYED) + if (dl.status() == DL_PLAYED) f << " played"; f << std::endl; } diff --git a/src/regexmanager.cpp b/src/regexmanager.cpp index dfee40bc..1d952d88 100644 --- a/src/regexmanager.cpp +++ b/src/regexmanager.cpp @@ -15,19 +15,18 @@ regexmanager::regexmanager() { } regexmanager::~regexmanager() { - for (std::map::iterator jt=locations.begin();jt!=locations.end();++jt) { - std::vector& regexes(jt->second.first); - if (regexes.size() > 0) { - for (std::vector::iterator it=regexes.begin();it!=regexes.end();++it) { - delete *it; + for (auto location : locations) { + if (location.second.first.size() > 0) { + for (auto regex : location.second.first) { + delete regex; } } } } void regexmanager::dump_config(std::vector& config_output) { - for (std::vector::iterator it=cheat_store_for_dump_config.begin();it!=cheat_store_for_dump_config.end();++it) { - config_output.push_back(*it); + for (auto foo : cheat_store_for_dump_config) { + config_output.push_back(foo); } } @@ -82,20 +81,20 @@ void regexmanager::handle_action(const std::string& action, const std::vector::iterator it=locations.begin();it!=locations.end();++it) { + for (auto location : locations) { LOG(LOG_DEBUG, "regexmanager::handle_action: adding rx = %s colorstr = %s to location %s", - params[1].c_str(), colorstr.c_str(), it->first.c_str()); + params[1].c_str(), colorstr.c_str(), location.first.c_str()); rx = new regex_t; // we need to create a new one for each push_back, otherwise we'd have double frees. regcomp(rx, params[1].c_str(), REG_EXTENDED | REG_ICASE); - it->second.first.push_back(rx); - it->second.second.push_back(colorstr); + location.second.first.push_back(rx); + location.second.second.push_back(colorstr); } } std::string line = "highlight"; - for (std::vector::const_iterator it=params.begin();it!=params.end();++it) { + for (const auto& param : params) { line.append(" "); - line.append(utils::quote(*it)); + line.append(utils::quote(param)); } cheat_store_for_dump_config.push_back(line); } else if (action == "highlight-article") { @@ -133,7 +132,7 @@ void regexmanager::handle_action(const std::string& action, const std::vector m(new matcher()); + std::shared_ptr m(new matcher()); if (!m->parse(params[0])) { throw confighandlerexception(utils::strprintf(_("couldn't parse filter expression `%s': %s"), params[0].c_str(), m->get_parse_error().c_str())); } @@ -143,16 +142,16 @@ void regexmanager::handle_action(const std::string& action, const std::vector, int>(m, pos)); + matchers.push_back(std::pair, int>(m, pos)); } else throw confighandlerexception(AHS_INVALID_COMMAND); } int regexmanager::article_matches(matchable * item) { - for (std::vector, int> >::iterator it=matchers.begin();it!=matchers.end();++it) { - if (it->first->matches(item)) { - return it->second; + for (auto matcher : matchers) { + if (matcher.first->matches(item)) { + return matcher.second; } } return -1; @@ -161,10 +160,7 @@ int regexmanager::article_matches(matchable * item) { void regexmanager::remove_last_regex(const std::string& location) { std::vector& regexes = locations[location].first; - std::vector::iterator it=regexes.begin(); - for (unsigned int i=0;i& regexes = locations[location].first; unsigned int i = 0; - for (std::vector::iterator it=regexes.begin();it!=regexes.end();++it, ++i) { - if (!*it) + for (auto regex : regexes) { + if (!regex) continue; std::string initial_marker = extract_initial_marker(str); regmatch_t pmatch; unsigned int offset = 0; - int err = regexec(*it, str.c_str(), 1, &pmatch, 0); + int err = regexec(regex, str.c_str(), 1, &pmatch, 0); while (err == 0) { // LOG(LOG_DEBUG, "regexmanager::quote_and_highlight: matched %s rm_so = %u rm_eo = %u", str.c_str() + offset, pmatch.rm_so, pmatch.rm_eo); std::string marker = utils::strprintf("<%u>", i); @@ -202,8 +198,9 @@ void regexmanager::quote_and_highlight(std::string& str, const std::string& loca str.insert(offset + pmatch.rm_so, marker); // LOG(LOG_DEBUG, "after second insert: %s", str.c_str()); offset += pmatch.rm_eo + marker.length() + strlen("") + initial_marker.length(); - err = regexec(*it, str.c_str() + offset, 1, &pmatch, 0); + err = regexec(regex, str.c_str() + offset, 1, &pmatch, 0); } + i++; } } diff --git a/src/reloadthread.cpp b/src/reloadthread.cpp index dcf41e99..96e57751 100644 --- a/src/reloadthread.cpp +++ b/src/reloadthread.cpp @@ -10,7 +10,7 @@ reloadthread::reloadthread(controller * c, configcontainer * cf) : ctrl(c), oldt reloadthread::~reloadthread() { } -void reloadthread::run() { +void reloadthread::operator()() { for (;;) { oldtime = time(NULL); LOG(LOG_INFO,"reloadthread: starting reload"); diff --git a/src/rss.cpp b/src/rss.cpp index 4e5cab5d..9c6d241f 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -119,10 +119,10 @@ std::string rss_item::pubDate() const { } unsigned int rss_feed::unread_item_count() { - scope_mutex lock(&item_mutex); + std::lock_guard lock(item_mutex); unsigned int count = 0; - for (std::vector >::const_iterator it=items_.begin();it!=items_.end();++it) { - if ((*it)->unread()) + for (auto item : items_) { + if (item->unread()) ++count; } return count; @@ -130,8 +130,8 @@ unsigned int rss_feed::unread_item_count() { bool rss_feed::matches_tag(const std::string& tag) { - for (std::vector::iterator it=tags_.begin();it!=tags_.end();++it) { - if (tag == *it) + for (auto t : tags_) { + if (tag == t) return true; } return false; @@ -145,9 +145,9 @@ std::string rss_feed::get_firsttag() { std::string rss_feed::get_tags() { std::string tags; - for (std::vector::iterator it=tags_.begin();it!=tags_.end();++it) { - if (it->substr(0,1) != "~" && it->substr(0,1) != "!") { - tags.append(*it); + for (auto t : tags_) { + if (t.substr(0,1) != "~" && t.substr(0,1) != "!") { + tags.append(t); tags.append(" "); } } @@ -156,8 +156,8 @@ std::string rss_feed::get_tags() { void rss_feed::set_tags(const std::vector& tags) { tags_.clear(); - for (std::vector::const_iterator it=tags.begin();it!=tags.end();++it) { - tags_.push_back(*it); + for (auto tag : tags) { + tags_.push_back(tag); } } @@ -187,10 +187,10 @@ std::string rss_item::description() const { std::string rss_feed::title() const { bool found_title = false; std::string alt_title; - for (std::vector::const_iterator it=tags_.begin();it!=tags_.end();++it) { - if (it->substr(0,1) == "~") { + for (auto tag : tags_) { + if (tag.substr(0,1) == "~" || tag.substr(0,1) == "!") { found_title = true; - alt_title = it->substr(1, it->length()-1); + alt_title = tag.substr(1, tag.length()-1); break; } } @@ -202,32 +202,28 @@ std::string rss_feed::description() const { } bool rss_feed::hidden() const { - for (std::vector::const_iterator it=tags_.begin();it!=tags_.end();++it) { - if (it->substr(0,1) == "!") { + for (auto tag : tags_) { + if (tag.substr(0,1) == "!") { return true; } } return false; } -std::tr1::shared_ptr rss_feed::get_item_by_guid(const std::string& guid) { - scope_mutex lock(&item_mutex); +std::shared_ptr rss_feed::get_item_by_guid(const std::string& guid) { + std::lock_guard lock(item_mutex); return get_item_by_guid_unlocked(guid); } -std::tr1::shared_ptr rss_feed::get_item_by_guid_unlocked(const std::string& guid) { - LOG(LOG_DEBUG, "get_item_by_guid_unlocked: guid = %s", guid.c_str()); - { - scope_mutex lock(&items_guid_map_mutex); - std::tr1::unordered_map >::const_iterator it; - if ((it = items_guid_map.find(guid)) != items_guid_map.end()) { - return it->second; - } +std::shared_ptr rss_feed::get_item_by_guid_unlocked(const std::string& guid) { + auto it = items_guid_map.find(guid); + if (it != items_guid_map.end()) { + return it->second; } - //abort(); LOG(LOG_DEBUG, "rss_feed::get_item_by_guid_unlocked: hit dummy item!"); LOG(LOG_DEBUG, "rss_feed::get_item_by_guid_unlocked: items_guid_map.size = %d", items_guid_map.size()); - return std::tr1::shared_ptr(new rss_item(ch)); + // abort(); + return std::shared_ptr(new rss_item(ch)); // should never happen! } bool rss_item::has_attribute(const std::string& attribname) { @@ -301,7 +297,7 @@ void rss_item::set_flags(const std::string& ff) { void rss_item::sort_flags() { std::sort(flags_.begin(), flags_.end()); - for (std::string::iterator it=flags_.begin();flags_.size() > 0 && it!=flags_.end();++it) { + for (auto it=flags_.begin();flags_.size() > 0 && it!=flags_.end();++it) { if (!isalpha(*it)) { flags_.erase(it); it = flags_.begin(); @@ -366,47 +362,47 @@ void rss_ignores::handle_action(const std::string& action, const std::vector::const_iterator it=params.begin();it!=params.end();++it) { - ignores_lastmodified.push_back(*it); + for (auto param : params) { + ignores_lastmodified.push_back(param); } } else if (action == "reset-unread-on-update") { - for (std::vector::const_iterator it=params.begin();it!=params.end();++it) { - resetflag.push_back(*it); + for (auto param : params) { + resetflag.push_back(param); } } else throw confighandlerexception(AHS_INVALID_COMMAND); } void rss_ignores::dump_config(std::vector& config_output) { - for (std::vector::iterator it = ignores.begin();it!=ignores.end();++it) { + for (auto ign : ignores) { std::string configline = "ignore-article "; - if (it->first == "*") + if (ign.first == "*") configline.append("*"); else - configline.append(utils::quote(it->first)); + configline.append(utils::quote(ign.first)); configline.append(" "); - configline.append(utils::quote(it->second->get_expression())); + configline.append(utils::quote(ign.second->get_expression())); config_output.push_back(configline); } - for (std::vector::iterator it=ignores_lastmodified.begin();it!=ignores_lastmodified.end();++it) { - config_output.push_back(utils::strprintf("always-download %s", utils::quote(*it).c_str())); + for (auto ign_lm : ignores_lastmodified) { + config_output.push_back(utils::strprintf("always-download %s", utils::quote(ign_lm).c_str())); } - for (std::vector::iterator it=resetflag.begin();it!=resetflag.end();++it) { - config_output.push_back(utils::strprintf("reset-unread-on-update %s", utils::quote(*it).c_str())); + for (auto rf : resetflag) { + config_output.push_back(utils::strprintf("reset-unread-on-update %s", utils::quote(rf).c_str())); } } rss_ignores::~rss_ignores() { - for (std::vector::iterator it=ignores.begin();it!=ignores.end();++it) { - delete it->second; + for (auto ign : ignores) { + delete ign.second; } } bool rss_ignores::matches(rss_item* item) { - for (std::vector::iterator it=ignores.begin();it!=ignores.end();++it) { - LOG(LOG_DEBUG, "rss_ignores::matches: it->first = `%s' item->feedurl = `%s'", it->first.c_str(), item->feedurl().c_str()); - if (it->first == "*" || item->feedurl() == it->first) { - if (it->second->matches(item)) { + for (auto ign : ignores) { + LOG(LOG_DEBUG, "rss_ignores::matches: ign.first = `%s' item->feedurl = `%s'", ign.first.c_str(), item->feedurl().c_str()); + if (ign.first == "*" || item->feedurl() == ign.first) { + if (ign.second->matches(item)) { LOG(LOG_DEBUG, "rss_ignores::matches: found match"); return true; } @@ -416,23 +412,23 @@ bool rss_ignores::matches(rss_item* item) { } bool rss_ignores::matches_lastmodified(const std::string& url) { - for (std::vector::iterator it=ignores_lastmodified.begin();it!=ignores_lastmodified.end();++it) { - if (url == *it) + for (auto ignore_url : ignores_lastmodified) { + if (url == ignore_url) return true; } return false; } bool rss_ignores::matches_resetunread(const std::string& url) { - for (std::vector::iterator it=resetflag.begin();it!=resetflag.end();++it) { - if (url == *it) + for (auto rf : resetflag) { + if (url == rf) return true; } return false; } -void rss_feed::update_items(std::vector > feeds) { - scope_mutex lock(&item_mutex); +void rss_feed::update_items(std::vector> feeds) { + std::lock_guard lock(item_mutex); if (query.length() == 0) return; @@ -445,19 +441,16 @@ void rss_feed::update_items(std::vector > feeds) matcher m(query); items_.clear(); - { - scope_mutex lock(&items_guid_map_mutex); - items_guid_map.clear(); - - for (std::vector >::iterator it=feeds.begin();it!=feeds.end();++it) { - if ((*it)->rssurl().substr(0,6) != "query:") { // don't fetch items from other query feeds! - for (std::vector >::iterator jt=(*it)->items().begin();jt!=(*it)->items().end();++jt) { - if (m.matches(jt->get())) { - LOG(LOG_DEBUG, "rss_feed::update_items: matcher matches!"); - (*jt)->set_feedptr(*it); - items_.push_back(*jt); - items_guid_map[(*jt)->guid()] = *jt; - } + items_guid_map.clear(); + + for (auto feed : feeds) { + if (feed->rssurl().substr(0,6) != "query:") { // don't fetch items from other query feeds! + for (auto item : feed->items()) { + if (m.matches(item.get())) { + LOG(LOG_DEBUG, "rss_feed::update_items: matcher matches!"); + item->set_feedptr(feed); + items_.push_back(item); + items_guid_map[item->guid()] = item; } } } @@ -487,56 +480,8 @@ void rss_feed::set_rssurl(const std::string& u) { } } -struct sort_item_by_title : public std::binary_function, std::tr1::shared_ptr, bool> { - bool reverse; - sort_item_by_title(bool b) : reverse(b) { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return reverse ? (strcasecmp(a->title().c_str(), b->title().c_str()) > 0) : (strcasecmp(a->title().c_str(), b->title().c_str()) < 0); - } -}; - -struct sort_item_by_flags : public std::binary_function, std::tr1::shared_ptr, bool> { - bool reverse; - sort_item_by_flags(bool b) : reverse(b) { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return reverse ? (strcmp(a->flags().c_str(), b->flags().c_str()) > 0) : (strcmp(a->flags().c_str(), b->flags().c_str()) < 0); - } -}; - -struct sort_item_by_author : public std::binary_function, std::tr1::shared_ptr, bool> { - bool reverse; - sort_item_by_author(bool b) : reverse(b) { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return reverse ? (strcmp(a->author().c_str(), b->author().c_str()) > 0) : (strcmp(a->author().c_str(), b->author().c_str()) < 0); - } -}; - -struct sort_item_by_link : public std::binary_function, std::tr1::shared_ptr, bool> { - bool reverse; - sort_item_by_link(bool b) : reverse(b) { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return reverse ? (strcmp(a->link().c_str(), b->link().c_str()) > 0) : (strcmp(a->link().c_str(), b->link().c_str()) < 0); - } -}; - -struct sort_item_by_guid : public std::binary_function, std::tr1::shared_ptr, bool> { - bool reverse; - sort_item_by_guid(bool b) : reverse(b) { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return reverse ? (strcmp(a->guid().c_str(), b->guid().c_str()) > 0) : (strcmp(a->guid().c_str(), b->guid().c_str()) < 0); - } -}; - -struct sort_item_by_date : public std::binary_function, std::tr1::shared_ptr, bool> { - bool reverse; - sort_item_by_date(bool b) : reverse(b) { } - bool operator()(std::tr1::shared_ptr a, std::tr1::shared_ptr b) { - return reverse ? (a->pubDate_timestamp() > b->pubDate_timestamp()) : (a->pubDate_timestamp() < b->pubDate_timestamp()); - } -}; - void rss_feed::sort(const std::string& method) { - scope_mutex lock(&item_mutex); + std::lock_guard lock(item_mutex); sort_unlocked(method); } @@ -556,38 +501,50 @@ void rss_feed::sort_unlocked(const std::string& method) { if (!methods.empty()) { if (methods[0] == "title") { - std::stable_sort(items_.begin(), items_.end(), sort_item_by_title(reverse)); + std::stable_sort(items_.begin(), items_.end(), [&](std::shared_ptr a, std::shared_ptr b) { + return reverse ? (strcasecmp(a->title().c_str(), b->title().c_str()) > 0) : (strcasecmp(a->title().c_str(), b->title().c_str()) < 0); + }); } else if (methods[0] == "flags") { - std::stable_sort(items_.begin(), items_.end(), sort_item_by_flags(reverse)); + std::stable_sort(items_.begin(), items_.end(), [&](std::shared_ptr a, std::shared_ptr b) { + return reverse ? (strcmp(a->flags().c_str(), b->flags().c_str()) > 0) : (strcmp(a->flags().c_str(), b->flags().c_str()) < 0); + }); } else if (methods[0] == "author") { - std::stable_sort(items_.begin(), items_.end(), sort_item_by_author(reverse)); + std::stable_sort(items_.begin(), items_.end(), [&](std::shared_ptr a, std::shared_ptr b) { + return reverse ? (strcmp(a->author().c_str(), b->author().c_str()) > 0) : (strcmp(a->author().c_str(), b->author().c_str()) < 0); + }); } else if (methods[0] == "link") { - std::stable_sort(items_.begin(), items_.end(), sort_item_by_link(reverse)); + std::stable_sort(items_.begin(), items_.end(), [&](std::shared_ptr a, std::shared_ptr b) { + return reverse ? (strcmp(a->link().c_str(), b->link().c_str()) > 0) : (strcmp(a->link().c_str(), b->link().c_str()) < 0); + }); } else if (methods[0] == "guid") { - std::stable_sort(items_.begin(), items_.end(), sort_item_by_guid(reverse)); + std::stable_sort(items_.begin(), items_.end(), [&](std::shared_ptr a, std::shared_ptr b) { + return reverse ? (strcmp(a->guid().c_str(), b->guid().c_str()) > 0) : (strcmp(a->guid().c_str(), b->guid().c_str()) < 0); + }); } else if (methods[0] == "date") { - std::stable_sort(items_.begin(), items_.end(), sort_item_by_date(reverse)); + std::stable_sort(items_.begin(), items_.end(), [&](std::shared_ptr a, std::shared_ptr b) { + return reverse ? (a->pubDate_timestamp() > b->pubDate_timestamp()) : (a->pubDate_timestamp() < b->pubDate_timestamp()); + }); } } } void rss_feed::remove_old_deleted_items() { - scope_mutex lock(&item_mutex); + std::lock_guard lock(item_mutex); std::vector guids; - for (std::vector >::iterator it=items_.begin();it!=items_.end();++it) { - guids.push_back((*it)->guid()); + for (auto item : items_) { + guids.push_back(item->guid()); } ch->remove_old_deleted_items(rssurl_, guids); } void rss_feed::purge_deleted_items() { - scope_mutex lock(&item_mutex); + std::lock_guard lock(item_mutex); scope_measure m1("rss_feed::purge_deleted_items"); - std::vector >::iterator it=items_.begin(); + auto it=items_.begin(); while (it!=items_.end()) { if ((*it)->deleted()) { { - scope_mutex lock2(&items_guid_map_mutex); + std::lock_guard lock2(items_guid_map_mutex); items_guid_map.erase((*it)->guid()); } items_.erase(it); @@ -598,14 +555,14 @@ void rss_feed::purge_deleted_items() { } } -void rss_feed::set_feedptrs(std::tr1::shared_ptr self) { - scope_mutex lock(&item_mutex); - for (std::vector >::iterator it=items_.begin();it!=items_.end();++it) { - (*it)->set_feedptr(self); +void rss_feed::set_feedptrs(std::shared_ptr self) { + std::lock_guard lock(item_mutex); + for (auto item : items_) { + item->set_feedptr(self); } } -void rss_item::set_feedptr(std::tr1::shared_ptr ptr) { +void rss_item::set_feedptr(std::shared_ptr ptr) { feedptr = ptr; } @@ -620,14 +577,14 @@ std::string rss_feed::get_status() { } void rss_feed::unload() { - scope_mutex lock(&item_mutex); - for (std::vector >::iterator it=items_.begin();it!=items_.end();++it) { - (*it)->unload(); + std::lock_guard lock(item_mutex); + for (auto item : items_) { + item->unload(); } } void rss_feed::load() { - scope_mutex lock(&item_mutex); + std::lock_guard lock(item_mutex); ch->fetch_descriptions(this); } diff --git a/src/rss_parser.cpp b/src/rss_parser.cpp index b6ba5d80..9ec78bfb 100644 --- a/src/rss_parser.cpp +++ b/src/rss_parser.cpp @@ -28,8 +28,8 @@ rss_parser::rss_parser(const std::string& uri, cache * c, configcontainer * cfg, rss_parser::~rss_parser() { } -std::tr1::shared_ptr rss_parser::parse() { - std::tr1::shared_ptr feed(new rss_feed(ch)); +std::shared_ptr rss_parser::parse() { + std::shared_ptr feed(new rss_feed(ch)); feed->set_rssurl(my_uri); @@ -86,7 +86,7 @@ std::string rss_parser::render_xhtml_title(const std::string& title, const std:: return ""; } -void rss_parser::set_rtl(std::tr1::shared_ptr feed, const char * lang) { +void rss_parser::set_rtl(std::shared_ptr feed, const char * lang) { // we implement right-to-left support for the languages listed in // http://blogs.msdn.com/rssteam/archive/2007/05/17/reading-feeds-in-right-to-left-order.aspx static const char * rtl_langprefix[] = { @@ -223,7 +223,7 @@ void rss_parser::download_filterplugin(const std::string& filter, const std::str LOG(LOG_DEBUG, "rss_parser::parse: filterplugin %s, is_valid = %s", filter.c_str(), is_valid ? "true" : "false"); } -void rss_parser::fill_feed_fields(std::tr1::shared_ptr feed) { +void rss_parser::fill_feed_fields(std::shared_ptr feed) { /* * we fill all the feed members with the appropriate values from the rsspp data structure */ @@ -247,33 +247,33 @@ void rss_parser::fill_feed_fields(std::tr1::shared_ptr feed) { LOG(LOG_DEBUG, "rss_parser::parse: feed title = `%s' link = `%s'", feed->title().c_str(), feed->link().c_str()); } -void rss_parser::fill_feed_items(std::tr1::shared_ptr feed) { +void rss_parser::fill_feed_items(std::shared_ptr feed) { /* * we iterate over all items of a feed, create an rss_item object for * each item, and fill it with the appropriate values from the data structure. */ - for (std::vector::iterator item=f.items.begin();item!=f.items.end();++item) { - std::tr1::shared_ptr x(new rss_item(ch)); + for (auto item : f.items) { + std::shared_ptr x(new rss_item(ch)); - set_item_title(feed, x, *item); + set_item_title(feed, x, item); - if (item->link != "") { - x->set_link(utils::absolute_url(feed->link(), item->link)); + if (item.link != "") { + x->set_link(utils::absolute_url(feed->link(), item.link)); } - if (x->link().empty() && item->guid_isPermaLink) { - x->set_link(item->guid); + if (x->link().empty() && item.guid_isPermaLink) { + x->set_link(item.guid); } - set_item_author(x, *item); + set_item_author(x, item); x->set_feedurl(feed->rssurl()); - x->set_feedptr(feed); + x->set_feedptr(feed); + + if ((f.rss_version == rsspp::ATOM_1_0 || f.rss_version == rsspp::TTRSS_JSON || f.rss_version == rsspp::NEWSBLUR_JSON) && item.labels.size() > 0) { + auto start = item.labels.begin(); + auto finish = item.labels.end(); - if ((f.rss_version == rsspp::ATOM_1_0 || f.rss_version == rsspp::TTRSS_JSON || f.rss_version == rsspp::NEWSBLUR_JSON) && item->labels.size() > 0) { - std::vector::const_iterator start, finish; - start = item->labels.begin(); - finish = item->labels.end(); if (std::find(start, finish, "fresh") != finish) { x->set_unread_nowrite(true); x->set_override_unread(true); @@ -304,18 +304,18 @@ void rss_parser::fill_feed_items(std::tr1::shared_ptr feed) { } } - set_item_content(x, *item); + set_item_content(x, item); - if (item->pubDate != "") - x->set_pubDate(parse_date(item->pubDate)); + if (item.pubDate != "") + x->set_pubDate(parse_date(item.pubDate)); else x->set_pubDate(::time(NULL)); - x->set_guid(get_guid(*item)); + x->set_guid(get_guid(item)); - x->set_base(item->base); + x->set_base(item.base); - set_item_enclosure(x, *item); + set_item_enclosure(x, item); LOG(LOG_DEBUG, "rss_parser::parse: item title = `%s' link = `%s' pubDate = `%s' (%d) description = `%s'", x->title().c_str(), x->link().c_str(), x->pubDate().c_str(), x->pubDate_timestamp(), x->description().c_str()); @@ -324,7 +324,7 @@ void rss_parser::fill_feed_items(std::tr1::shared_ptr feed) { } } -void rss_parser::set_item_title(std::tr1::shared_ptr feed, std::tr1::shared_ptr x, rsspp::item& item) { +void rss_parser::set_item_title(std::shared_ptr feed, std::shared_ptr x, rsspp::item& item) { if (is_html_type(item.title_type)) { x->set_title(render_xhtml_title(item.title, feed->link())); } else { @@ -334,7 +334,7 @@ void rss_parser::set_item_title(std::tr1::shared_ptr feed, std::tr1::s } } -void rss_parser::set_item_author(std::tr1::shared_ptr x, rsspp::item& item) { +void rss_parser::set_item_author(std::shared_ptr x, rsspp::item& item) { /* * some feeds only have a feed-wide managingEditor, which we use as an item's * author if there is no item-specific one available. @@ -350,7 +350,7 @@ void rss_parser::set_item_author(std::tr1::shared_ptr x, rsspp::item& } } -void rss_parser::set_item_content(std::tr1::shared_ptr x, rsspp::item& item) { +void rss_parser::set_item_content(std::shared_ptr x, rsspp::item& item) { handle_content_encoded(x, item); @@ -392,14 +392,14 @@ std::string rss_parser::get_guid(rsspp::item& item) { return ""; // too bad. } -void rss_parser::set_item_enclosure(std::tr1::shared_ptr x, rsspp::item& item) { +void rss_parser::set_item_enclosure(std::shared_ptr x, rsspp::item& item) { x->set_enclosure_url(item.enclosure_url); x->set_enclosure_type(item.enclosure_type); LOG(LOG_DEBUG, "rss_parser::parse: found enclosure_url: %s", item.enclosure_url.c_str()); LOG(LOG_DEBUG, "rss_parser::parse: found enclosure_type: %s", item.enclosure_type.c_str()); } -void rss_parser::add_item_to_feed(std::tr1::shared_ptr feed, std::tr1::shared_ptr item) { +void rss_parser::add_item_to_feed(std::shared_ptr feed, std::shared_ptr item) { // only add item to feed if it isn't on the ignore list or if there is no ignore list if (!ign || !ign->matches(item.get())) { feed->add_item(item); @@ -409,7 +409,7 @@ void rss_parser::add_item_to_feed(std::tr1::shared_ptr feed, std::tr1: } } -void rss_parser::handle_content_encoded(std::tr1::shared_ptr x, rsspp::item& item) { +void rss_parser::handle_content_encoded(std::shared_ptr x, rsspp::item& item) { if (x->description() != "") return; @@ -421,7 +421,7 @@ void rss_parser::handle_content_encoded(std::tr1::shared_ptr x, rsspp: } } -void rss_parser::handle_itunes_summary(std::tr1::shared_ptr x, rsspp::item& item) { +void rss_parser::handle_itunes_summary(std::shared_ptr x, rsspp::item& item) { if (x->description() != "") return; diff --git a/src/select_formaction.cpp b/src/select_formaction.cpp index a9bb6e19..9e59fa2e 100644 --- a/src/select_formaction.cpp +++ b/src/select_formaction.cpp @@ -90,16 +90,17 @@ void select_formaction::prepare() { unsigned int i=0; switch (type) { case SELECTTAG: - for (std::vector::const_iterator it=tags.begin();it!=tags.end();++it,++i) { - LOG(LOG_DEBUG, "select_formaction::prepare: tag = %s", it->c_str()); - std::string tagstr = utils::strprintf("%4u %s (%u)", i+1, it->c_str(), v->get_ctrl()->get_feed_count_per_tag(*it)); + for (auto tag : tags) { + std::string tagstr = utils::strprintf("%4u %s (%u)", i+1, tag.c_str(), v->get_ctrl()->get_feed_count_per_tag(tag)); listfmt.add_line(tagstr, i); + i++; } break; case SELECTFILTER: - for (std::vector::const_iterator it=filters.begin();it!=filters.end();++it,++i) { - std::string tagstr = utils::strprintf("%4u %s", i+1, it->first.c_str()); + for (auto filter : filters) { + std::string tagstr = utils::strprintf("%4u %s", i+1, filter.first.c_str()); listfmt.add_line(tagstr, i); + i++; } break; default: diff --git a/src/stflpp.cpp b/src/stflpp.cpp index adae3cf3..fb6dcaea 100644 --- a/src/stflpp.cpp +++ b/src/stflpp.cpp @@ -78,10 +78,10 @@ void stfl::reset() { stfl_reset(); } -static mutex quote_mtx; +static std::mutex quote_mtx; std::string stfl::quote(const std::string& text) { - scope_mutex lock("e_mtx); + std::lock_guard lock(quote_mtx); stfl_ipool * ipool = stfl_ipool_create((std::string(nl_langinfo(CODESET)) + "//TRANSLIT").c_str()); std::string retval = stfl_ipool_fromwc(ipool,stfl_quote(stfl_ipool_towc(ipool,text.c_str()))); stfl_ipool_destroy(ipool); diff --git a/src/tagsouppullparser.cpp b/src/tagsouppullparser.cpp index c5ed72ea..db33e0bf 100644 --- a/src/tagsouppullparser.cpp +++ b/src/tagsouppullparser.cpp @@ -34,11 +34,11 @@ void tagsouppullparser::setInput(std::istream& is) { } std::string tagsouppullparser::getAttributeValue(const std::string& name) const { - for (std::vector::const_iterator it=attributes.begin();it!=attributes.end();++it) { - if (it->first == name) { - return it->second; - } - } + for (auto attr : attributes) { + if (attr.first == name) { + return attr.second; + } + } throw std::invalid_argument(_("attribute not found")); } diff --git a/src/thread.cpp b/src/thread.cpp deleted file mode 100644 index f4924c0a..00000000 --- a/src/thread.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -namespace newsbeuter { - -/* - * The thread class is a wrapper around the pthread functions found on virtually - * all modern Unix systems. - * - * To run a thread, you need to derive your own class from thread and implement the - * run() method. Then you create an instance of your derived class with the new - * operator (very important!), and run the start() method of the object. - */ - - -thread::thread() { -} - -thread::~thread() { - -} - -pthread_t thread::start() { - int rc = pthread_create(&pt, 0, run_thread, this); - LOG(LOG_DEBUG, "thread::start: created new thread %d rc = %d", pt, rc); - if (rc != 0) { - throw exception(rc); - } - return pt; -} - -void thread::join() { - pthread_join(pt, NULL); -} - -void thread::detach() { - LOG(LOG_DEBUG, "thread::detach: detaching thread %d", pt); - pthread_detach(pt); -} - -void * run_thread(void * p) { - thread * t = reinterpret_cast(p); - LOG(LOG_DEBUG, "run_thread: p = %p", p); - t->run(); - delete t; - return 0; -} - -void thread::cleanup(thread * p) { - delete p; -} - -} diff --git a/src/ttrss_api.cpp b/src/ttrss_api.cpp index 60536b41..1f97a9ac 100644 --- a/src/ttrss_api.cpp +++ b/src/ttrss_api.cpp @@ -23,7 +23,7 @@ ttrss_api::~ttrss_api() { } bool ttrss_api::authenticate() { - if (auth_lock.trylock()) { + if (auth_lock.try_lock()) { sid = retrieve_sid(); auth_lock.unlock(); } else { @@ -103,8 +103,8 @@ struct json_object * ttrss_api::run_op(const std::string& op, std::string req_data = "{\"op\":\"" + op + "\",\"sid\":\"" + sid + "\""; - for (std::map::const_iterator it = args.begin(); it != args.end(); it++) { - req_data += ",\"" + it->first + "\":\"" + it->second + "\""; + for (auto arg : args) { + req_data += ",\"" + arg.first + "\":\"" + arg.second + "\""; } req_data += "}"; @@ -200,8 +200,8 @@ bool ttrss_api::mark_article_read(const std::string& guid, bool read) { // Do this in a thread, as we don't care about the result enough to wait for // it. - thread * mrt = new markreadthread( this, guid, read ); - mrt->start(); + std::thread t{markreadthread(this, guid, read)}; + t.detach(); return true; } @@ -230,10 +230,6 @@ bool ttrss_api::update_article_flags(const std::string& oldflags, const std::str return success; } -static bool sort_by_pubdate(const rsspp::item& a, const rsspp::item& b) { - return a.pubDate_ts > b.pubDate_ts; -} - rsspp::feed ttrss_api::fetch_feed(const std::string& id) { rsspp::feed f; @@ -308,7 +304,9 @@ rsspp::feed ttrss_api::fetch_feed(const std::string& id) { f.items.push_back(item); } - std::sort(f.items.begin(), f.items.end(), sort_by_pubdate); + std::sort(f.items.begin(), f.items.end(), [](const rsspp::item& a, const rsspp::item& b) { + return a.pubDate_ts > b.pubDate_ts; + }); json_object_put(content); return f; diff --git a/src/ttrss_urlreader.cpp b/src/ttrss_urlreader.cpp index f23f71dd..be3b6d20 100644 --- a/src/ttrss_urlreader.cpp +++ b/src/ttrss_urlreader.cpp @@ -19,27 +19,28 @@ void ttrss_urlreader::reload() { file_urlreader ur(file); ur.reload(); - std::vector& file_urls(ur.get_urls()); - for(std::vector::iterator it=file_urls.begin();it!=file_urls.end();++it) { - if (it->substr(0,6) == "query:") { - urls.push_back(*it); - std::vector& file_tags(ur.get_tags(*it)); - tags[*it] = ur.get_tags(*it); - for (std::vector::iterator jt=file_tags.begin();jt!=file_tags.end();++jt) { - alltags.insert(*jt); + //std::vector& file_urls(ur.get_urls()); + auto& file_urls(ur.get_urls()); + for (auto url : file_urls) { + if (url.substr(0,6) == "query:") { + urls.push_back(url); + std::vector& file_tags(ur.get_tags(url)); + tags[url] = ur.get_tags(url); + for (auto tag : file_tags) { + alltags.insert(tag); } } } - std::vector feedurls = api->get_subscribed_urls(); + auto feedurls = api->get_subscribed_urls(); - for (std::vector::iterator it=feedurls.begin();it!=feedurls.end();++it) { - LOG(LOG_DEBUG, "added %s to URL list", it->first.c_str()); - urls.push_back(it->first); - tags[it->first] = it->second; - for (std::vector::iterator jt=it->second.begin();jt!=it->second.end();++jt) { - LOG(LOG_DEBUG, "%s: added tag %s", it->first.c_str(), jt->c_str()); - alltags.insert(*jt); + for (auto url : feedurls) { + LOG(LOG_DEBUG, "added %s to URL list", url.first.c_str()); + urls.push_back(url.first); + tags[url.first] = url.second; + for (auto tag : url.second) { + LOG(LOG_DEBUG, "%s: added tag %s", url.first.c_str(), tag.c_str()); + alltags.insert(tag); } } } diff --git a/src/urlreader.cpp b/src/urlreader.cpp index bcc1f713..dffcfecc 100644 --- a/src/urlreader.cpp +++ b/src/urlreader.cpp @@ -22,9 +22,9 @@ std::vector& urlreader::get_tags(const std::string& url) { std::vector urlreader::get_alltags() { std::vector tmptags; - for (std::set::iterator it=alltags.begin();it!=alltags.end();++it) { - if (it->substr(0,1) != "~") - tmptags.push_back(*it); + for (auto t : alltags) { + if (t.substr(0,1) != "~") + tmptags.push_back(t); } return tmptags; } @@ -59,8 +59,8 @@ void file_urlreader::reload() { tokens.erase(tokens.begin()); if (!tokens.empty()) { tags[url] = tokens; - for (std::vector::iterator it=tokens.begin();it!=tokens.end();++it) { - alltags.insert(*it); + for (auto token : tokens) { + alltags.insert(token); } } } @@ -78,11 +78,11 @@ void file_urlreader::write_config() { std::fstream f; f.open(filename.c_str(),std::fstream::out); if (f.is_open()) { - for (std::vector::iterator it=urls.begin(); it != urls.end(); ++it) { - f << *it; - if (tags[*it].size() > 0) { - for (std::vector::iterator jt=tags[*it].begin();jt!=tags[*it].end();++jt) { - f << " \"" << *jt << "\""; + for (auto url : urls) { + f << url; + if (tags[url].size() > 0) { + for (auto tag : tags[url]) { + f << " \"" << tag << "\""; } } f << std::endl; @@ -112,9 +112,9 @@ void opml_urlreader::reload() { std::vector urls = utils::tokenize_quoted(this->get_source(), " "); - for (std::vector::iterator it=urls.begin();it!=urls.end();++it) { - LOG(LOG_DEBUG, "opml_urlreader::reload: downloading `%s'", it->c_str()); - std::string urlcontent = utils::retrieve_url(*it, cfg, this->get_auth()); + for (auto url : urls) { + LOG(LOG_DEBUG, "opml_urlreader::reload: downloading `%s'", url.c_str()); + std::string urlcontent = utils::retrieve_url(url, cfg, this->get_auth()); xmlDoc * doc = xmlParseMemory(urlcontent.c_str(), urlcontent.length()); diff --git a/src/urlview_formaction.cpp b/src/urlview_formaction.cpp index 71594025..d5255780 100644 --- a/src/urlview_formaction.cpp +++ b/src/urlview_formaction.cpp @@ -94,8 +94,9 @@ void urlview_formaction::prepare() { if (do_redraw) { listformatter listfmt; unsigned int i=0; - for (std::vector::iterator it = links.begin(); it != links.end(); ++it, ++i) { - listfmt.add_line(utils::strprintf("%2u %s",i+1,it->first.c_str()), i); + for (auto link : links) { + listfmt.add_line(utils::strprintf("%2u %s",i+1,link.first.c_str()), i); + i++; } f->modify("urls","replace_inner", listfmt.format_list()); } diff --git a/src/utils.cpp b/src/utils.cpp index 5e1347b9..37d63e0d 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -622,8 +622,8 @@ bool utils::is_valid_attribute(const std::string& attrib) { return false; } -std::vector > utils::partition_indexes(unsigned int start, unsigned int end, unsigned int parts) { - std::vector > partitions; +std::vector> utils::partition_indexes(unsigned int start, unsigned int end, unsigned int parts) { + std::vector> partitions; unsigned int count = end - start + 1; unsigned int size = count / parts; @@ -683,8 +683,8 @@ size_t utils::wcswidth_stfl(const std::wstring& str, size_t size) { std::string utils::join(const std::vector& strings, const std::string& separator) { std::string result; - for (std::vector::const_iterator it=strings.begin();it!=strings.end();++it) { - result.append(*it); + for (auto str : strings) { + result.append(str); result.append(separator); } @@ -920,7 +920,7 @@ std::wstring utils::clean_nonprintable_characters(std::wstring text) { */ #if HAVE_OPENSSL -static mutex * openssl_mutexes = NULL; +static std::mutex * openssl_mutexes = NULL; static int openssl_mutexes_size = 0; static void openssl_mth_locking_function(int mode, int n, const char * file, int line) { @@ -945,7 +945,7 @@ static unsigned long openssl_mth_id_function(void) { void utils::initialize_ssl_implementation(void) { #if HAVE_OPENSSL openssl_mutexes_size = CRYPTO_num_locks(); - openssl_mutexes = new mutex[openssl_mutexes_size]; + openssl_mutexes = new std::mutex[openssl_mutexes_size]; CRYPTO_set_id_callback(openssl_mth_id_function); CRYPTO_set_locking_callback(openssl_mth_locking_function); #endif diff --git a/src/view.cpp b/src/view.cpp index 6d0bb20e..cacecf77 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -55,13 +55,11 @@ extern "C" { namespace newsbeuter { -view::view(controller * c) : ctrl(c), cfg(0), keys(0), mtx(0), current_formaction(0), is_inside_qna(false), is_inside_cmdline(false), tab_count(0) { - mtx = new mutex(); +view::view(controller * c) : ctrl(c), cfg(0), keys(0), current_formaction(0), is_inside_qna(false), is_inside_cmdline(false), tab_count(0) { } view::~view() { stfl::reset(); - delete mtx; } void view::set_config_container(configcontainer * cfgcontainer) { @@ -74,14 +72,14 @@ void view::set_keymap(keymap * k) { void view::update_bindings() { - for (std::vector >::iterator it=formaction_stack.begin();it!=formaction_stack.end();++it) { - if (*it) { - set_bindings(*it); + for (auto& form : formaction_stack) { + if (form) { + set_bindings(form); } } } -void view::set_bindings(std::tr1::shared_ptr fa) { +void view::set_bindings(std::shared_ptr fa) { std::string upkey("** "); upkey.append(keys->getkey(OP_SK_UP, fa->id())); std::string downkey("** "); downkey.append(keys->getkey(OP_SK_DOWN, fa->id())); fa->get_form()->set("bind_up", upkey); @@ -109,16 +107,16 @@ void view::set_bindings(std::tr1::shared_ptr fa) { fa->get_form()->set("bind_end", endkey); } -std::tr1::shared_ptr view::get_current_formaction() { +std::shared_ptr view::get_current_formaction() { if (formaction_stack.size() > 0 && current_formaction < formaction_stack.size()) { return formaction_stack[current_formaction]; } - return std::tr1::shared_ptr(); + return std::shared_ptr(); } void view::set_status_unlocked(const std::string& msg) { if (formaction_stack.size() > 0 && get_current_formaction() != NULL) { - std::tr1::shared_ptr form = get_current_formaction()->get_form(); + std::shared_ptr form = get_current_formaction()->get_form(); if (form != NULL) { form->set("msg",msg); form->run(-1); @@ -129,7 +127,7 @@ void view::set_status_unlocked(const std::string& msg) { } void view::set_status(const std::string& msg) { - scope_mutex lock(mtx); + std::lock_guard lock(mtx); set_status_unlocked(msg); } @@ -142,7 +140,7 @@ void view::run() { std::vector macrocmds; // create feedlist - std::tr1::shared_ptr feedlist(new feedlist_formaction(this, feedlist_str)); + std::shared_ptr feedlist(new feedlist_formaction(this, feedlist_str)); set_bindings(feedlist); feedlist->set_regexmanager(rxman); feedlist->set_tags(tags); @@ -160,7 +158,7 @@ void view::run() { while (formaction_stack.size() > 0) { // first, we take the current formaction. - std::tr1::shared_ptr fa = get_current_formaction(); + std::shared_ptr fa = get_current_formaction(); // we signal "oh, you will receive an operation soon" fa->prepare(); @@ -190,7 +188,7 @@ void view::run() { if (!event || strcmp(event,"TIMEOUT")==0) { if (fa->id() == "article") - std::tr1::dynamic_pointer_cast(fa)->update_percent(); + std::dynamic_pointer_cast(fa)->update_percent(); continue; } @@ -244,7 +242,7 @@ void view::run() { stfl::reset(); } -std::string view::run_modal(std::tr1::shared_ptr f, const std::string& value) { +std::string view::run_modal(std::shared_ptr f, const std::string& value) { f->init(); unsigned int stacksize = formaction_stack.size(); @@ -252,7 +250,7 @@ std::string view::run_modal(std::tr1::shared_ptr f, const std::strin current_formaction = formaction_stack_size() - 1; while (formaction_stack.size() > stacksize) { - std::tr1::shared_ptr fa = get_current_formaction(); + std::shared_ptr fa = get_current_formaction(); fa->prepare(); @@ -297,12 +295,12 @@ std::string view::get_filename_suggestion(const std::string& s) { } void view::push_empty_formaction() { - formaction_stack.push_back(std::tr1::shared_ptr()); + formaction_stack.push_back(std::shared_ptr()); current_formaction = formaction_stack_size() - 1; } void view::open_in_pager(const std::string& filename) { - formaction_stack.push_back(std::tr1::shared_ptr()); + formaction_stack.push_back(std::shared_ptr()); current_formaction = formaction_stack_size() - 1; std::string cmdline; std::string pager = cfg->get_configvalue("pager"); @@ -328,7 +326,7 @@ void view::open_in_pager(const std::string& filename) { } void view::open_in_browser(const std::string& url) { - formaction_stack.push_back(std::tr1::shared_ptr()); + formaction_stack.push_back(std::shared_ptr()); current_formaction = formaction_stack_size() - 1; std::string cmdline; std::string browser = cfg->get_configvalue("browser"); @@ -355,11 +353,11 @@ void view::open_in_browser(const std::string& url) { pop_current_formaction(); } -void view::update_visible_feeds(std::vector > feeds) { +void view::update_visible_feeds(std::vector> feeds) { try { if (formaction_stack_size() > 0) { - scope_mutex lock(mtx); - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::lock_guard lock(mtx); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); feedlist->update_visible_feeds(feeds); } } catch (const matcherexception& e) { @@ -368,18 +366,18 @@ void view::update_visible_feeds(std::vector > fee } } -void view::set_feedlist(std::vector > feeds) { +void view::set_feedlist(std::vector> feeds) { try { - scope_mutex lock(mtx); + std::lock_guard lock(mtx); - for (std::vector >::iterator it=feeds.begin();it!=feeds.end();++it) { - if ((*it)->rssurl().substr(0,6) != "query:") { - (*it)->set_feedptrs(*it); + for (auto feed : feeds) { + if (feed->rssurl().substr(0,6) != "query:") { + feed->set_feedptrs(feed); } } if (formaction_stack_size() > 0) { - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); feedlist->set_feedlist(feeds); } } catch (const matcherexception& e) { @@ -392,12 +390,12 @@ void view::set_tags(const std::vector& t) { tags = t; } -void view::push_searchresult(std::tr1::shared_ptr feed, const std::string& phrase) { +void view::push_searchresult(std::shared_ptr feed, const std::string& phrase) { assert(feed != NULL); LOG(LOG_DEBUG, "view::push_searchresult: pushing search result"); if (feed->items().size() > 0) { - std::tr1::shared_ptr searchresult(new itemlist_formaction(this, itemlist_str)); + std::shared_ptr searchresult(new itemlist_formaction(this, itemlist_str)); set_bindings(searchresult); searchresult->set_regexmanager(rxman); searchresult->set_feed(feed); @@ -414,7 +412,7 @@ void view::push_searchresult(std::tr1::shared_ptr feed, const std::str } -void view::push_itemlist(std::tr1::shared_ptr feed) { +void view::push_itemlist(std::shared_ptr feed) { assert(feed != NULL); feed->purge_deleted_items(); @@ -422,7 +420,7 @@ void view::push_itemlist(std::tr1::shared_ptr feed) { prepare_query_feed(feed); if (feed->items().size() > 0) { - std::tr1::shared_ptr itemlist(new itemlist_formaction(this, itemlist_str)); + std::shared_ptr itemlist(new itemlist_formaction(this, itemlist_str)); set_bindings(itemlist); itemlist->set_regexmanager(rxman); itemlist->set_feed(feed); @@ -438,21 +436,21 @@ void view::push_itemlist(std::tr1::shared_ptr feed) { } void view::push_itemlist(unsigned int pos) { - std::tr1::shared_ptr feed = ctrl->get_feed(pos); + std::shared_ptr feed = ctrl->get_feed(pos); LOG(LOG_DEBUG, "view::push_itemlist: retrieved feed at position %d", pos); push_itemlist(feed); if (feed->items().size() > 0) { - std::tr1::shared_ptr itemlist = std::tr1::dynamic_pointer_cast(get_current_formaction()); + std::shared_ptr itemlist = std::dynamic_pointer_cast(get_current_formaction()); itemlist->set_pos(pos); } } -void view::push_itemview(std::tr1::shared_ptr f, const std::string& guid, const std::string& searchphrase) { +void view::push_itemview(std::shared_ptr f, const std::string& guid, const std::string& searchphrase) { std::string pager; if ((pager = cfg->get_configvalue("pager")) == "internal") { - std::tr1::shared_ptr itemlist = std::tr1::dynamic_pointer_cast(get_current_formaction()); + std::shared_ptr itemlist = std::dynamic_pointer_cast(get_current_formaction()); assert(itemlist != NULL); - std::tr1::shared_ptr itemview(new itemview_formaction(this, itemlist, itemview_str)); + std::shared_ptr itemview(new itemview_formaction(this, itemlist, itemview_str)); set_bindings(itemview); itemview->set_regexmanager(rxman); itemview->set_feed(f); @@ -473,7 +471,7 @@ void view::push_itemview(std::tr1::shared_ptr f, const std::string& gu void view::view_dialogs() { if (get_current_formaction() != NULL && get_current_formaction()->id() != "dialogs") { - std::tr1::shared_ptr dialogs(new dialogs_formaction(this, dialogs_str)); + std::shared_ptr dialogs(new dialogs_formaction(this, dialogs_str)); dialogs->set_parent_formaction(get_current_formaction()); apply_colors(dialogs); dialogs->init(); @@ -483,7 +481,7 @@ void view::view_dialogs() { } void view::push_help() { - std::tr1::shared_ptr helpview(new help_formaction(this, help_str)); + std::shared_ptr helpview(new help_formaction(this, help_str)); set_bindings(helpview); apply_colors(helpview); helpview->set_context(get_current_formaction()->id()); @@ -494,7 +492,7 @@ void view::push_help() { } void view::push_urlview(const std::vector& links) { - std::tr1::shared_ptr urlview(new urlview_formaction(this, urlview_str)); + std::shared_ptr urlview(new urlview_formaction(this, urlview_str)); set_bindings(urlview); apply_colors(urlview); urlview->set_parent_formaction(get_current_formaction()); @@ -505,7 +503,7 @@ void view::push_urlview(const std::vector& links) { } std::string view::run_filebrowser(const std::string& default_filename, const std::string& dir) { - std::tr1::shared_ptr filebrowser(new filebrowser_formaction(this, filebrowser_str)); + std::shared_ptr filebrowser(new filebrowser_formaction(this, filebrowser_str)); set_bindings(filebrowser); apply_colors(filebrowser); filebrowser->set_dir(dir); @@ -514,12 +512,13 @@ std::string view::run_filebrowser(const std::string& default_filename, const std return run_modal(filebrowser, "filenametext"); } + std::string view::select_tag() { if (tags.size() == 0) { show_error(_("No tags defined.")); return ""; } - std::tr1::shared_ptr selecttag(new select_formaction(this, selecttag_str)); + std::shared_ptr selecttag(new select_formaction(this, selecttag_str)); selecttag->set_type(select_formaction::SELECTTAG); set_bindings(selecttag); apply_colors(selecttag); @@ -530,7 +529,7 @@ std::string view::select_tag() { } std::string view::select_filter(const std::vector& filters) { - std::tr1::shared_ptr selecttag(new select_formaction(this, selecttag_str)); + std::shared_ptr selecttag(new select_formaction(this, selecttag_str)); selecttag->set_type(select_formaction::SELECTFILTER); set_bindings(selecttag); apply_colors(selecttag); @@ -543,8 +542,8 @@ std::string view::select_filter(const std::vector& filter char view::confirm(const std::string& prompt, const std::string& charset) { LOG(LOG_DEBUG, "view::confirm: charset = %s", charset.c_str()); - std::tr1::shared_ptr f = get_current_formaction(); - formaction_stack.push_back(std::tr1::shared_ptr()); + std::shared_ptr f = get_current_formaction(); + formaction_stack.push_back(std::shared_ptr()); current_formaction = formaction_stack_size() - 1; f->get_form()->set("msg", prompt); @@ -571,12 +570,12 @@ char view::confirm(const std::string& prompt, const std::string& charset) { return result; } -void view::notify_itemlist_change(std::tr1::shared_ptr feed) { - for (std::vector >::iterator it=formaction_stack.begin();it!=formaction_stack.end();++it) { - if (*it != NULL && (*it)->id() == "articlelist") { - std::tr1::shared_ptr itemlist = std::tr1::dynamic_pointer_cast(*it); +void view::notify_itemlist_change(std::shared_ptr feed) { + for (auto& form : formaction_stack) { + if (form != NULL && form->id() == "articlelist") { + std::shared_ptr itemlist = std::dynamic_pointer_cast(form); if (itemlist != NULL) { - std::tr1::shared_ptr f = itemlist->get_feed(); + std::shared_ptr f = itemlist->get_feed(); if (f != NULL && f->rssurl() == feed->rssurl()) { itemlist->set_feed(feed); itemlist->set_redraw(true); @@ -588,7 +587,7 @@ void view::notify_itemlist_change(std::tr1::shared_ptr feed) { bool view::get_random_unread(itemlist_formaction * itemlist, itemview_formaction * itemview) { unsigned int feedpos; - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); if (!cfg->get_configvalue_as_bool("goto-next-feed")) { return false; } @@ -613,7 +612,7 @@ bool view::get_random_unread(itemlist_formaction * itemlist, itemview_formaction bool view::get_previous_unread(itemlist_formaction * itemlist, itemview_formaction * itemview) { unsigned int feedpos; LOG(LOG_DEBUG, "view::get_previous_unread: trying to find previous unread"); - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); if (itemlist->jump_to_previous_unread_item(false)) { LOG(LOG_DEBUG, "view::get_previous_unread: found unread article in same feed"); if (itemview) { @@ -644,7 +643,7 @@ bool view::get_previous_unread(itemlist_formaction * itemlist, itemview_formacti } bool view::get_next_unread_feed(itemlist_formaction * itemlist) { - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); unsigned int feedpos; assert(feedlist != NULL); if (feedlist->jump_to_next_unread_feed(feedpos)) { @@ -658,7 +657,7 @@ bool view::get_next_unread_feed(itemlist_formaction * itemlist) { } bool view::get_prev_unread_feed(itemlist_formaction * itemlist) { - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); unsigned int feedpos; assert(feedlist != NULL); if (feedlist->jump_to_previous_unread_feed(feedpos)) { @@ -673,7 +672,7 @@ bool view::get_prev_unread_feed(itemlist_formaction * itemlist) { bool view::get_next_unread(itemlist_formaction * itemlist, itemview_formaction * itemview) { unsigned int feedpos; - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); LOG(LOG_DEBUG, "view::get_next_unread: trying to find next unread"); if (itemlist->jump_to_next_unread_item(false)) { LOG(LOG_DEBUG, "view::get_next_unread: found unread article in same feed"); @@ -706,7 +705,7 @@ bool view::get_next_unread(itemlist_formaction * itemlist, itemview_formaction * bool view::get_previous(itemlist_formaction * itemlist, itemview_formaction * itemview) { unsigned int feedpos; - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); if (itemlist->jump_to_previous_item(false)) { LOG(LOG_DEBUG, "view::get_previous: article in same feed"); if (itemview) { @@ -738,7 +737,7 @@ bool view::get_previous(itemlist_formaction * itemlist, itemview_formaction * it bool view::get_next(itemlist_formaction * itemlist, itemview_formaction * itemview) { unsigned int feedpos; - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); if (itemlist->jump_to_next_item(false)) { LOG(LOG_DEBUG, "view::get_next: article in same feed"); if (itemview) { @@ -769,7 +768,7 @@ bool view::get_next(itemlist_formaction * itemlist, itemview_formaction * itemvi } bool view::get_next_feed(itemlist_formaction * itemlist) { - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); unsigned int feedpos; assert(feedlist != NULL); if (feedlist->jump_to_next_feed(feedpos)) { @@ -783,7 +782,7 @@ bool view::get_next_feed(itemlist_formaction * itemlist) { } bool view::get_prev_feed(itemlist_formaction * itemlist) { - std::tr1::shared_ptr feedlist = std::tr1::dynamic_pointer_cast(formaction_stack[0]); + std::shared_ptr feedlist = std::dynamic_pointer_cast(formaction_stack[0]); unsigned int feedpos; assert(feedlist != NULL); if (feedlist->jump_to_previous_feed(feedpos)) { @@ -796,7 +795,7 @@ bool view::get_prev_feed(itemlist_formaction * itemlist) { return false; } -void view::prepare_query_feed(std::tr1::shared_ptr feed) { +void view::prepare_query_feed(std::shared_ptr feed) { if (feed->rssurl().substr(0,6) == "query:") { LOG(LOG_DEBUG, "view::prepare_query_feed: %s", feed->rssurl().c_str()); @@ -809,7 +808,7 @@ void view::prepare_query_feed(std::tr1::shared_ptr feed) { } void view::force_redraw() { - std::tr1::shared_ptr fa = get_current_formaction(); + std::shared_ptr fa = get_current_formaction(); if (fa != NULL) { fa->set_redraw(true); fa->prepare(); @@ -818,8 +817,8 @@ void view::force_redraw() { } void view::pop_current_formaction() { - std::tr1::shared_ptr f = get_current_formaction(); - std::vector >::iterator it=formaction_stack.begin(); + std::shared_ptr f = get_current_formaction(); + auto it=formaction_stack.begin(); for (unsigned int i=0;i 0) { // first, we set back the parent formactions of those who reference the formaction we just removed - for (std::vector >::iterator it=formaction_stack.begin();it!=formaction_stack.end();++it) { - if ((*it)->get_parent_formaction() == f) { - (*it)->set_parent_formaction(formaction_stack[0]); + for (auto& form : formaction_stack) { + if (form->get_parent_formaction() == f) { + form->set_parent_formaction(formaction_stack[0]); } } // we set the new formaction based on the removed formaction's parent. unsigned int i=0; - for (std::vector >::iterator it=formaction_stack.begin();it!=formaction_stack.end();++it,i++) { - if (*it == f->get_parent_formaction()) { + for (auto& form : formaction_stack) { + if (form == f->get_parent_formaction()) { current_formaction = i; break; } + i++; } - std::tr1::shared_ptr f = get_current_formaction(); + std::shared_ptr f = get_current_formaction(); if (f) { f->set_redraw(true); f->get_form()->set("msg",""); @@ -855,41 +855,42 @@ void view::set_current_formaction(unsigned int pos) { } void view::remove_formaction(unsigned int pos) { - std::tr1::shared_ptr f = formaction_stack[pos]; - std::vector >::iterator it=formaction_stack.begin(); + std::shared_ptr f = formaction_stack[pos]; + auto it = formaction_stack.begin(); for (unsigned int i=0;i 0) { // we set back the parent formactions of those who reference the formaction we just removed - for (std::vector >::iterator it=formaction_stack.begin();it!=formaction_stack.end();++it) { - if ((*it)->get_parent_formaction() == f) { - (*it)->set_parent_formaction(formaction_stack[0]); + for (auto& form : formaction_stack) { + if (form->get_parent_formaction() == f) { + form->set_parent_formaction(formaction_stack[0]); } } } } -void view::set_colors(std::map& fgc, std::map& bgc, std::map >& attribs) { +void view::set_colors(std::map& fgc, std::map& bgc, std::map>& attribs) { fg_colors = fgc; bg_colors = bgc; attributes = attribs; } void view::apply_colors_to_all_formactions() { - for (std::vector >::iterator it=formaction_stack.begin();it!=formaction_stack.end();++it) { - apply_colors(*it); + for (auto& form : formaction_stack) { + apply_colors(form); } if (formaction_stack.size() > 0 && formaction_stack[current_formaction]) { formaction_stack[current_formaction]->set_redraw(true); } } -void view::apply_colors(std::tr1::shared_ptr fa) { - std::map::const_iterator fgcit = fg_colors.begin(); - std::map::const_iterator bgcit = bg_colors.begin(); - std::map >::const_iterator attit = attributes.begin(); +void view::apply_colors(std::shared_ptr fa) { + auto fgcit = fg_colors.begin(); + auto bgcit = bg_colors.begin(); + auto attit = attributes.begin(); + LOG(LOG_DEBUG, "view::apply_colors: fa = %s", fa->id().c_str()); std::string article_colorstr; @@ -906,11 +907,11 @@ void view::apply_colors(std::tr1::shared_ptr fa) { colorattr.append("bg="); colorattr.append(bgcit->second); } - for (std::vector::const_iterator it=attit->second.begin(); it!= attit->second.end(); ++it) { + for (auto attr : attit->second) { if (colorattr.length() > 0) colorattr.append(","); colorattr.append("attr="); - colorattr.append(*it); + colorattr.append(attr); } if (fgcit->first == "article") { @@ -952,7 +953,7 @@ void view::apply_colors(std::tr1::shared_ptr fa) { void view::feedlist_mark_pos_if_visible(unsigned int pos) { if (formaction_stack_size() > 0) { - std::tr1::dynamic_pointer_cast(formaction_stack[0])->mark_pos_if_visible(pos); + std::dynamic_pointer_cast(formaction_stack[0])->mark_pos_if_visible(pos); } } @@ -961,13 +962,14 @@ void view::set_regexmanager(regexmanager * r) { } -std::vector > view::get_formaction_names() { - std::vector > formaction_names; +std::vector> view::get_formaction_names() { + std::vector> formaction_names; unsigned int i=0; - for (std::vector >::iterator it=formaction_stack.begin();it!=formaction_stack.end();++it,i++) { - if (*it && (*it)->id() != "dialogs") { - formaction_names.push_back(std::pair(i, (*it)->title())); + for (auto& form : formaction_stack) { + if (form && form->id() != "dialogs") { + formaction_names.push_back(std::pair(i, form->title())); } + i++; } return formaction_names; } @@ -994,13 +996,13 @@ void view::inside_cmdline(bool f) { is_inside_cmdline = f; } -void view::clear_line(std::tr1::shared_ptr fa) { +void view::clear_line(std::shared_ptr fa) { fa->get_form()->set("qna_value", ""); fa->get_form()->set("qna_value_pos", "0"); LOG(LOG_DEBUG, "view::clear_line: cleared line"); } -void view::clear_eol(std::tr1::shared_ptr fa) { +void view::clear_eol(std::shared_ptr fa) { unsigned int pos = utils::to_u(fa->get_form()->get("qna_value_pos")); std::string val = fa->get_form()->get("qna_value"); val.erase(pos, val.length()); @@ -1009,12 +1011,12 @@ void view::clear_eol(std::tr1::shared_ptr fa) { LOG(LOG_DEBUG, "view::clear_eol: cleared to end of line"); } -void view::cancel_input(std::tr1::shared_ptr fa) { +void view::cancel_input(std::shared_ptr fa) { fa->process_op(OP_INT_CANCEL_QNA); LOG(LOG_DEBUG, "view::cancel_input: cancelled input"); } -void view::delete_word(std::tr1::shared_ptr fa) { +void view::delete_word(std::shared_ptr fa) { std::string::size_type curpos = utils::to_u(fa->get_form()->get("qna_value_pos")); std::string val = fa->get_form()->get("qna_value"); std::string::size_type firstpos = curpos; @@ -1037,7 +1039,7 @@ void view::delete_word(std::tr1::shared_ptr fa) { fa->get_form()->set("qna_value_pos", utils::to_string(firstpos)); } -void view::handle_cmdline_completion(std::tr1::shared_ptr fa) { +void view::handle_cmdline_completion(std::shared_ptr fa) { std::string fragment = fa->get_form()->get("qna_value"); if (fragment != last_fragment || fragment == "") { last_fragment = fragment; diff --git a/test/test.cpp b/test/test.cpp index d977f922..2b680bfc 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -38,7 +38,7 @@ void TestNewsbeuterReload() { cache * rsscache = new cache("test-cache.db", cfg); rss_parser parser("http://testbed.newsbeuter.org/unit-test/rss.xml", rsscache, cfg, NULL); - std::tr1::shared_ptr feed = parser.parse(); + std::shared_ptr feed = parser.parse(); lemon.is(feed->items().size(), 8u, "rss.xml contains 8 items"); rsscache->externalize_rssfeed(feed, false); @@ -54,7 +54,7 @@ void TestNewsbeuterReload() { rsscache->externalize_rssfeed(feed, false); - std::tr1::shared_ptr feed2 = rsscache->internalize_rssfeed("http://testbed.newsbeuter.org/unit-test/rss.xml", NULL); + std::shared_ptr feed2 = rsscache->internalize_rssfeed("http://testbed.newsbeuter.org/unit-test/rss.xml", NULL); lemon.is(feed2->items().size(), 8u, "feed2 contains 8 items after internalizaton"); lemon.is(feed2->items()[0]->title(), "Another Title", "feed2 first item title"); @@ -64,7 +64,7 @@ void TestNewsbeuterReload() { lemon.is(feedurls.size(), 1u, "1 feed url"); lemon.is(feedurls[0], "http://testbed.newsbeuter.org/unit-test/rss.xml", "first feed url"); - std::vector > feedv; + std::vector> feedv; feedv.push_back(feed); cfg->set_configvalue("cleanup-on-quit", "true"); @@ -749,7 +749,7 @@ void TestHtmlRenderer() { } void TestIndexPartitioning() { - std::vector > partitions = utils::partition_indexes(0, 9, 2); + std::vector> partitions = utils::partition_indexes(0, 9, 2); lemon.is(partitions.size(), 2u, "partitioning of [0,9] in 2 parts produced 2 parts"); lemon.is(partitions[0].first, 0u, "first partition start is 0"); lemon.is(partitions[0].second, 4u, "first partition end is 4"); diff --git a/txt2h.pl b/txt2h.pl index 1ae0e4fe..98f2c5a9 100755 --- a/txt2h.pl +++ b/txt2h.pl @@ -9,7 +9,7 @@ } my ($filename, $extension) = @ARGV; -my $id = basename($filename, $extension); +my $id = basename($filename, $extension || ""); chomp($id); open(my $fh, '<', $filename) or die "couldn't open $filename: $!\n";