summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/atom
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/modules/atom')
-rw-r--r--sca-cpp/trunk/modules/atom/atom-test.cpp110
-rw-r--r--sca-cpp/trunk/modules/atom/atom.hpp46
2 files changed, 77 insertions, 79 deletions
diff --git a/sca-cpp/trunk/modules/atom/atom-test.cpp b/sca-cpp/trunk/modules/atom/atom-test.cpp
index ba651e8eb2..560c383a23 100644
--- a/sca-cpp/trunk/modules/atom/atom-test.cpp
+++ b/sca-cpp/trunk/modules/atom/atom-test.cpp
@@ -24,21 +24,19 @@
*/
#include <assert.h>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include "slist.hpp"
+#include "stream.hpp"
+#include "string.hpp"
#include "atom.hpp"
namespace tuscany {
namespace atom {
-std::ostringstream* writer(const std::string& s, std::ostringstream* os) {
+ostream* writer(const string& s, ostream* os) {
(*os) << s;
return os;
}
-std::string itemEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+string itemEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<entry xmlns=\"http://www.w3.org/2005/Atom\">"
"<title type=\"text\">item</title>"
"<id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>"
@@ -50,7 +48,7 @@ std::string itemEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>"
"</entry>\n");
-std::string incompleteEntry("<entry xmlns=\"http://www.w3.org/2005/Atom\">"
+string incompleteEntry("<entry xmlns=\"http://www.w3.org/2005/Atom\">"
"<title>item</title><content type=\"text/xml\">"
"<Item xmlns=\"http://services/\">"
"<name xmlns=\"\">Orange</name>"
@@ -59,7 +57,7 @@ std::string incompleteEntry("<entry xmlns=\"http://www.w3.org/2005/Atom\">"
"</content>"
"</entry>");
-std::string completedEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+string completedEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<entry xmlns=\"http://www.w3.org/2005/Atom\">"
"<title type=\"text\">item</title>"
"<id></id>"
@@ -73,36 +71,36 @@ std::string completedEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
bool testEntry() {
{
- const list<value> i = list<value>() << element << "item"
- << (list<value>() << element << "name" << std::string("Apple"))
- << (list<value>() << element << "price" << std::string("$2.99"));
- const list<value> a = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
- std::ostringstream os;
- writeATOMEntry<std::ostringstream*>(writer, &os, a);
- assert(os.str() == itemEntry);
+ 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 = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+ ostringstream os;
+ writeATOMEntry<ostream*>(writer, &os, a);
+ assert(str(os) == itemEntry);
}
{
const list<value> a = content(readEntry(mklist(itemEntry)));
- std::ostringstream os;
- writeATOMEntry<std::ostringstream*>(writer, &os, a);
- assert(os.str() == itemEntry);
+ ostringstream os;
+ writeATOMEntry<ostream*>(writer, &os, a);
+ assert(str(os) == itemEntry);
}
{
const list<value> a = content(readEntry(mklist(incompleteEntry)));
- std::ostringstream os;
- writeATOMEntry<std::ostringstream*>(writer, &os, a);
- assert(os.str() == completedEntry);
+ ostringstream os;
+ writeATOMEntry<ostream*>(writer, &os, a);
+ assert(str(os) == completedEntry);
}
return true;
}
-std::string emptyFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+string emptyFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<feed xmlns=\"http://www.w3.org/2005/Atom\">"
"<title type=\"text\">Feed</title>"
"<id>1234</id>"
"</feed>\n");
-std::string itemFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+string itemFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<feed xmlns=\"http://www.w3.org/2005/Atom\">"
"<title type=\"text\">Feed</title>"
"<id>1234</id>"
@@ -130,51 +128,51 @@ std::string itemFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
bool testFeed() {
{
- std::ostringstream os;
- writeATOMFeed<std::ostringstream*>(writer, &os, mklist<value>("Feed", "1234"));
- assert(os.str() == emptyFeed);
+ ostringstream os;
+ writeATOMFeed<ostream*>(writer, &os, mklist<value>("Feed", "1234"));
+ assert(str(os) == emptyFeed);
}
{
const list<value> a = content(readFeed(mklist(emptyFeed)));
- std::ostringstream os;
- writeATOMFeed<std::ostringstream*>(writer, &os, a);
- assert(os.str() == emptyFeed);
+ ostringstream os;
+ writeATOMFeed<ostream*>(writer, &os, a);
+ assert(str(os) == emptyFeed);
}
{
const list<value> i = list<value>()
- << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
- << (list<value>() << element << "item"
- << (list<value>() << element << "name" << "Apple")
- << (list<value>() << element << "price" << "$2.99")))
- << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
- << (list<value>() << element << "item"
- << (list<value>() << element << "name" << "Orange")
- << (list<value>() << element << "price" << "$3.55")));
+ + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
+ + (list<value>() + element + "item"
+ + (list<value>() + element + "name" + "Apple")
+ + (list<value>() + element + "price" + "$2.99")))
+ + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
+ + (list<value>() + element + "item"
+ + (list<value>() + element + "name" + "Orange")
+ + (list<value>() + element + "price" + "$3.55")));
const list<value> a = cons<value>("Feed", cons<value>("1234", i));
- std::ostringstream os;
- writeATOMFeed<std::ostringstream*>(writer, &os, a);
- assert(os.str() == itemFeed);
+ ostringstream os;
+ writeATOMFeed<ostream*>(writer, &os, a);
+ assert(str(os) == itemFeed);
}
{
const list<value> i = list<value>()
- << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
- << valueToElement(list<value>() << "item"
- << (list<value>() << "name" << "Apple")
- << (list<value>() << "price" << "$2.99")))
- << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
- << valueToElement(list<value>() << "item"
- << (list<value>() << "name" << "Orange")
- << (list<value>() << "price" << "$3.55")));
+ + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
+ + valueToElement(list<value>() + "item"
+ + (list<value>() + "name" + "Apple")
+ + (list<value>() + "price" + "$2.99")))
+ + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
+ + valueToElement(list<value>() + "item"
+ + (list<value>() + "name" + "Orange")
+ + (list<value>() + "price" + "$3.55")));
const list<value> a = cons<value>("Feed", cons<value>("1234", i));
- std::ostringstream os;
- writeATOMFeed<std::ostringstream*>(writer, &os, a);
- assert(os.str() == itemFeed);
+ ostringstream os;
+ writeATOMFeed<ostream*>(writer, &os, a);
+ assert(str(os) == itemFeed);
}
{
const list<value> a = content(readFeed(mklist(itemFeed)));
- std::ostringstream os;
- writeATOMFeed<std::ostringstream*>(writer, &os, a);
- assert(os.str() == itemFeed);
+ ostringstream os;
+ writeATOMFeed<ostream*>(writer, &os, a);
+ assert(str(os) == itemFeed);
}
return true;
}
@@ -183,12 +181,12 @@ bool testFeed() {
}
int main() {
- std::cout << "Testing..." << std::endl;
+ tuscany::cout << "Testing..." << tuscany::endl;
tuscany::atom::testEntry();
tuscany::atom::testFeed();
- std::cout << "OK" << std::endl;
+ tuscany::cout << "OK" << tuscany::endl;
return 0;
}
diff --git a/sca-cpp/trunk/modules/atom/atom.hpp b/sca-cpp/trunk/modules/atom/atom.hpp
index 7e2eb66cd2..4dbf7c7728 100644
--- a/sca-cpp/trunk/modules/atom/atom.hpp
+++ b/sca-cpp/trunk/modules/atom/atom.hpp
@@ -26,7 +26,7 @@
* ATOM data conversion functions.
*/
-#include <string>
+#include "string.hpp"
#include "list.hpp"
#include "value.hpp"
#include "monad.hpp"
@@ -40,9 +40,9 @@ namespace atom {
*/
const list<value> entryValues(const list<value>& e) {
const list<value> lt = filter<value>(selector(mklist<value>(element, "title")), e);
- const value t = isNil(lt)? value(std::string("")) : elementValue(car(lt));
+ const value t = isNil(lt)? value(emptyString) : elementValue(car(lt));
const list<value> li = filter<value>(selector(mklist<value>(element, "id")), e);
- const value i = isNil(li)? value(std::string("")) : elementValue(car(li));
+ const value i = isNil(li)? value(emptyString) : elementValue(car(li));
const list<value> lc = filter<value>(selector(mklist<value>(element, "content")), e);
return mklist<value>(t, i, cadr(elementChildren(car(lc))));
}
@@ -59,10 +59,10 @@ const list<value> entriesValues(const list<value>& e) {
/**
* Convert a list of strings to a list of values representing an ATOM entry.
*/
-const failable<list<value>, std::string> readEntry(const list<std::string>& ilist) {
+const failable<list<value> > readEntry(const list<string>& ilist) {
const list<value> e = readXML(ilist);
if (isNil(e))
- return mkfailure<list<value>, std::string>("Empty entry");
+ return mkfailure<list<value> >("Empty entry");
return entryValues(car(e));
}
@@ -77,10 +77,10 @@ const value entryValue(const list<value>& e) {
/**
* Convert a list of strings to a list of values representing an ATOM feed.
*/
-const failable<list<value>, std::string> readFeed(const list<std::string>& ilist) {
+const failable<list<value> > readFeed(const list<string>& ilist) {
const list<value> f = readXML(ilist);
if (isNil(f))
- return mkfailure<list<value>, std::string>("Empty feed");
+ return mkfailure<list<value> >("Empty feed");
const list<value> t = filter<value>(selector(mklist<value>(element, "title")), car(f));
const list<value> i = filter<value>(selector(mklist<value>(element, "id")), car(f));
const list<value> e = filter<value>(selector(mklist<value>(element, "entry")), car(f));
@@ -95,11 +95,11 @@ const failable<list<value>, std::string> readFeed(const list<std::string>& ilist
*/
const list<value> entryElement(const list<value>& l) {
return list<value>()
- << element << "entry" << (list<value>() << attribute << "xmlns" << "http://www.w3.org/2005/Atom")
- << (list<value>() << element << "title" << (list<value>() << attribute << "type" << "text") << car(l))
- << (list<value>() << element << "id" << cadr(l))
- << (list<value>() << element << "content" << (list<value>() << attribute << "type" << "application/xml") << caddr(l))
- << (list<value>() << element << "link" << (list<value>() << attribute << "href" << cadr(l)));
+ + element + "entry" + (list<value>() + attribute + "xmlns" + "http://www.w3.org/2005/Atom")
+ + (list<value>() + element + "title" + (list<value>() + attribute + "type" + "text") + car(l))
+ + (list<value>() + element + "id" + cadr(l))
+ + (list<value>() + element + "content" + (list<value>() + attribute + "type" + "application/xml") + caddr(l))
+ + (list<value>() + element + "link" + (list<value>() + attribute + "href" + cadr(l)));
}
/**
@@ -115,26 +115,26 @@ const list<value> entriesElements(const list<value>& l) {
* Convert a list of values representing an ATOM entry to an ATOM entry.
* The first two values in the list are the entry id and title.
*/
-template<typename R> const failable<R, std::string> writeATOMEntry(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const list<value>& l) {
+template<typename R> const failable<R> writeATOMEntry(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l) {
return writeXML<R>(reduce, initial, mklist<value>(entryElement(l)));
}
-const failable<list<std::string>, std::string> writeATOMEntry(const list<value>& l) {
- const failable<list<std::string>, std::string> ls = writeATOMEntry<list<std::string> >(rcons<std::string>, list<std::string>(), l);
+const failable<list<string> > writeATOMEntry(const list<value>& l) {
+ const failable<list<string> > ls = writeATOMEntry<list<string> >(rcons<string>, list<string>(), l);
if (!hasContent(ls))
return ls;
- return reverse(list<std::string>(content(ls)));
+ return reverse(list<string>(content(ls)));
}
/**
* Convert a list of values representing an ATOM feed to an ATOM feed.
* The first two values in the list are the feed id and title.
*/
-template<typename R> const failable<R, std::string> writeATOMFeed(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const list<value>& l) {
+template<typename R> const failable<R> writeATOMFeed(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l) {
const list<value> f = list<value>()
- << element << "feed" << (list<value>() << attribute << "xmlns" << "http://www.w3.org/2005/Atom")
- << (list<value>() << element << "title" << (list<value>() << attribute << "type" << "text") << car(l))
- << (list<value>() << element << "id" << cadr(l));
+ + element + "feed" + (list<value>() + attribute + "xmlns" + "http://www.w3.org/2005/Atom")
+ + (list<value>() + element + "title" + (list<value>() + attribute + "type" + "text") + car(l))
+ + (list<value>() + element + "id" + cadr(l));
if (isNil(cddr(l)))
return writeXML<R>(reduce, initial, mklist<value>(f));
const list<value> fe = append(f, entriesElements(cddr(l)));
@@ -145,11 +145,11 @@ template<typename R> const failable<R, std::string> writeATOMFeed(const lambda<R
* Convert a list of values representing an ATOM feed to a list of strings.
* The first two values in the list are the feed id and title.
*/
-const failable<list<std::string>, std::string> writeATOMFeed(const list<value>& l) {
- const failable<list<std::string>, std::string> ls = writeATOMFeed<list<std::string> >(rcons<std::string>, list<std::string>(), l);
+const failable<list<string> > writeATOMFeed(const list<value>& l) {
+ const failable<list<string> > ls = writeATOMFeed<list<string>>(rcons<string>, list<string>(), l);
if (!hasContent(ls))
return ls;
- return reverse(list<std::string>(content(ls)));
+ return reverse(list<string>(content(ls)));
}
/**