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
http://tinyurl.com/3qw4k

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')
            break;

        unsigned n = 0;
        roman roman_p(n);
        if (parse(str.c_str(), roman_p).full)
        {
            cout << n << endl;
        }
        else
        {
            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)
http://www.ootl.org


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk