diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2012-12-11 03:51:03 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2012-12-11 03:51:03 +0000 |
commit | ae0b7c0063db6236be2d7cf01ddbf2159f77c98c (patch) | |
tree | 2f64d65d018634b8728623e2ca99514541fab8aa /sca-cpp/trunk/modules/rss | |
parent | 1f3796522a078dda5906395ba471d151ad694b6b (diff) |
Port kernel to C++11 and refactor some of the core modules. Convert functors to lambdas, and add C++ const, noexcept and inline annotations to get more efficient generated code.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1419985 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/rss')
-rw-r--r-- | sca-cpp/trunk/modules/rss/rss-test.cpp | 208 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/rss/rss.hpp | 70 |
2 files changed, 139 insertions, 139 deletions
diff --git a/sca-cpp/trunk/modules/rss/rss-test.cpp b/sca-cpp/trunk/modules/rss/rss-test.cpp index be1dcac574..a6de6ed31a 100644 --- a/sca-cpp/trunk/modules/rss/rss-test.cpp +++ b/sca-cpp/trunk/modules/rss/rss-test.cpp @@ -37,78 +37,78 @@ ostream* writer(const string& s, ostream* os) { } const string itemEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - "<item>\n" - " <title>fruit</title>\n" - " <link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</link>\n" - " <description>\n" - " <item>\n" - " <name>Apple</name>\n" - " <price>$2.99</price>\n" - " </item>\n" - " </description>\n" + "<item>" + "<title>fruit</title>" + "<link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</link>" + "<description>" + "<item>" + "<name>Apple</name>" + "<price>$2.99</price>" + "</item>" + "</description>" "</item>\n"); const string itemTextEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - "<item>\n" - " <title>fruit</title>\n" - " <link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</link>\n" - " <description>Apple</description>\n" + "<item>" + "<title>fruit</title>" + "<link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</link>" + "<description>Apple</description>" "</item>\n"); const string itemNoDescriptionEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - "<item>\n" - " <title>fruit</title>\n" - " <link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</link>\n" + "<item>" + "<title>fruit</title>" + "<link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</link>" "</item>\n"); const string incompleteEntry("<item>\n" - " <title>fruit</title>\n" - " <description>\n" - " <Item xmlns=\"http://services/\">\n" - " <name xmlns=\"\">Orange</name>\n" - " <price xmlns=\"\">3.55</price>\n" - " </Item>\n" - " </description>\n" + "<title>fruit</title>" + "<description>" + "<Item xmlns=\"http://services/\">" + "<name xmlns=\"\">Orange</name>" + "<price xmlns=\"\">3.55</price>" + "</Item>" + "</description>" "</item>"); const string completedEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - "<item>\n" - " <title>fruit</title>\n" - " <link></link>\n" - " <description>\n" - " <Item xmlns=\"http://services/\">\n" - " <name xmlns=\"\">Orange</name>\n" - " <price xmlns=\"\">3.55</price>\n" - " </Item>\n" - " </description>\n" + "<item>" + "<title>fruit</title>" + "<link></link>" + "<description>" + "<Item xmlns=\"http://services/\">" + "<name xmlns=\"\">Orange</name>" + "<price xmlns=\"\">3.55</price>" + "</Item>" + "</description>" "</item>\n"); -bool testEntry() { +const bool testEntry() { { - const list<value> i = list<value>() + element + value("item") - + value(list<value>() + element + value("name") + value(string("Apple"))) - + value(list<value>() + element + value("price") + value(string("$2.99"))); - const list<value> a = list<value>() + (list<value>() + element + value("entry") - + value(list<value>() + element + value("title") + value(string("fruit"))) - + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))) - + value(list<value>() + element + value("content") + value(i))); + const list<value> i = nilListValue + element + value("item") + + value(nilListValue + element + value("name") + value(string("Apple"))) + + value(nilListValue + element + value("price") + value(string("$2.99"))); + const list<value> a = nilListValue + (nilListValue + element + value("entry") + + value(nilListValue + element + value("title") + value(string("fruit"))) + + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))) + + value(nilListValue + element + value("content") + value(i))); ostringstream os; writeRSSEntry<ostream*>(writer, &os, a); assert(str(os) == itemEntry); } { - const list<value> a = list<value>() + (list<value>() + element + value("entry") - + value(list<value>() + element + value("title") + value(string("fruit"))) - + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))) - + value(list<value>() + element + value("content") + value(string("Apple")))); + const list<value> a = nilListValue + (nilListValue + element + value("entry") + + value(nilListValue + element + value("title") + value(string("fruit"))) + + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))) + + value(nilListValue + element + value("content") + value(string("Apple")))); ostringstream os; writeRSSEntry<ostream*>(writer, &os, a); assert(str(os) == itemTextEntry); } { - const list<value> a = list<value>() + (list<value>() + element + value("entry") - + value(list<value>() + element + value("title") + value(string("fruit"))) - + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))); + const list<value> a = nilListValue + (nilListValue + element + value("entry") + + value(nilListValue + element + value("title") + value(string("fruit"))) + + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))); ostringstream os; writeRSSEntry<ostream*>(writer, &os, a); assert(str(os) == itemNoDescriptionEntry); @@ -141,48 +141,48 @@ bool testEntry() { } const string emptyFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - "<rss version=\"2.0\">\n" - " <channel>\n" - " <title>Feed</title>\n" - " <link>1234</link>\n" - " <description>Feed</description>\n" - " </channel>\n" + "<rss version=\"2.0\">" + "<channel>" + "<title>Feed</title>" + "<link>1234</link>" + "<description>Feed</description>" + "</channel>" "</rss>\n"); const string itemFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - "<rss version=\"2.0\">\n" - " <channel>\n" - " <title>Feed</title>\n" - " <link>1234</link>\n" - " <description>Feed</description>\n" - " <item>\n" - " <title>fruit</title>\n" - " <link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</link>\n" - " <description>\n" - " <item>\n" - " <name>Apple</name>\n" - " <price>$2.99</price>\n" - " </item>\n" - " </description>\n" - " </item>\n" - " <item>\n" - " <title>fruit</title>\n" - " <link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c</link>\n" - " <description>\n" - " <item>\n" - " <name>Orange</name>\n" - " <price>$3.55</price>\n" - " </item>\n" - " </description>\n" - " </item>\n" - " </channel>\n" + "<rss version=\"2.0\">" + "<channel>" + "<title>Feed</title>" + "<link>1234</link>" + "<description>Feed</description>" + "<item>" + "<title>fruit</title>" + "<link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</link>" + "<description>" + "<item>" + "<name>Apple</name>" + "<price>$2.99</price>" + "</item>" + "</description>" + "</item>" + "<item>" + "<title>fruit</title>" + "<link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c</link>" + "<description>" + "<item>" + "<name>Orange</name>" + "<price>$3.55</price>" + "</item>" + "</description>" + "</item>" + "</channel>" "</rss>\n"); -bool testFeed() { +const bool testFeed() { { - const list<value> a = list<value>() + (list<value>() + element + value("feed") - + value(list<value>() + element + value("title") + value(string("Feed"))) - + value(list<value>() + element + value("id") + value(string("1234")))); + const list<value> a = nilListValue + (nilListValue + element + value("feed") + + value(nilListValue + element + value("title") + value(string("Feed"))) + + value(nilListValue + element + value("id") + value(string("1234")))); ostringstream os; writeRSSFeed<ostream*>(writer, &os, a); assert(str(os) == emptyFeed); @@ -194,27 +194,27 @@ bool testFeed() { assert(str(os) == emptyFeed); } { - const list<value> i1 = list<value>() + element + "item" - + (list<value>() + element + "name" + "Apple") - + (list<value>() + element + "price" + "$2.99"); - - const list<value> i2 = list<value>() + element + "item" - + (list<value>() + element + "name" + "Orange") - + (list<value>() + element + "price" + "$3.55"); - - const list<value> i = list<value>() - + value(list<value>() + element + value("entry") - + value(list<value>() + element + value("title") + value(string("fruit"))) - + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))) - + value(list<value>() + element + value("content") + value(i1))) - + value(list<value>() + element + value("entry") - + value(list<value>() + element + value("title") + value(string("fruit"))) - + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"))) - + value(list<value>() + element + value("content") + value(i2))); + const list<value> i1 = nilListValue + element + "item" + + (nilListValue + element + "name" + "Apple") + + (nilListValue + element + "price" + "$2.99"); + + const list<value> i2 = nilListValue + element + "item" + + (nilListValue + element + "name" + "Orange") + + (nilListValue + element + "price" + "$3.55"); + + const list<value> i = nilListValue + + value(nilListValue + element + value("entry") + + value(nilListValue + element + value("title") + value(string("fruit"))) + + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))) + + value(nilListValue + element + value("content") + value(i1))) + + value(nilListValue + element + value("entry") + + value(nilListValue + element + value("title") + value(string("fruit"))) + + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"))) + + value(nilListValue + element + value("content") + value(i2))); - const list<value> a = list<value>() + (append<value>(list<value>() + element + value("feed") - + value(list<value>() + element + value("title") + value(string("Feed"))) - + value(list<value>() + element + value("id") + value("1234")), + const list<value> a = nilListValue + (append<value>(nilListValue + element + value("feed") + + value(nilListValue + element + value("title") + value(string("Feed"))) + + value(nilListValue + element + value("id") + value("1234")), i)); ostringstream os; @@ -240,7 +240,7 @@ bool testFeed() { } int main() { - tuscany::gc_scoped_pool p; + const tuscany::gc_scoped_pool p; tuscany::cout << "Testing..." << tuscany::endl; tuscany::rss::testEntry(); diff --git a/sca-cpp/trunk/modules/rss/rss.hpp b/sca-cpp/trunk/modules/rss/rss.hpp index c62d137adc..7fba736065 100644 --- a/sca-cpp/trunk/modules/rss/rss.hpp +++ b/sca-cpp/trunk/modules/rss/rss.hpp @@ -30,7 +30,7 @@ #include "list.hpp" #include "value.hpp" #include "monad.hpp" -#include "xml.hpp" +#include "../xml/xml.hpp" namespace tuscany { namespace rss { @@ -50,10 +50,10 @@ const list<value> entryElementValues(const list<value>& e) { const list<value> li = filter<value>(selector(mklist<value>(element, "link")), e); const value i = isNil(li)? value(emptyString) : elementValue(car(li)); const list<value> ld = filter<value>(selector(mklist<value>(element, "description")), e); - return append<value>(list<value>() + element + entry - + value(list<value>() + element + value("title") + t) - + value(list<value>() + element + value("id") + i), - isNil(ld)? list<value>() : mklist<value>(value(list<value>() + element + value("content") + elementValue(car(ld))))); + return append<value>(nilListValue + element + entry + + value(nilListValue + element + value("title") + t) + + value(nilListValue + element + value("id") + i), + isNil(ld)? nilListValue : mklist<value>(value(nilListValue + element + value("content") + elementValue(car(ld))))); } /** @@ -69,7 +69,7 @@ const list<value> entriesElementValues(const list<value>& e) { * Return true if a list of strings contains an RSS feed. */ const bool isRSSFeed(const list<string>& ls) { - if (!isXML(ls)) + if (!xml::isXML(ls)) return false; return contains(car(ls), "<rss"); } @@ -78,7 +78,7 @@ const bool isRSSFeed(const list<string>& ls) { * Convert a list of strings to a list of values representing an RSS entry. */ const failable<list<value> > readRSSEntry(const list<string>& ilist) { - const list<value> e = readXML(ilist); + const list<value> e = content(xml::readElements(ilist)); if (isNil(e)) return mkfailure<list<value> >("Empty entry"); return mklist<value>(entryElementValues(car(e))); @@ -88,16 +88,16 @@ const failable<list<value> > readRSSEntry(const list<string>& ilist) { * Convert a list of strings to a list of values representing an RSS feed. */ const failable<list<value> > readRSSFeed(const list<string>& ilist) { - const list<value> f = readXML(ilist); + const list<value> f = content(xml::readElements(ilist)); if (isNil(f)) return mkfailure<list<value> >("Empty feed"); const list<value> c = filter<value>(selector(mklist<value>(element, "channel")), car(f)); const list<value> t = filter<value>(selector(mklist<value>(element, "title")), car(c)); const list<value> i = filter<value>(selector(mklist<value>(element, "link")), car(c)); const list<value> e = filter<value>(selector(mklist<value>(element, "item")), car(c)); - return mklist<value>(append<value>(list<value>() + element + feed - + value(list<value>() + element + value("title") + elementValue(car(t))) - + value(list<value>() + element + value("id") + elementValue(car(i))), + return mklist<value>(append<value>(nilListValue + element + feed + + value(nilListValue + element + value("title") + elementValue(car(t))) + + value(nilListValue + element + value("id") + elementValue(car(i))), entriesElementValues(e))); } @@ -109,13 +109,13 @@ const list<value> entryElement(const list<value>& l) { const value id = elementValue(elementChild("id", l)); const value content = elementChild("content", l); const bool text = isNil(content)? false : elementHasValue(content); - return append<value>(list<value>() + return append<value>(nilListValue + element + "item" - + (list<value>() + element + "title" + title) - + (list<value>() + element + "link" + id), + + (nilListValue + element + "title" + title) + + (nilListValue + element + "link" + id), isNil(content)? - list<value>() : - mklist<value>(append<value>(list<value>() + element + "description", + nilListValue : + mklist<value>(append<value>(nilListValue + element + "description", text? mklist<value>(elementValue(content)) : elementChildren(content)))); } @@ -132,9 +132,9 @@ const list<value> entriesElements(const list<value>& l) { * Convert a list of values representing an RSS entry to an RSS entry. * The first two values in the list are the entry id and title. */ -template<typename R> const failable<R> writeRSSEntry(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& ll) { +template<typename R> const failable<R> writeRSSEntry(const lambda<const R(const string&, const R)>& reduce, const R& initial, const list<value>& ll) { const list<value> l = isNil(ll)? ll : (list<value>)car(ll); - return writeXML<R>(reduce, initial, mklist<value>(entryElement(l))); + return xml::writeElements<R>(reduce, initial, mklist<value>(entryElement(l))); } const failable<list<string> > writeRSSEntry(const list<value>& l) { @@ -148,41 +148,41 @@ const failable<list<string> > writeRSSEntry(const list<value>& l) { * Convert a list of values representing an RSS feed to an RSS feed. * The first two values in the list are the feed id and title. */ -template<typename R> const failable<R> writeRSSFeed(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& ll) { +template<typename R> const failable<R> writeRSSFeed(const lambda<const R(const string&, const R)>& reduce, const R& initial, const list<value>& ll) { const list<value> l = isNil(ll)? ll : (list<value>)car(ll); const list<value> lt = filter<value>(selector(mklist<value>(element, "title")), l); const value t = isNil(lt)? value(emptyString) : elementValue(car(lt)); const list<value> li = filter<value>(selector(mklist<value>(element, "id")), l); const value i = isNil(li)? value(emptyString) : elementValue(car(li)); - const list<value> c = list<value>() - + (list<value>() + element + "title" + t) - + (list<value>() + element + "link" + i) - + (list<value>() + element + "description" + t); + const list<value> c = nilListValue + + (nilListValue + element + "title" + t) + + (nilListValue + element + "link" + i) + + (nilListValue + element + "description" + t); // Write RSS entries const list<value> le = filter<value>(selector(mklist<value>(element, entry)), l); if (isNil(le)) { - const list<value> fe = list<value>() - + element + "rss" + (list<value>() + attribute + "version" + "2.0") - + append(list<value>() + element + "channel", c); - return writeXML<R>(reduce, initial, mklist<value>(fe)); + const list<value> fe = nilListValue + + element + "rss" + (nilListValue + attribute + "version" + "2.0") + + append(nilListValue + element + "channel", c); + return xml::writeElements<R>(reduce, initial, mklist<value>(fe)); } // Write a single RSS entry element with a list of values if (!isNil(le) && !isNil(car(le)) && isList(car<value>(caddr<value>(car(le))))) { const list<value> ce = append(c, entriesElements(caddr<value>(car(le)))); - const list<value> fe = list<value>() - + element + "rss" + (list<value>() + attribute + "version" + "2.0") - + append(list<value>() + element + "channel", ce); - return writeXML<R>(reduce, initial, mklist<value>(fe)); + const list<value> fe = nilListValue + + element + "rss" + (nilListValue + attribute + "version" + "2.0") + + append(nilListValue + element + "channel", ce); + return xml::writeElements<R>(reduce, initial, mklist<value>(fe)); } // Write separate RSS entry elements const list<value> ce = append(c, entriesElements(le)); - const list<value> fe = list<value>() - + element + "rss" + (list<value>() + attribute + "version" + "2.0") - + append(list<value>() + element + "channel", ce); - return writeXML<R>(reduce, initial, mklist<value>(fe)); + const list<value> fe = nilListValue + + element + "rss" + (nilListValue + attribute + "version" + "2.0") + + append(nilListValue + element + "channel", ce); + return xml::writeElements<R>(reduce, initial, mklist<value>(fe)); } /** |