← Back to team overview

yade-users team mailing list archive

Re: How to communicate between two independent Engines

 

>              std::vector<shared_ptr<Engine> >::iterator itFirst =
> ncb->engines.begin();
>              std::vector<shared_ptr<Engine> >::iterator itLast =
> ncb->engines.end();
>              for ( ;itFirst!=itLast; ++itFirst )
>              {
>                  if ( ( *itFirst )->getClassName() ==
> "ConvergenceEstimater" )
>                  {
>                    ///FIXME here should be dynamic_cast or static_cast???
>                    convergenceEstimater =
> static_pointer_cast<ConvergenceEstimater>(*itFirst);
>
static_cast is fine, as long as the supposition that if a class gives
"ConvergenceEstimater" as its name, it is really an instance of
ConvergenEstimater.
>
>         return convergenceEstimater->getCCValue();
>
I would rewrite th return part like this:

    if(convergenceEstimater) return convergenceEstimater->getCCValue();
    else throw runtime_error("No ConvergenceEstimater engine was found!");

Since if you happen to forget to add that engine, the loop will end
without having found anything a you will get NULL pointer access in
return. It is true that it will result in the same: crash. But the
exception can hint for the user about what went wrong.

_______________________________________________
Yade-users mailing list
Yade-users@xxxxxxxxxxxxxxxx
https://lists.berlios.de/mailman/listinfo/yade-users



References