diff options
Diffstat (limited to '')
-rw-r--r-- | cpp/sca/modules/atom/atom.hpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/cpp/sca/modules/atom/atom.hpp b/cpp/sca/modules/atom/atom.hpp index 5bb8d45e38..78b60da70f 100644 --- a/cpp/sca/modules/atom/atom.hpp +++ b/cpp/sca/modules/atom/atom.hpp @@ -33,40 +33,43 @@ #include "xml.hpp" namespace tuscany { +namespace atom { /** * Convert a list of elements to a list of values representing an ATOM entry. */ -const list<value> atomEntry(const list<value>& e) { - const list<value> t = filter<value>(selector(mklist<value>(element, "title")), e); - const list<value> i = filter<value>(selector(mklist<value>(element, "id")), e); - const list<value> c = filter<value>(selector(mklist<value>(element, "content")), e); - return mklist<value>(elementValue(car(t)), elementValue(car(i)), cadr(elementChildren(car(c)))); +const list<value> entry(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 list<value> li = filter<value>(selector(mklist<value>(element, "id")), e); + const value i = isNil(li)? value(std::string("")) : elementValue(car(li)); + const list<value> lc = filter<value>(selector(mklist<value>(element, "content")), e); + return mklist<value>(t, i, cadr(elementChildren(car(lc)))); } /** * Convert a list of elements to a list of values representing ATOM entries. */ -const list<value> atomEntries(const list<value>& e) { +const list<value> entries(const list<value>& e) { if (isNil(e)) return list<value>(); - return cons<value>(atomEntry(car(e)), atomEntries(cdr(e))); + return cons<value>(entry(car(e)), entries(cdr(e))); } /** * Convert a list of strings to a list of values representing an ATOM entry. */ -const failable<list<value>, std::string> readATOMEntry(const list<std::string>& ilist) { +const failable<list<value>, std::string> readEntry(const list<std::string>& ilist) { const list<value> e = readXML(ilist); if (isNil(e)) return std::string("Empty entry"); - return atomEntry(car(e)); + return entry(car(e)); } /** * Convert a list of strings to a list of values representing an ATOM feed. */ -const failable<list<value>, std::string> readATOMFeed(const list<std::string>& ilist) { +const failable<list<value>, std::string> readFeed(const list<std::string>& ilist) { const list<value> f = readXML(ilist); if (isNil(f)) return std::string("Empty feed"); @@ -75,14 +78,14 @@ const failable<list<value>, std::string> readATOMFeed(const list<std::string>& i const list<value> e = filter<value>(selector(mklist<value>(element, "entry")), car(f)); if (isNil(e)) return mklist<value>(elementValue(car(t)), elementValue(car(i))); - return cons<value>(elementValue(car(t)), cons(elementValue(car(i)), atomEntries(e))); + return cons<value>(elementValue(car(t)), cons(elementValue(car(i)), entries(e))); } /** * Convert a list of values representing an ATOM entry to a list of elements. * The first two values in the list are the entry title and id. */ -const list<value> atomEntryElement(const list<value>& l) { +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)) @@ -94,30 +97,30 @@ const list<value> atomEntryElement(const list<value>& l) { /** * Convert a list of values representing ATOM entries to a list of elements. */ -const list<value> atomEntriesElements(const list<value>& l) { +const list<value> entriesElements(const list<value>& l) { if (isNil(l)) return list<value>(); - return cons<value>(atomEntryElement(car(l)), atomEntriesElements(cdr(l))); + return cons<value>(entryElement(car(l)), entriesElements(cdr(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(R, std::string)>& reduce, const R& initial, const list<value>& l) { - return writeXML<R>(reduce, initial, mklist<value>(atomEntryElement(l))); +template<typename R> const failable<R, std::string> writeEntry(const lambda<R(R, std::string)>& reduce, const R& initial, const list<value>& l) { + return writeXML<R>(reduce, initial, mklist<value>(entryElement(l))); } /** * Convert a list of values representing an ATOM entry to a list of strings. * The first two values in the list are the entry id and title. */ -const list<std::string> writeATOMList(const list<std::string>& listSoFar, const std::string& s) { +const list<std::string> writeStrings(const list<std::string>& listSoFar, const std::string& s) { return cons(s, listSoFar); } -const failable<list<std::string>, std::string> writeATOMEntry(const list<value>& l) { - const failable<list<std::string>, std::string> ls = writeATOMEntry<list<std::string> >(writeATOMList, list<std::string>(), l); +const failable<list<std::string>, std::string> writeEntry(const list<value>& l) { + const failable<list<std::string>, std::string> ls = writeEntry<list<std::string> >(writeStrings, list<std::string>(), l); if (!hasValue(ls)) return ls; return reverse(list<std::string>(ls)); @@ -127,14 +130,14 @@ const failable<list<std::string>, std::string> writeATOMEntry(const list<value>& * 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(R, std::string)>& reduce, const R& initial, const list<value>& l) { +template<typename R> const failable<R, std::string> writeFeed(const lambda<R(R, std::string)>& 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)); if (isNil(cddr(l))) return writeXML<R>(reduce, initial, mklist<value>(f)); - const list<value> fe = append(f, atomEntriesElements(cddr(l))); + const list<value> fe = append(f, entriesElements(cddr(l))); return writeXML<R>(reduce, initial, mklist<value>(fe)); } @@ -142,13 +145,14 @@ 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> >(writeATOMList, list<std::string>(), l); +const failable<list<std::string>, std::string> writeFeed(const list<value>& l) { + const failable<list<std::string>, std::string> ls = writeFeed<list<std::string> >(writeStrings, list<std::string>(), l); if (!hasValue(ls)) return ls; return reverse(list<std::string>(ls)); } } +} #endif /* tuscany_atom_hpp */ |