BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IParameter< T > Class Template Referenceabstract

Abstract base class for parameter wrapper classes RealParameter, ComponentParameter. More...

Public Member Functions

 IParameter ()=delete
 
 IParameter (const std::string &name, T *data, const std::string &parent_name, const std::function< void()> &onChange)
 
virtual ~IParameter ()=default
 
virtual IParameterclone (const std::string &new_name="") const =0
 
T & getData () const
 
const std::string & getName () const
 
bool hasSameData (const IParameter &other)
 Returns true if two parameters are pointing to the same raw data. More...
 
virtual bool isNull () const
 Returns true if wrapped parameter was not initialized with proper real value. More...
 
void setData (T &data)
 

Protected Member Functions

std::string fullName () const
 For use in error messages. More...
 

Protected Attributes

T * m_data
 
const std::string m_name
 
const std::function< void()> m_onChange
 
const std::string m_parent_name
 

Detailed Description

template<class T>
class IParameter< T >

Abstract base class for parameter wrapper classes RealParameter, ComponentParameter.

Holds a pointer to the wrapped parameter, a name, and a callback function to be called when the parameter is changed. This class is templated on the data type of the wrapped parameter.

Definition at line 29 of file IParameter.h.

Constructor & Destructor Documentation

◆ IParameter() [1/2]

template<class T >
IParameter< T >::IParameter ( )
delete

◆ IParameter() [2/2]

template<class T >
IParameter< T >::IParameter ( const std::string &  name,
T *  data,
const std::string &  parent_name,
const std::function< void()> &  onChange 
)

Definition at line 62 of file IParameter.h.

64  : m_name(name), m_data(data), m_parent_name(parent_name), m_onChange(onChange)
65 {
66  if (!m_data)
67  throw std::runtime_error("Attempt to construct an IParameter with null data pointer");
68 }
const std::string m_name
Definition: IParameter.h:52
const std::function< void()> m_onChange
Definition: IParameter.h:55
T * m_data
Definition: IParameter.h:53
const std::string m_parent_name
Definition: IParameter.h:54
QString const & name(EShape k)
Definition: particles.cpp:21

References IParameter< T >::m_data.

◆ ~IParameter()

template<class T >
virtual IParameter< T >::~IParameter ( )
virtualdefault

Member Function Documentation

◆ clone()

template<class T >
virtual IParameter* IParameter< T >::clone ( const std::string &  new_name = "") const
pure virtual

Implemented in RealParameter.

◆ fullName()

template<class T >
std::string IParameter< T >::fullName ( ) const
inlineprotected

For use in error messages.

Definition at line 58 of file IParameter.h.

58 { return m_parent_name + "/" + m_name; }

References IParameter< T >::m_name, and IParameter< T >::m_parent_name.

◆ getData()

template<class T >
T& IParameter< T >::getData ( ) const
inline

Definition at line 41 of file IParameter.h.

41 { return *m_data; }

References IParameter< T >::m_data.

Referenced by IParameter< T >::hasSameData().

◆ getName()

template<class T >
const std::string& IParameter< T >::getName ( ) const
inline

Definition at line 49 of file IParameter.h.

49 { return m_name; }

References IParameter< T >::m_name.

Referenced by ParameterPool::addParameter().

◆ hasSameData()

template<class T >
bool IParameter< T >::hasSameData ( const IParameter< T > &  other)

Returns true if two parameters are pointing to the same raw data.

Definition at line 72 of file IParameter.h.

73 {
74  return &getData() == &other.getData();
75 }
T & getData() const
Definition: IParameter.h:41

References IParameter< T >::getData().

Here is the call graph for this function:

◆ isNull()

template<class T >
virtual bool IParameter< T >::isNull ( ) const
inlinevirtual

Returns true if wrapped parameter was not initialized with proper real value.

Definition at line 39 of file IParameter.h.

39 { return m_data ? false : true; }

References IParameter< T >::m_data.

◆ setData()

template<class T >
void IParameter< T >::setData ( T &  data)
inline

Definition at line 42 of file IParameter.h.

43  {
44  m_data = &data;
45  m_onChange();
46  }

References IParameter< T >::m_data, and IParameter< T >::m_onChange.

Member Data Documentation

◆ m_data

template<class T >
T* IParameter< T >::m_data
protected

◆ m_name

template<class T >
const std::string IParameter< T >::m_name
protected

Definition at line 52 of file IParameter.h.

Referenced by IParameter< T >::fullName(), and IParameter< T >::getName().

◆ m_onChange

template<class T >
const std::function<void()> IParameter< T >::m_onChange
protected

Definition at line 55 of file IParameter.h.

Referenced by IParameter< T >::setData().

◆ m_parent_name

template<class T >
const std::string IParameter< T >::m_parent_name
protected

Definition at line 54 of file IParameter.h.

Referenced by IParameter< T >::fullName().


The documentation for this class was generated from the following file: