tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r895165 [2/4] - in /tuscany/sca-cpp/trunk: ./ components/cache/ etc/ kernel/ modules/ modules/atom/ modules/eval/ modules/http/ modules/json/ modules/scdl/ modules/server/ test/store-script/
Date Sat, 02 Jan 2010 10:27:29 GMT
Added: tuscany/sca-cpp/trunk/kernel/sstream.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/sstream.hpp?rev=895165&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/sstream.hpp (added)
+++ tuscany/sca-cpp/trunk/kernel/sstream.hpp Sat Jan  2 10:27:26 2010
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef tuscany_sstream_hpp
+#define tuscany_sstream_hpp
+
+/**
+ * Char buffer based streams.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <memory.h>
+#include "string.hpp"
+#include "stream.hpp"
+#include "list.hpp"
+
+namespace tuscany {
+
+/**
+ * Instrumentable memcpy.
+ */
+void* stream_memcpy(void* t, const void* s, const size_t n) {
+    return memcpy(t, s, n);
+}
+
+/**
+ * Output stream backed by a char buffer.
+ */
+class ostringstream : public ostream {
+public:
+    ostringstream() : len(0) {
+    }
+
+    ~ostringstream() {
+    }
+
+    ostringstream(const ostringstream& os) {
+        len = os.len;
+        buf = os.buf;
+    }
+
+    ostringstream& vprintf(const char* fmt, ...) {
+        va_list args;
+        va_start (args, fmt);
+        string s;
+        s.len = vsnprintf(NULL, 0, fmt, args);
+        s.buf = gc_cnew(s.len + 1);
+        vsnprintf(s.buf, s.len + 1, fmt, args);
+        buf = cons(s, buf);
+        len += s.len;
+        va_end (args);
+        return *this;
+    }
+
+    ostringstream& flush() {
+        return *this;
+    }
+
+private:
+    static const bool strHelper(const list<string> l, char* buf) {
+        if (isNil(l))
+            return true;
+        const string c = car(l);
+        char* b = buf - length(c);
+        memcpy(b, c_str(c), length(c));
+        return strHelper(cdr(l), b);
+    }
+
+    const string str() {
+        if (isNil(buf))
+            return string();
+        string s;
+        s.len = len;
+        s.buf = gc_cnew(s.len + 1);
+        strHelper(buf, s.buf + len);
+        s.buf[s.len] = '\0';
+        return s;
+    }
+
+    friend const string str(ostringstream& os);
+
+    int len;
+    list<string> buf;
+};
+
+/**
+ * Return a string representation of a stream.
+ */
+const string str(ostringstream& os) {
+    return os.str();
+}
+
+/**
+ * Input stream backed by a char buffer
+ */
+class istringstream : public istream {
+public:
+    istringstream(const string& s) {
+        cur = 0;
+        const int slen = length(s);
+        len = slen;
+        buf = c_str(s);
+      }
+
+    ~istringstream() {
+    }
+
+    istringstream(const istringstream& is) {
+        len = is.len;
+        cur = is.cur;
+        buf = is.buf;
+    }
+
+    const int read(void* b, int size) {
+        const int n = len - cur;
+        if (n == 0)
+            return 0;
+        if (n > size) {
+            stream_memcpy(b, buf + cur, size);
+            cur = cur + size;
+            return size;
+        }
+        stream_memcpy(b, buf + cur, n);
+        cur = cur + n;
+        return n;
+    }
+
+    const bool eof() {
+        return cur == len;
+    }
+
+    const bool fail() {
+        return false;
+    }
+
+    const int get() {
+        if (eof())
+            return -1;
+        const int c = buf[cur];
+        cur += 1;
+        return c;
+    }
+
+    const int peek() {
+        if (eof())
+            return -1;
+        return buf[cur];
+    }
+
+private:
+    int len;
+    int cur;
+    const char* buf;
+};
+
+/**
+ * Tokenize a string into a list of strings.
+ */
+const list<string> tokenize(const char* sep, const string& str) {
+    struct nested {
+        static const list<string> tokenize(const char* sep, const string& str, const int start = 0) {
+            if (start >= length(str))
+                return list<string>();
+            const int i = find(str, sep, start);
+            if (i == length(str))
+                return mklist(string(substr(str, start)));
+            return cons(string(substr(str, start, i - start)), tokenize(sep, str, i + 1));
+        }
+    };
+    return nested::tokenize(sep, str, 0);
+}
+
+/**
+ * Returns a lazy list view of an input stream.
+ */
+struct ilistRead{
+    istream &is;
+    ilistRead(istream& is) : is(is) {
+    }
+    const list<string> operator()() {
+        char buffer[1024];
+        const int n = read(is, buffer, sizeof(buffer));
+        if (n ==0)
+            return list<string>();
+        return cons(string(buffer, n), (*this)());
+    }
+};
+
+const list<string> streamList(istream& is) {
+    return ilistRead(is)();
+}
+
+/**
+ * Fragment the first element of a list of strings to fit the given max length.
+ */
+const list<string> fragment(list<string> l, int max) {
+    const string s = car(l);
+    if (length(s) <= max)
+        return l;
+    return cons(substr(s, 0, max), cons(substr(s, max), cdr(l)));
+}
+
+/**
+ * Write a list of strings to an output stream.
+ */
+ostream& write(const list<string>& l, ostream& os) {
+    if(isNil(l))
+        return os;
+    os << car(l);
+    return write(cdr(l), os);
+}
+
+}
+
+#endif /* tuscany_sstream_hpp */

Added: tuscany/sca-cpp/trunk/kernel/stream.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/stream.hpp?rev=895165&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/stream.hpp (added)
+++ tuscany/sca-cpp/trunk/kernel/stream.hpp Sat Jan  2 10:27:26 2010
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef tuscany_stream_hpp
+#define tuscany_stream_hpp
+
+/**
+ * Basic stream type and functions.
+ */
+
+#include <stdarg.h>
+#include "debug.hpp"
+#include "gc.hpp"
+#include "string.hpp"
+
+namespace tuscany {
+
+/**
+ * Base output stream.
+ */
+class ostream {
+public:
+    virtual ostream& vprintf(const char* fmt, ...) = 0;
+    virtual ostream& flush() = 0;
+};
+
+/**
+ * Flush a stream.
+ */
+ostream& flush(ostream& os) {
+    return os.flush();
+}
+
+/**
+ * Write simple values to a stream.
+ */
+ostream& operator<<(ostream& os, const char* v) {
+    return os.vprintf("%s", v);
+}
+
+ostream& operator<<(ostream& os, const unsigned char* v) {
+    return os.vprintf("%s", v);
+}
+
+ostream& operator<<(ostream& os, const char v) {
+    return os.vprintf("%c", v);
+}
+
+ostream& operator<<(ostream& os, const int v) {
+    return os.vprintf("%d", v);
+}
+
+ostream& operator<<(ostream& os, const long int v) {
+    return os.vprintf("%ld", v);
+}
+
+ostream& operator<<(ostream& os, const double v) {
+    return os.vprintf("%g", v);
+}
+
+ostream& operator<<(ostream& os, const void* v) {
+    return os.vprintf("%p", v);
+}
+
+ostream& operator<<(ostream& os, const string& v) {
+    return os.vprintf("%s", c_str(v));
+}
+
+class stream_endl {
+} endl;
+
+ostream& operator<<(ostream& os, unused const stream_endl e) {
+    os.vprintf("%s", "\n");
+    return os.flush();
+}
+
+/*
+ * Input stream.
+ */
+class istream {
+public:
+    virtual const int read(void* buf, int size) = 0;
+    virtual const bool eof() = 0;
+    virtual const bool fail() = 0;
+    virtual const int get() = 0;
+    virtual const int peek() = 0;
+};
+
+/**
+ * Read from an input stream.
+ */
+const int read(istream& is, void * buf, int size) {
+    return is.read(buf, size);
+}
+
+/**
+ * Return true if the end of an input stream has been reached.
+ */
+const bool eof(istream& is) {
+    return is.eof();
+}
+
+/**
+ * Return true if an input stream can't be accessed.
+ */
+const bool fail(istream& is) {
+    return is.fail();
+}
+
+/**
+ * Read a character from a stream.
+ */
+const int get(istream& is) {
+    return is.get();
+}
+
+/**
+ * Peek a character from a stream.
+ */
+const int peek(istream& is) {
+    return is.peek();
+}
+
+template<typename T> ostream& operator<<(ostream& out, const gc_ptr<T>& p) {
+    return out << p.ptr;
+}
+
+}
+
+#endif /* tuscany_stream_hpp */

