From c97b82158747269250d7048fbd06ba55a4faef97 Mon Sep 17 00:00:00 2001 From: Clortox Date: Sun, 25 Jul 2021 20:00:12 -0400 Subject: [PATCH] Add Image accessor functions --- src/rss.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/rss.hpp | 9 ++++++-- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/rss.cpp b/src/rss.cpp index 2ff0f5c..e0b089e 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -221,6 +221,71 @@ std::string rss::getLastBuildDate() const { return cdata_to_string(tmp); } +std::string rss::getImageURL() const { + if(!_ok) + return ""; + + rapidxml::xml_node<> *tmp = _item_node->first_node("image"); + if(tmp == 0) + return ""; + tmp = tmp->first_node("url"); + if(tmp == 0) + return ""; + return cdata_to_string(tmp); +} + +std::string rss::getImageTitle() const { + if(!_ok) + return ""; + + rapidxml::xml_node<> *tmp = _item_node->first_node("image"); + if(tmp == 0) + return ""; + tmp = tmp->first_node("title"); + if(tmp == 0) + return ""; + return cdata_to_string(tmp); +} + +std::string rss::getimageLink() const { + if(!_ok) + return ""; + + rapidxml::xml_node<> *tmp = _item_node->first_node("image"); + if(tmp == 0) + return ""; + tmp = tmp->first_node("link"); + if(tmp == 0) + return ""; + return cdata_to_string(tmp); +} + +int rss::getimageWidth() const { + if(!_ok) + return 0; + + rapidxml::xml_node<> *tmp = _item_node->first_node("image"); + if(tmp == 0) + return 0; + tmp = tmp->first_node("width"); + if(tmp == 0) + return 0; + return atoi(tmp->value()); +} + +int rss::getimageHeight() const { + if(!_ok) + return 0; + + rapidxml::xml_node<> *tmp = _item_node->first_node("image"); + if(tmp == 0) + return 0; + tmp = tmp->first_node("height"); + if(tmp == 0) + return 0; + return atoi(tmp->value()); +} + int rss::getItemCount() const { if(!_ok) return -1; diff --git a/src/rss.hpp b/src/rss.hpp index 7f315c1..aa7daa5 100644 --- a/src/rss.hpp +++ b/src/rss.hpp @@ -54,8 +54,14 @@ namespace rss_utils { std::string getDocs() const; std::string getTTL() const; std::string getLastBuildDate() const; - int getItemCount() const; + std::string getImageURL() const; + std::string getImageTitle() const; + std::string getImageLink() const; + int getImageWidth() const; + int getImageHeight() const; + + int getItemCount() const; std::vector getItems(); item& getItem(const int); @@ -64,7 +70,6 @@ namespace rss_utils { const item& operator[](const int) const; //TODO - //std::string getImage() const; //std::string getCloud() const; private: