tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r895165 [3/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
Modified: tuscany/sca-cpp/trunk/modules/eval/io.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/eval/io.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/eval/io.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/eval/io.hpp Sat Jan  2 10:27:26 2010
@@ -26,10 +26,9 @@
  * Script evaluator IO functions.
  */
 
-#include <iostream>
-#include <string>
-#include <sstream>
 #include <ctype.h>
+#include "stream.hpp"
+#include "string.hpp"
 
 #include "list.hpp"
 #include "value.hpp"
@@ -42,11 +41,8 @@
 const value leftParenthesis(mklist<value>("("));
 const value comment(mklist<value>(";"));
 
-const double stringToNumber(const std::string& str) {
-    double d;
-    std::istringstream is(str);
-    is >> d;
-    return d;
+const double stringToNumber(const string& str) {
+    return atof(c_str(str));
 }
 
 const bool isWhitespace(const char ch) {
@@ -73,18 +69,18 @@
     return rightParenthesis == token;
 }
 
-const char readChar(std::istream& in) {
+const char readChar(istream& in) {
     if(in.eof()) {
         return -1;
     }
-    char c = (char)in.get();
+    char c = (char)get(in);
     return c;
 }
 
-const char peekChar(std::istream& in) {
-    if(in.eof())
+const char peekChar(istream& in) {
+    if(eof(in))
         return -1;
-    char c = (char)in.peek();
+    char c = (char)peek(in);
     return c;
 }
 
@@ -92,14 +88,14 @@
     return token == quoteSymbol;
 }
 
-const value skipComment(std::istream& in);
-const value readQuoted(std::istream& in);
-const value readIdentifier(const char chr, std::istream& in);
-const value readString(std::istream& in);
-const value readNumber(const char chr, std::istream& in);
-const value readValue(std::istream& in);
+const value skipComment(istream& in);
+const value readQuoted(istream& in);
+const value readIdentifier(const char chr, istream& in);
+const value readString(istream& in);
+const value readNumber(const char chr, istream& in);
+const value readValue(istream& in);
 
-const value readToken(std::istream& in) {
+const value readToken(istream& in) {
     const char firstChar = readChar(in);
     if(isWhitespace(firstChar))
         return readToken(in);
@@ -119,22 +115,22 @@
         return readNumber(firstChar, in);
     if(firstChar == -1)
         return value();
-    logStream() << "Illegal lexical syntax '" << firstChar << "'" << std::endl;
+    logStream() << "Illegal lexical syntax '" << firstChar << "'" << endl;
     return readToken(in);
 }
 
-const value skipComment(std::istream& in) {
+const value skipComment(istream& in) {
     const char nextChar = readChar(in);
     if (nextChar == '\n')
         return readToken(in);
     return skipComment(in);
 }
 
-const value readQuoted(std::istream& in) {
+const value readQuoted(istream& in) {
     return mklist(quoteSymbol, readValue(in));
 }
 
-const list<value> readList(const list<value>& listSoFar, std::istream& in) {
+const list<value> readList(const list<value>& listSoFar, istream& in) {
     const value token = readToken(in);
     if(isNil(token) || isRightParenthesis(token))
         return reverse(listSoFar);
@@ -143,72 +139,73 @@
     return readList(cons(token, listSoFar), in);
 }
 
-const std::string listToString(const list<char>& l) {
+const string listToString(const list<char>& l) {
     if(isNil(l))
         return "";
-    return car(l) + listToString(cdr(l));
+    const char buf[1] = { car(l) };
+    return string(buf, 1) + listToString(cdr(l));
 }
 
-const list<char> readIdentifierHelper(const list<char>& listSoFar, std::istream& in) {
+const list<char> readIdentifierHelper(const list<char>& listSoFar, istream& in) {
     const char nextChar = peekChar(in);
     if(isIdentifierPart(nextChar))
         return readIdentifierHelper(cons(readChar(in), listSoFar), in);
     return reverse(listSoFar);
 }
 
-const value readIdentifier(const char chr, std::istream& in) {
-    return listToString(readIdentifierHelper(mklist(chr), in)).c_str();
+const value readIdentifier(const char chr, istream& in) {
+    return c_str(listToString(readIdentifierHelper(mklist(chr), in)));
 }
 
-const list<char> readStringHelper(const list<char>& listSoFar, std::istream& in) {
+const list<char> readStringHelper(const list<char>& listSoFar, istream& in) {
     const char nextChar = readChar(in);
     if(nextChar != -1 && nextChar != '"')
         return readStringHelper(cons(nextChar, listSoFar), in);
     return reverse(listSoFar);
 }
 
-const value readString(std::istream& in) {
+const value readString(istream& in) {
     return listToString(readStringHelper(list<char>(), in));
 }
 
-const list<char> readNumberHelper(const list<char>& listSoFar, std::istream& in) {
+const list<char> readNumberHelper(const list<char>& listSoFar, istream& in) {
     const char nextChar = peekChar(in);
     if(isDigit(nextChar))
         return readNumberHelper(cons(readChar(in), listSoFar), in);
     return reverse(listSoFar);
 }
 
-const value readNumber(const char chr, std::istream& in) {
+const value readNumber(const char chr, istream& in) {
     return stringToNumber(listToString(readNumberHelper(mklist(chr), in)));
 }
 
-const value readValue(std::istream& in) {
+const value readValue(istream& in) {
     const value nextToken = readToken(in);
     if(isLeftParenthesis(nextToken))
         return readList(list<value> (), in);
     return nextToken;
 }
 
-const value readValue(const std::string s) {
-    std::istringstream in(s);
+const value readValue(const string s) {
+    istringstream in(s);
     const value nextToken = readToken(in);
     if(isLeftParenthesis(nextToken))
         return readList(list<value> (), in);
     return nextToken;
 }
 
-const bool writeValue(const value& val, std::ostream& out) {
+const bool writeValue(const value& val, ostream& out) {
     out << val;
     return true;
 }
 
-const std::string writeValue(const value& val) {
-    std::ostringstream out;
+const string writeValue(const value& val) {
+    ostringstream out;
     out << val;
-    return out.str();
+    return str(out);
 }
 
-const value readScript(std::istream& in) {
+const value readScript(istream& in) {
     const value val = readValue(in);
     if (isNil(val))
         return list<value>();

Modified: tuscany/sca-cpp/trunk/modules/eval/primitive.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/eval/primitive.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/eval/primitive.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/eval/primitive.hpp Sat Jan  2 10:27:26 2010
@@ -28,7 +28,7 @@
 
 #include <apr_general.h>
 #include <apr_uuid.h>
-#include <iostream>
+#include "stream.hpp"
 #include "function.hpp"
 #include "list.hpp"
 #include "value.hpp"
@@ -40,24 +40,24 @@
 const value quoteSymbol("'");
 const value lambdaSymbol("lambda");
 
-std::ostream* displayOutStream = &std::cout;
-std::ostream* logOutStream = &std::cerr;
+ostream* displayOutStream = &cout;
+ostream* logOutStream = &cerr;
 
-const bool setupDisplay(std::ostream& out) {
+const bool setupDisplay(ostream& out) {
     displayOutStream = &out;
     return true;
 }
 
-std::ostream& displayStream() {
+ostream& displayStream() {
     return *displayOutStream;
 }
 
-const bool setupLog(std::ostream& out) {
+const bool setupLog(ostream& out) {
     logOutStream = &out;
     return true;
 }
 
-std::ostream& logStream() {
+ostream& logStream() {
     return *logOutStream;
 }
 
@@ -116,7 +116,7 @@
 
 const value displayProc(const list<value>& args) {
     if (isNil(args)) {
-        displayStream() << std::endl;
+        displayStream() << endl;
         return true;
     }
     displayStream() << car(args);
@@ -125,7 +125,7 @@
 
 const value logProc(const list<value>& args) {
     if (isNil(args)) {
-        logStream() << std::endl;
+        logStream() << endl;
         return true;
     }
     logStream() << car(args);
@@ -137,7 +137,7 @@
     apr_uuid_get(&uuid);
     char buf[APR_UUID_FORMATTED_LENGTH];
     apr_uuid_format(buf, &uuid);
-    return std::string(buf, APR_UUID_FORMATTED_LENGTH);
+    return string(buf, APR_UUID_FORMATTED_LENGTH);
 }
 
 const value cadrProc(unused const list<value>& args) {
@@ -194,51 +194,49 @@
 }
 
 const list<value> primitiveProcedureNames() {
-    list<value> l = mklist<value>("car");
-    l = cons<value>("cdr", l);
-    l = cons<value>("cons", l);
-    l = cons<value>("list", l);
-    l = cons<value>("nul", l);
-    l = cons<value>("=", l);
-    l = cons<value>("equal?", l);
-    l = cons<value>("+", l);
-    l = cons<value>("-", l);
-    l = cons<value>("*", l);
-    l = cons<value>("/", l);
-    l = cons<value>("assoc", l);
-    l = cons<value>("cadr", l);
-    l = cons<value>("caddr", l);
-    l = cons<value>("cadddr", l);
-    l = cons<value>("cddr", l);
-    l = cons<value>("cdddr", l);
-    l = cons<value>("display", l);
-    l = cons<value>("log", l);
-    l = cons<value>("uuid", l);
-    return l;
+    return mklist<value>("car")
+    + "cdr"
+    + "cons"
+    + "list"
+    + "nul"
+    + "="
+    + "equal?"
+    + "+"
+    + "-"
+    + "*"
+    + "/"
+    + "assoc"
+    + "cadr"
+    + "caddr"
+    + "cadddr"
+    + "cddr"
+    + "cdddr"
+    + "display"
+    + "log"
+    + "uuid";
 }
 
 const list<value> primitiveProcedureObjects() {
-    list<value> l = mklist(primitiveProcedure(carProc));
-    l = cons(primitiveProcedure(cdrProc), l);
-    l = cons(primitiveProcedure(consProc), l);
-    l = cons(primitiveProcedure(listProc), l);
-    l = cons(primitiveProcedure(nulProc), l);
-    l = cons(primitiveProcedure(equalProc), l);
-    l = cons(primitiveProcedure(equalProc), l);
-    l = cons(primitiveProcedure(addProc), l);
-    l = cons(primitiveProcedure(subProc), l);
-    l = cons(primitiveProcedure(mulProc), l);
-    l = cons(primitiveProcedure(divProc), l);
-    l = cons(primitiveProcedure(assocProc), l);
-    l = cons(primitiveProcedure(cadrProc), l);
-    l = cons(primitiveProcedure(caddrProc), l);
-    l = cons(primitiveProcedure(cadddrProc), l);
-    l = cons(primitiveProcedure(cddrProc), l);
-    l = cons(primitiveProcedure(cdddrProc), l);
-    l = cons(primitiveProcedure(displayProc), l);
-    l = cons(primitiveProcedure(logProc), l);
-    l = cons(primitiveProcedure(uuidProc), l);
-    return l;
+    return mklist(primitiveProcedure(carProc))
+    + primitiveProcedure(cdrProc)
+    + primitiveProcedure(consProc)
+    + primitiveProcedure(listProc)
+    + primitiveProcedure(nulProc)
+    + primitiveProcedure(equalProc)
+    + primitiveProcedure(equalProc)
+    + primitiveProcedure(addProc)
+    + primitiveProcedure(subProc)
+    + primitiveProcedure(mulProc)
+    + primitiveProcedure(divProc)
+    + primitiveProcedure(assocProc)
+    + primitiveProcedure(cadrProc)
+    + primitiveProcedure(caddrProc)
+    + primitiveProcedure(cadddrProc)
+    + primitiveProcedure(cddrProc)
+    + primitiveProcedure(cdddrProc)
+    + primitiveProcedure(displayProc)
+    + primitiveProcedure(logProc)
+    + primitiveProcedure(uuidProc);
 }
 
 const bool isFalse(const value& exp) {

Modified: tuscany/sca-cpp/trunk/modules/http/curl-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/curl-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/curl-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/curl-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,21 +24,15 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include "slist.hpp"
+#include "stream.hpp"
+#include "string.hpp"
 #include "perf.hpp"
 #include "curl.hpp"
 
 namespace tuscany {
 namespace http {
 
-const bool contains(const std::string& str, const std::string& pattern) {
-    return str.find(pattern) != str.npos;
-}
-
-std::ostringstream* curlWriter(const std::string& s, std::ostringstream* os) {
+ostream* curlWriter(const string& s, ostream* os) {
     (*os) << s;
     return os;
 }
@@ -46,16 +40,16 @@
 const bool testGet() {
     CURLSession ch;
     {
-        std::ostringstream os;
-        const failable<list<std::ostringstream*>, std::string> r = get<std::ostringstream*>(curlWriter, &os, "http://localhost:8090", ch);
+        ostringstream os;
+        const failable<list<ostream*> > r = get<ostream*>(curlWriter, &os, "http://localhost:8090", ch);
         assert(hasContent(r));
-        assert(contains(os.str(), "HTTP/1.1 200 OK"));
-        assert(contains(os.str(), "It works"));
+        assert(contains(str(os), "HTTP/1.1 200 OK"));
+        assert(contains(str(os), "It works"));
     }
     {
-        const failable<value, std::string> r = get("http://localhost:8090", ch);
+        const failable<value> r = getcontent("http://localhost:8090", ch);
         assert(hasContent(r));
-        assert(contains(content(r), "It works"));
+        assert(contains(car(reverse(list<value>(content(r)))), "It works"));
     }
     return true;
 }
@@ -65,9 +59,9 @@
     getLoop(CURLSession& ch) : ch(ch) {
     }
     const bool operator()() const {
-        const failable<value, std::string> r = get("http://localhost:8090", ch);
+        const failable<value> r = getcontent("http://localhost:8090", ch);
         assert(hasContent(r));
-        assert(contains(content(r), "It works"));
+        assert(contains(car(reverse(list<value>(content(r)))), "It works"));
         return true;
     }
 };
@@ -75,7 +69,7 @@
 const bool testGetPerf() {
     CURLSession ch;
     lambda<bool()> gl = getLoop(ch);
-    std::cout << "Static GET test " << time(gl, 5, 200) << " ms" << std::endl;
+    cout << "Static GET test " << time(gl, 5, 200) << " ms" << endl;
     return true;
 }
 
@@ -83,12 +77,12 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::http::testGet();
     tuscany::http::testGetPerf();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/modules/http/curl.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/curl.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/curl.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/curl.hpp Sat Jan  2 10:27:26 2010
@@ -29,7 +29,7 @@
 #include <curl/curl.h>
 #include <curl/types.h>
 #include <curl/easy.h>
-#include <string>
+#include "string.hpp"
 #include "gc.hpp"
 #include "list.hpp"
 #include "value.hpp"
@@ -62,7 +62,7 @@
  */
 class CURLSession {
 public:
-    CURLSession() : ch(new CURLHandle()) {
+    CURLSession() : ch(new (gc_new<CURLHandle>()) CURLHandle()) {
     }
 
     ~CURLSession() {
@@ -103,9 +103,9 @@
  */
 class CURLReadContext {
 public:
-    CURLReadContext(const list<std::string>& ilist) : ilist(ilist) {
+    CURLReadContext(const list<string>& ilist) : ilist(ilist) {
     }
-    list<std::string> ilist;
+    list<string> ilist;
 };
 
 /**
@@ -115,11 +115,11 @@
     CURLReadContext& rcx = *static_cast<CURLReadContext*>(data);
     if (isNil(rcx.ilist))
         return 0;
-    rcx.ilist = fragment(rcx.ilist, size * nmemb);
-    const std::string s = car(rcx.ilist);
-    rcx.ilist = cdr(rcx.ilist);
-    s.copy((char*)ptr, s.length());
-    return s.length();
+    const list<string> f(fragment(rcx.ilist, size * nmemb));
+    const string s = car(f);
+    rcx.ilist = cdr(f);
+    memcpy(ptr, c_str(s), length(s));
+    return length(s);
 }
 
 /**
@@ -127,9 +127,9 @@
  */
 template<typename R> class CURLWriteContext {
 public:
-    CURLWriteContext(const lambda<R(const std::string&, const R)>& reduce, const R& accum) : reduce(reduce), accum(accum) {
+    CURLWriteContext(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;
 };
 
@@ -137,33 +137,23 @@
  * Called by CURL to write received data.
  */
 template<typename R> size_t writeCallback(void *ptr, size_t size, size_t nmemb, void *data) {
-  CURLWriteContext<R>& wcx = *(static_cast<CURLWriteContext<R>*> (data));
-  const size_t realsize = size * nmemb;
-  wcx.accum = wcx.reduce(std::string((const char*)ptr, realsize), wcx.accum);
-  return realsize;
-}
-            
-/**
- * Called by CURL to write received header data.
- */
-template<typename R> size_t headerCallback(void *ptr, size_t size, size_t nmemb, void *data) {
-  CURLWriteContext<R>& wcx = *(static_cast<CURLWriteContext<R>*> (data));
-  const size_t realsize = size * nmemb;
-  wcx.accum = wcx.reduce(std::string((const char*)ptr, realsize), wcx.accum);
-  return realsize;
+    CURLWriteContext<R>& wcx = *(static_cast<CURLWriteContext<R>*> (data));
+    const size_t realsize = size * nmemb;
+    wcx.accum = wcx.reduce(string((const char*)ptr, realsize), wcx.accum);
+    return realsize;
 }
 
 /**
  * Apply an HTTP verb to a list containing a list of headers and a list of content, and
  * a reduce function used to process the response.
  */
-curl_slist* headers(curl_slist* cl, const list<std::string>& h) {
+curl_slist* headers(curl_slist* cl, const list<string>& h) {
     if (isNil(h))
         return cl;
-    return headers(curl_slist_append(cl, std::string(car(h)).c_str()), cdr(h));
+    return headers(curl_slist_append(cl, c_str(string(car(h)))), cdr(h));
 }
 
-template<typename R> const failable<list<R>, std::string> apply(const list<list<std::string> >& req, const lambda<R(const std::string&, const R)>& reduce, const R& initial, const std::string& url, const std::string& verb, const CURLSession& cs) {
+template<typename R> const failable<list<R> > apply(const list<list<string> >& hdr, const lambda<R(const string&, const R)>& reduce, const R& initial, const string& url, const string& verb, const CURLSession& cs) {
 
     // Init the curl session
     CURL* ch = handle(cs);
@@ -171,30 +161,30 @@
     curl_easy_setopt(ch, CURLOPT_USERAGENT, "libcurl/1.0");
 
     //TODO use HTTP chunking, for now just convert request to a single string
-    std::ostringstream os;
-    write(cadr(req), os);
-    const std::string s = os.str();
-    const int sz = s.length();
+    ostringstream os;
+    write(cadr(hdr), os);
+    const string s = str(os);
+    const int sz = length(s);
 
     // Setup the read, header and write callbacks
     CURLReadContext rcx(mklist(s));
     curl_easy_setopt(ch, CURLOPT_READFUNCTION, (size_t (*)(void*, size_t, size_t, void*))readCallback);
     curl_easy_setopt(ch, CURLOPT_READDATA, &rcx);
     CURLWriteContext<R> hcx(reduce, initial);
-    curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, (size_t (*)(void*, size_t, size_t, void*))headerCallback<R>);
+    curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, (size_t (*)(void*, size_t, size_t, void*))(writeCallback<R>));
     curl_easy_setopt(ch, CURLOPT_HEADERDATA, &hcx);
     CURLWriteContext<R> wcx(reduce, initial);
-    curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, (size_t (*)(void*, size_t, size_t, void*))writeCallback<R>);
+    curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, (size_t (*)(void*, size_t, size_t, void*))(writeCallback<R>));
     curl_easy_setopt(ch, CURLOPT_WRITEDATA, &wcx);
     curl_easy_setopt(ch, CURLOPT_TCP_NODELAY, true);
 
     // Set the request headers
-    curl_slist* hl = headers(NULL, car(req));
+    curl_slist* hl = headers(NULL, car(hdr));
     if (hl != NULL)
         curl_easy_setopt(ch, CURLOPT_HTTPHEADER, hl);
 
     // Apply the HTTP verb
-    curl_easy_setopt(ch, CURLOPT_URL, url.c_str());
+    curl_easy_setopt(ch, CURLOPT_URL, c_str(url));
     if (verb == "POST") {
         curl_easy_setopt(ch, CURLOPT_POST, true);
         curl_easy_setopt(ch, CURLOPT_POSTFIELDSIZE, sz);
@@ -210,13 +200,13 @@
 
     // Return the HTTP return code or content
     if (rc)
-        return mkfailure<list<R>, std::string>(curl_easy_strerror(rc));
+        return mkfailure<list<R> >(string(curl_easy_strerror(rc)));
     long httprc;
     curl_easy_getinfo (ch, CURLINFO_RESPONSE_CODE, &httprc);
     if (httprc != 200 && httprc != 201) {
-        std::ostringstream es;
+        ostringstream es;
         es << "HTTP code " << httprc;
-        return mkfailure<list<R>, std::string>(es.str());
+        return mkfailure<list<R> >(str(es));
     }
     return mklist<R>(hcx.accum, wcx.accum);
 }
@@ -224,26 +214,26 @@
 /**
  * Evaluate an expression remotely, at the given URL.
  */
-const failable<value, std::string> evalExpr(const value& expr, const std::string& url, const CURLSession& ch) {
+const failable<value> evalExpr(const value& expr, const string& url, const CURLSession& ch) {
     debug(url, "http::evalExpr::url");
     debug(expr, "http::evalExpr::input");
 
     // Convert expression to a JSON-RPC request
     json::JSONContext cx;
-    const failable<list<std::string>, std::string> jsreq = jsonRequest(1, car<value>(expr), cdr<value>(expr), cx);
+    const failable<list<string> > jsreq = json::jsonRequest(1, car<value>(expr), cdr<value>(expr), cx);
     if (!hasContent(jsreq))
-        return mkfailure<value, std::string>(reason(jsreq));
+        return mkfailure<value>(reason(jsreq));
 
     // POST it to the URL
-    const list<std::string> h = mklist<std::string>("Content-Type: application/json-rpc");
-    const failable<list<list<std::string> >, std::string> res = apply<list<std::string> >(mklist<list<std::string> >(h, content(jsreq)), rcons<std::string>, list<std::string>(), url, "POST", ch);
+    const list<string> h = mklist<string>("Content-Type: application/json-rpc");
+    const failable<list<list<string> > > res = apply<list<string> >(mklist<list<string> >(h, content(jsreq)), rcons<string>, list<string>(), url, "POST", ch);
     if (!hasContent(res))
-        return mkfailure<value, std::string>(reason(res));
+        return mkfailure<value>(reason(res));
 
     // Return result
-    failable<list<value>, std::string> jsres = json::readJSON(cadr<list<std::string> >(content(res)), cx);
+    failable<list<value> > jsres = json::readJSON(cadr<list<string> >(content(res)), cx);
     if (!hasContent(jsres))
-        return mkfailure<value, std::string>(reason(jsres));
+        return mkfailure<value>(reason(jsres));
     const list<value> val = elementsToValues(content(jsres));
 
     const value rval(cadr<value>(cadr<value>(val)));
@@ -254,72 +244,88 @@
 /**
  * Find and return a header.
  */
-const failable<std::string, std::string> header(const std::string& prefix, const list<std::string>& h) {
+const failable<string> header(const char* prefix, const list<string>& h) {
     if (isNil(h))
-        return mkfailure<std::string, std::string>(std::string("Couldn't find header: ") + prefix);
-    const std::string s = car(h);
-    if (s.find(prefix) != 0)
+        return mkfailure<string>(string("Couldn't find header: ") + prefix);
+    const string s = car(h);
+    if (find(s, prefix) != 0)
         return header(prefix, cdr(h));
-    const std::string l(s.substr(prefix.length()));
-    return l.substr(0, l.find_first_of("\r\n"));
+    const string l(substr(s, length(prefix)));
+    return substr(l, 0, find_first_of(l, "\r\n"));
 }
 
 /**
  * Find and return a location header.
  */
-const failable<std::string, std::string> location(const list<std::string>& h) {
+const failable<string> location(const list<string>& h) {
     return header("Location: ", h);
 }
 
 /**
  * Convert a location to an entry id.
  */
-const failable<value, std::string> entryId(const failable<std::string, std::string> l) {
+const failable<value> entryId(const failable<string> l) {
     if (!hasContent(l))
-        return mkfailure<value, std::string>(reason(l));
-    const std::string ls(content(l));
-    return value(ls.substr(ls.find_last_of("/") + 1));
+        return mkfailure<value>(reason(l));
+    const string ls(content(l));
+    return value(string(substr(ls, find_last(ls, '/') + 1)));
 }
 
 /**
  * Find and return a content-type header.
  */
-const failable<std::string, std::string> contentType(const list<std::string>& h) {
+const failable<string> contentType(const list<string>& h) {
     return header("Content-Type: ", h);
 }
 
 /**
  * HTTP GET, return the resource at the given URL.
  */
-template<typename R> const failable<list<R>, std::string> get(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const std::string& url, const CURLSession& ch) {
+template<typename R> const failable<list<R> > get(const lambda<R(const string&, const R)>& reduce, const R& initial, const string& url, const CURLSession& ch) {
     debug(url, "http::get::url");
-    const list<list<std::string> > req = mklist(list<std::string>(), list<std::string>());
+    const list<list<string> > req = mklist(list<string>(), list<string>());
     return apply(req, reduce, initial, url, "GET", ch);
 }
 
 /**
  * HTTP GET, return a list of values representing the resource at the given URL.
  */
-const failable<value, std::string> get(const std::string& url, const CURLSession& ch) {
+const failable<value> getcontent(const string& url, const CURLSession& ch) {
     debug(url, "http::get::url");
 
     // Get the contents of the resource at the given URL
-    const failable<list<list<std::string> >, std::string> res = get<list<std::string> >(rcons<std::string>, list<std::string>(), url, ch);
+    const failable<list<list<string> > > res = get<list<string>>(rcons<string>, list<string>(), url, ch);
     if (!hasContent(res))
-        return mkfailure<value, std::string>(reason(res));
-    const list<std::string> ls(reverse(cadr(content(res))));
+        return mkfailure<value>(reason(res));
+    const list<string> ls(reverse(cadr(content(res))));
 
-    const std::string ct(content(contentType(car(content(res)))));
+    // Return the content as a list of values
+    const value val(mkvalues(ls));
+    debug(val, "http::get::result");
+    return val;
+}
+
+/**
+ * HTTP GET, return a list of values representing the resource at the given URL.
+ */
+const failable<value> get(const string& url, const CURLSession& ch) {
+    debug(url, "http::get::url");
+
+    // Get the contents of the resource at the given URL
+    const failable<list<list<string> > > res = get<list<string> >(rcons<string>, list<string>(), url, ch);
+    if (!hasContent(res))
+        return mkfailure<value>(reason(res));
+    const list<string> ls(reverse(cadr(content(res))));
+
+    const string ct(content(contentType(car(content(res)))));
     if (ct == "application/atom+xml;type=entry") {
         const value val(atom::entryValue(content(atom::readEntry(ls))));
         debug(val, "http::get::result");
         return val;
     }
 
-    // Return the content as a string value
-    std::ostringstream os;
-    write(ls, os);
-    const value val(os.str());
+    // Return the content as a list of values
+    const value val(mkvalues(ls));
     debug(val, "http::get::result");
     return val;
 }
@@ -327,24 +333,24 @@
 /**
  * HTTP POST.
  */
-const failable<value, std::string> post(const value& val, const std::string& url, const CURLSession& ch) {
+const failable<value> post(const value& val, const string& url, const CURLSession& ch) {
 
     // Convert value to an ATOM entry
-    const failable<list<std::string>, std::string> entry = atom::writeATOMEntry(atom::entryValuesToElements(val));
+    const failable<list<string> > entry = atom::writeATOMEntry(atom::entryValuesToElements(val));
     if (!hasContent(entry))
-        return mkfailure<value, std::string>(reason(entry));
+        return mkfailure<value>(reason(entry));
     debug(url, "http::post::url");
     debug(content(entry), "http::post::input");
 
     // POST it to the URL
-    const list<std::string> h = mklist<std::string>("Content-Type: application/atom+xml");
-    const list<list<std::string> > req = mklist<list<std::string> >(h, content(entry));
-    const failable<list<list<std::string> >, std::string> res = apply<list<std::string> >(req, rcons<std::string>, list<std::string>(), url, "POST", ch);
+    const list<string> h = mklist<string>("Content-Type: application/atom+xml");
+    const list<list<string> > req = mklist<list<string> >(h, content(entry));
+    const failable<list<list<string> > > res = apply<list<string>>(req, rcons<string>, list<string>(), url, "POST", ch);
     if (!hasContent(res))
-        return mkfailure<value, std::string>(reason(res));
+        return mkfailure<value>(reason(res));
 
     // Return the new entry id from the HTTP location header
-    const failable<value, std::string> eid(entryId(location(car(content(res)))));
+    const failable<value> eid(entryId(location(car(content(res)))));
     debug(eid, "http::post::result");
     return eid;
 }
@@ -352,21 +358,21 @@
 /**
  * HTTP PUT.
  */
-const failable<value, std::string> put(const value& val, const std::string& url, const CURLSession& ch) {
+const failable<value> put(const value& val, const string& url, const CURLSession& ch) {
 
     // Convert value to an ATOM entry
-    const failable<list<std::string>, std::string> entry = atom::writeATOMEntry(atom::entryValuesToElements(val));
+    const failable<list<string> > entry = atom::writeATOMEntry(atom::entryValuesToElements(val));
     if (!hasContent(entry))
-        return mkfailure<value, std::string>(reason(entry));
+        return mkfailure<value>(reason(entry));
     debug(url, "http::put::url");
     debug(content(entry), "http::put::input");
 
     // PUT it to the URL
-    const list<std::string> h = mklist<std::string>("Content-Type: application/atom+xml");
-    const list<list<std::string> > req = mklist<list<std::string> >(h, content(entry));
-    const failable<list<list<std::string> >, std::string> res = apply<list<std::string> >(req, rcons<std::string>, list<std::string>(), url, "PUT", ch);
+    const list<string> h = mklist<string>("Content-Type: application/atom+xml");
+    const list<list<string> > req = mklist<list<string> >(h, content(entry));
+    const failable<list<list<string> > > res = apply<list<string> >(req, rcons<string>, list<string>(), url, "PUT", ch);
     if (!hasContent(res))
-        return mkfailure<value, std::string>(reason(res));
+        return mkfailure<value>(reason(res));
 
     debug(true, "http::put::result");
     return value(true);
@@ -375,13 +381,13 @@
 /**
  * HTTP DELETE.
  */
-const failable<value, std::string> del(const std::string& url, const CURLSession& ch) {
+const failable<value, string> del(const string& url, const CURLSession& ch) {
     debug(url, "http::delete::url");
 
-    const list<list<std::string> > req = mklist(list<std::string>(), list<std::string>());
-    const failable<list<list<std::string> >, std::string> res = apply<list<std::string> >(req, rcons<std::string>, list<std::string>(), url, "DELETE", ch);
+    const list<list<string> > req = mklist(list<string>(), list<string>());
+    const failable<list<list<string> > > res = apply<list<string> >(req, rcons<string>, list<string>(), url, "DELETE", ch);
     if (!hasContent(res))
-        return mkfailure<value, std::string>(reason(res));
+        return mkfailure<value>(reason(res));
 
     debug(true, "http::delete::result");
     return value(true);
@@ -391,18 +397,18 @@
  * HTTP client proxy function.
  */
 struct proxy {
-    proxy(const std::string& url) : url(url) {
+    proxy(const string& url) : url(url) {
     }
 
     const value operator()(const list<value>& args) const {
         CURLSession cs;
-        failable<value, std::string> val = evalExpr(args, url, cs);
+        failable<value> val = evalExpr(args, url, cs);
         if (!hasContent(val))
             return value();
         return content(val);
     }
 
-    const std::string url;
+    const string url;
 };
 
 }

Modified: tuscany/sca-cpp/trunk/modules/http/httpd.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd.hpp Sat Jan  2 10:27:26 2010
@@ -26,8 +26,8 @@
  * HTTPD module implementation functions.
  */
 
-#include <string>
-#include <iostream>
+#include "string.hpp"
+#include "stream.hpp"
 
 #include "apr_strings.h"
 #include "apr_fnmatch.h"
@@ -60,9 +60,7 @@
  * Returns a server-scoped module configuration.
  */
 template<typename C> void* makeServerConf(apr_pool_t *p, server_rec *s) {
-    C* c = new (apr_palloc(p, sizeof(C))) C(s);
-    apr_pool_cleanup_register(p, c, gc_pool_cleanupCallback<C>, apr_pool_cleanup_null) ;
-    return c;
+    return new (gc_new<C>(p)) C(s);
 }
 
 template<typename C> const C& serverConf(const request_rec* r, const module* mod) {
@@ -78,9 +76,7 @@
  * Returns a directory-scoped module configuration.
  */
 template<typename C> void *makeDirConf(apr_pool_t *p, char *dirspec) {
-    C* c = new (apr_palloc(p, sizeof(C))) C(dirspec);
-    apr_pool_cleanup_register(p, c, gc_pool_cleanupCallback<C>, apr_pool_cleanup_null) ;
-    return c;
+    return new (gc_new<C>(p)) C(dirspec);
 }
 
 template<typename C> C& dirConf(const request_rec* r, const module* mod) {
@@ -90,31 +86,25 @@
 /**
  * Convert a path string to a list of values.
  */
-const list<std::string> pathTokens(const char* p) {
+const list<string> pathTokens(const char* p) {
     if (p == NULL || p[0] == '\0')
-        return list<std::string>();
+        return list<string>();
     if (p[0] == '/')
         return tokenize("/", p + 1);
     return tokenize("/", p);
 }
 
-const list<value> pathValues(const list<std::string>& l) {
-    if (isNil(l))
-        return list<value>();
-    return cons<value>(car(l), pathValues(cdr(l)));
-}
-
-const list<value> path(const char* p) {
-    return pathValues(pathTokens(p));
+const list<value> pathValues(const char* p) {
+    return mkvalues(pathTokens(p));
 }
 
 /**
  * Convert a path represented as a list of values to a string.
  */
-const std::string path(const list<value>& p) {
+const string path(const list<value>& p) {
     if (isNil(p))
         return "";
-    return std::string("/") + std::string(car(p)) + path(cdr(p));
+    return string("/") + car(p) + path(cdr(p));
 }
 
 /**
@@ -126,7 +116,7 @@
     return s;
 }
 
-const std::string contentType(const request_rec* r) {
+const string contentType(const request_rec* r) {
     return optional(apr_table_get(r->headers_in, "Content-Type"));
 }
 
@@ -136,24 +126,24 @@
  * Debug log.
  */
 int debugHeader(unused void* r, const char* key, const char* value) {
-    std::cerr << "  header key: " << key << ", value: " << value << std::endl;
+    cerr << "  header key: " << key << ", value: " << value << endl;
     return 1;
 }
 
-const bool debugRequest(request_rec* r, const std::string& msg) {
-    std::cerr << msg << ":" << std::endl;
-    std::cerr << "  protocol: " << optional(r->protocol) << std::endl;
-    std::cerr << "  method: " << optional(r->method) << std::endl;
-    std::cerr << "  method number: " << r->method_number << std::endl;
-    std::cerr << "  content type: " << contentType(r) << std::endl;
-    std::cerr << "  content encoding: " << optional(r->content_encoding) << std::endl;
+const bool debugRequest(request_rec* r, const string& msg) {
+    cerr << msg << ":" << endl;
+    cerr << "  protocol: " << optional(r->protocol) << endl;
+    cerr << "  method: " << optional(r->method) << endl;
+    cerr << "  method number: " << r->method_number << endl;
+    cerr << "  content type: " << contentType(r) << endl;
+    cerr << "  content encoding: " << optional(r->content_encoding) << endl;
     apr_table_do(debugHeader, r, r->headers_in, NULL);
-    std::cerr << "  unparsed uri: " << optional(r->unparsed_uri) << std::endl;
-    std::cerr << "  uri: " << optional(r->uri) << std::endl;
-    std::cerr << "  path info: " << optional(r->path_info) << std::endl;
-    std::cerr << "  filename: " << optional(r->filename) << std::endl;
-    std::cerr << "  uri tokens: " << pathTokens(r->uri) << std::endl;
-    std::cerr << "  args: " << optional(r->args) << std::endl;
+    cerr << "  unparsed uri: " << optional(r->unparsed_uri) << endl;
+    cerr << "  uri: " << optional(r->uri) << endl;
+    cerr << "  path info: " << optional(r->path_info) << endl;
+    cerr << "  filename: " << optional(r->filename) << endl;
+    cerr << "  uri tokens: " << pathTokens(r->uri) << endl;
+    cerr << "  args: " << optional(r->args) << endl;
     return true;
 }
 
@@ -177,16 +167,16 @@
 /**
  * Returns a list of key value pairs from the args in a query string.
  */
-const list<value> queryArg(const std::string& s) {
-    const list<std::string> t = tokenize("=", s);
-    return mklist<value>(car(t).c_str(), cadr(t));
+const list<value> queryArg(const string& s) {
+    const list<string> t = tokenize("=", s);
+    return mklist<value>(c_str(car(t)), cadr(t));
 }
 
 const list<list<value> > queryArgs(const request_rec* r) {
     const char* a = r->args;
     if (a == NULL)
         return list<list<value> >();
-    return map<std::string, list<value>>(queryArg, tokenize("&", a));
+    return map<string, list<value>>(queryArg, tokenize("&", a));
 }
 
 /**
@@ -229,50 +219,49 @@
 /**
  * Read the content of a POST or PUT.
  */
-const list<std::string> read(request_rec* r) {
-    char b[2048];
-    const int n = ap_get_client_block(r, b, 2048);
+const list<string> read(request_rec* r) {
+    char b[1024];
+    const int n = ap_get_client_block(r, b, sizeof(b));
     if (n <= 0)
-        return list<std::string>();
-    return cons(std::string(b, n), read(r));
+        return list<string>();
+    return cons(string(b, n), read(r));
 }
 
 /**
  * Convert a URI value to an absolute URL.
  */
 const char* url(const value& v, request_rec* r) {
-    std::string u = r->uri;
-    u.append("/");
-    u.append(v);
-    return ap_construct_url(r->pool, u.c_str(), r);
+    const string u = string(r->uri) + "/" + v;
+    return ap_construct_url(r->pool, c_str(u), r);
 }
 
 /**
  * Write an HTTP result.
  */
-const failable<int, std::string> writeResult(const failable<list<std::string>, std::string>& ls, const std::string& ct, request_rec* r) {
+const failable<int> writeResult(const failable<list<string> >& ls, const string& ct, request_rec* r) {
     if (!hasContent(ls))
-        return mkfailure<int, std::string>(reason(ls));
-    std::ostringstream os;
+        return mkfailure<int>(reason(ls));
+    ostringstream os;
     write(content(ls), os);
-    debug(os.str(), "httpd::result");
+    const string ob(str(os));
+    debug(ob, "httpd::result");
 
-    const std::string etag(ap_md5(r->pool, (const unsigned char*)std::string(os.str()).c_str()));
+    const string etag(ap_md5(r->pool, (const unsigned char*)c_str(ob)));
     const char* match = apr_table_get(r->headers_in, "If-None-Match");
-    apr_table_setn(r->headers_out, "ETag", apr_pstrdup(r->pool, etag.c_str()));
+    apr_table_setn(r->headers_out, "ETag", apr_pstrdup(r->pool, c_str(etag)));
     if (match != NULL  && etag == match) {
         r->status = HTTP_NOT_MODIFIED;
         return OK;
     }
-    ap_set_content_type(r, apr_pstrdup(r->pool, ct.c_str()));
-    ap_rputs(std::string(os.str()).c_str(), r);
+    ap_set_content_type(r, apr_pstrdup(r->pool, c_str(ct)));
+    ap_rputs(c_str(ob), r);
     return OK;
 }
 
 /**
  * Report request execution status.
  */
-const int reportStatus(const failable<int, std::string>& rc) {
+const int reportStatus(const failable<int>& rc) {
     if (!hasContent(rc))
         return HTTP_INTERNAL_SERVER_ERROR;
     return content(rc);

Modified: tuscany/sca-cpp/trunk/modules/json/json-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/json/json-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/json/json-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/json/json-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,10 +24,8 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include "slist.hpp"
+#include "stream.hpp"
+#include "string.hpp"
 #include "json.hpp"
 
 namespace tuscany {
@@ -35,15 +33,15 @@
 
 bool testJSEval() {
     JSONContext cx;
-    const std::string script("(function testJSON(n){ return JSON.parse(JSON.stringify(n)) })(5)");
+    const string script("(function testJSON(n){ return JSON.parse(JSON.stringify(n)) })(5)");
     jsval rval;
-    assert(JS_EvaluateScript(cx, cx.getGlobal(), script.c_str(), script.length(), "testJSON.js", 1, &rval));
-    const std::string r(JS_GetStringBytes(JS_ValueToString(cx, rval)));
+    assert(JS_EvaluateScript(cx, cx.getGlobal(), c_str(script), length(script), "testJSON.js", 1, &rval));
+    const string r(JS_GetStringBytes(JS_ValueToString(cx, rval)));
     assert(r == "5");
     return true;
 }
 
-std::ostringstream* jsonWriter(const std::string& s, std::ostringstream* os) {
+ostream* jsonWriter(const string& s, ostream* os) {
     (*os) << s;
     return os;
 }
@@ -52,30 +50,30 @@
     const JSONContext cx;
 
     {
-        const list<value> ad = mklist<value>(mklist<value>(attribute, "city", std::string("san francisco")), mklist<value>(attribute, "state", std::string("ca")));
-        const list<value> ac = mklist<value>(mklist<value>(element, "id", std::string("1234")), mklist<value>(attribute, "balance", 1000));
-        const list<value> cr = mklist<value>(mklist<value> (attribute, "name", std::string("jdoe")), cons<value>(element, cons<value>("address", ad)), cons<value>(element, cons<value>("account", ac)));
+        const list<value> ad = mklist<value>(mklist<value>(attribute, "city", string("san francisco")), mklist<value>(attribute, "state", string("ca")));
+        const list<value> ac = mklist<value>(mklist<value>(element, "id", string("1234")), mklist<value>(attribute, "balance", 1000));
+        const list<value> cr = mklist<value>(mklist<value> (attribute, "name", string("jdoe")), cons<value>(element, cons<value>("address", ad)), cons<value>(element, cons<value>("account", ac)));
         const list<value> c = mklist<value>(cons<value>(element, cons<value>("customer", cr)));
-        std::ostringstream os;
-        writeJSON<std::ostringstream*>(jsonWriter, &os, c, cx);
-        assert(os.str() == "{\"customer\":{\"name\":\"jdoe\",\"address\":{\"city\":\"san francisco\",\"state\":\"ca\"},\"account\":{\"id\":\"1234\",\"balance\":1000}}}");
+        ostringstream os;
+        writeJSON<ostream*>(jsonWriter, &os, c, cx);
+        assert(str(os) == "{\"customer\":{\"name\":\"jdoe\",\"address\":{\"city\":\"san francisco\",\"state\":\"ca\"},\"account\":{\"id\":\"1234\",\"balance\":1000}}}");
     }
     {
-        const list<value> phones = mklist<value> (std::string("408-1234"), std::string("650-1234"));
-        const list<value> l = mklist<value> (mklist<value> (element, "phones", phones), mklist<value> (element, "lastName", std::string("test\ttab")), mklist<value> (element, "firstName", std::string("test1")));
+        const list<value> phones = mklist<value> (string("408-1234"), string("650-1234"));
+        const list<value> l = mklist<value> (mklist<value> (element, "phones", phones), mklist<value> (element, "lastName", string("test\ttab")), mklist<value> (element, "firstName", string("test1")));
 
-        std::ostringstream os;
-        writeJSON<std::ostringstream*>(jsonWriter, &os, l, cx);
-        assert(os.str() == "{\"phones\":[\"408-1234\",\"650-1234\"],\"lastName\":\"test\\u0009tab\",\"firstName\":\"test1\"}");
+        ostringstream os;
+        writeJSON<ostream*>(jsonWriter, &os, l, cx);
+        assert(str(os) == "{\"phones\":[\"408-1234\",\"650-1234\"],\"lastName\":\"test\\u0009tab\",\"firstName\":\"test1\"}");
 
-        std::istringstream is(os.str());
-        const list<std::string> il = streamList(is);
+        istringstream is(str(os));
+        const list<string> il = streamList(is);
         const list<value> r = content(readJSON(il, cx));
         assert(r == l);
 
-        std::ostringstream wos;
+        ostringstream wos;
         write(content(writeJSON(r, cx)), wos);
-        assert(wos.str() == os.str());
+        assert(str(wos) == str(os));
     }
     return true;
 }
@@ -83,45 +81,45 @@
 bool testJSONRPC() {
     JSONContext cx;
     {
-        const std::string lm("{\"id\": 1, \"method\": \"system.listMethods\", \"params\": []}");
+        const string lm("{\"id\": 1, \"method\": \"system.listMethods\", \"params\": []}");
         const list<value> e = content(readJSON(mklist(lm), cx));
         const list<value> v = elementsToValues(e);
         assert(assoc<value>("id", v) == mklist<value>("id", 1));
-        assert(assoc<value>("method", v) == mklist<value>("method", std::string("system.listMethods")));
+        assert(assoc<value>("method", v) == mklist<value>("method", string("system.listMethods")));
         assert(assoc<value>("params", v) == mklist<value>("params", list<value>()));
     }
     {
-        const std::string i("{\"id\":3,\"result\":[{\"price\":\"$2.99\",\"name\":\"Apple\"},{\"price\":\"$3.55\",\"name\":\"Orange\"},{\"price\":\"$1.55\",\"name\":\"Pear\"}]}");
+        const string i("{\"id\":3,\"result\":[{\"price\":\"$2.99\",\"name\":\"Apple\"},{\"price\":\"$3.55\",\"name\":\"Orange\"},{\"price\":\"$1.55\",\"name\":\"Pear\"}]}");
         const list<value> e = content(readJSON(mklist(i), cx));
-        const std::string i2("{\"id\":3,\"result\":{\"0\":{\"price\":\"$2.99\",\"name\":\"Apple\"},\"1\":{\"price\":\"$3.55\",\"name\":\"Orange\"},\"2\":{\"price\":\"$1.55\",\"name\":\"Pear\"}}}");
+        const string i2("{\"id\":3,\"result\":{\"0\":{\"price\":\"$2.99\",\"name\":\"Apple\"},\"1\":{\"price\":\"$3.55\",\"name\":\"Orange\"},\"2\":{\"price\":\"$1.55\",\"name\":\"Pear\"}}}");
         const list<value> e2 = content(readJSON(mklist(i), cx));
         assert(e == e2);
     }
     {
-        const std::string i("{\"id\":3,\"result\":[{\"price\":\"$2.99\",\"name\":\"Apple\"},{\"price\":\"$3.55\",\"name\":\"Orange\"},{\"price\":\"$1.55\",\"name\":\"Pear\"}]}");
+        const string i("{\"id\":3,\"result\":[{\"price\":\"$2.99\",\"name\":\"Apple\"},{\"price\":\"$3.55\",\"name\":\"Orange\"},{\"price\":\"$1.55\",\"name\":\"Pear\"}]}");
         const list<value> e = content(readJSON(mklist(i), cx));
-        std::ostringstream os;
+        ostringstream os;
         write(content(writeJSON(e, cx)), os);
-        assert(os.str() == i);
+        assert(str(os) == i);
         const list<value> v = elementsToValues(e);
         const list<value> r = valuesToElements(v);
         assert(r == e);
     }
     {
-        const list<value> r = mklist<value>(mklist<value>("id", 1), mklist<value>("result", mklist<value>(std::string("Service.get"), std::string("Service.getTotal"))));
+        const list<value> r = mklist<value>(mklist<value>("id", 1), mklist<value>("result", mklist<value>(string("Service.get"), string("Service.getTotal"))));
         const list<value> e = valuesToElements(r);
-        std::ostringstream os;
+        ostringstream os;
         write(content(writeJSON(e, cx)), os);
-        assert(os.str() == "{\"id\":1,\"result\":[\"Service.get\",\"Service.getTotal\"]}");
+        assert(str(os) == "{\"id\":1,\"result\":[\"Service.get\",\"Service.getTotal\"]}");
     }
     {
-        const std::string f("{\"id\":1,\"result\":[\"Sample Feed\",\"123456789\",[\"Item\",\"111\",{\"javaClass\":\"services.Item\",\"name\":\"Apple\",\"currencyCode\":\"USD\",\"currencySymbol\":\"$\",\"price\":2.99}],[\"Item\",\"222\",{\"javaClass\":\"services.Item\",\"name\":\"Orange\",\"currencyCode\":\"USD\",\"currencySymbol\":\"$\",\"price\":3.55}],[\"Item\",\"333\",{\"javaClass\":\"services.Item\",\"name\":\"Pear\",\"currencyCode\":\"USD\",\"currencySymbol\":\"$\",\"price\":1.55}]]}");
+        const string f("{\"id\":1,\"result\":[\"Sample Feed\",\"123456789\",[\"Item\",\"111\",{\"javaClass\":\"services.Item\",\"name\":\"Apple\",\"currencyCode\":\"USD\",\"currencySymbol\":\"$\",\"price\":2.99}],[\"Item\",\"222\",{\"javaClass\":\"services.Item\",\"name\":\"Orange\",\"currencyCode\":\"USD\",\"currencySymbol\":\"$\",\"price\":3.55}],[\"Item\",\"333\",{\"javaClass\":\"services.Item\",\"name\":\"Pear\",\"currencyCode\":\"USD\",\"currencySymbol\":\"$\",\"price\":1.55}]]}");
         const list<value> r = content(readJSON(mklist(f), cx));
         const list<value> v = elementsToValues(r);
         const list<value> e = valuesToElements(v);
-        std::ostringstream os;
+        ostringstream os;
         write(content(writeJSON(e, cx)), os);
-        assert(os.str() == f);
+        assert(str(os) == f);
     }
     return true;
 }
@@ -130,13 +128,13 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::json::testJSEval();
     tuscany::json::testJSON();
     tuscany::json::testJSONRPC();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/modules/json/json.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/json/json.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/json/json.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/json/json.hpp Sat Jan  2 10:27:26 2010
@@ -28,7 +28,7 @@
 
 #define XP_UNIX
 #include <jsapi.h>
-#include <string>
+#include "string.hpp"
 #include "list.hpp"
 #include "value.hpp"
 #include "element.hpp"
@@ -41,8 +41,8 @@
  * Report JSON errors.
  */
 void reportError(unused JSContext *cx, const char *message, JSErrorReport *report) {
-    std::cerr << (const char*)(report->filename? report->filename : "<no filename>") << ":"
-            << (unsigned int)report->lineno << ":" << message << std::endl;
+    cerr << (const char*)(report->filename? report->filename : "<no filename>") << ":"
+            << (int)report->lineno << ":" << message << endl;
 }
 
 /**
@@ -168,7 +168,7 @@
 const value jsValToValue(const jsval& jsv, const JSONContext& cx) {
     switch(JS_TypeOfValue(cx, jsv)) {
     case JSTYPE_STRING: {
-        return value(std::string(JS_GetStringBytes(JSVAL_TO_STRING(jsv))));
+        return value(string(JS_GetStringBytes(JSVAL_TO_STRING(jsv))));
     }
     case JSTYPE_BOOLEAN: {
         return value((bool)JSVAL_TO_BOOLEAN(jsv));
@@ -195,30 +195,30 @@
 /**
  * Consumes JSON strings and populates a JS object.
  */
-failable<bool, std::string> consume(JSONParser* parser, const list<std::string>& ilist, const JSONContext& cx) {
+failable<bool> consume(JSONParser* parser, const list<string>& ilist, const JSONContext& cx) {
     if (isNil(ilist))
         return true;
-    JSString* jstr = JS_NewStringCopyZ(cx, car(ilist).c_str());
+    JSString* jstr = JS_NewStringCopyZ(cx, c_str(car(ilist)));
     if(!JS_ConsumeJSONText(cx, parser, JS_GetStringChars(jstr), JS_GetStringLength(jstr)))
-        return mkfailure<bool, std::string>("JS_ConsumeJSONText failed");
+        return mkfailure<bool>("JS_ConsumeJSONText failed");
     return consume(parser, cdr(ilist), cx);
 }
 
 /**
  * Convert a list of strings representing a JSON document to a list of values.
  */
-const failable<list<value>, std::string> readJSON(const list<std::string>& ilist, const JSONContext& cx) {
+const failable<list<value> > readJSON(const list<string>& ilist, const JSONContext& cx) {
     jsval val;
     JSONParser* parser = JS_BeginJSONParse(cx, &val);
     if(parser == NULL)
-        return mkfailure<list<value>, std::string>("JS_BeginJSONParse failed");
+        return mkfailure<list<value> >("JS_BeginJSONParse failed");
 
-    const failable<bool, std::string> consumed = consume(parser, ilist, cx);
+    const failable<bool> consumed = consume(parser, ilist, cx);
 
     if(!JS_FinishJSONParse(cx, parser, JSVAL_NULL))
-        return mkfailure<list<value>, std::string>("JS_FinishJSONParse failed");
+        return mkfailure<list<value> >("JS_FinishJSONParse failed");
     if(!hasContent(consumed))
-        return mkfailure<list<value>, std::string>(reason(consumed));
+        return mkfailure<list<value> >(reason(consumed));
 
     return list<value>(jsValToValue(val, cx));
 }
@@ -261,7 +261,7 @@
         return o;
     const list<value> p = car(l);
     jsval pv = valueToJSVal(caddr(p), cx);
-    JS_SetProperty(cx, o, ((std::string)cadr(p)).c_str(), &pv);
+    JS_SetProperty(cx, o, c_str((string)cadr(p)), &pv);
     return valuesToJSProperties(o, cdr(l), cx);
 }
 
@@ -272,7 +272,7 @@
     switch(type(val)) {
     case value::String:
     case value::Symbol: {
-        return STRING_TO_JSVAL(JS_NewStringCopyZ(cx, ((std::string)val).c_str()));
+        return STRING_TO_JSVAL(JS_NewStringCopyZ(cx, c_str((string)val)));
     }
     case value::Bool: {
         return BOOLEAN_TO_JSVAL((bool)val);
@@ -291,7 +291,7 @@
     }
 }
 
-const failable<bool, std::string> writeList(const list<value>& l, JSObject* o, const JSONContext& cx) {
+const failable<bool> writeList(const list<value>& l, JSObject* o, const JSONContext& cx) {
     if (isNil(l))
         return true;
 
@@ -300,24 +300,24 @@
 
     if (isTaggedList(token, attribute)) {
         jsval pv = valueToJSVal(attributeValue(token), cx);
-        JS_SetProperty(cx, o, std::string(attributeName(token)).c_str(), &pv);
+        JS_SetProperty(cx, o, c_str(string(attributeName(token))), &pv);
 
     } else if (isTaggedList(token, element)) {
 
         // Write the value of an element
         if (elementHasValue(token)) {
             jsval pv = valueToJSVal(elementValue(token), cx);
-            JS_SetProperty(cx, o, std::string(elementName(token)).c_str(), &pv);
+            JS_SetProperty(cx, o, c_str(string(elementName(token))), &pv);
 
         } else {
 
             // Write a parent element
             JSObject* child = JS_NewObject(cx, NULL, NULL, NULL);
             jsval pv = OBJECT_TO_JSVAL(child);
-            JS_SetProperty(cx, o, std::string(elementName(token)).c_str(), &pv);
+            JS_SetProperty(cx, o, c_str(string(elementName(token))), &pv);
 
             // Write its children
-            const failable<bool, std::string> w = writeList(elementChildren(token), child, cx);
+            const failable<bool> w = writeList(elementChildren(token), child, cx);
             if (!hasContent(w))
                 return w;
         }
@@ -332,10 +332,10 @@
  */
 template<typename R> class WriteContext {
 public:
-    WriteContext(const lambda<R(const std::string&, const R)>& reduce, const R& accum, const JSONContext& cx) : cx(cx), reduce(reduce), accum(accum) {
+    WriteContext(const lambda<R(const string&, const R)>& reduce, const R& accum, const JSONContext& cx) : cx(cx), reduce(reduce), accum(accum) {
     }
     const JSONContext& cx;
-    const lambda<R(const std::string&, const R)> reduce;
+    const lambda<R(const string&, const R)> reduce;
     R accum;
 };
 
@@ -345,40 +345,40 @@
 template<typename R> JSBool writeCallback(const jschar *buf, uint32 len, void *data) {
     WriteContext<R>& wcx = *(static_cast<WriteContext<R>*> (data));
     JSString* jstr = JS_NewUCStringCopyN(wcx.cx, buf, len);
-    wcx.accum = wcx.reduce(std::string(JS_GetStringBytes(jstr), JS_GetStringLength(jstr)), wcx.accum);
+    wcx.accum = wcx.reduce(string(JS_GetStringBytes(jstr), JS_GetStringLength(jstr)), wcx.accum);
     return JS_TRUE;
 }
 
 /**
  * Convert a list of values to a JSON document.
  */
-template<typename R> const failable<R, std::string> writeJSON(const lambda<R(const std::string&, const R)>& reduce, const R& initial, const list<value>& l, const JSONContext& cx) {
+template<typename R> const failable<R> writeJSON(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l, const JSONContext& cx) {
     JSObject* o = JS_NewObject(cx, NULL, NULL, NULL);
     jsval val = OBJECT_TO_JSVAL(o);
-    const failable<bool, std::string> w = writeList(l, o, cx);
+    const failable<bool> w = writeList(l, o, cx);
     if (!hasContent(w))
-        return mkfailure<R, std::string>(reason(w));
+        return mkfailure<R>(reason(w));
 
     WriteContext<R> wcx(reduce, initial, cx);
     if (!JS_Stringify(cx, &val, NULL, JSVAL_NULL, writeCallback<R>, &wcx))
-        return mkfailure<R, std::string>("JS_Stringify failed");
+        return mkfailure<R>("JS_Stringify failed");
     return wcx.accum;
 }
 
 /**
  * Convert a list of values to a list of strings representing a JSON document.
  */
-const failable<list<std::string>, std::string> writeJSON(const list<value>& l, const JSONContext& cx) {
-    const failable<list<std::string>, std::string> ls = writeJSON<list<std::string> >(rcons<std::string>, list<std::string>(), l, cx);
+const failable<list<string> > writeJSON(const list<value>& l, const JSONContext& cx) {
+    const failable<list<string> > ls = writeJSON<list<string>>(rcons<string>, list<string>(), l, cx);
     if (!hasContent(ls))
         return ls;
-    return reverse(list<std::string>(content(ls)));
+    return reverse(list<string>(content(ls)));
 }
 
 /**
  * Convert a function + params to a JSON request.
  */
-const failable<list<std::string>, std::string> jsonRequest(const value& id, const value& func, const value& params, json::JSONContext& cx) {
+const failable<list<string> > jsonRequest(const value& id, const value& func, const value& params, json::JSONContext& cx) {
     const list<value> r = mklist<value>(mklist<value>("id", id), mklist<value>("method", func), mklist<value>("params", params));
     return writeJSON(valuesToElements(r), cx);
 }
@@ -386,7 +386,7 @@
 /**
  * Convert a value to a JSON result.
  */
-const failable<list<std::string>, std::string> jsonResult(const value& id, const value& val, JSONContext& cx) {
+const failable<list<string> > jsonResult(const value& id, const value& val, JSONContext& cx) {
     return writeJSON(valuesToElements(mklist<value>(mklist<value>("id", id), mklist<value>("result", val))), cx);
 }
 

Modified: tuscany/sca-cpp/trunk/modules/scdl/scdl-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/scdl/scdl-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/scdl/scdl-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/scdl/scdl-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,12 +24,9 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <sstream>
-#include <fstream>
-#include <string>
+#include "stream.hpp"
+#include "string.hpp"
 #include "list.hpp"
-#include "slist.hpp"
 #include "tree.hpp"
 #include "scdl.hpp"
 
@@ -37,24 +34,24 @@
 namespace scdl {
 
 bool testComposite() {
-    std::ifstream is("test.composite");
+    ifstream is("test.composite");
     const list<value> c = readXML(streamList(is));
     return true;
 }
 
 bool testComponents() {
-    std::ifstream is("test.composite");
+    ifstream is("test.composite");
     const list<value> c = components(readXML(streamList(is)));
     assert(length(c) == 4);
 
     const value store = car(c);
-    assert(name(store) == std::string("Store"));
+    assert(name(store) == string("Store"));
     const value impl = implementation(store);
-    assert(uri(impl) == std::string("store.html"));
+    assert(uri(impl) == string("store.html"));
     assert(implementationType(impl) == "t:implementation.widget");
 
-    const value catalog = named(std::string("Catalog"), c);
-    assert(name(catalog) == std::string("Catalog"));
+    const value catalog = named(string("Catalog"), c);
+    assert(name(catalog) == string("Catalog"));
 
     const list<value> t = mkbtree(sort(nameToElementAssoc(c)));
     assert(assoctree<value>("Catalog", t) == mklist<value>("Catalog" , cadr(c)));
@@ -62,30 +59,30 @@
 }
 
 bool testServices() {
-    std::ifstream is("test.composite");
+    ifstream is("test.composite");
     const list<value> c = components(readXML(streamList(is)));
     const value store = car(c);
 
     assert(length(services(store)) == 1);
     const value widget = car(services(store));
-    assert(name(widget) == std::string("Widget"));
+    assert(name(widget) == string("Widget"));
 
     assert(length(bindings(widget)) == 1);
     const value binding = car(bindings(widget));
-    assert(uri(binding) == std::string("/store"));
+    assert(uri(binding) == string("/store"));
     assert(bindingType(binding) == "t:binding.http");
     return true;
 }
 
 bool testReferences() {
-    std::ifstream is("test.composite");
+    ifstream is("test.composite");
     const list<value> c = components(readXML(streamList(is)));
     const value store = car(c);
 
     assert(length(references(store)) == 3);
     const value catalog = car(references(store));
-    assert(name(catalog) == std::string("catalog"));
-    assert(target(catalog) == std::string("Catalog"));
+    assert(name(catalog) == string("catalog"));
+    assert(target(catalog) == string("Catalog"));
 
     assert(length(bindings(catalog)) == 1);
     const value binding = car(bindings(catalog));
@@ -93,19 +90,19 @@
     assert(bindingType(binding) == "t:binding.jsonrpc");
 
     const list<value> t = mkbtree(sort(referenceToTargetAssoc(references(store))));
-    assert(assoctree<value>("shoppingCart", t) == mklist<value>(std::string("shoppingCart"), std::string("ShoppingCart/Cart")));
+    assert(assoctree<value>("shoppingCart", t) == mklist<value>(string("shoppingCart"), string("ShoppingCart/Cart")));
     return true;
 }
 
 bool testProperties() {
-    std::ifstream is("test.composite");
+    ifstream is("test.composite");
     const list<value> c = components(readXML(streamList(is)));
-    const value catalog = named(std::string("Catalog"), c);
+    const value catalog = named(string("Catalog"), c);
 
     assert(length(properties(catalog)) == 1);
     const value currencyCode = car(properties(catalog));
-    assert(name(currencyCode) == std::string("currencyCode"));
-    assert(propertyValue(currencyCode) == std::string("USD"));
+    assert(name(currencyCode) == string("currencyCode"));
+    assert(propertyValue(currencyCode) == string("USD"));
     return true;
 }
 
@@ -113,7 +110,7 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::scdl::testComposite();
     tuscany::scdl::testComponents();
@@ -121,7 +118,7 @@
     tuscany::scdl::testReferences();
     tuscany::scdl::testProperties();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/modules/scdl/scdl.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/scdl/scdl.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/scdl/scdl.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/scdl/scdl.hpp Sat Jan  2 10:27:26 2010
@@ -26,7 +26,7 @@
  * SCDL read functions.
  */
 
-#include <string>
+#include "string.hpp"
 #include "list.hpp"
 #include "value.hpp"
 #include "monad.hpp"
@@ -85,7 +85,7 @@
  * Returns the implementation of a component.
  */
 const bool filterImplementation(const value& v) {
-    return isElement(v) && std::string(cadr<value>(v)).find("implementation.") != std::string::npos;
+    return isElement(v) && contains(string(cadr<value>(v)), "implementation.");
 }
 
 const value implementation(const value& l) {
@@ -137,7 +137,7 @@
  * Returns a list of bindings in a service or reference.
  */
 const bool filterBinding(const value& v) {
-    return isElement(v) && std::string(cadr<value>(v)).find("binding.") != std::string::npos;
+    return isElement(v) && contains(string(cadr<value>(v)), "binding.");
 }
 
 const list<value> bindings(const value& l) {

Modified: tuscany/sca-cpp/trunk/modules/server/client-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/client-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/client-test.cpp Sat Jan  2 10:27:26 2010
@@ -23,11 +23,12 @@
  * Test HTTP client functions.
  */
 
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
 #include <assert.h>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include "slist.hpp"
+#include "stream.hpp"
+#include "string.hpp"
 #include "parallel.hpp"
 #include "perf.hpp"
 #include "../http/curl.hpp"
@@ -35,11 +36,7 @@
 namespace tuscany {
 namespace server {
 
-const bool contains(const std::string& str, const std::string& pattern) {
-    return str.find(pattern) != str.npos;
-}
-
-std::ostringstream* curlWriter(const std::string& s, std::ostringstream* os) {
+ostream* curlWriter(const string& s, ostream* os) {
     (*os) << s;
     return os;
 }
@@ -47,16 +44,16 @@
 const bool testGet() {
     http::CURLSession ch;
     {
-        std::ostringstream os;
-        const failable<list<std::ostringstream*>, std::string> r = http::get<std::ostringstream*>(curlWriter, &os, "http://localhost:8090", ch);
+        ostringstream os;
+        const failable<list<ostream*> > r = http::get<ostream*>(curlWriter, &os, "http://localhost:8090", ch);
         assert(hasContent(r));
-        assert(contains(os.str(), "HTTP/1.1 200 OK"));
-        assert(contains(os.str(), "It works"));
+        assert(contains(str(os), "HTTP/1.1 200 OK"));
+        assert(contains(str(os), "It works"));
     }
     {
-        const failable<value, std::string> r = http::get("http://localhost:8090", ch);
+        const failable<value> r = http::getcontent("http://localhost:8090", ch);
         assert(hasContent(r));
-        assert(contains(content(r), "It works"));
+        assert(contains(car(reverse(list<value>(content(r)))), "It works"));
     }
     return true;
 }
@@ -66,9 +63,9 @@
     getLoop(http::CURLSession& ch) : ch(ch) {
     }
     const bool operator()() const {
-        const failable<value, std::string> r = get("http://localhost:8090", ch);
+        const failable<value> r = http::getcontent("http://localhost:8090", ch);
         assert(hasContent(r));
-        assert(contains(content(r), "It works"));
+        assert(contains(car(reverse(list<value>(content(r)))), "It works"));
         return true;
     }
 };
@@ -76,14 +73,14 @@
 const bool testGetPerf() {
     http::CURLSession ch;
     const lambda<bool()> gl = getLoop(ch);
-    std::cout << "Static GET test " << time(gl, 5, 200) << " ms" << std::endl;
+    cout << "Static GET test " << time(gl, 5, 200) << " ms" << endl;
     return true;
 }
 
 const bool testEval() {
     http::CURLSession ch;
-    const value val = content(http::evalExpr(mklist<value>(std::string("echo"), std::string("Hello")), "http://localhost:8090/test", ch));
-    assert(val == std::string("Hello"));
+    const value val = content(http::evalExpr(mklist<value>(string("echo"), string("Hello")), "http://localhost:8090/test", ch));
+    assert(val == string("Hello"));
     return true;
 }
 
@@ -92,13 +89,13 @@
     evalLoop(http::CURLSession& ch) : ch(ch) {
     }
     const bool operator()() const {
-        const value val = content(http::evalExpr(mklist<value>(std::string("echo"), std::string("Hello")), "http://localhost:8090/test", ch));
-        assert(val == std::string("Hello"));
+        const value val = content(http::evalExpr(mklist<value>(string("echo"), string("Hello")), "http://localhost:8090/test", ch));
+        assert(val == string("Hello"));
         return true;
     }
 };
 
-const value blob(std::string(3000, 'A'));
+const value blob(string(3000, 'A'));
 const list<value> blobs = mklist(blob, blob, blob, blob, blob);
 
 struct blobEvalLoop {
@@ -106,7 +103,7 @@
     blobEvalLoop(http::CURLSession& ch) : ch(ch) {
     }
     const bool operator()() const {
-        const value val = content(http::evalExpr(mklist<value>(std::string("echo"), blobs), "http://localhost:8090/test", ch));
+        const value val = content(http::evalExpr(mklist<value>(string("echo"), blobs), "http://localhost:8090/test", ch));
         assert(val == blobs);
         return true;
     }
@@ -115,19 +112,19 @@
 const bool testEvalPerf() {
     http::CURLSession ch;
     const lambda<bool()> el = evalLoop(ch);
-    std::cout << "JSON-RPC eval echo test " << time(el, 5, 200) << " ms" << std::endl;
+    cout << "JSON-RPC eval echo test " << time(el, 5, 200) << " ms" << endl;
     const lambda<bool()> bel = blobEvalLoop(ch);
-    std::cout << "JSON-RPC eval blob test " << time(bel, 5, 200) << " ms" << std::endl;
+    cout << "JSON-RPC eval blob test " << time(bel, 5, 200) << " ms" << endl;
     return true;
 }
 
 bool testPost() {
     const list<value> i = list<value>()
-            << (list<value>() << "name" << std::string("Apple"))
-            << (list<value>() << "price" << std::string("$2.99"));
-    const list<value> a = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+            + (list<value>() + "name" + string("Apple"))
+            + (list<value>() + "price" + string("$2.99"));
+    const list<value> a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
     http::CURLSession ch;
-    const failable<value, std::string> id = http::post(a, "http://localhost:8090/test", ch);
+    const failable<value> id = http::post(a, "http://localhost:8090/test", ch);
     assert(hasContent(id));
     return true;
 }
@@ -138,7 +135,7 @@
     postLoop(const value& val, http::CURLSession& ch) : val(val), ch(ch) {
     }
     const bool operator()() const {
-        const failable<value, std::string> id = http::post(val, "http://localhost:8090/test", ch);
+        const failable<value> id = http::post(val, "http://localhost:8090/test", ch);
         assert(hasContent(id));
         return true;
     }
@@ -148,28 +145,30 @@
     http::CURLSession ch;
     {
         const list<value> i = list<value>()
-            << (list<value>() << "name" << std::string("Apple"))
-            << (list<value>() << "price" << std::string("$2.99"));
-        const list<value> val = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+            + (list<value>() + "name" + string("Apple"))
+            + (list<value>() + "price" + string("$2.99"));
+        const list<value> val = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
         const lambda<bool()> pl = postLoop(val, ch);
-        std::cout << "ATOMPub POST small test " << time(pl, 5, 200) << " ms" << std::endl;
+        cout << "ATOMPub POST small test " << time(pl, 5, 200) << " ms" << endl;
     }
     {
         const list<value> i = list<value>()
-            << (list<value>() << "name" << std::string("Apple"))
-            << (list<value>() << "blob1" << blob)
-            << (list<value>() << "blob2" << blob)
-            << (list<value>() << "blob3" << blob)
-            << (list<value>() << "blob4" << blob)
-            << (list<value>() << "blob5" << blob)
-            << (list<value>() << "price" << std::string("$2.99"));
-        const list<value> val = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+            + (list<value>() + "name" + string("Apple"))
+            + (list<value>() + "blob1" + blob)
+            + (list<value>() + "blob2" + blob)
+            + (list<value>() + "blob3" + blob)
+            + (list<value>() + "blob4" + blob)
+            + (list<value>() + "blob5" + blob)
+            + (list<value>() + "price" + string("$2.99"));
+        const list<value> val = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
         const lambda<bool()> pl = postLoop(val, ch);
-        std::cout << "ATOMPub POST blob test  " << time(pl, 5, 200) << " ms" << std::endl;
+        cout << "ATOMPub POST blob test  " << time(pl, 5, 200) << " ms" << endl;
     }
     return true;
 }
 
+#ifdef _REENTRANT
+
 const bool postThread(const int count, const value& val) {
     http::CURLSession ch;
     const lambda<bool()> pl = postLoop(val, ch);
@@ -194,7 +193,7 @@
     const lambda<bool()> l;
     const int threads;
     const gc_ptr<worker> w;
-    postThreadLoop(const lambda<bool()>& l, const int threads) : l(l), threads(threads), w(new worker(threads)) {
+    postThreadLoop(const lambda<bool()>& l, const int threads) : l(l), threads(threads), w(new (gc_new<worker>()) worker(threads)) {
     }
     const bool operator()() const {
         list<future<bool> > r = startPost(*w, threads, l);
@@ -208,23 +207,83 @@
     const int threads = 10;
 
     const list<value> i = list<value>()
-        << (list<value>() << "name" << std::string("Apple"))
-        << (list<value>() << "price" << std::string("$2.99"));
-    const value val = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+        + (list<value>() + "name" + string("Apple"))
+        + (list<value>() + "price" + string("$2.99"));
+    const value val = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
 
     const lambda<bool()> pl= curry(lambda<bool(const int, const value)>(postThread), count, val);
     const lambda<bool()> ptl = postThreadLoop(pl, threads);
     double t = time(ptl, 0, 1) / (threads * count);
-    std::cout << "ATOMPub POST thread test " << t << " ms" << std::endl;
+    cout << "ATOMPub POST thread test " << t << " ms" << endl;
 
     return true;
 }
 
+#else
+
+const bool postProc(const int count, const value& val) {
+    http::CURLSession ch;
+    const lambda<bool()> pl = postLoop(val, ch);
+    time(pl, 0, count);
+    return true;
+}
+
+const list<pid_t> startPost(const int procs, const lambda<bool()>& l) {
+    if (procs == 0)
+        return list<pid_t>();
+    pid_t pid = fork();
+    if (pid == 0) {
+        assert(l() == true);
+        exit(0);
+    }
+    return cons(pid, startPost(procs - 1, l));
+}
+
+const bool checkPost(const list<pid_t>& r) {
+    if (isNil(r))
+        return true;
+    int status;
+    waitpid(car(r), &status, 0);
+    assert(status == 0);
+    return checkPost(cdr(r));
+}
+
+struct postForkLoop {
+    const lambda<bool()> l;
+    const int procs;
+    postForkLoop(const lambda<bool()>& l, const int procs) : l(l), procs(procs) {
+    }
+    const bool operator()() const {
+        list<pid_t> r = startPost(procs, l);
+        checkPost(r);
+        return true;
+    }
+};
+
+const bool testPostForkPerf() {
+    const int count = 50;
+    const int procs = 10;
+
+    const list<value> i = list<value>()
+        + (list<value>() + "name" + string("Apple"))
+        + (list<value>() + "price" + string("$2.99"));
+    const value val = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+
+    const lambda<bool()> pl= curry(lambda<bool(const int, const value)>(postProc), count, val);
+    const lambda<bool()> ptl = postForkLoop(pl, procs);
+    double t = time(ptl, 0, 1) / (procs * count);
+    cout << "ATOMPub POST fork test " << t << " ms" << endl;
+
+    return true;
+}
+
+#endif
+
 const bool testPut() {
     const list<value> i = list<value>()
-            << (list<value>() << "name" << std::string("Apple"))
-            << (list<value>() << "price" << std::string("$2.99"));
-    const list<value> a = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+            + (list<value>() + "name" + string("Apple"))
+            + (list<value>() + "price" + string("$2.99"));
+    const list<value> a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
     http::CURLSession ch;
     value rc = content(http::put(a, "http://localhost:8090/test/111", ch));
     assert(rc == value(true));
@@ -240,8 +299,8 @@
 
 const bool testEvalCpp() {
     http::CURLSession ch;
-    const value val = content(http::evalExpr(mklist<value>(std::string("hello"), std::string("world")), "http://localhost:8090/cpp", ch));
-    assert(val == std::string("hello world"));
+    const value val = content(http::evalExpr(mklist<value>(string("hello"), string("world")), "http://localhost:8090/cpp", ch));
+    assert(val == string("hello world"));
     return true;
 }
 
@@ -250,8 +309,8 @@
     evalCppLoop(http::CURLSession& ch) : ch(ch) {
     }
     const bool operator()() const {
-        const value val = content(http::evalExpr(mklist<value>(std::string("hello"), std::string("world")), "http://localhost:8090/cpp", ch));
-        assert(val == std::string("hello world"));
+        const value val = content(http::evalExpr(mklist<value>(string("hello"), string("world")), "http://localhost:8090/cpp", ch));
+        assert(val == string("hello world"));
         return true;
     }
 };
@@ -259,7 +318,7 @@
 const bool testEvalCppPerf() {
     http::CURLSession ch;
     const lambda<bool()> el = evalCppLoop(ch);
-    std::cout << "JSON-RPC C++ eval test " << time(el, 5, 200) << " ms" << std::endl;
+    cout << "JSON-RPC C++ eval test " << time(el, 5, 200) << " ms" << endl;
     return true;
 }
 
@@ -267,13 +326,17 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::server::testGet();
     tuscany::server::testGetPerf();
     tuscany::server::testPost();
     tuscany::server::testPostPerf();
+#ifdef _REENTRANT
     tuscany::server::testPostThreadPerf();
+#else
+    tuscany::server::testPostForkPerf();
+#endif
     tuscany::server::testEval();
     tuscany::server::testEvalPerf();
     tuscany::server::testPut();
@@ -281,7 +344,7 @@
     tuscany::server::testEvalCpp();
     tuscany::server::testEvalCppPerf();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/modules/server/impl-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/impl-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/impl-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/impl-test.cpp Sat Jan  2 10:27:26 2010
@@ -23,7 +23,7 @@
  * Test component implementation.
  */
 
-#include <string>
+#include "string.hpp"
 
 #include "function.hpp"
 #include "list.hpp"
@@ -34,24 +34,24 @@
 namespace tuscany {
 namespace server {
 
-const failable<value, std::string> get(unused const list<value>& params) {
-    return value(std::string("Hey"));
+const failable<value> get(unused const list<value>& params) {
+    return value(string("Hey"));
 }
 
-const failable<value, std::string> post(unused const list<value>& params) {
-    return value(std::string("1234"));
+const failable<value> post(unused const list<value>& params) {
+    return value(string("1234"));
 }
 
-const failable<value, std::string> put(unused const list<value>& params) {
+const failable<value> put(unused const list<value>& params) {
     return value(true);
 }
 
-const failable<value, std::string> del(unused const list<value>& params) {
+const failable<value> del(unused const list<value>& params) {
     return value(true);
 }
 
-const failable<value, std::string> hello(const list<value>& params) {
-    return value(std::string("hello ") + std::string(car(params)));
+const failable<value> hello(const list<value>& params) {
+    return value(string("hello ") + string(car(params)));
 }
 
 }
@@ -71,7 +71,7 @@
         return tuscany::server::del(cdr(params));
     if (func == "hello")
         return tuscany::server::hello(cdr(params));
-    return tuscany::mkfailure<tuscany::value, std::string>(std::string("Function not supported: ") + std::string(func));
+    return tuscany::mkfailure<tuscany::value>(tuscany::string("Function not supported: ") + func);
 }
 
 }

Modified: tuscany/sca-cpp/trunk/modules/server/mod-cpp.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-cpp.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-cpp.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-cpp.hpp Sat Jan  2 10:27:26 2010
@@ -27,9 +27,8 @@
  * component implementations.
  */
 
-#include <string>
-#include <iostream>
-#include <fstream>
+#include "string.hpp"
+#include "stream.hpp"
 
 #include "function.hpp"
 #include "list.hpp"
@@ -65,12 +64,12 @@
 /**
  * Read a C++ component implementation.
  */
-const failable<lambda<value(const list<value>&)>, std::string> readImplementation(const std::string path, const list<value>& px) {
-    const failable<lib, std::string> ilib(dynlib(path + dynlibExt));
+const failable<lambda<value(const list<value>&)> > readImplementation(const string& path, const list<value>& px) {
+    const failable<lib> ilib(dynlib(path + dynlibExt));
     if (!hasContent(ilib))
-        return mkfailure<lambda<value(const list<value>&)>, std::string>(reason(ilib));
+        return mkfailure<lambda<value(const list<value>&)> >(reason(ilib));
 
-    const failable<lambda<value(const list<value>&)>, std::string> impl(dynlambda<value(const list<value>&)>("eval", content(ilib)));
+    const failable<lambda<value(const list<value>&)> > impl(dynlambda<value(const list<value>&)>("eval", content(ilib)));
     if (!hasContent(impl))
         return impl;
     return lambda<value(const list<value>&)>(evalImplementation(content(ilib), content(impl), px));



Mime
View raw message