Added: tuscany/sca-cpp/trunk/kernel/string-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/string-test.cpp?rev=895165&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/string-test.cpp (added)
+++ tuscany/sca-cpp/trunk/kernel/string-test.cpp Sat Jan  2 10:27:26 2010
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * Test string functions.
+ */
+
+#include <assert.h>
+#include <string>
+#include "sstream.hpp"
+#include "string.hpp"
+#include "list.hpp"
+#include "perf.hpp"
+
+namespace tuscany {
+
+bool testCopies() {
+    resetStringCopyCounters();
+    string x("abcd");
+    assert(checkStringCopyCounters(1));
+    resetStringCopyCounters();
+    string y = string("abcd");
+    assert(checkStringCopyCounters(1));
+    resetStringCopyCounters();
+    string z = y;
+    assert(checkStringCopyCounters(0));
+    resetStringCopyCounters();
+    const list<string> pl = list<string>() + "abcd" + "efgh";
+    printStringCopyCounters();
+    resetStringCopyCounters();
+    const list<string> cl = cons<string>("efgh", mklist<string>("abcd"));
+    printStringCopyCounters();
+    return true;
+}
+
+bool testString() {
+    const string s("abcd");
+    assert(length(s) == 4);
+    assert(!strcmp(c_str(s), "abcd"));
+
+    assert(s == "abcd");
+    assert(s == string("abcd"));
+    assert(s != "zbcd");
+
+    assert(s < "zbcd");
+    assert(s < "zbc");
+    assert(s < "abzd");
+    assert(s < "abcdz");
+
+    assert(s > "Abcd");
+    assert(s > "Abc");
+    assert(s > "abCd");
+    assert(s > "Abcdz");
+
+    const string x = "abcd";
+    assert(!strcmp(c_str(x), "abcd"));
+
+    const string y = string("abcd");
+    assert(!strcmp(c_str(y), "abcd"));
+
+    assert(string("ab") + "cd" == "abcd");
+
+    assert(find("abcd", "cd") == 2);
+    assert(find("abcd", "xy") == length("abcd"));
+    assert(substr("abcdef", 4) == "ef");
+    assert(substr("abcdef", 4, 2) == "ef");
+    assert(substr("abcdef", 4, 3) == "ef");
+    assert(substr("abcdef", 6, 3) == "");
+    return true;
+}
+
+bool testStream() {
+    ostringstream os;
+    os << "ab" << "cd";
+    cout << str(os) << endl;
+    assert(str(os) == "abcd");
+
+    ostringstream cs;
+    cs << "\'";
+    assert(str(cs) == "\'");
+    cs << '\'';
+    assert(str(cs) == "\'\'");
+
+    istringstream is("abcd");
+    char b[2];
+    assert(read(is, b, 2) == 2);
+    assert(string("ab") == string(b, 2));
+    assert(eof(is) == false);
+    assert(read(is, b, 2) == 2);
+    assert(string("cd") == string(b, 2));
+    assert(eof(is) == true);
+    assert(read(is, b, 2) == 0);
+    return true;
+}
+
+std::string stdAdd(std::string& x, std::string& y) {
+    return x + y;
+}
+
+string add(string& x, string& y) {
+    return x + y;
+}
+
+char charBuffer[16384];
+
+struct addStrings{
+    const int size;
+    addStrings(const int size) : size(size) {
+    }
+    bool operator()() const {
+        const int sz = size / 4;
+        string x(charBuffer, sz);
+        string y(charBuffer, sz);
+        assert(length(add(x, y)) == sz * 2);
+        return true;
+    }
+};
+
+struct addStdStrings{
+    const int size;
+    addStdStrings(const int size) : size(size) {
+    }
+    bool operator()() const {
+        const int sz = size / 4;
+        std::string x(charBuffer, sz);
+        std::string y(charBuffer, sz);
+        assert(stdAdd(x, y).length() == (unsigned int)(sz * 2));
+        return true;
+    }
+};
+
+bool testStringPerf() {
+    memset(charBuffer, 'A', 16384);
+    charBuffer[16384] = '\0';
+
+    const int count = 100000;
+    {
+        const lambda<bool()> a16 = addStrings(16);
+        cout << "string test " << time(a16, 5, count) << " ms" << endl;
+        const lambda<bool()> a32 =addStrings(32);
+        cout << "string test " << time(a32, 5, count) << " ms" << endl;
+        const lambda<bool()> a256 =addStrings(256);
+        cout << "string test " << time(a256, 5, count) << " ms" << endl;
+        const lambda<bool()> a1024 =addStrings(1024);
+        cout << "string test " << time(a1024, 5, count) << " ms" << endl;
+        const lambda<bool()> a4096 =addStrings(4096);
+        cout << "string test " << time(a4096, 5, count) << " ms" << endl;
+    }
+    {
+        const lambda<bool()> a16 =addStdStrings(16);
+        cout << "Std string test " << time(a16, 5, count) << " ms" << endl;
+        const lambda<bool()> a32 =addStdStrings(32);
+        cout << "Std string test " << time(a32, 5, count) << " ms" << endl;
+        const lambda<bool()> a256 =addStdStrings(256);
+        cout << "Std string test " << time(a256, 5, count) << " ms" << endl;
+        const lambda<bool()> a1024 =addStdStrings(1024);
+        cout << "Std string test " << time(a1024, 5, count) << " ms" << endl;
+        const lambda<bool()> a4096 =addStdStrings(4096);
+        cout << "Std string test " << time(a4096, 5, count) << " ms" << endl;
+    }
+
+    return true;
+}
+
+}
+
+int main() {
+    tuscany::cout << "Testing..." << tuscany::endl;
+
+    tuscany::testCopies();
+    tuscany::testString();
+    tuscany::testStream();
+    tuscany::testStringPerf();
+
+    tuscany::cout << "OK" << tuscany::endl;
+
+    return 0;
+}

Added: tuscany/sca-cpp/trunk/kernel/string.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/string.hpp?rev=895165&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/string.hpp (added)
+++ tuscany/sca-cpp/trunk/kernel/string.hpp Sat Jan  2 10:27:26 2010
@@ -0,0 +1,288 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef tuscany_string_hpp
+#define tuscany_string_hpp
+
+/**
+ * Simple and fast string type backed by a char buffer
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <memory.h>
+#include <stdio.h>
+#include "gc.hpp"
+
+namespace tuscany {
+
+#ifdef _DEBUG
+
+/**
+ * Debug utilities. Counters used to track string copies.
+ */
+long countStringCopies = 0;
+
+bool resetStringCopyCounters() {
+    countStringCopies = 0;
+    return true;
+}
+
+bool checkStringCopyCounters(long c) {
+    return countStringCopies == c;
+}
+
+bool printStringCopyCounters() {
+    printf("countStringCopies %ld\n", countStringCopies);
+    return true;
+}
+
+#else
+
+#define resetStringCopyCounters()
+#define checkStringCopyCounters(c) true
+#define printStringCopyCounters()
+
+#endif
+
+/**
+ * Instrumented memcpy.
+ */
+void* string_memcpy(void* t, const void* s, const size_t n) {
+#ifdef _DEBUG
+    countStringCopies += 1;
+#endif
+    return memcpy(t, s, n);
+}
+
+char stringEmptyBuffer[1] = { '\0' };
+
+/**
+ * String class. The maximum string size is specified as a template parameter.
+ */
+class string {
+public:
+    string() : len(0) {
+        buf = stringEmptyBuffer;
+    }
+
+    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 int n) {
+        len = n;
+        if (len == 0) {
+            buf = stringEmptyBuffer;
+            return;
+        }
+        buf = gc_cnew(len + 1);
+        string_memcpy(buf, s, len);
+        buf[len] = '\0';
+    }
+
+    string(const int 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;
+    }
+
+    const bool operator==(const string& s) const {
+        if (len != s.len)
+            return false;
+        if (buf == s.buf)
+            return true;
+        return memcmp(buf, s.buf, len) == 0;
+    }
+
+    const bool operator!=(const string& s) const {
+        return !(*this == s);
+    }
+
+    const bool operator==(const char* s) const {
+        if (buf == s)
+            return true;
+        return strcmp(buf, s) == 0;
+    }
+
+    const bool operator!=(const char* s) const {
+        return !(*this == s);
+    }
+
+    const bool operator<(const string& s) const {
+        const int n = len < s.len? len : s.len;
+        const int c = memcmp(buf, s.buf, n);
+        if (c < 0)
+            return true;
+        if (c == 0)
+            return len < s.len;
+        return false;
+    }
+
+    const bool operator>(const string& s) const {
+        const int n = len < s.len? len : s.len;
+        int c = memcmp(buf, s.buf, n);
+        if (c > 0)
+            return true;
+        if (c == 0)
+            return len > s.len;
+        return false;
+    }
+
+private:
+    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 int length(const string& s);
+    friend const char* c_str(const string& s);
+    friend const int find(const string& s1, const char* s2, const int start);
+    friend const string substr(const string& s, const int pos, const int n);
+
+    int len;
+    char* buf;
+};
+
+/**
+ * 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 int 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;
+}
+
+/**
+ * Returns the length of a string.
+ */
+const int length(const string& s) {
+    return s.len;
+}
+
+/**
+ * Returns a string as a C zero terminated string.
+ */
+const char* c_str(const string& s) {
+    return s.buf;
+}
+
+/**
+ * Find the first occurrence of string s2 in s1, starting at the given position.
+ */
+const int find(const string& s1, const char* s2, const int start) {
+    if (start >= s1.len)
+        return s1.len;
+    const char *f = strstr(s1.buf + start, s2);
+    if (f == NULL)
+        return s1.len;
+    return f - s1.buf;
+}
+
+const int find(const string& s1, const char* s2) {
+    return find(s1, s2, 0);
+}
+
+const bool contains(const string& s1, const char* s2) {
+    return find(s1, s2) != length(s1);
+}
+
+/**
+ * Find the first occurence of any character from a string in a string.
+ */
+const int find_first_of(const string& s1, const string& s2) {
+    return strcspn(c_str(s1), c_str(s2));
+}
+
+/**
+ * Find the last occurence of a character in a string.
+ */
+const int find_last(const string& s, const char c) {
+    const char* cs = c_str(s);
+    const char* f = strrchr(cs, c);
+    if (f == NULL)
+        return length(s);
+    return f - cs;
+}
+
+/**
+ * Return a substring of a string.
+ */
+const string substr(const string& s, const int pos, const int n) {
+    if (pos >= s.len)
+        return string();
+    if (pos + n > s.len)
+        return string(s.buf + pos, s.len - pos);
+    return string(s.buf + pos, n);
+}
+
+const string substr(const string& s, const int pos) {
+    return substr(s, pos, length(s));
+}
+
+/**
+ * Common string constants.
+ */
+
+string trueString("true");
+string falseString("false");
+string emptyString("");
+
+}
+
+#endif /* tuscany_string_hpp */

