From 8584857578c3a2946a03de98ff3803431143297a Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 30 Aug 2018 20:43:23 -0400 Subject: Refactored tweet and user classes The only API-visible change is that these classes are no longer default constructible. Other than that, tweet now uses hatkirby::recptr to wrap its retweeted_status (tweet) and author (user) member objects, removing the need to implement the Rule of Five. --- src/tweet.h | 122 +++++++++++++++++++++++++----------------------------------- 1 file changed, 50 insertions(+), 72 deletions(-) (limited to 'src/tweet.h') diff --git a/src/tweet.h b/src/tweet.h index 71a27bd..23882e2 100644 --- a/src/tweet.h +++ b/src/tweet.h @@ -4,94 +4,72 @@ #include #include #include -#include -#include -#include #include +#include "../vendor/hkutil/hkutil/recptr.h" #include "user.h" namespace twitter { - class client; - typedef unsigned long long tweet_id; class tweet { - public: - - tweet() {} - tweet(std::string data); - - tweet(const tweet& other); - tweet(tweet&& other); - - tweet& operator=(tweet other); - - friend void swap(tweet& first, tweet& second); - - tweet_id getID() const + public: + + tweet(std::string data); + + tweet_id getID() const + { + return _id; + } + + std::string getText() const + { + return _text; + } + + const user& getAuthor() const + { + return *_author; + } + + const std::time_t& getCreatedAt() const + { + return _created_at; + } + + bool isRetweet() const + { + return _is_retweet; + } + + const tweet& getRetweet() const + { + if (!_is_retweet) { - assert(_valid); - - return _id; + throw std::logic_error("Tweet is not a retweet"); } - std::string getText() const - { - assert(_valid); + return *_retweeted_status; + } - return _text; - } - - const user& getAuthor() const - { - assert(_valid); - - return *_author; - } - - const std::time_t& getCreatedAt() const - { - assert(_valid); - - return _created_at; - } - - bool isRetweet() const - { - assert(_valid); - - return _is_retweet; - } - - const tweet& getRetweet() const - { - assert(_valid && _is_retweet); - - return *_retweeted_status; - } - - const std::vector>& getMentions() const - { - assert(_valid); - - return _mentions; - } + const std::vector>& getMentions() const + { + return _mentions; + } - std::string generateReplyPrefill(const user& me) const; + std::string generateReplyPrefill(const user& me) const; - std::string getURL() const; + std::string getURL() const; - private: + private: - bool _valid = false; - tweet_id _id; - std::string _text; - std::unique_ptr _author; - std::time_t _created_at; - bool _is_retweet = false; - std::unique_ptr _retweeted_status; - std::vector> _mentions; + tweet_id _id; + std::string _text; + hatkirby::recptr _author; + std::time_t _created_at; + bool _is_retweet = false; + hatkirby::recptr _retweeted_status; + std::vector> _mentions; }; }; -- cgit 1.4.1