Boost logo

Boost :

From: christopher diggins (cdiggins_at_[hidden])
Date: 2005-01-31 14:08:58

I may finally have a good motivating example for stdio_filter:

Consider the roman_numerals.cpp example from the Boost spirit library at

If I make a couple of minor modifications exclusively to the main, such as
remove the superflous user prompting and rename it to something legal, i.e.:

int RomanNumeralParse()
    string str;
    while (getline(cin, str))
        if (str[0] == 'q' || str[0] == 'Q')

        unsigned n = 0;
        roman roman_p(n);
        if (parse(str.c_str(), roman_p).full)
            cout << n << endl;
            cerr << "parsing failure" << endl;
            return 1;
    return 0;

Using my current version of my filters library (not available online yet) I
can now reuse the entire program from another, such as the following:

  void RomanNumeralParserTest() {
    stringstream sIn("MCMLXXIV"), sOut;
    sIn > SimpleMainFilter(RomanNumeralParse) > sOut;
    int n;
    sOut >> n;
    TEST(n == 1974);

Many examples from the Spirit examples, can be refactored in this manner, to
become reusable with relatively little effort. I suppose one of the
calculators would be even more interesting. Is this a good motivating
example for introducing a stdio_filter into boost::iostreams?

Christopher Diggins
Object Oriented Template Library (OOTL)

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