cpp-ElementTree
Python ElementTree-alike XML API for C++
feed.hpp
1 #ifndef ETREE_FEED_H
2 #define ETREE_FEED_H
3 
4 /*
5  * Copyright David Wilson, 2013.
6  * License: http://opensource.org/licenses/MIT
7  */
8 
9 #include <ctime>
10 #include <string>
11 #include <iostream>
12 
13 #include "element.hpp"
14 
15 
16 namespace etree {
17 
18 class Element;
19 
20 
24 namespace feed {
25 
26 class Feed;
27 class Item;
28 class FeedFormat;
29 class ItemFormat;
30 
31 // Internal.
32 time_t parseRfc822Date_(std::string);
33 time_t parseIso8601Date_(std::string s);
34 std::string stripWs_(const std::string &s);
35 std::string
36 formatIso8601_(time_t t);
37 std::string
38 formatRfc822_(time_t t);
39 
40 
49 };
50 
51 
60 };
61 
62 
66 Feed create(enum feed_format format);
67 
68 
76 
77 
78 Item itemFromElement(Element elem, enum feed_format format);
79 
80 
84 class Item
85 {
86  template<typename T>
87  friend FeedFormat &formatFor__(const T &);
88 
89  const ItemFormat &format_;
90  Element elem_;
91 
92  public:
93  Item(const Item &);
94  Item(const ItemFormat &, const Element &);
95 
99  void remove();
100 
104  std::string title() const;
105 
111  void title(const std::string &s);
112 
116  std::string link() const;
117 
123  void link(const std::string &s);
124 
128  std::string content() const;
129 
135  void content(const std::string &s);
136 
140  enum content_type type() const;
141 
147  void type(enum content_type);
148 
152  std::string author() const;
153 
160  void author(const std::string &author);
161 
165  std::string guid() const;
166 
172  void guid(const std::string &s);
173 
180  std::string originalGuid() const;
181 
185  time_t published() const;
186 
193  void published(time_t published);
194 
198  time_t updated() const;
199 
206  void updated(time_t updated);
207 
208  Element element() const;
209 };
210 
211 
215 class Feed
216 {
217  template<typename T>
218  friend FeedFormat &formatFor__(const T &);
219 
220  const FeedFormat &format_;
221  Element elem_;
222 
223  public:
224  Feed();
225  Feed(const Feed &);
226  Feed(const FeedFormat &format, const Element &elem);
227 
231  enum feed_format format() const;
232 
236  std::string title() const;
237 
241  void title(const std::string &s);
242 
247  std::string link() const;
248 
252  void link(const std::string &s);
253 
257  std::string description() const;
258 
262  void description(const std::string &s);
263 
267  std::string icon() const;
268 
272  void icon(const std::string &s);
273 
277  std::vector<Item> items() const;
278 
287  Item append();
288 
297  void append(Item item);
298 
302  Element element() const;
303 };
304 
305 
306 } // namespace
307 } // namespace
308 
309 #endif
Equivalent to MIME type text/html.
Definition: feed.hpp:59
Represents a reference to a single XML element.
Definition: element.hpp:721
time_t published() const
Return the item&#39;s published date as a UNIX timestamp.
Definition: feed.cpp:216
std::string link() const
Return the item link URL, or the empty string.
Definition: feed.cpp:152
ATOM.
Definition: feed.hpp:48
feed_format
Enumeration of supported feed types.
Definition: feed.hpp:44
std::string title() const
Return the item title.
Definition: feed.cpp:140
Represents a feed.
Definition: feed.hpp:215
ElementTree namespace; public classes and functions are defined here.
Definition: element.cpp:28
Represent a single feed item.
Definition: feed.hpp:84
content_type
Enumeration of possible content types for an element&#39;s content.
Definition: feed.hpp:55
enum content_type type() const
Return the item content&#39;s content type.
Definition: feed.cpp:174
std::string originalGuid() const
Return the item&#39;s GUID as it appeared in the original source feed, or the present GUID if no original...
Definition: feed.cpp:210
RSS 2.0.
Definition: feed.hpp:46
Equivalent to MIME type text/plain.
Definition: feed.hpp:57
std::string guid() const
Return the item GUID, often this is simply the item URL.
Definition: feed.cpp:198
std::string author() const
Return the item author name, or the empty string.
Definition: feed.cpp:186
Feed fromelement(Element elem)
Wrap an Element containing a feed and return a reference.
Definition: feed.cpp:804
std::string content() const
Return the item content, or the empty string.
Definition: feed.cpp:163
Feed create(enum feed_format f)
Create a new completely empty feed in the specified format.
Definition: feed.cpp:796
time_t updated() const
Return the item&#39;s updated date as a UNIX timestamp.
Definition: feed.cpp:228