Skip to content

Commit

Permalink
Refs #4394 moved initialization steps from constructor to init
Browse files Browse the repository at this point in the history
  • Loading branch information
jmborr committed Dec 20, 2013
1 parent e0f10f1 commit a193f37
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
Expand Up @@ -44,32 +44,34 @@ namespace CurveFitting

class DLLExport DiffSphere : public API::ImmutableCompositeFunction
{

public:
/// Constructor
DiffSphere();

/// Destructor
~DiffSphere() {};

/// overwrite IFunction base class methods
std::string name()const{return "DiffSphere";}
std::string name()const{ return "DiffSphere"; }

virtual const std::string category() const { return "QuasiElastic";}
virtual const std::string category() const { return "QENS"; }

virtual int version() const { return 1;}
virtual int version() const { return 1; }

/// Propagate an attribute to member functions
virtual void trickleDownAttribute( const std::string& name );

/// Override parent definition
virtual void declareAttribute(const std::string & name,const API::IFunction::Attribute & defaultValue);
virtual void declareAttribute(const std::string & name,const API::IFunction::Attribute & defaultValue );

/// Override parent definition
virtual void setAttribute(const std::string& attName,const Attribute& att);
virtual void setAttribute( const std::string& attName, const Attribute& att );

/// overwrite IFunction base class method, which declare function parameters
virtual void init();

private:
//API::IFunctionMW* m_elastic; //elastic intensity of the DiffSphere structure factor
boost::shared_ptr<ElasticDiffSphere> m_elastic;

boost::shared_ptr<ElasticDiffSphere> m_elastic; //elastic intensity of the DiffSphere structure factor
boost::shared_ptr<InelasticDiffSphere> m_inelastic; //inelastic intensity of the DiffSphere structure factor
};

Expand Down
38 changes: 20 additions & 18 deletions Code/Mantid/Framework/CurveFitting/src/DiffSphere.cpp
Expand Up @@ -27,54 +27,56 @@ DECLARE_FUNCTION(DiffSphere);
* NOTE: we pass this->getAttribute(name) by reference, thus the same
* object is shared by the composite function and its members.
*/
void DiffSphere::trickleDownAttribute( const std::string& name )
void DiffSphere::trickleDownAttribute( const std::string & name )
{
for(size_t iFun=0;iFun<nFunctions();iFun++)
for( size_t iFun = 0; iFun < nFunctions(); iFun++ )
{
IFunction_sptr fun = getFunction(iFun);
IFunction_sptr fun = getFunction( iFun );
if( fun->hasAttribute( name ) )
fun->setAttribute( name, this->getAttribute(name) );
{
fun->setAttribute( name, this->getAttribute( name ) );
}
}
}

/* Same as parent except we overwrite attributes of member functions
* having the same name
*/
void DiffSphere::declareAttribute(const std::string & name,const API::IFunction::Attribute & defaultValue)
void DiffSphere::declareAttribute( const std::string & name, const API::IFunction::Attribute & defaultValue )
{
API::ImmutableCompositeFunction::declareAttribute(name, defaultValue);
API::ImmutableCompositeFunction::declareAttribute( name, defaultValue );
trickleDownAttribute( name );
}

/* Same as parent except we overwrite attributes of member functions
* having the same name
*/
void DiffSphere::setAttribute(const std::string& name,const Attribute& att)
void DiffSphere::setAttribute( const std::string & name, const Attribute & att )
{
API::ImmutableCompositeFunction::setAttribute( name, att );
trickleDownAttribute( name );
}

DiffSphere::DiffSphere()
void DiffSphere::init()
{
m_elastic = boost::dynamic_pointer_cast<ElasticDiffSphere>(API::FunctionFactory::Instance().createFunction("ElasticDiffSphere"));
m_elastic = boost::dynamic_pointer_cast< ElasticDiffSphere >( API::FunctionFactory::Instance().createFunction( "ElasticDiffSphere" ) );
addFunction( m_elastic );
m_inelastic = boost::dynamic_pointer_cast<InelasticDiffSphere>(API::FunctionFactory::Instance().createFunction("InelasticDiffSphere"));
m_inelastic = boost::dynamic_pointer_cast< InelasticDiffSphere >( API::FunctionFactory::Instance().createFunction( "InelasticDiffSphere" ) );
addFunction( m_inelastic );

this->setAttributeValue("NumDeriv", true );
this->setAttributeValue( "NumDeriv", true );

this->declareAttribute("Q", API::IFunction::Attribute(1.0) );
this->declareAttribute( "Q", API::IFunction::Attribute( 1.0 ) );

//Set the aliases
this->setAlias("f0.Height","elasticHeight");
this->setAlias("f0.Radius","elasticRadius");
this->setAlias("f1.Intensity","Intensity");
this->setAlias("f1.Radius","Radius");
this->setAlias("f1.Diffusion","Diffusion");
this->setAlias( "f0.Height", "elasticHeight" );
this->setAlias( "f0.Radius", "elasticRadius" );
this->setAlias( "f1.Intensity", "Intensity" );
this->setAlias( "f1.Radius", "Radius" );
this->setAlias( "f1.Diffusion", "Diffusion" );

//Set the ties between Elastic and Inelastic parameters
this->addDefaultTies("f0.Height=f1.Intensity,f0.Radius=f1.Radius");
this->addDefaultTies( "f0.Height=f1.Intensity,f0.Radius=f1.Radius" );
this->applyTies();
}

Expand Down

0 comments on commit a193f37

Please sign in to comment.