diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tweet.cpp | 65 | ||||
-rw-r--r-- | src/tweet.h | 10 |
2 files changed, 72 insertions, 3 deletions
diff --git a/src/tweet.cpp b/src/tweet.cpp index bf95bc0..2927018 100644 --- a/src/tweet.cpp +++ b/src/tweet.cpp | |||
@@ -17,7 +17,14 @@ namespace twitter { | |||
17 | _id = _data.at("id"); | 17 | _id = _data.at("id"); |
18 | _text = _data.at("text"); | 18 | _text = _data.at("text"); |
19 | _author = user(_data.at("user").dump()); | 19 | _author = user(_data.at("user").dump()); |
20 | _retweeted = _data.at("retweeted"); | 20 | |
21 | if (_data.find("retweeted_status") != _data.end()) | ||
22 | { | ||
23 | _is_retweet = true; | ||
24 | |||
25 | std::string retweet = _data.at("retweeted_status").dump(); | ||
26 | _retweeted_status = new tweet(retweet); | ||
27 | } | ||
21 | 28 | ||
22 | if (_data.find("entities") != _data.end()) | 29 | if (_data.find("entities") != _data.end()) |
23 | { | 30 | { |
@@ -32,6 +39,53 @@ namespace twitter { | |||
32 | } | 39 | } |
33 | } | 40 | } |
34 | 41 | ||
42 | tweet::tweet(const tweet& other) | ||
43 | { | ||
44 | _valid = other._valid; | ||
45 | _id = other._id; | ||
46 | _text = other._text; | ||
47 | _author = other._author; | ||
48 | _is_retweet = other._is_retweet; | ||
49 | |||
50 | if (_is_retweet) | ||
51 | { | ||
52 | _retweeted_status = new tweet(*other._retweeted_status); | ||
53 | } | ||
54 | |||
55 | _mentions = other._mentions; | ||
56 | } | ||
57 | |||
58 | tweet::tweet(tweet&& other) : tweet() | ||
59 | { | ||
60 | swap(*this, other); | ||
61 | } | ||
62 | |||
63 | tweet::~tweet() | ||
64 | { | ||
65 | if (_is_retweet) | ||
66 | { | ||
67 | delete _retweeted_status; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | tweet& tweet::operator=(tweet other) | ||
72 | { | ||
73 | swap(*this, other); | ||
74 | |||
75 | return *this; | ||
76 | } | ||
77 | |||
78 | void swap(tweet& first, tweet& second) | ||
79 | { | ||
80 | std::swap(first._valid, second._valid); | ||
81 | std::swap(first._id, second._id); | ||
82 | std::swap(first._text, second._text); | ||
83 | std::swap(first._author, second._author); | ||
84 | std::swap(first._is_retweet, second._is_retweet); | ||
85 | std::swap(first._retweeted_status, second._retweeted_status); | ||
86 | std::swap(first._mentions, second._mentions); | ||
87 | } | ||
88 | |||
35 | tweet_id tweet::getID() const | 89 | tweet_id tweet::getID() const |
36 | { | 90 | { |
37 | assert(_valid); | 91 | assert(_valid); |
@@ -57,7 +111,14 @@ namespace twitter { | |||
57 | { | 111 | { |
58 | assert(_valid); | 112 | assert(_valid); |
59 | 113 | ||
60 | return _retweeted; | 114 | return _is_retweet; |
115 | } | ||
116 | |||
117 | tweet tweet::getRetweet() const | ||
118 | { | ||
119 | assert(_valid && _is_retweet); | ||
120 | |||
121 | return *_retweeted_status; | ||
61 | } | 122 | } |
62 | 123 | ||
63 | std::vector<std::pair<user_id, std::string>> tweet::getMentions() const | 124 | std::vector<std::pair<user_id, std::string>> tweet::getMentions() const |
diff --git a/src/tweet.h b/src/tweet.h index 34a9cd7..387f73a 100644 --- a/src/tweet.h +++ b/src/tweet.h | |||
@@ -14,11 +14,18 @@ namespace twitter { | |||
14 | public: | 14 | public: |
15 | tweet(); | 15 | tweet(); |
16 | tweet(std::string data); | 16 | tweet(std::string data); |
17 | tweet(const tweet& other); | ||
18 | tweet(tweet&& other); | ||
19 | ~tweet(); | ||
20 | |||
21 | tweet& operator=(tweet other); | ||
22 | friend void swap(tweet& first, tweet& second); | ||
17 | 23 | ||
18 | tweet_id getID() const; | 24 | tweet_id getID() const; |
19 | std::string getText() const; | 25 | std::string getText() const; |
20 | const user& getAuthor() const; | 26 | const user& getAuthor() const; |
21 | bool isRetweet() const; | 27 | bool isRetweet() const; |
28 | tweet getRetweet() const; | ||
22 | std::vector<std::pair<user_id, std::string>> getMentions() const; | 29 | std::vector<std::pair<user_id, std::string>> getMentions() const; |
23 | 30 | ||
24 | operator bool() const; | 31 | operator bool() const; |
@@ -28,7 +35,8 @@ namespace twitter { | |||
28 | tweet_id _id; | 35 | tweet_id _id; |
29 | std::string _text; | 36 | std::string _text; |
30 | user _author; | 37 | user _author; |
31 | bool _retweeted; | 38 | bool _is_retweet = false; |
39 | tweet* _retweeted_status = nullptr; | ||
32 | std::vector<std::pair<user_id, std::string>> _mentions; | 40 | std::vector<std::pair<user_id, std::string>> _mentions; |
33 | }; | 41 | }; |
34 | 42 | ||