Modified: tuscany/sca-cpp/trunk/kernel/tree.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/tree.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/tree.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/tree.hpp Sat Jan  2 10:27:26 2010
@@ -26,8 +26,8 @@
  * Functions to work with trees.
  */
 
-#include <iostream>
-#include <string>
+#include "stream.hpp"
+#include "string.hpp"
 #include "function.hpp"
 #include "list.hpp"
 #include "monad.hpp"

Modified: tuscany/sca-cpp/trunk/kernel/value.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/value.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/value.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/value.hpp Sat Jan  2 10:27:26 2010
@@ -26,9 +26,9 @@
  * Generic value type.
  */
 
-#include <string>
-#include <iostream>
-#include <sstream>
+#include <stdlib.h>
+#include "string.hpp"
+#include "sstream.hpp"
 #include "gc.hpp"
 #include "function.hpp"
 #include "list.hpp"
@@ -60,23 +60,29 @@
 }
 
 bool printValueCounters() {
-    std::cout << "countValues " << countValues << std::endl;
-    std::cout << "countEValues " << countEValues << std::endl;
-    std::cout << "countCValues " << countCValues << std::endl;
-    std::cout << "countVValues " << countVValues << std::endl;
+    cout << "countValues " << countValues << endl;
+    cout << "countEValues " << countEValues << endl;
+    cout << "countCValues " << countCValues << endl;
+    cout << "countVValues " << countVValues << endl;
     return true;
 }
 
-#define debug_watchValue() do { \
-        this->watch = watchValue(*this); \
-    } while (0)
-
 #else
 
 #define resetValueCounters()
 #define checkValueCounters() true
 #define printValueCounters()
 
+#endif
+
+#ifdef _DEBUG_WATCH
+
+#define debug_watchValue() do { \
+        this->watch = watchValue(*this); \
+    } while (0)
+
+#else
+
 #define debug_watchValue()
 
 #endif
@@ -90,8 +96,7 @@
         Undefined, Symbol, String, List, Number, Bool, Char, Lambda, Ptr, PoolPtr
     };
 
-    value() :
-        type(value::Undefined) {
+    value() : type(value::Undefined) {
         debug_inc(countValues);
         debug_inc(countEValues);
         debug_watchValue();
@@ -123,43 +128,11 @@
         default:
             break;
         }
-#ifdef _DEBUG
+#ifdef _DEBUG_WATCH
         watch = v.watch;
 #endif
     }
 
-    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::Char:
-            chr() = v.chr();
-        case value::Ptr:
-            ptr() = v.ptr();
-        case value::PoolPtr:
-            poolptr() = v.poolptr();
-        default:
-            break;
-        }
-#ifdef _DEBUG
-        watch = v.watch;
-#endif
-        return *this;
-    }
-
     virtual ~value() {
         debug_dec(countValues);
     }
@@ -170,13 +143,13 @@
         debug_watchValue();
     }
 
-    value(const std::string& str) : type(value::String), data(vdata(result(str))) {
+    value(const string& str) : type(value::String), data(vdata(result(str))) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const char* str) : type(value::Symbol), data(vdata(result(std::string(str)))) {
+    value(const char* str) : type(value::Symbol), data(vdata(result(string(str)))) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
@@ -218,19 +191,21 @@
         debug_watchValue();
     }
 
+#ifdef _GC_REFCOUNT
     value(const gc_ptr<value> ptr) : type(value::Ptr), data(vdata(result(ptr))) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
+#endif
 
-    value(const gc_pool_ptr<value> ptr) : type(value::PoolPtr), data(vdata(result(ptr))) {
+    value(const gc_ptr<value> ptr) : type(value::PoolPtr), data(vdata(result(ptr))) {
         debug_inc(countValues);
         debug_inc(countVValues);
         debug_watchValue();
     }
 
-    value(const failable<value, std::string>& m) : type(value::List),
+    value(const failable<value>& m) : type(value::List),
         data(vdata(result(hasContent(m)? mklist<value>(content(m)) : mklist<value>(value(), reason(m))))) {
         debug_inc(countValues);
         debug_inc(countVValues);
@@ -244,6 +219,38 @@
         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::Char:
+            chr() = v.chr();
+        case value::Ptr:
+            ptr() = v.ptr();
+        case value::PoolPtr:
+            poolptr() = v.poolptr();
+        default:
+            break;
+        }
+#ifdef _DEBUG_WATCH
+        watch = v.watch;
+#endif
+        return *this;
+    }
+
     const bool operator!=(const value& v) const {
         return !this->operator==(v);
     }
@@ -259,9 +266,8 @@
         case value::Lambda:
             return v.type == value::Lambda && func() == v.func();
         case value::Symbol:
-            return str()() == (std::string)v;
         case value::String:
-            return str()() == (std::string)v;
+            return str()() == (string)v;
         case value::Number:
             return num()() == (double)v;
         case value::Bool:
@@ -285,8 +291,7 @@
             return v.type == value::List && lst()() < v.lst()();
         case value::Symbol:
         case value::String:
-            return str()() < (std::string)v;
-            return str()() < (std::string)v;
+            return str()() < (string)v;
         case value::Bool:
             return boo()() < (bool)v;
         case value::Number:
@@ -306,8 +311,7 @@
             return v.type == value::List && lst()() > v.lst()();
         case value::Symbol:
         case value::String:
-            return str()() > (std::string)v;
-            return str()() > (std::string)v;
+            return str()() > (string)v;
         case value::Bool:
             return boo()() > (bool)v;
         case value::Number:
@@ -323,25 +327,25 @@
         return func()(args);
     }
 
