set_param_by_name for bm

Felix Salfelder <[email protected]>
Newsgroups gmane.comp.gnu.gnucap.devel
Message-ID <[email protected]>
Hi List.

first of all, congratulations to Savant!

i'm working on the once mentioned set_param_by_name patch, and if it's
useful for the gsoc plugin, i'll try to complete it soon.

i've figured out a way to avoid linear search (mostly for adms models, as
they have much more parameters), and i'd like to do the bm*-parameters
the same way. what it looks like is this:

- add a static std::map< > param_dict to the EVAL_BM_* classes
- add PARA_BASE, a base class for the PARAMETER<T> classes.
- have boost installed
- do some class-member-pointer mess

finally, for example bm_pulse.cc reads something like this:
/*--------------------------------------------------------------------------*/
map<string, PARA_BASE EVAL_BM_PULSE::*> EVAL_BM_PULSE::param_dict =
  boost::assign::map_list_of
    ("iv",    (PARA_BASE EVAL_BM_PULSE::*) &EVAL_BM_PULSE::_iv)
    [..]
    ("period",(PARA_BASE EVAL_BM_PULSE::*) &EVAL_BM_PULSE::_period);
/*--------------------------------------------------------------------------*/
void EVAL_BM_PULSE::set_param_by_name(string Name, string Value)
{
  if( PARA_BASE EVAL_BM_PULSE::* x = (param_dict[Name]) ) {
    PARA_BASE* p = &(this->*x);
    *p = Value;
  } else {
    throw Exception_No_Match(Name);
  }
}
/*--------------------------------------------------------------------------*/

so, PARA_BASE EVAL_BM_PULSE::* is somewhat the C++ type specifying an
offset to a member in a struct. these should imho be stored in a stack
allocated map.

do you agree, that this is better than linear search? any clues on how
to avoid the extra casts in the map initialization?

regards
felix
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.