tuscany-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Sebastien Delfino <jsdelf...@apache.org>
Subject Re: Porting Tuscany C++ to C++11 and some code cleanup
Date Thu, 06 Dec 2012 09:04:09 GMT
On Fri, Nov 30, 2012 at 9:43 AM, Thomas Gentsch <tg@e-tge.de> wrote:

>
> OK, many thx for this info!
>
> Regarding SDO - yes, I noticed that there was not a lot of activity
> during the last years.
> Hello out there: Is there anybody else still using this?
>
> Rgd SDO as SCA-internal data-flow mechanism - what is being used now?
> I know about libxml2 (actually its being used in SCA/SDO :-), nothing
> yet about JSON, will read.
>

Hi Thomas,

Here's a short overview of what's used now.

Data read/write functions are provided for XML (using Libxml2 [1]), JSON
(using Mozilla SpiderMonkey but I've started to migrate to Jansson [2]),
and Lisp/Scheme S-expressions [3].

Here's how to read XML in a C++ component:
<customer
age="21"><name>johndoe</name><phone>(650)123-4567</phone><phone>(415)765-4321</phone></customer>

// A list of strings containing the above XML doc, obtained from an input
stream for example
const list<string> ls = ...;

// Read the XML doc (the failable<...> result type helps encapsulate error
handling)
// See below for a description of the 'value' data type
const failable<value> fe = xml::readElements(ls);

// Assuming no failure, get and print the result
const value e = content(fe);
cout << e << endl;

The result is a list like follows (using the S-expression syntax here for
conciseness: element, customer, attribute, age are symbols, 21 is a number,
"johndoe" is a string, (x y) is a list of x, y):
((element customer (attribute age "21") (element name "johndoe") (element
phone "(650)123-4567") (element phone "(415)765-4321")))

The runtime is schema-less. You do not need an XML schema to read/write any
XML.

If you don't care about the XML element vs attribute representation you can
strip it like this:
const value v = elementsToValues(e);
to get this:
((customer (@age "21") (name "johndoe") (phone ("(650)123-4567"
"(415)765-4321"))))

Note the @age attribute name, which follows the Badgerfish [4] convention
often used to name XML attributes in JSON documents for example.

The same data can be constructed and represented in the various programming
languages supported by the runtime, as follows:

C++:
list<value>(list<value>("customer", list<value>("@age", 21),
list<value>("name", string("johndoe")), list<value>("phone",
list<value>("(650)123-4567", "(415)765-4321"))));
using the following C++ types:
- string, similar to std::string but lighter and faster for small strings,
with builtin conversions from/to native char*;
- list<T>, a lightweight list/lazy-list type with useful Lisp/Scheme-like
[5] functions incl. cons, car, cdr, map, filter, reduce, assoc, etc;
- lambda<R(P...)>, a function type similar to std::function but lighter and
faster;
- value, a dynamic value type (type can be number, boolean, symbol, string,
list<value>, lambda<value(list<value>)>, value*) with builtin conversions
from/to native double, bool, char*, C++ lambdas and pointers.

Python:
((customer, ("'@age" 21), ("'name", "johndoe") (phone, ("(650)123-4567"
"(415)765-4321"))),)
using Python tuples [6] and native Python data types for strings, numbers
and booleans.

JavaScript / JSON:
{"customer":{"@age":"21","name":"johndoe","phone":["(650)123-4567","(415)765-4321"]}}
using JSON arrays and native Javascript types.

Scheme:
((customer (@age "21") (name "johndoe") (phone ("(650)123-4567"
"(415)765-4321"))))
just an S-expression.

Java (there's experimental support for running Java components on the C++
runtime):
list(list("'customer", list("'@age", 21), list("'name", "johndoe"),
list("'phone", list("(650)123-4567", "(415)765-4321"))));
using java.lang.Iterable [7] for lists and native Java data types for
strings, numbers and booleans (the list(...) function is a static 'builder'
function returning a java.lang.Iterable<?>.)

To summarize: fast and schemaless support for XML, JSON and S-expressions,
with lightweight representation using lists and simple types in the
supported programming languages.

Hope that helps.

[1] http://www.xmlsoft.org
[2] http://www.digip.org/jansson/
[3] http://en.wikipedia.org/wiki/S-expression
[4] http://badgerfish.ning.com
[5]
http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-ref/Lists.html#Lists
[6]
http://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences
[7] http://docs.oracle.com/javase/6/docs/api/java/lang/Iterable.html

- Jean-Sebastien

Mime
View raw message