-    operator const std::string() const {
+    operator const string() const {
         switch(type) {
         case value::Symbol:
         case value::String:
             return str()();
         case value::Number: {
-            std::ostringstream sos;
-            sos << num()();
-            return sos.str();
+            ostringstream os;
+            os << num()();
+            return tuscany::str(os);
         }
         case value::Bool:
-            return boo()()? "true" : "false";
+            return boo()()? trueString : falseString;
         case value::Char: {
-            std::ostringstream sos;
-            sos << chr()();
-            return sos.str();
+            ostringstream os;
+            os << chr()();
+            return tuscany::str(os);
         }
         default:
-            return "";
+            return emptyString;
         }
     }
 
@@ -349,7 +353,7 @@
         switch(type) {
         case value::Symbol:
         case value::String:
-            return atof(str()().c_str());
+            return atof(c_str(str()()));
         case value::Number:
             return (double)num()();
         case value::Bool:
@@ -365,7 +369,7 @@
         switch(type) {
         case value::Symbol:
         case value::String:
-            return atoi(str()().c_str());
+            return atoi(c_str(str()()));
         case value::Number:
             return (int)num()();
         case value::Bool:
@@ -381,7 +385,7 @@
         switch(type) {
         case value::Symbol:
         case value::String:
-            return str()() == "true";
+            return str()() == string("true");
         case value::Number:
             return (int)num()() != 0;
         case value::Bool:
@@ -409,11 +413,13 @@
         }
     }
 
+#ifdef _GC_REFCOUNT
     operator const gc_ptr<value>() const {
         return ptr()();
     }
+#endif
 
-    operator const gc_pool_ptr<value>() const {
+    operator const gc_ptr<value>() const {
         return poolptr()();
     }
 
@@ -454,12 +460,12 @@
         return vdata<gc_ptr<value>()> ();
     }
 
-    lambda<gc_pool_ptr<value>()>& poolptr() const {
-        return vdata<gc_pool_ptr<value>()> ();
+    lambda<gc_ptr<value>()>& poolptr() const {
+        return vdata<gc_ptr<value>()> ();
     }
 
-    lambda<std::string()>& str() const {
-        return vdata<std::string()> ();
+    lambda<string()>& str() const {
+        return vdata<string()> ();
     }
 
     lambda<list<value>()>& lst() const {
@@ -482,37 +488,38 @@
         return cons<list<value> >(list<value>(car(l)), listOfListOfValues(cdr(l)));
     }
 
-    friend std::ostream& operator<<(std::ostream&, const value&);
+    friend ostream& operator<<(ostream&, const value&);
     friend const value::ValueType type(const value& v);
 
-#ifdef _DEBUG
-    friend const std::string watchValue(const value& v);
-    std::string watch;
+#ifdef _DEBUG_WATCH
+    friend const string watchValue(const value& v);
+    string watch;
 #endif
 
     ValueType type;
      lambda<char()> data;
 };
 
-#ifdef _DEBUG
+#ifdef _DEBUG_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 std::string watchValue(const value& v) {
+const string watchValue(const value& v) {
     if (v.type == value::List)
         return watchList<value>(v);
-    std::ostringstream os;
+    ostringstream<string::npos> os;
     os << v;
-    return os.str();
+    return str(os);
 }
+
 #endif
 
 /**
  * Write a value to a stream.
  */
-std::ostream& operator<<(std::ostream& out, const value& v) {
+ostream& operator<<(ostream& out, const value& v) {
     switch(v.type) {
     case value::List:
         return out << v.lst()();
@@ -538,8 +545,8 @@
         return out << "gc_ptr::" << p;
     }
     case value::PoolPtr: {
-        const gc_pool_ptr<value> p =  v.poolptr()();
-        if (p == gc_pool_ptr<value>(NULL))
+        const gc_ptr<value> p =  v.poolptr()();
+        if (p == gc_ptr<value>(NULL))
             return out << "pool_ptr::null";
         return out << "pool_ptr::" << p;
     }
@@ -634,5 +641,14 @@
     return false;
 }
 
+/**
+ * Make a list of values from a list of other things.
+ */
+template<typename T> const list<value> mkvalues(const list<T>& l) {
+    if (isNil(l))
+        return list<value>();
+    return cons<value>(car(l), mkvalues(cdr(l)));
+}
+
 }
 #endif /* tuscany_value_hpp */

Modified: tuscany/sca-cpp/trunk/kernel/xml-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/xml-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/xml-test.cpp (original)
+++ tuscany/sca-cpp/trunk/kernel/xml-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,9 +24,8 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <string>
-#include <sstream>
+#include "stream.hpp"
+#include "string.hpp"
 #include "list.hpp"
 #include "value.hpp"
 #include "element.hpp"
@@ -34,7 +33,7 @@
 
 namespace tuscany {
 
-const std::string currencyXML =
+const string currencyXML =
 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" "
 "xmlns:t=\"http://tuscany.apache.org/xmlns/sca/1.1\" "
@@ -56,7 +55,7 @@
 "</composite>"
 "\n";
 
-const std::string customerXML =
+const string customerXML =
 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
 "<customer>"
 "<name>jdoe</name>"
@@ -74,78 +73,78 @@
 
 bool testReadXML() {
     {
-        std::istringstream is(customerXML);
+        istringstream is(customerXML);
         const list<value> c = readXML(streamList(is));
     }
     {
-        std::istringstream is(currencyXML);
+        istringstream is(currencyXML);
         const list<value> c = readXML(streamList(is));
 
         const value composite = car(c);
         assert(isTaggedList(composite, element));
         assert(elementName(composite) == "composite");
-        assert(attributeValue(car(filter<value>(isName, elementChildren(composite)))) == std::string("currency"));
+        assert(attributeValue(car(filter<value>(isName, elementChildren(composite)))) == string("currency"));
     }
     return true;
 }
 
-std::ostringstream* xmlWriter(const std::string& s, std::ostringstream* os) {
+ostream* xmlWriter(const string& s, ostream* os) {
     (*os) << s;
     return os;
 }
 
 bool testWriteXML() {
     {
-        std::istringstream is(customerXML);
+        istringstream is(customerXML);
         const list<value> c = readXML(streamList(is));
-        std::ostringstream os;
-        writeXML<std::ostringstream*>(xmlWriter, &os, c);
-        assert(os.str() == customerXML);
+        ostringstream os;
+        writeXML<ostream*>(xmlWriter, &os, c);
+        assert(str(os) == customerXML);
     }
     {
-        std::istringstream is(currencyXML);
+        istringstream is(currencyXML);
         const list<value> c = readXML(streamList(is));
-        std::ostringstream os;
-        writeXML<std::ostringstream*>(xmlWriter, &os, c);
-        assert(os.str() == currencyXML);
+        ostringstream os;
+        writeXML<ostream*>(xmlWriter, &os, c);
+        assert(str(os) == currencyXML);
     }
     return true;
 }
 
 bool testElement() {
     {
-        const list<value> ad = mklist<value>(mklist<value>("city", std::string("san francisco")), mklist<value>("state", std::string("ca")));
-        const list<value> ac1 = mklist<value>(mklist<value>("id", std::string("1234")), mklist<value>("balance", 1000));
-        const list<value> ac2 = mklist<value>(mklist<value>("id", std::string("6789")), mklist<value>("balance", 2000));
-        const list<value> ac3 = mklist<value>(mklist<value>("id", std::string("4567")), mklist<value>("balance", 3000));
+        const list<value> ad = mklist<value>(mklist<value>("city", string("san francisco")), mklist<value>("state", string("ca")));
+        const list<value> ac1 = mklist<value>(mklist<value>("id", string("1234")), mklist<value>("balance", 1000));
+        const list<value> ac2 = mklist<value>(mklist<value>("id", string("6789")), mklist<value>("balance", 2000));
+        const list<value> ac3 = mklist<value>(mklist<value>("id", string("4567")), mklist<value>("balance", 3000));
         {
-            const list<value> c = mklist<value>(mklist<value>("customer", mklist<value>("name", std::string("jdoe")), cons<value>("address", ad), mklist<value>("account", mklist<value>(ac1, ac2, ac3))));
+            const list<value> c = mklist<value>(mklist<value>("customer", mklist<value>("name", string("jdoe")), cons<value>("address", ad), mklist<value>("account", mklist<value>(ac1, ac2, ac3))));
             const list<value> e = valuesToElements(c);
             const list<value> v = elementsToValues(e);
             assert(v == c);
 
-            std::ostringstream os;
-            writeXML<std::ostringstream*>(xmlWriter, &os, e);
-            assert(os.str() == customerXML);
+            ostringstream os;
+            writeXML<ostream*>(xmlWriter, &os, e);
+            assert(str(os) == customerXML);
         }
         {
-            const list<value> c = mklist<value>(mklist<value>("customer", mklist<value>("name", std::string("jdoe")), cons<value>("address", ad), cons<value>("account", ac1), cons<value>("account", ac2), cons<value>("account", ac3)));
+            const list<value> c = mklist<value>(mklist<value>("customer", mklist<value>("name", string("jdoe")), cons<value>("address", ad), cons<value>("account", ac1), cons<value>("account", ac2), cons<value>("account", ac3)));
             const list<value> e = valuesToElements(c);
             const list<value> v = elementsToValues(e);
 
-            std::ostringstream os;
-            writeXML<std::ostringstream*>(xmlWriter, &os, e);
-            assert(os.str() == customerXML);
+            ostringstream os;
+            writeXML<ostream*>(xmlWriter, &os, e);
+            assert(str(os) == customerXML);
         }
     }
     {
-        std::istringstream is(customerXML);
+        istringstream is(customerXML);
         const list<value> c = readXML(streamList(is));
         const list<value> v = elementsToValues(c);
         const list<value> e = valuesToElements(v);
-        std::ostringstream os;
-        writeXML<std::ostringstream*>(xmlWriter, &os, e);
-        assert(os.str() == customerXML);
+        ostringstream os;
+        writeXML<ostream*>(xmlWriter, &os, e);
+        assert(str(os) == customerXML);
     }
     return true;
 }
@@ -153,13 +152,13 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::testReadXML();
     tuscany::testWriteXML();
     tuscany::testElement();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/kernel/xml.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/xml.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/xml.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/xml.hpp Sat Jan  2 10:27:26 2010
@@ -30,9 +30,9 @@
 #include <libxml/xmlwriter.h>
 #include <libxml/xmlschemas.h>
 #include <libxml/globals.h>
-#include <string>
+#include "string.hpp"
 #include "list.hpp"
-#include "slist.hpp"
+#include "stream.hpp"
 #include "value.hpp"
 #include "element.hpp"
 #include "monad.hpp"
@@ -127,7 +127,7 @@
  */
 const value readText(XMLReader& reader) {
     const char *val = (const char*)xmlTextReaderConstValue(reader);
-    return std::string(val);
+    return string(val);
 }
 
 /**
@@ -136,7 +136,7 @@
 const value readAttribute(XMLReader& reader) {
     const char *name = (const char*)xmlTextReaderConstName(reader);
     const char *val = (const char*)xmlTextReaderConstValue(reader);
-    return mklist<value>(attribute, name, std::string(val));
+    return mklist<value>(attribute, name, string(val));
 }
 
 /**
@@ -186,9 +186,9 @@
  */
 class XMLReadContext {
 public:
-    XMLReadContext(const list<std::string>& ilist) : ilist(ilist) {
+    XMLReadContext(const list<string>& ilist) : ilist(ilist) {
     }
-    list<std::string> ilist;
+    list<string> ilist;
 };
 
 /**
@@ -198,17 +198,17 @@
     XMLReadContext& rc = *static_cast<XMLReadContext*>(context);
     if (isNil(rc.ilist))
         return 0;
-    rc.ilist = fragment(rc.ilist, len);
-    std::string s = car(rc.ilist);
-    rc.ilist = cdr(rc.ilist);
-    s.copy(buffer, s.length());
-    return s.length();
+    const list<string> f(fragment(rc.ilist, len));
+    const string s(car(f));
+    rc.ilist = cdr(f);
+    memcpy(buffer, c_str(s), length(s));
+    return length(s);
 }
 
 /**
- * Read a list values from a list of strings representing an XML document.
+ * Read a list of values from a list of strings representing an XML document.
  */
-const list<value> readXML(const list<std::string>& ilist) {
+const list<value> readXML(const list<string>& ilist) {
     XMLReadContext cx(ilist);
     xmlTextReaderPtr xml = xmlReaderForIO(readCallback, NULL, &cx, NULL, NULL, XML_PARSE_NONET);
     if (xml == NULL)
@@ -232,15 +232,15 @@
     return cons<value>(value(cons<value>(element, cons<value>(n, (list<value>)car(l)))), expandElementValues(n, cdr(l)));
 }
 
-const failable<bool, std::string> writeList(const list<value>& l, const xmlTextWriterPtr xml) {
+const failable<bool> writeList(const list<value>& l, const xmlTextWriterPtr xml) {
     if (isNil(l))
         return true;
 
     // Write an attribute
     const value token(car(l));
     if (isTaggedList(token, attribute)) {
-        if (xmlTextWriterWriteAttribute(xml, (const xmlChar*)std::string(attributeName(token)).c_str(), (const xmlChar*)std::string(attributeValue(token)).c_str()) < 0)
-            return mkfailure<bool, std::string>("xmlTextWriterWriteAttribute failed");
+        if (xmlTextWriterWriteAttribute(xml, (const xmlChar*)c_str(string(attributeName(token))), (const xmlChar*)c_str(string(attributeValue(token)))) < 0)
+            return mkfailure<bool>("xmlTextWriterWriteAttribute failed");
 
     } else if (isTaggedList(token, element)) {
 
@@ -256,38 +256,37 @@
             } else {
 
                 // Write an element with a single value
-                if (xmlTextWriterStartElement(xml, (const xmlChar*)std::string(elementName(token)).c_str()) < 0)
-                    return mkfailure<bool, std::string>("xmlTextWriterStartElement failed");
+                if (xmlTextWriterStartElement(xml, (const xmlChar*)c_str(string(elementName(token)))) < 0)
+                    return mkfailure<bool>("xmlTextWriterStartElement failed");
 
                 // Write its children
-                const failable<bool, std::string> w = writeList(elementChildren(token), xml);
+                const failable<bool> w = writeList(elementChildren(token), xml);
                 if (!hasContent(w))
                     return w;
 
                 if (xmlTextWriterEndElement(xml) < 0)
-                    return mkfailure<bool, std::string>("xmlTextWriterEndElement failed");
+                    return mkfailure<bool>("xmlTextWriterEndElement failed");
             }
         }
         else {
 
             // Write an element
-            if (xmlTextWriterStartElement(xml, (const xmlChar*)std::string(elementName(token)).c_str()) < 0)
-                return mkfailure<bool, std::string>("xmlTextWriterStartElement failed");
+            if (xmlTextWriterStartElement(xml, (const xmlChar*)c_str(string(elementName(token)))) < 0)
+                return mkfailure<bool>("xmlTextWriterStartElement failed");
 
             // Write its children
-            const failable<bool, std::string> w = writeList(elementChildren(token), xml);
+            const failable<bool> w = writeList(elementChildren(token), xml);
             if (!hasContent(w))
                 return w;
 
             if (xmlTextWriterEndElement(xml) < 0)
-                return mkfailure<bool, std::string>("xmlTextWriterEndElement failed");
+                return mkfailure<bool>("xmlTextWriterEndElement failed");
         }
     } else {
 
         // Write XML text
-        if (xmlTextWriterWriteString(xml, (const xmlChar*)std::string(token).c_str()) < 0)
-            return mkfailure<bool, std::string>("xmlTextWriterWriteString failed");
-
+        if (xmlTextWriterWriteString(xml, (const xmlChar*)c_str(string(token))) < 0)
+            return mkfailure<bool>("xmlTextWriterWriteString failed");
     }
 
     // Go on
@@ -297,16 +296,16 @@
 /**
  * Write a list of values to a libxml2 XML writer.
  */
-const failable<bool, std::string> write(const list<value>& l, const xmlTextWriterPtr xml) {
+const failable<bool> write(const list<value>& l, const xmlTextWriterPtr xml) {
     if (xmlTextWriterStartDocument(xml, NULL, encoding, NULL) < 0)
-        return mkfailure<bool, std::string>("xmlTextWriterStartDocument failed");
+        return mkfailure<bool>(string("xmlTextWriterStartDocument failed"));
 
-    const failable<bool, std::string> w = writeList(l, xml);
+    const failable<bool> w = writeList(l, xml);
     if (!hasContent(w))
         return w;
 
     if (xmlTextWriterEndDocument(xml) < 0)
-        return mkfailure<bool, std::string>("xmlTextWriterEndDocument failed");
+        return mkfailure<bool>("xmlTextWriterEndDocument failed");
     return true;
 }
 
@@ -315,9 +314,9 @@
  */
 template<typename R> class XMLWriteContext {
 public:
-    XMLWriteContext(const lambda<R(const std::string&, const R)>& reduce, const R& accum) : reduce(reduce), accum(accum) {
+    XMLWriteContext(const lambda<R(const string&, const R)>& reduce, const R& accum) : reduce(reduce), accum(accum) {
     }
-    const lambda<R(const std::string&, const R)> reduce;
+    const lambda<R(const string&, const R)> reduce;
     R accum;
 };
 
@@ -326,26 +325,26 @@
  */
 template<typename R> int writeCallback(void *context, const char* buffer, int len) {
     XMLWriteContext<R>& cx = *static_cast<XMLWriteContext<R>*>(context);
-    cx.accum = cx.reduce(std::string(buffer, len), cx.accum);
+    cx.accum = cx.reduce(string(buffer, len), cx.accum);
     return len;
 }
 
 /**
  * Convert a list of values to an XML document.
  */
-template<typename R> const failable<R, std::string> writeXML(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const list<value>& l) {
+template<typename R> const failable<R> writeXML(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l) {
     XMLWriteContext<R> cx(reduce, initial);
     xmlOutputBufferPtr out = xmlOutputBufferCreateIO(writeCallback<R>, NULL, &cx, NULL);
     if (out == NULL)
-        return mkfailure<R, std::string>("xmlOutputBufferCreateIO failed");
+        return mkfailure<R>("xmlOutputBufferCreateIO failed");
     xmlTextWriterPtr xml = xmlNewTextWriter(out);
     if (xml == NULL)
-        return mkfailure<R, std::string>("xmlNewTextWriter failed");
+        return mkfailure<R>("xmlNewTextWriter failed");
 
-    const failable<bool, std::string> w = write(l, xml);
+    const failable<bool> w = write(l, xml);
     xmlFreeTextWriter(xml);
     if (!hasContent(w)) {
-        return mkfailure<R, std::string>(reason(w));
+        return mkfailure<R>(reason(w));
     }
     return cx.accum;
 }
@@ -353,11 +352,11 @@
 /**
  * Convert a list of values to a list of strings representing an XML document.
  */
-const failable<list<std::string>, std::string> writeXML(const list<value>& l) {
-    const failable<list<std::string>, std::string> ls = writeXML<list<std::string> >(rcons<std::string>, list<std::string>(), l);
+const failable<list<string> > writeXML(const list<value>& l) {
+    const failable<list<string> > ls = writeXML<list<string> >(rcons<string>, list<string>(), l);
     if (!hasContent(ls))
         return ls;
-    return reverse(list<std::string>(content(ls)));
+    return reverse(list<string>(content(ls)));
 }
 
 }

Modified: tuscany/sca-cpp/trunk/kernel/xsd-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/xsd-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/xsd-test.cpp (original)
+++ tuscany/sca-cpp/trunk/kernel/xsd-test.cpp Sat Jan  2 10:27:26 2010
@@ -23,8 +23,8 @@
  * Test validation of a composite file against an SCDL schema.
  */
 
-#include <iostream>
-#include <string>
+#include "string.hpp"
+#include "fstream.hpp"
 #include <libxml/xmlreader.h>
 #include <libxml/xmlschemas.h>
 
@@ -35,12 +35,12 @@
     if(name == NULL)
         name = (xmlChar *)"<unknown>";
     const xmlChar* value = xmlTextReaderConstValue(reader);
-    std::cout << xmlTextReaderDepth(reader) << " " << xmlTextReaderNodeType(reader) << " " << name << " "
+    cout << xmlTextReaderDepth(reader) << " " << xmlTextReaderNodeType(reader) << " " << name << " "
             << xmlTextReaderIsEmptyElement(reader) << " " << xmlTextReaderHasValue(reader);
     if(value == NULL)
-        std::cout << std::endl;
+        cout << endl;
     else
-        std::cout << value << std::endl;
+        cout << value << endl;
     return true;
 }
 
@@ -54,13 +54,13 @@
 }
 
 bool readFile(const char*xsdfilename, const char *filename) {
-    std::cout << "Loading schemas...\n";
+    cout << "Loading schemas...\n";
     const xmlDocPtr xsddoc = xmlReadFile(xsdfilename, NULL, XML_PARSE_NONET);
     const xmlSchemaParserCtxtPtr xsdctx = xmlSchemaNewDocParserCtxt(xsddoc);
     const xmlSchemaPtr xsd = xmlSchemaParse(xsdctx);
     const xmlSchemaValidCtxtPtr validctx = xmlSchemaNewValidCtxt(xsd);
 
-    std::cout << "Reading file...\n";
+    cout << "Reading file...\n";
     FILE* file = fopen(filename, "r");
     if (file != NULL) {
         const xmlTextReaderPtr reader = xmlReaderForIO(xmlRead, xmlClose, file, filename, NULL, XML_PARSE_NONET);
@@ -75,14 +75,14 @@
                 printNode(reader);
             }
             if(xmlTextReaderIsValid(reader) != 1)
-                std::cout << "Could not validate document" << std::endl;
+                cout << "Could not validate document" << endl;
             xmlFreeTextReader(reader);
             if(rc != 0)
-                std::cout << "Could not parse document" << std::endl;
+                cout << "Could not parse document" << endl;
         } else
-            std::cout << "Could not create parser" << std::endl;
+            cout << "Could not create parser" << endl;
     } else
-        std::cout << "Could not open document" << std::endl;
+        cout << "Could not open document" << endl;
 
     xmlSchemaFreeValidCtxt(validctx);
     xmlSchemaFree(xsd);
@@ -94,7 +94,7 @@
 }
 
 int main(int argc, char **argv) {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
     if(argc != 3)
         return 1;
 
@@ -102,6 +102,6 @@
 
     xmlCleanupParser();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/modules/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/Makefile.am?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/Makefile.am Sat Jan  2 10:27:26 2010
@@ -15,7 +15,7 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-SUBDIRS = atom eval http json scdl server
+SUBDIRS = atom eval json scdl http server
 
 includedir = $(prefix)/include/modules
 nobase_include_HEADERS = */*.hpp

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=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/atom/atom-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/atom/atom-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,21 +24,19 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include "slist.hpp"
+#include "stream.hpp"
+#include "string.hpp"
 #include "atom.hpp"
 
 namespace tuscany {
 namespace atom {
 
-std::ostringstream* writer(const std::string& s, std::ostringstream* os) {
+ostream* writer(const string& s, ostream* os) {
     (*os) << s;
     return os;
 }
 
-std::string itemEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+string itemEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
         "<entry xmlns=\"http://www.w3.org/2005/Atom\">"
         "<title type=\"text\">item</title>"
         "<id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>"
@@ -50,7 +48,7 @@
         "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>"
         "</entry>\n");
 
-std::string incompleteEntry("<entry xmlns=\"http://www.w3.org/2005/Atom\">"
+string incompleteEntry("<entry xmlns=\"http://www.w3.org/2005/Atom\">"
         "<title>item</title><content type=\"text/xml\">"
         "<Item xmlns=\"http://services/\">"
         "<name xmlns=\"\">Orange</name>"
@@ -59,7 +57,7 @@
         "</content>"
         "</entry>");
 
-std::string completedEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+string completedEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
         "<entry xmlns=\"http://www.w3.org/2005/Atom\">"
         "<title type=\"text\">item</title>"
         "<id></id>"
@@ -73,36 +71,36 @@
 
 bool testEntry() {
     {
-        const list<value> i = list<value>() << element << "item"
-                << (list<value>() << element << "name" << std::string("Apple"))
-                << (list<value>() << element << "price" << std::string("$2.99"));
-        const list<value> a = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
-        std::ostringstream os;
-        writeATOMEntry<std::ostringstream*>(writer, &os, a);
-        assert(os.str() == itemEntry);
+        const list<value> i = list<value>() + element + value("item")
+                + value(list<value>() + element + value("name") + value(string("Apple")))
+                + value(list<value>() + element + value("price") + value(string("$2.99")));
+        const list<value> a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+        ostringstream os;
+        writeATOMEntry<ostream*>(writer, &os, a);
+        assert(str(os) == itemEntry);
     }
     {
         const list<value> a = content(readEntry(mklist(itemEntry)));
-        std::ostringstream os;
-        writeATOMEntry<std::ostringstream*>(writer, &os, a);
-        assert(os.str() == itemEntry);
+        ostringstream os;
+        writeATOMEntry<ostream*>(writer, &os, a);
+        assert(str(os) == itemEntry);
     }
     {
         const list<value> a = content(readEntry(mklist(incompleteEntry)));
-        std::ostringstream os;
-        writeATOMEntry<std::ostringstream*>(writer, &os, a);
-        assert(os.str() == completedEntry);
+        ostringstream os;
+        writeATOMEntry<ostream*>(writer, &os, a);
+        assert(str(os) == completedEntry);
     }
     return true;
 }
 
-std::string emptyFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+string emptyFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
         "<feed xmlns=\"http://www.w3.org/2005/Atom\">"
         "<title type=\"text\">Feed</title>"
         "<id>1234</id>"
         "</feed>\n");
 
-std::string itemFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+string itemFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
         "<feed xmlns=\"http://www.w3.org/2005/Atom\">"
         "<title type=\"text\">Feed</title>"
         "<id>1234</id>"
@@ -130,51 +128,51 @@
 
 bool testFeed() {
     {
-        std::ostringstream os;
-        writeATOMFeed<std::ostringstream*>(writer, &os, mklist<value>("Feed", "1234"));
-        assert(os.str() == emptyFeed);
+        ostringstream os;
+        writeATOMFeed<ostream*>(writer, &os, mklist<value>("Feed", "1234"));
+        assert(str(os) == emptyFeed);
     }
     {
         const list<value> a = content(readFeed(mklist(emptyFeed)));
-        std::ostringstream os;
-        writeATOMFeed<std::ostringstream*>(writer, &os, a);
-        assert(os.str() == emptyFeed);
+        ostringstream os;
+        writeATOMFeed<ostream*>(writer, &os, a);
+        assert(str(os) == emptyFeed);
     }
     {
         const list<value> i = list<value>()
-                << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
-                    << (list<value>() << element << "item"
-                        << (list<value>() << element << "name" << "Apple")
-                        << (list<value>() << element << "price" << "$2.99")))
-                << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
-                    << (list<value>() << element << "item"
-                        << (list<value>() << element << "name" << "Orange")
-                        << (list<value>() << element << "price" << "$3.55")));
+                + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
+                    + (list<value>() + element + "item"
+                        + (list<value>() + element + "name" + "Apple")
+                        + (list<value>() + element + "price" + "$2.99")))
+                + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
+                    + (list<value>() + element + "item"
+                        + (list<value>() + element + "name" + "Orange")
+                        + (list<value>() + element + "price" + "$3.55")));
         const list<value> a = cons<value>("Feed", cons<value>("1234", i));
-        std::ostringstream os;
-        writeATOMFeed<std::ostringstream*>(writer, &os, a);
-        assert(os.str() == itemFeed);
+        ostringstream os;
+        writeATOMFeed<ostream*>(writer, &os, a);
+        assert(str(os) == itemFeed);
     }
     {
         const list<value> i = list<value>()
-                << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
-                    << valueToElement(list<value>() << "item"
-                        << (list<value>() << "name" << "Apple")
-                        << (list<value>() << "price" << "$2.99")))
-                << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
-                    << valueToElement(list<value>() << "item"
-                        << (list<value>() << "name" << "Orange")
-                        << (list<value>() << "price" << "$3.55")));
+                + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
+                    + valueToElement(list<value>() + "item"
+                        + (list<value>() + "name" + "Apple")
+                        + (list<value>() + "price" + "$2.99")))
+                + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
+                    + valueToElement(list<value>() + "item"
+                        + (list<value>() + "name" + "Orange")
+                        + (list<value>() + "price" + "$3.55")));
         const list<value> a = cons<value>("Feed", cons<value>("1234", i));
-        std::ostringstream os;
-        writeATOMFeed<std::ostringstream*>(writer, &os, a);
-        assert(os.str() == itemFeed);
+        ostringstream os;
+        writeATOMFeed<ostream*>(writer, &os, a);
+        assert(str(os) == itemFeed);
     }
     {
         const list<value> a = content(readFeed(mklist(itemFeed)));
-        std::ostringstream os;
-        writeATOMFeed<std::ostringstream*>(writer, &os, a);
-        assert(os.str() == itemFeed);
+        ostringstream os;
+        writeATOMFeed<ostream*>(writer, &os, a);
+        assert(str(os) == itemFeed);
     }
     return true;
 }
@@ -183,12 +181,12 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::atom::testEntry();
     tuscany::atom::testFeed();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/modules/atom/atom.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/atom/atom.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/atom/atom.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/atom/atom.hpp Sat Jan  2 10:27:26 2010
@@ -26,7 +26,7 @@
  * ATOM data conversion functions.
  */
 
-#include <string>
+#include "string.hpp"
 #include "list.hpp"
 #include "value.hpp"
 #include "monad.hpp"
@@ -40,9 +40,9 @@
  */
 const list<value> entryValues(const list<value>& e) {
     const list<value> lt = filter<value>(selector(mklist<value>(element, "title")), e);
-    const value t = isNil(lt)? value(std::string("")) : elementValue(car(lt));
+    const value t = isNil(lt)? value(emptyString) : elementValue(car(lt));
     const list<value> li = filter<value>(selector(mklist<value>(element, "id")), e);
-    const value i = isNil(li)? value(std::string("")) : elementValue(car(li));
+    const value i = isNil(li)? value(emptyString) : elementValue(car(li));
     const list<value> lc = filter<value>(selector(mklist<value>(element, "content")), e);
     return mklist<value>(t, i, cadr(elementChildren(car(lc))));
 }
@@ -59,10 +59,10 @@
 /**
  * Convert a list of strings to a list of values representing an ATOM entry.
  */
-const failable<list<value>, std::string> readEntry(const list<std::string>& ilist) {
+const failable<list<value> > readEntry(const list<string>& ilist) {
     const list<value> e = readXML(ilist);
     if (isNil(e))
-        return mkfailure<list<value>, std::string>("Empty entry");
+        return mkfailure<list<value> >("Empty entry");
     return entryValues(car(e));
 }
 
@@ -77,10 +77,10 @@
 /**
  * Convert a list of strings to a list of values representing an ATOM feed.
  */
-const failable<list<value>, std::string> readFeed(const list<std::string>& ilist) {
+const failable<list<value> > readFeed(const list<string>& ilist) {
     const list<value> f = readXML(ilist);
     if (isNil(f))
-        return mkfailure<list<value>, std::string>("Empty feed");
+        return mkfailure<list<value> >("Empty feed");
     const list<value> t = filter<value>(selector(mklist<value>(element, "title")), car(f));
     const list<value> i = filter<value>(selector(mklist<value>(element, "id")), car(f));
     const list<value> e = filter<value>(selector(mklist<value>(element, "entry")), car(f));
@@ -95,11 +95,11 @@
  */
 const list<value> entryElement(const list<value>& l) {
     return list<value>()
-        << element << "entry" << (list<value>() << attribute << "xmlns" << "http://www.w3.org/2005/Atom")
-        << (list<value>() << element << "title" << (list<value>() << attribute << "type" << "text") << car(l))
-        << (list<value>() << element << "id" << cadr(l))
-        << (list<value>() << element << "content" << (list<value>() << attribute << "type" << "application/xml") << caddr(l))
-        << (list<value>() << element << "link" << (list<value>() << attribute << "href" << cadr(l)));
+        + element + "entry" + (list<value>() + attribute + "xmlns" + "http://www.w3.org/2005/Atom")
+        + (list<value>() + element + "title" + (list<value>() + attribute + "type" + "text") + car(l))
+        + (list<value>() + element + "id" + cadr(l))
+        + (list<value>() + element + "content" + (list<value>() + attribute + "type" + "application/xml") + caddr(l))
+        + (list<value>() + element + "link" + (list<value>() + attribute + "href" + cadr(l)));
 }
 
 /**
@@ -115,26 +115,26 @@
  * Convert a list of values representing an ATOM entry to an ATOM entry.
  * The first two values in the list are the entry id and title.
  */
-template<typename R> const failable<R, std::string> writeATOMEntry(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const list<value>& l) {
+template<typename R> const failable<R> writeATOMEntry(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l) {
     return writeXML<R>(reduce, initial, mklist<value>(entryElement(l)));
 }
 
-const failable<list<std::string>, std::string> writeATOMEntry(const list<value>& l) {
-    const failable<list<std::string>, std::string> ls = writeATOMEntry<list<std::string> >(rcons<std::string>, list<std::string>(), l);
+const failable<list<string> > writeATOMEntry(const list<value>& l) {
+    const failable<list<string> > ls = writeATOMEntry<list<string> >(rcons<string>, list<string>(), l);
     if (!hasContent(ls))
         return ls;
-    return reverse(list<std::string>(content(ls)));
+    return reverse(list<string>(content(ls)));
 }
 
 /**
  * Convert a list of values representing an ATOM feed to an ATOM feed.
  * The first two values in the list are the feed id and title.
  */
-template<typename R> const failable<R, std::string> writeATOMFeed(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const list<value>& l) {
+template<typename R> const failable<R> writeATOMFeed(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l) {
     const list<value> f = list<value>()
-        << element << "feed" << (list<value>() << attribute << "xmlns" << "http://www.w3.org/2005/Atom")
-        << (list<value>() << element << "title" << (list<value>() << attribute << "type" << "text") << car(l))
-        << (list<value>() << element << "id" << cadr(l));
+        + element + "feed" + (list<value>() + attribute + "xmlns" + "http://www.w3.org/2005/Atom")
+        + (list<value>() + element + "title" + (list<value>() + attribute + "type" + "text") + car(l))
+        + (list<value>() + element + "id" + cadr(l));
     if (isNil(cddr(l)))
         return writeXML<R>(reduce, initial, mklist<value>(f));
     const list<value> fe = append(f, entriesElements(cddr(l)));
@@ -145,11 +145,11 @@
  * Convert a list of values representing an ATOM feed to a list of strings.
  * The first two values in the list are the feed id and title.
  */
-const failable<list<std::string>, std::string> writeATOMFeed(const list<value>& l) {
-    const failable<list<std::string>, std::string> ls = writeATOMFeed<list<std::string> >(rcons<std::string>, list<std::string>(), l);
+const failable<list<string> > writeATOMFeed(const list<value>& l) {
+    const failable<list<string> > ls = writeATOMFeed<list<string>>(rcons<string>, list<string>(), l);
     if (!hasContent(ls))
         return ls;
-    return reverse(list<std::string>(content(ls)));
+    return reverse(list<string>(content(ls)));
 }
 
 /**

Modified: tuscany/sca-cpp/trunk/modules/eval/driver.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/eval/driver.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/eval/driver.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/eval/driver.hpp Sat Jan  2 10:27:26 2010
@@ -26,34 +26,34 @@
  * Script evaluator main driver loop.
  */
 
-#include <string>
-#include <iostream>
+#include "string.hpp"
+#include "stream.hpp"
 #include "eval.hpp"
 
 namespace tuscany {
 namespace eval {
 
-const std::string evalOutputPrompt("; ");
-const std::string evalInputPrompt("=> ");
+const string evalOutputPrompt("; ");
+const string evalInputPrompt("=> ");
 
-const bool promptForInput(const std::string str, std::ostream& out) {
-    out << std::endl << std::endl << str;
+const bool promptForInput(const string& str, ostream& out) {
+    out << endl << endl << str;
     return true;
 }
 
-const bool announceOutput(const std::string str, std::ostream& out) {
-    out << std::endl << str;
+const bool announceOutput(const string str, ostream& out) {
+    out << endl << str;
     return true;
 }
 
-const bool userPrint(const value val, std::ostream& out) {
+const bool userPrint(const value val, ostream& out) {
     if(isCompoundProcedure(val))
         writeValue(mklist<value>(compoundProcedureSymbol, procedureParameters(val), procedureBody(val), "<procedure-env>"), out);
     writeValue(val, out);
     return true;
 }
 
-const value evalDriverLoop(std::istream& in, std::ostream& out, Env& globalEnv, const gc_pool& pool) {
+const value evalDriverLoop(istream& in, ostream& out, Env& globalEnv, const gc_pool& pool) {
     promptForInput(evalInputPrompt, out);
     value input = readValue(in);
     if (isNil(input))
@@ -64,8 +64,7 @@
     return evalDriverLoop(in, out, globalEnv, pool);
 }
 
-const bool evalDriverRun(std::istream& in, std::ostream& out) {
-    gc_pool pool;
+const bool evalDriverRun(istream& in, ostream& out, const gc_pool& pool) {
     setupDisplay(out);
     Env globalEnv = setupEnvironment(pool);
     evalDriverLoop(in, out, globalEnv, pool);

Modified: tuscany/sca-cpp/trunk/modules/eval/environment.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/eval/environment.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/eval/environment.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/eval/environment.hpp Sat Jan  2 10:27:26 2010
@@ -26,10 +26,11 @@
  * Script evaluator environment implementation.
  */
 
-#include <string>
+#include "string.hpp"
 #include "list.hpp"
 #include "value.hpp"
 #include "primitive.hpp"
+#include <string>
 
 namespace tuscany {
 namespace eval {
@@ -63,7 +64,7 @@
     return cdr(env);
 }
 
-const gc_pool_ptr<Frame> firstFrame(const Env& env) {
+const gc_ptr<Frame> firstFrame(const Env& env) {
     return car(env);
 }
 
@@ -82,7 +83,7 @@
 const Frame makeBinding(const Frame& frameSoFar, const list<value>& variables, const list<value> values) {
     if (isNil(variables)) {
         if (!isNil(values))
-            logStream() << "Too many arguments supplied " << values << std::endl;
+            logStream() << "Too many arguments supplied " << values << endl;
         return frameSoFar;
     }
     if (isDotVariable(car(variables)))
@@ -90,7 +91,7 @@
 
     if (isNil(values)) {
         if (!isNil(variables))
-            logStream() << "Too few arguments supplied " << variables << std::endl;
+            logStream() << "Too few arguments supplied " << variables << endl;
         return frameSoFar;
     }
 
@@ -101,8 +102,8 @@
     return makeBinding(newFrame, cdr(variables), cdr(values));
 }
 
-const gc_pool_ptr<Frame> makeFrame(const list<value>& variables, const list<value> values, const gc_pool& pool) {
-    gc_pool_ptr<Frame> frame = gc_pool_new<Frame>(pool);
+const gc_ptr<Frame> makeFrame(const list<value>& variables, const list<value> values, const gc_pool& pool) {
+    gc_ptr<Frame> frame = new (gc_new<Frame>(pool)) Frame();
     *frame = value(makeBinding(cons(value(list<value>()), list<value>()), variables, values));
     return frame;
 }
@@ -163,7 +164,7 @@
 
 const value lookupEnvLoop(const value& var, const Env& env) {
     if(env == theEmptyEnvironment()) {
-        logStream() << "Unbound variable " << var << std::endl;
+        logStream() << "Unbound variable " << var << endl;
         return value();
     }
     return lookupEnvScan(var, frameVariables(*firstFrame(env)), frameValues(*firstFrame(env)), env);

Modified: tuscany/sca-cpp/trunk/modules/eval/eval-shell.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/eval/eval-shell.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/eval/eval-shell.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/eval/eval-shell.cpp Sat Jan  2 10:27:26 2010
@@ -24,12 +24,13 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <string>
-#include <sstream>
+#include "gc.hpp"
+#include "stream.hpp"
+#include "string.hpp"
 #include "driver.hpp"
 
 int main() {
-    tuscany::eval::evalDriverRun(std::cin, std::cout);
+    tuscany::gc_scoped_pool pool;
+    tuscany::eval::evalDriverRun(tuscany::cin, tuscany::cout, pool);
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/modules/eval/eval-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/eval/eval-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/eval/eval-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/eval/eval-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,16 +24,15 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <string>
-#include <sstream>
+#include "stream.hpp"
+#include "string.hpp"
 #include "driver.hpp"
 
 namespace tuscany {
 namespace eval {
 
 bool testEnv() {
-    gc_pool pool;
+    gc_scoped_pool pool;
     Env globalEnv = list<value>();
     Env env = extendEnvironment(mklist<value>("a"), mklist<value>(1), globalEnv, pool);
     defineVariable("x", env, env);
@@ -50,26 +49,23 @@
     assert(checkValueCounters());
     assert(checkLambdaCounters());
     assert(checkListCounters());
-    //printLambdaCounters();
-    //printListCounters();
-    //printValueCounters();
     return true;
 }
 
 bool testRead() {
-    std::istringstream is("abcd");
+    istringstream is("abcd");
     assert(readValue(is) == "abcd");
 
-    std::istringstream is2("123");
+    istringstream is2("123");
     assert(readValue(is2) == value(123));
 
-    std::istringstream is3("(abcd)");
+    istringstream is3("(abcd)");
     assert(readValue(is3) == mklist(value("abcd")));
 
-    std::istringstream is4("(abcd xyz)");
+    istringstream is4("(abcd xyz)");
     assert(readValue(is4) == mklist<value>("abcd", "xyz"));
 
-    std::istringstream is5("(abcd (xyz tuv))");
+    istringstream is5("(abcd (xyz tuv))");
     assert(readValue(is5) == mklist<value>("abcd", mklist<value>("xyz", "tuv")));
 
     return true;
@@ -77,43 +73,43 @@
 
 bool testWrite() {
     const list<value> i = list<value>()
-            << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
-                << (list<value>() << "item"
-                    << (list<value>() << "name" << "Apple")
-                    << (list<value>() << "price" << "$2.99")))
-            << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
-                << (list<value>() << "item"
-                    << (list<value>() << "name" << "Orange")
-                    << (list<value>() << "price" << "$3.55")));
+            + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"
+                + (list<value>() + "item"
+                    + (list<value>() + "name" + "Apple")
+                    + (list<value>() + "price" + "$2.99")))
+            + (list<value>() + "item" + "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c"
+                + (list<value>() + "item"
+                    + (list<value>() + "name" + "Orange")
+                    + (list<value>() + "price" + "$3.55")));
     const list<value> a = cons<value>("Feed", cons<value>("feed-1234", i));
-    std::ostringstream os;
+    ostringstream os;
     writeValue(a, os);
-    std::istringstream is(os.str());
+    istringstream is(str(os));
     assert(readValue(is) == a);
     return true;
 }
 
-const std::string testSchemeNumber(
+const string testSchemeNumber(
   "(define (testNumber) (if (= 1 1) (display \"testNumber ok\") (error \"testNumber\"))) "
   "(testNumber)");
 
-const std::string testSchemeString(
+const string testSchemeString(
   "(define (testString) (if (= \"abc\" \"abc\") (display \"testString ok\") (error \"testString\"))) "
   "(testString)");
 
-const std::string testSchemeDefinition(
+const string testSchemeDefinition(
   "(define a \"abc\") (define (testDefinition) (if (= a \"abc\") (display \"testDefinition ok\") (error \"testDefinition\"))) "
   "(testDefinition)");
 
-const std::string testSchemeIf(
+const string testSchemeIf(
   "(define (testIf) (if (= \"abc\" \"abc\") (if (= \"xyz\" \"xyz\") (display \"testIf ok\") (error \"testNestedIf\")) (error \"testIf\"))) "
   "(testIf)");
 
-const std::string testSchemeCond(
+const string testSchemeCond(
   "(define (testCond) (cond ((= \"abc\" \"abc\") (display \"testCond ok\")) (else (error \"testIf\"))))"
   "(testCond)");
 
-const std::string testSchemeBegin(
+const string testSchemeBegin(
   "(define (testBegin) "
     "(begin "
         "(define a \"abc\") "
@@ -124,42 +120,39 @@
   ") "
   "(testBegin)");
 
-const std::string testSchemeLambda(
+const string testSchemeLambda(
   "(define sqrt (lambda (x) (* x x))) "
   "(define (testLambda) (if (= 4 (sqrt 2)) (display \"testLambda ok\") (error \"testLambda\"))) "
   "(testLambda)");
 
-const std::string testSchemeForward(
+const string testSchemeForward(
   "(define (testLambda) (if (= 4 (sqrt 2)) (display \"testForward ok\") (error \"testForward\"))) "
   "(define sqrt (lambda (x) (* x x))) "
   "(testLambda)");
 
-bool contains(const std::string& str, const std::string& pattern) {
-    return str.find(pattern) != str.npos;
-}
-
-const std::string evalOutput(const std::string& scm) {
-    std::istringstream is(scm);
-    std::ostringstream os;
-    evalDriverRun(is, os);
-    return os.str();
+const string evalOutput(const string& scm, const gc_pool& pool) {
+    istringstream is(scm);
+    ostringstream os;
+    evalDriverRun(is, os, pool);
+    return str(os);
 }
 
 bool testEval() {
-    assert(contains(evalOutput(testSchemeNumber), "testNumber ok"));
-    assert(contains(evalOutput(testSchemeString), "testString ok"));
-    assert(contains(evalOutput(testSchemeDefinition), "testDefinition ok"));
-    assert(contains(evalOutput(testSchemeIf), "testIf ok"));
-    assert(contains(evalOutput(testSchemeCond), "testCond ok"));
-    assert(contains(evalOutput(testSchemeBegin), "testBegin1 ok"));
-    assert(contains(evalOutput(testSchemeBegin), "testBegin2 ok"));
-    assert(contains(evalOutput(testSchemeLambda), "testLambda ok"));
-    assert(contains(evalOutput(testSchemeForward), "testForward ok"));
+    gc_scoped_pool pool;
+    assert(contains(evalOutput(testSchemeNumber, pool), "testNumber ok"));
+    assert(contains(evalOutput(testSchemeString, pool), "testString ok"));
+    assert(contains(evalOutput(testSchemeDefinition, pool), "testDefinition ok"));
+    assert(contains(evalOutput(testSchemeIf, pool), "testIf ok"));
+    assert(contains(evalOutput(testSchemeCond, pool), "testCond ok"));
+    assert(contains(evalOutput(testSchemeBegin, pool), "testBegin1 ok"));
+    assert(contains(evalOutput(testSchemeBegin, pool), "testBegin2 ok"));
+    assert(contains(evalOutput(testSchemeLambda, pool), "testLambda ok"));
+    assert(contains(evalOutput(testSchemeForward, pool), "testForward ok"));
     return true;
 }
 
 bool testEvalExpr() {
-    gc_pool pool;
+    gc_scoped_pool pool;
     const value exp = mklist<value>("+", 2, 3);
     Env env = setupEnvironment(pool);
     const value r = evalExpr(exp, env, pool);
@@ -168,7 +161,8 @@
 }
 
 bool testEvalRun() {
-    evalDriverRun(std::cin, std::cout);
+    gc_scoped_pool pool;
+    evalDriverRun(cin, cout, pool);
     return true;
 }
 
@@ -178,26 +172,26 @@
     return x * y;
 }
 
-const std::string testReturnLambda(
+const string testReturnLambda(
   "(define (testReturnLambda) * )");
 
-const std::string testCallLambda(
+const string testCallLambda(
   "(define (testCallLambda l x y) (l x y))");
 
 bool testEvalLambda() {
-    gc_pool pool;
+    gc_scoped_pool pool;
     Env env = setupEnvironment(pool);
 
     const value trl = mklist<value>("testReturnLambda");
-    std::istringstream trlis(testReturnLambda);
+    istringstream trlis(testReturnLambda);
     const value trlv = evalScript(trl, trlis, env, pool);
 
-    std::istringstream tclis(testCallLambda);
+    istringstream tclis(testCallLambda);
     const value tcl = cons<value>("testCallLambda", quotedParameters(mklist<value>(trlv, 2, 3)));
     const value tclv = evalScript(tcl, tclis, env, pool);
     assert(tclv == value(6));
 
-    std::istringstream tcelis(testCallLambda);
+    istringstream tcelis(testCallLambda);
     const value tcel = cons<value>("testCallLambda", quotedParameters(mklist<value>(primitiveProcedure(mult), 3, 4)));
     const value tcelv = evalScript(tcel, tcelis, env, pool);
     assert(tcelv == value(12));
@@ -214,9 +208,6 @@
     assert(checkValueCounters());
     assert(checkLambdaCounters());
     assert(checkListCounters());
-    //printLambdaCounters();
-    //printListCounters();
-    //printValueCounters();
     return true;
 }
 
@@ -224,7 +215,7 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::eval::testEnv();
     tuscany::eval::testEnvGC();
@@ -235,6 +226,6 @@
     tuscany::eval::testEvalLambda();
     tuscany::eval::testEvalGC();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/modules/eval/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/eval/eval.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/eval/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/eval/eval.hpp Sat Jan  2 10:27:26 2010
@@ -146,7 +146,7 @@
         Env env = extendEnvironment(procedureParameters(procedure), arguments, procedureEnvironment(procedure), pool);
         return evalSequence(procedureBody(procedure), env, pool);
     }
-    logStream() << "Unknown procedure type " << procedure << std::endl;
+    logStream() << "Unknown procedure type " << procedure << endl;
     return value();
 }
 
@@ -208,7 +208,7 @@
     if(isCondElseClause(first)) {
         if(isNil(rest))
             return sequenceToExp(condActions(first));
-        logStream() << "else clause isn't last " << clauses << std::endl;
+        logStream() << "else clause isn't last " << clauses << endl;
         return value();
     }
     return makeIf(condPredicate(first), sequenceToExp(condActions(first)), expandClauses(rest));
@@ -254,7 +254,7 @@
         list<value> operandValues = listOfValues(operands(exp), env, pool);
         return applyProcedure(evalExpr(operat(exp), env, pool), operandValues, pool);
     }
-    logStream() << "Unknown expression type " << exp << std::endl;
+    logStream() << "Unknown expression type " << exp << endl;
     return value();
 }
 
@@ -281,7 +281,7 @@
 /**
  * Evaluate an expression against a script provided as an input stream.
  */
-const value evalScript(const value& expr, std::istream& is, Env& env, const gc_pool& pool) {
+const value evalScript(const value& expr, istream& is, Env& env, const gc_pool& pool) {
     return evalScript(expr, readScript(is), env, pool);
 }
 



Mime
View raw message