Boost logo

Boost Users :

Subject: [Boost-users] inheritance, input streams, parsing and arithmetic range of values
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-12-18 09:55:00


I would like your opinions about design/implementation choices for an
application I am writing.

I have a list of models. Each model is a kind of black box that takes inputs
and produces outputs.
All the inputs are either of boolean or arithmetic type. (bool, int,
A subset of inputs is valid for all models. Then different models have
different number of other inputs.

For a fixed set of inputs, the model produces 1 fixed set of outputs.

It is desired to vary the values of some/all (at least 1) of the inputs and
get different outputs sets, and then plot that.

The inputs are specified in files (considered as std::istream in the code),
the syntax is trivial:

input1 = value1
inputn = valuen

When it is desired to vary the input values, the syntax changes a little:

input1 = value1
input2 = value21..value22
inputn = valuen

in this example only input2 changes, and the idea is to plot one of the
outputs over the differnt values of input2.

Each derived model has a concrete struct input_i_s { ... } that holds its

class model {
   virtual fixed_inputs get_fixed_inputs( std::istream& ) const =0; ///
throws if syntax error, or not all inputs are specified, or some values are
not valid
   virtual variable_inputs get_variable_inputs( std::istream& ) const =0;
/// the same, allows the '..' notation though for ranges, at least of the
inputs need to be a range

// fixed_inputs is a pointer to a base class of all inputs for all models

1 implementation pseud-code looks like:
fixed_inputs model_i::get_fixed_inputs( std::istream& input) const
   size_t inputs = 7;
   std::string buffer;

  while (inputs>0 && input.good()) {
      input >> buffer;

     if ( buffer.substr(0, sizeof("input1")) == "input1=") {
           std::istringstream is(buffer.substr(0, sizeof("input1")));
           is >> .... ; /// pseudo-code : stores the value
into a field in fixed_input1s
        // if wrong value, throws an exception
     else if ...
  return fixed_inputs( new input_i_s() ); // pseudo-code, say for
model number i

I would like then to write the implementation for the syntax which accepts
ranges as well. (the get_variable_inputs function)
I hope to be able to factorize code between the 2 implementations.

1. boost::program_options can read options from input streams. Given that I
am interested in ranges as well, is it adviced to go down that road?

2. Is there a library that helps to generate the expected format of the
input stream from the struct of inputs for each model, and reads the stream
automatically. Can it do range values as well?

3. is it possible then to factorize code between the get_fixed_inputs and


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at