tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r1419985 [3/5] - in /tuscany/sca-cpp/trunk: ./ etc/ kernel/ modules/ modules/atom/ modules/rss/ modules/scdl/ modules/scheme/ modules/xml/
Date Tue, 11 Dec 2012 03:51:12 GMT
Modified: tuscany/sca-cpp/trunk/kernel/string.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/string.hpp?rev=1419985&r1=1419984&r2=1419985&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/string.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/string.hpp Tue Dec 11 03:51:03 2012
@@ -41,16 +41,16 @@ namespace tuscany {
  */
 long countStringCopies = 0;
 
-bool resetStringCopyCounters() {
+inline const bool resetStringCopyCounters() {
     countStringCopies = 0;
     return true;
 }
 
-bool checkStringCopyCounters(long c) {
+inline const bool checkStringCopyCounters(long c) {
     return countStringCopies == c;
 }
 
-bool printStringCopyCounters() {
+inline const bool printStringCopyCounters() {
     printf("countStringCopies %ld\n", countStringCopies);
     return true;
 }
@@ -66,13 +66,19 @@ bool printStringCopyCounters() {
 /**
  * Instrumented memcpy.
  */
-void* string_memcpy(void* t, const void* s, const size_t n) {
 #ifdef WANT_MAINTAINER_COUNTERS
+
+inline void* string_memcpy(void* t, const void* s, const size_t n) {
     countStringCopies += 1;
-#endif
     return memcpy(t, s, n);
 }
 
+#else
+
+#define string_memcpy(t, s, n) memcpy(t, s, n)
+
+#endif
+
 char stringEmptyBuffer[1] = { '\0' };
 
 /**
@@ -80,56 +86,27 @@ char stringEmptyBuffer[1] = { '\0' };
  */
 class string {
 public:
-    string() : len(0) {
-        buf = stringEmptyBuffer;
+    inline string() noexcept : len(0), buf(stringEmptyBuffer) {
+    }
+
+    inline string(const char* const s) noexcept : len(strlen(s)), buf(mksbuf(s, len)) {
+    }
+
+    inline string(const char* const s, const size_t n) noexcept : len(n), buf(mksbuf(s, n)) {
+    }
+
+    inline string(const char* const s, const size_t n, const bool copy) noexcept : len(n), buf(mksbuf(s, n, copy)) {
     }
 
-    string(const char* s) {
-        len = strlen(s);
-        if (len == 0) {
-            buf = stringEmptyBuffer;
-            return;
-        }
-        buf = gc_cnew(len + 1);
-        string_memcpy(buf, s, len + 1);
-    }
-
-    string(const char* s, const size_t n) {
-        len = n;
-        if (len == 0) {
-            buf = stringEmptyBuffer;
-            return;
-        }
-        buf = gc_cnew(len + 1);
-        string_memcpy(buf, s, len);
-        buf[len] = '\0';
-    }
-
-    string(const size_t n, const char c) {
-        len = n;
-        if (len == 0) {
-            buf = stringEmptyBuffer;
-            return;
-        }
-        buf = gc_cnew(len + 1);
-        memset(buf, c, n);
-        buf[len] = '\0';
-    }
-
-    string(const string& s) {
-        len = s.len;
-        buf = s.buf;
-    }
-
-    const string& operator=(const string& s) {
-        if (&s == this)
-            return *this;
-        len = s.len;
-        buf = s.buf;
-        return *this;
+    inline string(const size_t n, const char c) noexcept : len(n), buf(mkcbuf(c, n)) {
     }
 
-    const bool operator==(const string& s) const {
+    inline string(const string& s) noexcept : len(s.len), buf(s.buf) {
+    }
+
+    string& operator=(const string& s) = delete;
+
+    inline const bool operator==(const string& s) const noexcept {
         if (len != s.len)
             return false;
         if (buf == s.buf)
@@ -137,21 +114,21 @@ public:
         return memcmp(buf, s.buf, len) == 0;
     }
 
-    const bool operator!=(const string& s) const {
+    inline const bool operator!=(const string& s) const noexcept {
         return !(*this == s);
     }
 
-    const bool operator==(const char* s) const {
+    inline const bool operator==(const char* const s) const noexcept {
         if (buf == s)
             return true;
         return strcmp(buf, s) == 0;
     }
 
-    const bool operator!=(const char* s) const {
+    inline const bool operator!=(const char* const s) const noexcept {
         return !(*this == s);
     }
 
-    const bool operator<(const string& s) const {
+    inline const bool operator<(const string& s) const noexcept {
         const size_t n = len < s.len? len : s.len;
         const int c = memcmp(buf, s.buf, n);
         if (c < 0)
@@ -161,9 +138,9 @@ public:
         return false;
     }
 
-    const bool operator>(const string& s) const {
+    inline const bool operator>(const string& s) const noexcept {
         const size_t n = len < s.len? len : s.len;
-        int c = memcmp(buf, s.buf, n);
+        const int c = memcmp(buf, s.buf, n);
         if (c > 0)
             return true;
         if (c == 0)
@@ -176,91 +153,137 @@ private:
     friend class odebugstream;
 #endif
     friend class ostringstream;
-    friend const string operator+(const string& a, const string& b);
-    friend const string operator+(const string& a, const char* b);
-    friend const size_t length(const string& s);
-    friend const char* c_str(const string& s);
-    friend const size_t find(const string& s1, const char* s2, const size_t start);
-    friend const string substr(const string& s, const size_t pos, const size_t n);
-
-    size_t len;
-    char* buf;
+    friend const string operator+(const string& a, const string& b) noexcept;
+    friend const string operator+(const string& a, const char* const b) noexcept;
+    friend const string operator+(const string& a, const char c) noexcept;
+    friend const size_t length(const string& s) noexcept;
+    friend const char* const c_str(const string& s) noexcept;
+    friend const size_t find(const string& s1, const char* const s2, const size_t start) noexcept;
+    friend const string substr(const string& s, const size_t pos, const size_t n) noexcept;
+    friend const bool setstring(string& target, const string& s);
+
+    const size_t len;
+    const char* const buf;
+
+    const char* const mkbuf(const size_t n) {
+        if (n == 0)
+            return stringEmptyBuffer;
+        char* const b = gc_cnew(n + 1);
+        b[n] = '\0';
+        return b;
+    }
+
+    const char* const mksbuf(const char* const s, const size_t n) {
+        if (n == 0)
+            return stringEmptyBuffer;
+        char* const b = gc_cnew(n + 1);
+        string_memcpy(b, s, n);
+        b[n] = '\0';
+        return b;
+    }
+
+    const char* const mksbuf(const char* const s, const size_t n, const bool copy) {
+        if (!copy)
+            return s;
+        if (n == 0)
+            return stringEmptyBuffer;
+        char* const b = gc_cnew(n + 1);
+        string_memcpy(b, s, n);
+        b[n] = '\0';
+        return b;
+    }
+
+    const char* const mkcbuf(const char c, const size_t n) {
+        if (n == 0)
+            return stringEmptyBuffer;
+        char* const b = gc_cnew(n + 1);
+        memset(b, c, n);
+        b[n] = '\0';
+        return b;
+    }
 };
 
 /**
  * Adds two strings.
  */
-const string operator+(const string& a, const string& b) {
-    string s;
-    s.len = a.len + b.len;
-    s.buf = gc_cnew(s.len + 1);
-    string_memcpy(s.buf, a.buf, a.len);
-    string_memcpy(s.buf + a.len, b.buf, b.len);
-    s.buf[s.len] = '\0';
-    return s;
-}
-
-const string operator+(const string& a, const char* b) {
-    string s;
-    const size_t blen = strlen(b);
-    s.len = a.len + blen;
-    s.buf = gc_cnew(s.len + 1);
-    string_memcpy(s.buf, a.buf, a.len);
-    string_memcpy(s.buf + a.len, b, blen);
-    s.buf[s.len] = '\0';
-    return s;
+inline const string operator+(const string& sa, const string& sb) noexcept {
+    const size_t n = sa.len + sb.len;
+    char* const b = gc_cnew(n + 1);
+    string_memcpy(b, sa.buf, sa.len);
+    string_memcpy(b + sa.len, sb.buf, sb.len);
+    b[n] = '\0';
+    return string(b, n, false);
+}
+
+inline const string operator+(const string& sa, const char* const sb) noexcept {
+    const size_t bn = strlen(sb);
+    const size_t n = sa.len + bn;
+    char* const b = gc_cnew(n + 1);
+    string_memcpy(b, sa.buf, sa.len);
+    string_memcpy(b + sa.len, sb, bn);
+    b[n] = '\0';
+    return string(b, n, false);
+}
+
+inline const string operator+(const string& sa, const char c) noexcept {
+    const size_t n = sa.len + 1;
+    char* const b = gc_cnew(n + 1);
+    string_memcpy(b, sa.buf, sa.len);
+    b[n - 1] = c;
+    b[n] = '\0';
+    return string(b, n, false);
 }
 
 /**
  * Returns the length of a string.
  */
-const size_t length(const string& s) {
+inline const size_t length(const string& s) noexcept {
     return s.len;
 }
 
 /**
  * Returns a string as a C zero terminated string.
  */
-const char* c_str(const string& s) {
+inline const char* const c_str(const string& s) noexcept {
     return s.buf;
 }
 
 /**
  * Find the first occurrence of string s2 in s1, starting at the given position.
  */
-const size_t find(const string& s1, const char* s2, const size_t start) {
+inline const size_t find(const string& s1, const char* const s2, const size_t start) noexcept {
     if (start >= s1.len)
         return s1.len;
-    const char *f = strstr(s1.buf + start, s2);
+    const char* const f = strstr(s1.buf + start, s2);
     if (f == NULL)
         return s1.len;
     return f - s1.buf;
 }
 
-const size_t find(const string& s1, const char* s2) {
+inline const size_t find(const string& s1, const char* const s2) noexcept {
     return find(s1, s2, 0);
 }
 
 /**
  * Return true if string s1 contains s2.
  */
-const bool contains(const string& s1, const char* s2) {
+inline const bool contains(const string& s1, const char* const s2) noexcept {
     return find(s1, s2) != length(s1);
 }
 
 /**
  * Find the first occurence of any character from a string in a string.
  */
-const size_t find_first_of(const string& s1, const string& s2) {
+inline const size_t find_first_of(const string& s1, const string& s2) noexcept {
     return strcspn(c_str(s1), c_str(s2));
 }
 
 /**
  * Find the first occurence of a character in a string.
  */
-const size_t find(const string& s, const char c) {
-    const char* cs = c_str(s);
-    const char* f = strchr(cs, c);
+inline const size_t find(const string& s, const char c) noexcept {
+    const char* const cs = c_str(s);
+    const char* const f = strchr(cs, c);
     if (f == NULL)
         return length(s);
     return f - cs;
@@ -269,9 +292,9 @@ const size_t find(const string& s, const
 /**
  * Find the last occurence of a character in a string.
  */
-const size_t find_last(const string& s, const char c) {
-    const char* cs = c_str(s);
-    const char* f = strrchr(cs, c);
+inline const size_t find_last(const string& s, const char c) noexcept {
+    const char* const cs = c_str(s);
+    const char* const f = strrchr(cs, c);
     if (f == NULL)
         return length(s);
     return f - cs;
@@ -280,7 +303,7 @@ const size_t find_last(const string& s, 
 /**
  * Return a substring of a string.
  */
-const string substr(const string& s, const size_t pos, const size_t n) {
+inline const string substr(const string& s, const size_t pos, const size_t n) noexcept {
     if (pos >= s.len)
         return string();
     if (pos + n > s.len)
@@ -288,17 +311,29 @@ const string substr(const string& s, con
     return string(s.buf + pos, n);
 }
 
-const string substr(const string& s, const size_t pos) {
+inline const string substr(const string& s, const size_t pos) noexcept {
     return substr(s, pos, length(s));
 }
 
 /**
- * Common string constants.
+ * Set a string. Use with moderation.
  */
+/*
+inline const bool setstring(string& target, const string& s) {
+    if (&target == &s)
+        return true;
+    memcpy((void*)&target.len, (void*)&s.len, sizeof(size_t));
+    memcpy((void*)&target.buf, (void*)&s.buf, sizeof(char*));
+    return true;
+}
+*/
 
-string trueString("true");
-string falseString("false");
-string emptyString("");
+/**
+ * Common string constants.
+ */
+const string trueString("true");
+const string falseString("false");
+const string emptyString("");
 
 }
 

Modified: tuscany/sca-cpp/trunk/kernel/tree.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/tree.hpp?rev=1419985&r1=1419984&r2=1419985&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/tree.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/tree.hpp Tue Dec 11 03:51:03 2012
@@ -38,14 +38,14 @@ namespace tuscany {
 /**
  * Make a tree from a leaf and two branches.
  */
-template<typename T> const list<T> mktree(const T& e, const list<T>& left, const list<T>& right) {
+template<typename T> inline const list<T> mktree(const T& e, const list<T>& left, const list<T>& right) {
     return mklist<T>(e, left, right);
 }
 
 /**
  * Find a leaf with the given key in a tree.
  */
-template<typename T> const list<T> assoctree(const T& k, const list<T>& tree) {
+template<typename T> inline const list<T> assoctree(const T& k, const list<T>& tree) {
     if (isNil(tree))
         return tree;
     if (k == car<T>(car(tree)))
@@ -58,7 +58,7 @@ template<typename T> const list<T> assoc
 /**
  * Construct a new tree from a leaf and a tree.
  */
-template<typename T> const list<T> constree(const T& e, const list<T>& tree) {
+template<typename T> inline const list<T> constree(const T& e, const list<T>& tree) {
     if (isNil(tree))
         return mktree(e, list<T>(), list<T>());
     if (e == car(tree))
@@ -71,7 +71,7 @@ template<typename T> const list<T> const
 /**
  * Make a tree from an unordered list of leaves.
  */
-template<typename T> const list<T> mktree(const list<T>& l) {
+template<typename T> inline const list<T> mktree(const list<T>& l) {
     if (isNil(l))
         return l;
     return constree(car(l), mktree(cdr(l)));
@@ -80,7 +80,7 @@ template<typename T> const list<T> mktre
 /**
  * Convert a tree to an ordered list of leaves.
  */
-template<typename T> const list<T> flatten(const list<T>& tree) {
+template<typename T> inline const list<T> flatten(const list<T>& tree) {
     if (isNil(tree))
         return tree;
     return append<T>(flatten<T>(cadr(tree)), cons<T>(car(tree), flatten<T>(caddr(tree))));
@@ -89,14 +89,14 @@ template<typename T> const list<T> flatt
 /**
  * Sort a list.
  */
-template<typename T> const list<T> sort(const list<T>& l) {
+template<typename T> inline const list<T> sort(const list<T>& l) {
     return flatten(mktree(l));
 }
 
 /**
  * Make a balanced tree from an ordered list of leaves.
  */
-template<typename T> const list<T> btreeHelper(const list<T>& elements, const size_t n) {
+template<typename T> inline const list<T> btreeHelper(const list<T>& elements, const size_t n) {
     if (n == 0)
         return cons<T>(list<T>(), elements);
     const size_t leftSize = (n - 1) / 2; {
@@ -116,7 +116,7 @@ template<typename T> const list<T> btree
     }
 }
 
-template<typename T> const list<T> mkbtree(const list<T>& elements) {
+template<typename T> inline const list<T> mkbtree(const list<T>& elements) {
     return car(btreeHelper<T>(elements, length(elements)));
 }
 

Modified: tuscany/sca-cpp/trunk/kernel/value.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/value.hpp?rev=1419985&r1=1419984&r2=1419985&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/value.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/value.hpp Tue Dec 11 03:51:03 2012
@@ -50,16 +50,16 @@ long int countEValues = 0;
 long int countCValues = 0;
 long int countVValues = 0;
 
-bool resetValueCounters() {
+inline const bool resetValueCounters() {
     countValues = countEValues = countCValues = countVValues = 0;
     return true;
 }
 
-bool checkValueCounters() {
+inline const bool checkValueCounters() {
     return countValues == 0;
 }
 
-bool printValueCounters() {
+inline const bool printValueCounters() {
     cout << "countValues " << countValues << endl;
     cout << "countEValues " << countEValues << endl;
     cout << "countCValues " << countCValues << endl;
@@ -92,7 +92,28 @@ bool printValueCounters() {
 
 #endif
 
+/**
+ * Common value constants.
+ */
 class value;
+extern const value nilValue;
+extern const list<value> nilListValue;
+extern const list<value> nilPairValue;
+extern const value emptyStringValue;
+extern const value trueValue;
+extern const value falseValue;
+
+/**
+ * Common value-based lambda types.
+ */
+typedef lambda<const value(const list<value>&)> lvvlambda;
+typedef lambda<const value(const value&)> vvlambda;
+typedef lambda<const bool(const value&)> vblambda;
+typedef lambda<const value()> vlambda;
+
+/**
+ * Generic value type class.
+ */
 
 class value {
 public:
@@ -101,346 +122,309 @@ public:
         Nil, Symbol, String, List, Number, Bool, Lambda, Ptr
     };
 
-    value() : type(value::Nil) {
+    typedef union {
+        const void* mix;
+        const gc_ptr<list<value> > lst;
+        const string str;
+        const lvvlambda func;
+        const gc_ptr<value> ptr;
+        const double num;
+        const bool boo;
+    } ValueMix;
+
+    inline value() noexcept : type(value::Nil) {
         debug_inc(countValues);
         debug_inc(countEValues);
         debug_watchValue();
     }
 
-    value(const value& v) {
+    inline value(const value& v) noexcept : type(v.type) {
         debug_inc(countValues);
         debug_inc(countCValues);
-        type = v.type;
-        switch(type) {
-        case value::List:
-            lst() = v.lst();
-        case value::Lambda:
-            func() = v.func();
-        case value::Symbol:
-            str() = v.str();
-        case value::String:
-            str() = v.str();
-        case value::Number:
-            num() = v.num();
-        case value::Bool:
-            boo() = v.boo();
-        case value::Ptr:
-            ptr() = v.ptr();
-        default:
-            break;
-        }
+        memcpy((void*)&mix, (void*)&v.mix, sizeof(ValueMix));
 #ifdef WANT_MAINTAINER_WATCH
         watch = v.watch;
 #endif
     }
 
-    virtual ~value() {
+    inline value(const gc_mutable_ref<value>& r) noexcept : type(((value*)r)->type) {
+        debug_inc(countValues);
+        debug_inc(countCValues);
+        memcpy((void*)&mix, (void*)&(((value*)r)->mix), sizeof(ValueMix));
+#ifdef WANT_MAINTAINER_WATCH
+        watch = v.watch;
+#endif
+    }
+
+    inline virtual ~value() noexcept {
         debug_dec(countValues);
     }
 
-    value(const lambda<value(const list<value>&)>& func) : type(value::Lambda), data(vdata(func)) {
+    inline value(const lvvlambda& f) noexcept : type(value::Lambda), func(f) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const string& str) : type(value::String), data(vdata(result(str))) {
+    inline value(const string& s) noexcept : type(value::String), str(s) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const char* str) : type(value::Symbol), data(vdata(result(string(str)))) {
+    inline value(const char* s) noexcept : type(value::Symbol), str(s) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const list<value>& lst) : type(value::List), data(vdata(result(lst))) {
+    inline value(const list<value>& l) noexcept : type(value::List), lst(new (gc_new<list<value> >()) list<value>(l)) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const list<list<value> >& l) : type(value::List), data(vdata(result(listOfValues(l)))) {
+    inline value(const list<list<value> >& l) noexcept : type(value::List), lst(new (gc_new<list<value> >()) list<value>(listOfValues(l))) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const double num) : type(value::Number), data(vdata(result(num))) {
+    inline value(const double d) noexcept : type(value::Number), num(d) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const int num) : type(value::Number), data(vdata(result((double)num))) {
+    inline value(const int i) noexcept : type(value::Number), num((double)i) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const bool boo) : type(value::Bool), data(vdata(result(boo))) {
+    inline value(const bool b) noexcept : type(value::Bool), boo(b) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const gc_ptr<value> ptr) : type(value::Ptr), data(vdata(result(ptr))) {
+    inline value(const gc_ptr<value> p) noexcept : type(value::Ptr), ptr(p) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const failable<value>& m) : type(value::List),
-        data(vdata(result(hasContent(m)? mklist<value>(content(m)) : rcode(m) == 1? mklist<value>(value(), reason(m)) : mklist<value>(value(), reason(m), rcode(m))))) {
+    inline value(const failable<value>& m) noexcept : type(value::List),
+        lst(new (gc_new<list<value> >()) list<value>(hasContent(m)? mklist<value>(content(m)) :
+            rcode(m) == 1? mklist<value>(nilValue, reason(m)) : mklist<value>(nilValue, reason(m), rcode(m)))) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const maybe<value>& m) : type(value::List),
-        data(vdata(result(hasContent(m)? mklist<value>(content(m)) : list<value>()))) {
+    inline value(const maybe<value>& m) noexcept : type(value::List),
+        lst(new (gc_new<list<value> >()) list<value>(hasContent(m)? mklist<value>(content(m)) : nilListValue)) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    const value& operator=(const value& v) {
-        if(this == &v)
-            return *this;
-        type = v.type;
-        switch(type) {
-        case value::List:
-            lst() = v.lst();
-        case value::Lambda:
-            func() = v.func();
-        case value::Symbol:
-            str() = v.str();
-        case value::String:
-            str() = v.str();
-        case value::Number:
-            num() = v.num();
-        case value::Bool:
-            boo() = v.boo();
-        case value::Ptr:
-            ptr() = v.ptr();
-        default:
-            break;
-        }
-#ifdef WANT_MAINTAINER_WATCH
-        watch = v.watch;
-#endif
-        return *this;
-    }
+    value& operator=(const value& v) = delete;
 
-    const bool operator!=(const value& v) const {
+    inline const bool operator!=(const value& v) const noexcept {
         return !this->operator==(v);
     }
 
-    const bool operator==(const value& v) const {
+    inline const bool operator==(const value& v) const noexcept {
         if(this == &v)
             return true;
         switch(type) {
         case value::Nil:
             return v.type == value::Nil;
         case value::List:
-            return v.type == value::List && lst()() == v.lst()();
+            return v.type == value::List && *lst == *v.lst;
         case value::Lambda:
-            return v.type == value::Lambda && func() == v.func();
+            return v.type == value::Lambda && func == v.func;
         case value::Symbol:
         case value::String:
-            return str()() == (string)v;
+            return (v.type == value::Symbol || v.type == value::String) && str == v.str;
         case value::Number:
-            return num()() == (double)v;
+            return v.type == value::Number && num == v.num;
         case value::Bool:
-            return boo()() == (bool)v;
+            return v.type == value::Bool && boo == v.boo;
         case value::Ptr:
-            return v.type == value::Ptr && ptr()() == v.ptr()();
+            return v.type == value::Ptr && ptr == v.ptr;
         default:
             return false;
         }
     }
 
-    const bool operator<(const value& v) const {
+    inline const bool operator<(const value& v) const noexcept {
         if(this == &v)
             return false;
         switch(type) {
         case value::List:
-            return v.type == value::List && lst()() < v.lst()();
+            return v.type == value::List && *lst < *v.lst;
         case value::Symbol:
         case value::String:
-            return str()() < (string)v;
+            return (v.type == value::Symbol || v.type == value::String) && str < v.str;
         case value::Bool:
-            return boo()() < (bool)v;
+            return v.type == value::Bool && boo < v.boo;
         case value::Number:
-            return num()() < (double)v;
+            return v.type == value::Number && num < v.num;
         default:
             return false;
         }
     }
 
-    const bool operator>(const value& v) const {
+    inline const bool operator>(const value& v) const noexcept {
         if(this == &v)
             return false;
         switch(type) {
         case value::List:
-            return v.type == value::List && lst()() > v.lst()();
+            return v.type == value::List && *lst > *v.lst;
         case value::Symbol:
         case value::String:
-            return str()() > (string)v;
+            return (v.type == value::Symbol || v.type == value::String) && str > v.str;
         case value::Bool:
-            return boo()() > (bool)v;
+            return v.type == value::Bool && boo > v.boo;
         case value::Number:
-            return num()() > (double)v;
+            return v.type == value::Number && num > v.num;
         default:
             return false;
         }
     }
 
-    const value operator()(const list<value>& args) const {
-        return func()(args);
+    inline const value operator()(const list<value>& args) const noexcept {
+        return func(args);
     }
 
-    operator const string() const {
+    inline operator const string() const noexcept {
         switch(type) {
         case value::Symbol:
         case value::String:
-            return str()();
+            return str;
         case value::Number: {
             ostringstream os;
-            os << num()();
+            os << num;
             return tuscany::str(os);
         }
         case value::Bool:
-            return boo()()? trueString : falseString;
+            return boo? trueString : falseString;
         default:
             return emptyString;
         }
     }
 
-    operator const double() const {
+    inline operator const double() const noexcept {
         switch(type) {
         case value::Symbol:
         case value::String:
-            return atof(c_str(str()()));
+            return atof(c_str(str));
         case value::Number:
-            return (double)num()();
+            return (double)num;
         case value::Bool:
-            return boo()()? 1.0 : 0.0;
+            return boo? 1.0 : 0.0;
         default:
             return 0.0;
         }
     }
 
-    operator const int() const {
+    inline operator const int() const noexcept {
         switch(type) {
         case value::Symbol:
         case value::String:
-            return atoi(c_str(str()()));
+            return atoi(c_str(str));
         case value::Number:
-            return (int)num()();
+            return (int)num;
         case value::Bool:
-            return boo()()? 1 : 0;
+            return boo? 1 : 0;
         default:
             return 0;
         }
     }
 
-    operator const bool() const {
+    inline operator const bool() const noexcept {
         switch(type) {
         case value::Symbol:
         case value::String:
-            return str()() == string("true");
+            return str == trueString;
         case value::Number:
-            return (int)num()() != 0;
+            return num != 0.0;
         case value::Bool:
-            return boo()();
+            return boo;
         default:
-            return 0;
+            return false;
         }
     }
 
-    operator const gc_ptr<value>() const {
-        return ptr()();
+    inline operator const gc_ptr<value>() const noexcept {
+        return ptr;
     }
 
-    operator const list<value>() const {
-        return lst()();
+    inline operator const list<value>() const noexcept {
+        return *lst;
     }
 
-    operator const list<list<value> >() const {
-        return listOfListOfValues(lst()());
+    inline operator const list<list<value> >() const noexcept {
+        return listOfListOfValues(*lst);
     }
 
-    operator const lambda<value(const list<value>&)>() const {
-        return func();
+    inline operator const lvvlambda() const noexcept {
+        return func;
     }
 
 private:
-     template<typename T> lambda<T>& vdata() const {
-        return *reinterpret_cast<lambda<T> *> (const_cast<lambda<char()> *> (&data));
-    }
-
-    template<typename T> const lambda<char()>& vdata(const T& v) const {
-        return *reinterpret_cast<const lambda<char()> *> (&v);
-    }
-
-    lambda<double()>& num() const {
-        return vdata<double()> ();
-    }
-
-    lambda<bool()>& boo() const {
-        return vdata<bool()> ();
-    }
-
-    lambda<gc_ptr<value>()>& ptr() const {
-        return vdata<gc_ptr<value>()> ();
-    }
-
-    lambda<string()>& str() const {
-        return vdata<string()> ();
-    }
-
-    lambda<list<value>()>& lst() const {
-        return vdata<list<value>()> ();
-    }
-
-    lambda<value(const list<value>&)>& func() const {
-        return vdata<value(const list<value>&)> ();
-    }
-
-    const list<value> listOfValues(const list<list<value> >& l) const {
+    inline const list<value> listOfValues(const list<list<value> >& l) const noexcept {
         if (isNil(l))
-            return list<value>();
+            return nilListValue;
         return cons<value>(car(l), listOfValues(cdr(l)));
     }
 
-    const list<list<value> > listOfListOfValues(const list<value>& l) const {
+    inline const list<list<value> > listOfListOfValues(const list<value>& l) const noexcept {
         if (isNil(l))
             return list<list<value> >();
-        return cons<list<value> >(list<value>(car(l)), listOfListOfValues(cdr(l)));
+        return cons<list<value> >(car(l).type == value::List? list<value>(car(l)) : nilPairValue, listOfListOfValues(cdr(l)));
     }
 
-    friend ostream& operator<<(ostream&, const value&);
-    friend const value::ValueType type(const value& v);
+    friend ostream& operator<<(ostream&, const value&) noexcept;
+    friend const value::ValueType type(const value& v) noexcept;
+    friend const bool setvalue(value& target, const value& v);
 
 #ifdef WANT_MAINTAINER_WATCH
     friend const string watchValue(const value& v);
     string watch;
 #endif
 
-    ValueType type;
-     lambda<char()> data;
+    const ValueType type;
+    union {
+        void* mix;
+        const gc_ptr<list<value> > lst;
+        const string str;
+        const lvvlambda func;
+        const gc_ptr<value> ptr;
+        const double num;
+        const bool boo;
+    };
 };
 
+/**
+ * Common value constants.
+ */
+const value nilValue;
+const list<value> nilListValue = list<value>();
+const list<value> nilPairValue = mklist<value>(nilValue, nilValue);
+const value emptyStringValue(emptyString);
+const value trueValue(true);
+const value falseValue(false);
+
 #ifdef WANT_MAINTAINER_WATCH
 
 /**
  * Debug utility used to write the contents of a value to a string, easier
  * to watch than the value itself in a debugger.
  */
-const string watchValue(const value& v) {
+inline const string watchValue(const value& v) {
     if (v.type == value::List)
         return watchList<value>(v);
     odebugstream os;
@@ -453,7 +437,7 @@ const string watchValue(const value& v) 
 /**
  * Write an escape string to a buffer.
  */
-const char* escapestr(const char* s, char* buf) {
+inline const char* escapestr(const char* const s, char* const buf) noexcept {
     if (*s == '\0') {
         *buf = '\0';
         return buf;
@@ -470,7 +454,7 @@ const char* escapestr(const char* s, cha
 /**
  * Write an escaped string value to a stream.
  */
-ostream& escvwrite(const string& str, ostream& out) {
+inline ostream& escvwrite(const string& str, ostream& out) noexcept {
     char* buf = gc_cnew(length(str) * 2 + 1);
     escapestr(c_str(str), buf);
     out << buf;
@@ -480,30 +464,29 @@ ostream& escvwrite(const string& str, os
 /**
  * Write a value to a stream.
  */
-ostream& operator<<(ostream& out, const value& v) {
+inline ostream& operator<<(ostream& out, const value& v) noexcept {
     switch(v.type) {
     case value::List:
-        return out << v.lst()();
+        return out << *v.lst;
     case value::Lambda:
-        return out << "lambda::" << v.func();
+        return out << "lambda::" << v.func;
     case value::Symbol:
-        return out << v.str()();
+        return out << v.str;
     case value::String:
         out << '\"';
-        escvwrite(v.str()(), out);
+        escvwrite(v.str, out);
         return out << '\"';
     case value::Number:
-        return out << v.num()();
+        return out << v.num;
     case value::Bool:
-        if(v.boo()())
-            return out << "true";
+        if(v.boo)
+            return out << trueString;
         else
-            return out << "false";
+            return out << falseString;
     case value::Ptr: {
-        const gc_ptr<value> p =  v.ptr()();
-        if (p == gc_ptr<value>(NULL))
+        if (v.ptr == gc_ptr<value>(NULL))
             return out << "gc_ptr::null";
-        return out << "gc_ptr::" << p;
+        return out << "gc_ptr::" << v.ptr;
     }
     default:
         return out << "nil";
@@ -513,70 +496,70 @@ ostream& operator<<(ostream& out, const 
 /**
  * Returns the type of a value.
  */
-const value::ValueType type(const value& v) {
+inline const value::ValueType type(const value& v) noexcept {
     return v.type;
 }
 
 /**
  * Returns true if a value is nil.
  */
-const bool isNil(const value& v) {
+inline const bool isNil(const value& v) noexcept {
     return type(v) == value::Nil;
 }
 
 /**
  * Returns true if a value is a lambda.
  */
-const bool isLambda(const value& v) {
+inline const bool isLambda(const value& v) noexcept {
     return type(v) == value::Lambda;
 }
 
 /**
  * Returns true if a value is a string.
  */
-const bool isString(const value& v) {
+inline const bool isString(const value& v) noexcept {
     return type(v) == value::String;
 }
 
 /**
  * Returns true if a value is a symbol.
  */
-const bool isSymbol(const value& v) {
+inline const bool isSymbol(const value& v) noexcept {
     return type(v) == value::Symbol;
 }
 
 /**
  * Returns true if a value is a list.
  */
-const bool isList(const value& v) {
+inline const bool isList(const value& v) noexcept {
     return type(v) == value::List;
 }
 
 /**
  * Returns true if a value is a number.
  */
-const bool isNumber(const value& v) {
+inline const bool isNumber(const value& v) noexcept {
     return type(v) == value::Number;
 }
 
 /**
  * Returns true if a value is a boolean.
  */
-const bool isBool(const value& v) {
+inline const bool isBool(const value& v) noexcept {
     return type(v) == value::Bool;
 }
 
 /**
  * Returns true if a value is a pointer.
  */
-const bool isPtr(const value& v) {
+inline const bool isPtr(const value& v) noexcept {
     return type(v) == value::Ptr;
 }
 
 /**
  * Returns true if a value is a tagged list.
  */
-const bool isTaggedList(const value& exp, value tag) {
+inline const bool isTaggedList(const value& exp, const value& tag) noexcept {
     if(isList(exp) && !isNil((list<value>)exp))
         return car((list<value>)exp) == tag;
     return false;
@@ -585,16 +568,16 @@ const bool isTaggedList(const value& exp
 /**
  * Make a list of values from a list of other things.
  */
-template<typename T> const list<value> mkvalues(const list<T>& l) {
+template<typename T> inline const list<value> mkvalues(const list<T>& l) noexcept {
     if (isNil(l))
-        return list<value>();
+        return nilListValue;
     return cons<value>(car(l), mkvalues(cdr(l)));
 }
 
 /**
  * Convert a list of values to a list of other things.
  */
-template<typename T> const list<T> convertValues(const list<value>& l) {
+template<typename T> inline const list<T> convertValues(const list<value>& l) noexcept {
     if (isNil(l))
         return list<T>();
     return cons<T>(car(l), convertValues<T>(cdr(l)));
@@ -603,7 +586,7 @@ template<typename T> const list<T> conve
 /**
  * Convert a path string value to a list of values.
  */
-const list<string> pathTokens(const char* p) {
+inline const list<string> pathTokens(const char* const p) noexcept {
     if (p == NULL || p[0] == '\0')
         return list<string>();
     if (p[0] == '/')
@@ -611,23 +594,23 @@ const list<string> pathTokens(const char
     return tokenize("/", p);
 }
 
-const list<value> pathValues(const value& p) {
+inline const list<value> pathValues(const value& p) noexcept {
     return mkvalues(pathTokens(c_str(p)));
 }
 
 /**
  * Convert a path represented as a list of values to a string value.
  */
-const value path(const list<value>& p) {
+inline const value path(const list<value>& p) noexcept {
     if (isNil(p))
-        return "";
-    return string("/") + car(p) + path(cdr(p));
+        return emptyString;
+    return string("/") + (string)car(p) + (string)path(cdr(p));
 }
 
 /**
  * Make a uuid value.
  */
-const value mkuuid() {
+inline const value mkuuid() noexcept {
     apr_uuid_t id;
     apr_uuid_get(&id);
     char buf[APR_UUID_FORMATTED_LENGTH];
@@ -638,19 +621,33 @@ const value mkuuid() {
 /**
  * Make a random alphanumeric value.
  */
-const int intrand() {
+inline const int intrand() noexcept {
     const apr_uint64_t now = apr_time_now();
     srand((unsigned int)(((now >> 32) ^ now) & 0xffffffff));
     return rand() & 0x0FFFF;
 }       
 
-const value mkrand() {
+inline const value mkrand() noexcept {
     char buf[32];
-    const char* an = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+    const char* const an = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
     for (int i =0; i < 32; i++)
         buf[i] = an[intrand() % 62];
     return value(string(buf, 32));
 }
 
+/**
+ * Set a value. Use with moderation.
+ */
+inline const bool setvalue(value& target, const value& v) {
+    if (&target == &v)
+        return true;
+#ifdef WANT_MAINTAINER_WATCH
+    memcpy(&target.watch, &v.watch, sizeof(string));
+#endif
+    memcpy((void*)&target.type, (void*)&v.type, sizeof(value::ValueType));
+    memcpy((void*)&target.mix, (void*)&v.mix, sizeof(value::ValueMix));
+    return true;
+}
+
 }
 #endif /* tuscany_value_hpp */

Modified: tuscany/sca-cpp/trunk/modules/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/Makefile.am?rev=1419985&r1=1419984&r2=1419985&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/Makefile.am Tue Dec 11 03:51:03 2012
@@ -15,5 +15,5 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-SUBDIRS = scheme atom rss js json scdl http server python opencl java openid oauth wsgi
+SUBDIRS = xml json scheme atom rss js scdl http server python opencl java openid oauth wsgi
 

Modified: tuscany/sca-cpp/trunk/modules/atom/atom-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/atom/atom-test.cpp?rev=1419985&r1=1419984&r2=1419985&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/atom/atom-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/atom/atom-test.cpp Tue Dec 11 03:51:03 2012
@@ -38,100 +38,100 @@ ostream* writer(const string& s, ostream
 
 const string itemEntry(
         "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-        "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
-        " <title type=\"text\">item</title>\n"
-        " <id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>\n"
-        " <author>\n"
-        "  <email>jane@example.com</email>\n"
-        " </author>\n"
-        " <updated>Fri Jan 01 08:11:36 PDT 2012</updated>\n"
-        " <content type=\"application/xml\">\n"
-        "  <item>\n"
-        "   <name>Apple</name>\n"
-        "   <price>$2.99</price>\n"
-        "  </item>\n"
-        " </content>\n"
-        " <link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>\n"
+        "<entry xmlns=\"http://www.w3.org/2005/Atom\">"
+        "<title type=\"text\">item</title>"
+        "<id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>"
+        "<author>"
+        "<email>jane@example.com</email>"
+        "</author>"
+        "<updated>Fri Jan 01 08:11:36 PDT 2012</updated>"
+        "<content type=\"application/xml\">"
+        "<item>"
+        "<name>Apple</name>"
+        "<price>$2.99</price>"
+        "</item>"
+        "</content>"
+        "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>"
         "</entry>\n");
 
 const string itemTextEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-        "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
-        " <title type=\"text\">item</title>\n"
-        " <id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>\n"
-        " <author>\n"
-        "  <email>jane@example.com</email>\n"
-        " </author>\n"
-        " <updated>Fri Jan 01 08:11:36 PDT 2012</updated>\n"
-        " <content type=\"text\">Apple</content>\n"
-        " <link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>\n"
+        "<entry xmlns=\"http://www.w3.org/2005/Atom\">"
+        "<title type=\"text\">item</title>"
+        "<id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>"
+        "<author>"
+        "<email>jane@example.com</email>"
+        "</author>"
+        "<updated>Fri Jan 01 08:11:36 PDT 2012</updated>"
+        "<content type=\"text\">Apple</content>"
+        "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>"
         "</entry>\n");
 
 const string itemNoContentEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-        "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
-        " <title type=\"text\">item</title>\n"
-        " <id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>\n"
-        " <author>\n"
-        "  <name>jane</name>\n"
-        " </author>\n"
-        " <updated>Fri Jan 01 08:11:36 PDT 2012</updated>\n"
-        " <link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>\n"
+        "<entry xmlns=\"http://www.w3.org/2005/Atom\">"
+        "<title type=\"text\">item</title>"
+        "<id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>"
+        "<author>"
+        "<name>jane</name>"
+        "</author>"
+        "<updated>Fri Jan 01 08:11:36 PDT 2012</updated>"
+        "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>"
         "</entry>\n");
 
 const string incompleteEntry("<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
-        " <title>item</title>\n"
-        " <content type=\"text/xml\">\n"
-        "  <Item xmlns=\"http://services/\">\n"
-        "   <name xmlns=\"\">Orange</name>\n"
-        "   <price xmlns=\"\">3.55</price>\n"
-        "  </Item>\n"
-        " </content>\n"
+        "<title>item</title>"
+        "<content type=\"text/xml\">"
+        "<Item xmlns=\"http://services/\">"
+        "<name xmlns=\"\">Orange</name>"
+        "<price xmlns=\"\">3.55</price>"
+        "</Item>"
+        "</content>"
         "</entry>\n");
 
 const string completedEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-        "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
-        " <title type=\"text\">item</title>\n"
-        " <id></id>\n"
-        " <content type=\"application/xml\">\n"
-        "  <Item xmlns=\"http://services/\">\n"
-        "   <name xmlns=\"\">Orange</name>\n"
-        "   <price xmlns=\"\">3.55</price>\n"
-        "  </Item>\n"
-        " </content>\n"
-        " <link href=\"\"/>\n"
+        "<entry xmlns=\"http://www.w3.org/2005/Atom\">"
+        "<title type=\"text\">item</title>"
+        "<id></id>"
+        "<content type=\"application/xml\">"
+        "<Item xmlns=\"http://services/\">"
+        "<name xmlns=\"\">Orange</name>"
+        "<price xmlns=\"\">3.55</price>"
+        "</Item>"
+        "</content>"
+        "<link href=\"\"/>"
         "</entry>\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("item")))
-                + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))
-                + value(list<value>() + element + value("author") + value(string("jane@example.com")))
-                + value(list<value>() + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012")))
-                + 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("item")))
+                + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))
+                + value(nilListValue + element + value("author") + value(string("jane@example.com")))
+                + value(nilListValue + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012")))
+                + value(nilListValue + element + value("content") + value(i)));
         ostringstream os;
         writeATOMEntry<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("item")))
-                + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))
-                + value(list<value>() + element + value("author") + value(string("jane@example.com")))
-                + value(list<value>() + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012")))
-                + 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("item")))
+                + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))
+                + value(nilListValue + element + value("author") + value(string("jane@example.com")))
+                + value(nilListValue + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012")))
+                + value(nilListValue + element + value("content") + value(string("Apple"))));
         ostringstream os;
         writeATOMEntry<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("item")))
-                + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))
-                + value(list<value>() + element + value("author") + value(string("jane")))
-                + value(list<value>() + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012"))));
+        const list<value> a = nilListValue + (nilListValue + element + value("entry")
+                + value(nilListValue + element + value("title") + value(string("item")))
+                + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))
+                + value(nilListValue + element + value("author") + value(string("jane")))
+                + value(nilListValue + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012"))));
         ostringstream os;
         writeATOMEntry<ostream*>(writer, &os, a);
         assert(str(os) == itemNoContentEntry);
@@ -164,54 +164,54 @@ bool testEntry() {
 }
 
 const string emptyFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-        "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
-        " <title type=\"text\">Feed</title>\n"
-        " <id>1234</id>\n"
+        "<feed xmlns=\"http://www.w3.org/2005/Atom\">"
+        "<title type=\"text\">Feed</title>"
+        "<id>1234</id>"
         "</feed>\n");
 
 const string itemFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-        "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
-        " <title type=\"text\">Feed</title>\n"
-        " <id>1234</id>\n"
-        " <entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
-        "  <title type=\"text\">item</title>\n"
-        "  <id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>\n"
-        "  <author>\n"
-        "   <email>jane@example.com</email>\n"
-        "  </author>\n"
-        "  <updated>Fri Jan 01 08:11:36 PDT 2012</updated>\n"
-        "  <content type=\"application/xml\">\n"
-        "   <item>\n"
-        "    <name>Apple</name>\n"
-        "    <price>$2.99</price>\n"
-        "   </item>\n"
-        "  </content>\n"
-        "  <link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>\n"
-        " </entry>\n"
-        " <entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
-        "  <title type=\"text\">item</title>\n"
-        "  <id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c</id>\n"
-        "  <author>\n"
-        "   <email>jane@example.com</email>\n"
-        "  </author>\n"
-        "  <updated>Fri Jan 01 08:11:36 PDT 2012</updated>\n"
-        "  <content type=\"application/xml\">\n"
-        "   <item>\n"
-        "    <name>Orange</name>\n"
-        "    <price>$3.55</price>\n"
-        "   </item>\n"
-        "  </content>\n"
-        "  <link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c\"/>\n"
-        " </entry>\n"
+        "<feed xmlns=\"http://www.w3.org/2005/Atom\">"
+        "<title type=\"text\">Feed</title>"
+        "<id>1234</id>"
+        "<entry xmlns=\"http://www.w3.org/2005/Atom\">"
+        "<title type=\"text\">item</title>"
+        "<id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>"
+        "<author>"
+        "<email>jane@example.com</email>"
+        "</author>"
+        "<updated>Fri Jan 01 08:11:36 PDT 2012</updated>"
+        "<content type=\"application/xml\">"
+        "<item>"
+        "<name>Apple</name>"
+        "<price>$2.99</price>"
+        "</item>"
+        "</content>"
+        "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>"
+        "</entry>"
+        "<entry xmlns=\"http://www.w3.org/2005/Atom\">"
+        "<title type=\"text\">item</title>"
+        "<id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c</id>"
+        "<author>"
+        "<email>jane@example.com</email>"
+        "</author>"
+        "<updated>Fri Jan 01 08:11:36 PDT 2012</updated>"
+        "<content type=\"application/xml\">"
+        "<item>"
+        "<name>Orange</name>"
+        "<price>$3.55</price>"
+        "</item>"
+        "</content>"
+        "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c\"/>"
+        "</entry>"
         "</feed>\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")))
-                + value(list<value>() + element + value("author") + value(string("jane@example.com")))
-                + value(list<value>() + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012"))));
+        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")))
+                + value(nilListValue + element + value("author") + value(string("jane@example.com")))
+                + value(nilListValue + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012"))));
         ostringstream os;
         writeATOMFeed<ostream*>(writer, &os, a);
         assert(str(os) == emptyFeed);
@@ -223,31 +223,31 @@ 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("item")))
-                + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))
-                + value(list<value>() + element + value("author") + value(string("jane@example.com")))
-                + value(list<value>() + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012")))
-                + value(list<value>() + element + value("content") + value(i1)))
-            + value(list<value>() + element + value("entry")
-                + value(list<value>() + element + value("title") + value(string("item")))
-                + value(list<value>() + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c")))
-                + value(list<value>() + element + value("author") + value(string("jane@example.com")))
-                + value(list<value>() + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012")))
-                + 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("item")))
+                + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")))
+                + value(nilListValue + element + value("author") + value(string("jane@example.com")))
+                + value(nilListValue + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012")))
+                + value(nilListValue + element + value("content") + value(i1)))
+            + value(nilListValue + element + value("entry")
+                + value(nilListValue + element + value("title") + value(string("item")))
+                + value(nilListValue + element + value("id") + value(string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c")))
+                + value(nilListValue + element + value("author") + value(string("jane@example.com")))
+                + value(nilListValue + element + value("updated") + value(string("Fri Jan 01 08:11:36 PDT 2012")))
+                + 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;
@@ -273,7 +273,7 @@ bool testFeed() {
 }
 
 int main() {
-    tuscany::gc_scoped_pool p;
+    const tuscany::gc_scoped_pool p;
     tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::atom::testEntry();

Modified: tuscany/sca-cpp/trunk/modules/atom/atom.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/atom/atom.hpp?rev=1419985&r1=1419984&r2=1419985&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/atom/atom.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/atom/atom.hpp Tue Dec 11 03:51:03 2012
@@ -30,7 +30,7 @@
 #include "list.hpp"
 #include "value.hpp"
 #include "monad.hpp"
-#include "xml.hpp"
+#include "../xml/xml.hpp"
 
 namespace tuscany {
 namespace atom {
@@ -46,24 +46,24 @@ const value entry("entry");
  */
 const list<value> entryElementValues(const list<value>& e) {
     const list<value> lt = filter<value>(selector(mklist<value>(element, "title")), e);
-    const list<value> t = list<value>() + element + value("title") + (isNil(lt)? value(emptyString) : elementValue(car(lt)));
+    const list<value> t = nilListValue + element + value("title") + (isNil(lt)? value(emptyString) : elementValue(car(lt)));
 
     const list<value> li = filter<value>(selector(mklist<value>(element, "id")), e);
-    const list<value> i = list<value>() + element + value("id") + (isNil(li)? value(emptyString) : elementValue(car(li)));
+    const list<value> i = nilListValue + element + value("id") + (isNil(li)? value(emptyString) : elementValue(car(li)));
 
     const list<value> la = filter<value>(selector(mklist<value>(element, "author")), e);
-    const list<value> lan = isNil(la)? list<value>() : filter<value>(selector(mklist<value>(element, "name")), car(la));
-    const list<value> lae = isNil(la)? list<value>() : filter<value>(selector(mklist<value>(element, "email")), car(la));
+    const list<value> lan = isNil(la)? nilListValue : filter<value>(selector(mklist<value>(element, "name")), car(la));
+    const list<value> lae = isNil(la)? nilListValue : filter<value>(selector(mklist<value>(element, "email")), car(la));
     const list<value> laa = isNil(lan)? lae : lan;
-    const list<value> a = isNil(laa)? list<value>() : mklist<value>(list<value>() + element + value("author") + elementValue(car(laa)));
+    const list<value> a = isNil(laa)? nilListValue : mklist<value>(nilListValue + element + value("author") + elementValue(car(laa)));
 
     const list<value> lu = filter<value>(selector(mklist<value>(element, "updated")), e);
-    const list<value> u = isNil(lu)? list<value>() : mklist<value>(list<value>() + element + value("updated") + elementValue(car(lu)));
+    const list<value> u = isNil(lu)? nilListValue : mklist<value>(nilListValue + element + value("updated") + elementValue(car(lu)));
 
     const list<value> lc = filter<value>(selector(mklist<value>(element, "content")), e);
-    const list<value> c = isNil(lc)? list<value>() : mklist<value>(list<value>() + element + value("content") + elementValue(car(lc)));
+    const list<value> c = isNil(lc)? nilListValue : mklist<value>(nilListValue + element + value("content") + elementValue(car(lc)));
 
-    return append<value>(append<value>(append<value>(list<value>() + element + entry + value(t) + value(i), a), u), c);
+    return append<value>(append<value>(append<value>(nilListValue + element + entry + value(t) + value(i), a), u), c);
 }
 
 /**
@@ -79,7 +79,7 @@ const list<value> entriesElementValues(c
  * Return true if a list of strings contains an ATOM feed.
  */
 const bool isATOMFeed(const list<string>& ls) {
-    if (!isXML(ls))
+    if (!xml::isXML(ls))
         return false;
     return contains(car(ls), "<feed") && contains(car(ls), "=\"http://www.w3.org/2005/Atom\"");
 }
@@ -88,7 +88,7 @@ const bool isATOMFeed(const list<string>
  * Return true if a list of strings contains an ATOM entry.
  */
 const bool isATOMEntry(const list<string>& ls) {
-    if (!isXML(ls))
+    if (!xml::isXML(ls))
         return false;
     return contains(car(ls), "<entry") && !contains(car(ls), "<feed") && contains(car(ls), "=\"http://www.w3.org/2005/Atom\"");
 }
@@ -97,7 +97,7 @@ const bool isATOMEntry(const list<string
  * Convert a list of strings to a list of values representing an ATOM entry.
  */
 const failable<list<value> > readATOMEntry(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)));
@@ -107,32 +107,25 @@ const failable<list<value> > readATOMEnt
  * Convert a list of strings to a list of values representing an ATOM feed.
  */
 const failable<list<value> > readATOMFeed(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> 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));
-    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)));
 }
 
 /**
  * Returns children of an ATOM content element.
  */
-struct filterContentElementChildren {
-    const value type;
-    filterContentElementChildren() : type("type") {
-    }
-    const bool operator()(const value& v) const {
-        return !(isAttribute(v) && attributeName((list<value>)v) == type);
-    }
-};
-
 const list<value> contentElementChildren(const value& content) {
-    return filter<value>(filterContentElementChildren(), elementChildren(content));
+    return filter<value>([](const value& v) {
+                return !(isAttribute(v) && attributeName((list<value>)v) == "type");
+            }, elementChildren(content));
 }
 
 /**
@@ -146,18 +139,18 @@ const list<value> entryElement(const lis
     const value updated = elementChild("updated", l);
     const value content = elementChild("content", l);
     const bool text = isNil(content)? false : elementHasValue(content);
-    return list<value>()
-        + element + entry + (list<value>() + attribute + "xmlns" + "http://www.w3.org/2005/Atom")
-        + (list<value>() + element + "title" + (list<value>() + attribute + "type" + "text") + elementValue(title))
-        + (list<value>() + element + "id" + elementValue(id))
-        + (isNil(author)? list<value>() : (list<value>() + element + "author" +
-            (email? (list<value>() + element + "email" + elementValue(author)) : (list<value>() + element + "name" + elementValue(author)))))
-        + (isNil(updated)? list<value>() : (list<value>() + element + "updated" + elementValue(updated)))
+    return nilListValue
+        + element + entry + (nilListValue + attribute + "xmlns" + "http://www.w3.org/2005/Atom")
+        + (nilListValue + element + "title" + (nilListValue + attribute + "type" + "text") + elementValue(title))
+        + (nilListValue + element + "id" + elementValue(id))
+        + (isNil(author)? nilListValue : (nilListValue + element + "author" +
+            (email? (nilListValue + element + "email" + elementValue(author)) : (nilListValue + element + "name" + elementValue(author)))))
+        + (isNil(updated)? nilListValue : (nilListValue + element + "updated" + elementValue(updated)))
         + (isNil(content)?
-            list<value>() :
-            append<value>(list<value>() + element + "content" + (list<value>() + attribute + "type" + (text? "text" : "application/xml")),
+            nilListValue :
+            append<value>(nilListValue + element + "content" + (nilListValue + attribute + "type" + (text? "text" : "application/xml")),
                 text? mklist<value>(elementValue(content)) : contentElementChildren(content)))
-        + (list<value>() + element + "link" + (list<value>() + attribute + "href" + elementValue(id)));
+        + (nilListValue + element + "link" + (nilListValue + attribute + "href" + elementValue(id)));
 }
 
 /**
@@ -172,9 +165,9 @@ const list<value> entriesElements(const 
 /**
  * Convert a list of element values representing an ATOM entry to an ATOM entry.
  */
-template<typename R> const failable<R> writeATOMEntry(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& ll) {
+template<typename R> const failable<R> writeATOMEntry(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> > writeATOMEntry(const list<value>& l) {
@@ -187,31 +180,31 @@ const failable<list<string> > writeATOME
 /**
  * Convert a list of element values representing an ATOM feed to an ATOM feed.
  */
-template<typename R> const failable<R> writeATOMFeed(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& ll) {
+template<typename R> const failable<R> writeATOMFeed(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> f = list<value>()
-        + element + feed + (list<value>() + attribute + "xmlns" + "http://www.w3.org/2005/Atom")
-        + (list<value>() + element + "title" + (list<value>() + attribute + "type" + "text") + t)
-        + (list<value>() + element + "id" + i);
+    const list<value> f = nilListValue
+        + element + feed + (nilListValue + attribute + "xmlns" + "http://www.w3.org/2005/Atom")
+        + (nilListValue + element + "title" + (nilListValue + attribute + "type" + "text") + t)
+        + (nilListValue + element + "id" + i);
 
     // Write ATOM entries
     const list<value> le = filter<value>(selector(mklist<value>(element, entry)), l);
     if (isNil(le))
-        return writeXML<R>(reduce, initial, mklist<value>(f));
+        return xml::writeElements<R>(reduce, initial, mklist<value>(f));
 
     // Write a single ATOM entry element with a list of values
     if (!isNil(le) && !isNil(car(le)) && isList(car<value>(caddr<value>(car(le))))) {
         const list<value> fe = append(f, entriesElements(caddr<value>(car(le))));
-        return writeXML<R>(reduce, initial, mklist<value>(fe));
+        return xml::writeElements<R>(reduce, initial, mklist<value>(fe));
     }
 
     // Write separate ATOM entry elements
     const list<value> fe = append(f, entriesElements(le));
-    return writeXML<R>(reduce, initial, mklist<value>(fe));
+    return xml::writeElements<R>(reduce, initial, mklist<value>(fe));
 }
 
 /**

Modified: tuscany/sca-cpp/trunk/modules/rss/rss-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/rss/rss-test.cpp?rev=1419985&r1=1419984&r2=1419985&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/rss/rss-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/rss/rss-test.cpp Tue Dec 11 03:51:03 2012
@@ -37,78 +37,78 @@ ostream* writer(const string& s, ostream
 }
 
 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();

Modified: tuscany/sca-cpp/trunk/modules/rss/rss.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/rss/rss.hpp?rev=1419985&r1=1419984&r2=1419985&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/rss/rss.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/rss/rss.hpp Tue Dec 11 03:51:03 2012
@@ -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(con
     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(c
  * 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>&
  * 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> > readRSSEntr
  * 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 lis
     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 
  * 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> > writeRSSEn
  * 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));
 }
 
 /**



Mime
View raw message