R
RThaden
Hi all,
I looked in several books, articles, etc. but did not find a solution
to my problem. Maybe somebody out there can help a desperate, not toooo
experienced programmer:
I want to represent functional blocks by lists of parameters.
Lets say, functional blocks represent different algorithms which, of
course, have very different parameters.
Thus, a functional block contains lists of parameters which, and now
comes the problem, can be of different types. It is not known at
compile time, how many parameters and which types.
The parameters are characterized by their name.
A parameter should be an object like this
set/getValue()
set/get/MaxMin()
string set/getName()
The value can be of type int or double (and maybe, who knows, in the
future there will be other types).
Thus, it is not possible to do it via an abstract base class
abstractParam and inheritance since the inherited classes would differ
in type (and which type should I supply to the abstract base class).
Sounds like templates would be a solution but, then, how should I
maintain a list of parameters in a functional block?
Parameter:
template <class T> param:
FunctionalBlock ... {
list<param> params;
....
}
does not work since the list expects specialized values, thus, params
must carry type information.
I could just put two lists in a functional block, one with int
parameters and one with double parameters.
Disadvantages: I have to iterate over two lists which is not that bad,
but if in the future a third type will be added, I have to modify all
the code dealing with this.
Any ideas for a solution?
Thanks in advance,
Rainer
I looked in several books, articles, etc. but did not find a solution
to my problem. Maybe somebody out there can help a desperate, not toooo
experienced programmer:
I want to represent functional blocks by lists of parameters.
Lets say, functional blocks represent different algorithms which, of
course, have very different parameters.
Thus, a functional block contains lists of parameters which, and now
comes the problem, can be of different types. It is not known at
compile time, how many parameters and which types.
The parameters are characterized by their name.
A parameter should be an object like this
set/getValue()
set/get/MaxMin()
string set/getName()
The value can be of type int or double (and maybe, who knows, in the
future there will be other types).
Thus, it is not possible to do it via an abstract base class
abstractParam and inheritance since the inherited classes would differ
in type (and which type should I supply to the abstract base class).
Sounds like templates would be a solution but, then, how should I
maintain a list of parameters in a functional block?
Parameter:
template <class T> param:
FunctionalBlock ... {
list<param> params;
....
}
does not work since the list expects specialized values, thus, params
must carry type information.
I could just put two lists in a functional block, one with int
parameters and one with double parameters.
Disadvantages: I have to iterate over two lists which is not that bad,
but if in the future a third type will be added, I have to modify all
the code dealing with this.
Any ideas for a solution?
Thanks in advance,
Rainer