Feature/issue 405 refactor init

#### Summary:

Splits out the initialization portion of src/stan/common/command.hpp into functions.

#### Intended Effect:

Functions are created that can be called from the interfaces.

The var_context_factory allows the interfaces to define how it handles a string.

#### How to Verify:

See added unit tests.


#### Side Effects:

No behavioral side effects.
RStan and PyStan will have to change to incorporate these changes, although it isn't necessary.

#### Documentation:

None.

#### Reviewer Suggestions:

Michael? Bob?

I know, it's still short on tests, but baby steps. There are more tests than there were before.
Updated to catch the bad_lexical_cast.

On Aug 27, 2014, at 11:01 PM, Bob Carpenter <notifications@github.com> wrote:

> In src/stan/common/initialize_state.hpp:
> 
> > +                          Model& model,
> > +                          RNG& base_rng,
> > +                          std::ostream* output,
> > +                          ContextFactory& context_factory) {
> > +    
> > +      try {
> > +        
> > +        double R = std::fabs(boost::lexical_cast<double>(init));
> > +        
> > +        if (R == 0) {
> > +          return initialize_state_zero(cont_params, model, output);
> > +        } else {
> > +          return initialize_state_random(R, cont_params, model,
> > +                                         base_rng, output);
> > +        }
> > +      } catch(...) {
> Instead of ..., we should be catching the specific exception thrown by Boost lexical cast. Otherwise, we'll trap errors that might arise in initialize_state_zero. Even better would be to encapsulate this all in some kind of getter, like:
> 
> bool get_double_from_string(const std::string& s, double& val) {
>   try {
>     val = boost::lexical_cast<double>(s);
>     return true;
>   } catch (...whatever gets thrown by bad cast...)
>     val = NaN; // not sure this is necessary
>     return false;
> }
> and then use that in the code.
> 
> —
> Reply to this email directly or view it on GitHub.
>