Boost logo

Boost :

From: Hartmut Kaiser (hartmutkaiser_at_[hidden])
Date: 2004-09-23 01:01:30

Jonathan Turkanis wrote:

> > I see the library as the inverse of Spirit. Spirit takes
> a linear
> > text and builds complex objects, while the output
> formatting library
> > takes complex objects and renders them as linear text. Just as an
> > abstract syntax tree does not preserve all the information in the
> > input text, in many cases it will be desirable to loose information
> > when an object is formatted using the present library. For example,
> > sometime you might want a dog to be formatted as follows

I 100% agree with that. Moreover I have a first experimental implementation
of such a library here, which is able to do formatted output controlled by a
structure, which is very much similar to the Spirit grammar DSL. BTW, the
name of this library is Tirips (reversed Spirit) :-).

For instance you could write:

    generate(str("abc") << char('d'), someoutputiter);

Which will simply output "abcd". The different generator objects are
parametrizable with lazy constructs:

    char const *str = "abc";
    char ch = 'd';
        str[phoenix::const_(str)] << char_[phoenix::const_(ch)],

Would output "abcd" as well.

More sophisticated constructs like the list_ would help in outputting
container structures:

    vector<int> v = ...;
    generate(list_(',', int_)[phoenix::const_(v)], someoutputiter);

outputs a comma separeted list of integers, and so on.

I'm currently at the early stages of such a library so there isn't very much
code to show, but if anybody is interested I'm happy to collaborate on
discussing and implementing this.

Regards Hartmut

Boost list run by bdawes at, gregod at, cpdaniel at, john at