Skip to content
Snippets Groups Projects
Commit 41eff71f authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

Small refactoring to addAxis

parent c2d13c11
No related branches found
No related tags found
No related merge requests found
...@@ -253,6 +253,9 @@ private: ...@@ -253,6 +253,9 @@ private:
//! returns serial number of axis with given name //! returns serial number of axis with given name
size_t getAxisIndex(const std::string& axis_name) const; size_t getAxisIndex(const std::string& axis_name) const;
//! checks if given axis name exists
bool axisNameExists(const std::string& axis_name) const;
SafePointerVector<IAxis> m_value_axes; SafePointerVector<IAxis> m_value_axes;
LLData<T>* mp_ll_data; LLData<T>* mp_ll_data;
double m_variability; double m_variability;
...@@ -325,7 +328,7 @@ OutputData<double>* OutputData<T>::meanValues() const ...@@ -325,7 +328,7 @@ OutputData<double>* OutputData<T>::meanValues() const
template <class T> template <class T>
void OutputData<T>::addAxis(const IAxis& new_axis) void OutputData<T>::addAxis(const IAxis& new_axis)
{ {
if( getAxis(new_axis.getName()) ) if( axisNameExists(new_axis.getName()) )
throw Exceptions::LogicErrorException( throw Exceptions::LogicErrorException(
"OutputData<T>::addAxis(const IAxis& new_axis) -> " "OutputData<T>::addAxis(const IAxis& new_axis) -> "
"Error! Attempt to add axis with already existing name '" + "Error! Attempt to add axis with already existing name '" +
...@@ -339,7 +342,7 @@ void OutputData<T>::addAxis(const IAxis& new_axis) ...@@ -339,7 +342,7 @@ void OutputData<T>::addAxis(const IAxis& new_axis)
template <class T> template <class T>
void OutputData<T>::addAxis(const std::string& name, size_t size, double start, double end) void OutputData<T>::addAxis(const std::string& name, size_t size, double start, double end)
{ {
if( getAxis(name) ) if( axisNameExists(name) )
throw Exceptions::LogicErrorException( throw Exceptions::LogicErrorException(
"OutputData<T>::addAxis(std::string name) -> " "OutputData<T>::addAxis(std::string name) -> "
"Error! Attempt to add axis with already existing name '" + "Error! Attempt to add axis with already existing name '" +
...@@ -357,10 +360,7 @@ const IAxis* OutputData<T>::getAxis(size_t serial_number) const ...@@ -357,10 +360,7 @@ const IAxis* OutputData<T>::getAxis(size_t serial_number) const
template <class T> template <class T>
const IAxis* OutputData<T>::getAxis(const std::string& axis_name) const const IAxis* OutputData<T>::getAxis(const std::string& axis_name) const
{ {
for (size_t i = 0; i < m_value_axes.size(); ++i) return getAxis(getAxisIndex(axis_name));
if (m_value_axes[i]->getName() == axis_name)
return m_value_axes[i];
return 0;
} }
template<class T> template<class T>
...@@ -677,9 +677,17 @@ size_t OutputData<T>::getAxisIndex(const std::string &axis_name) const ...@@ -677,9 +677,17 @@ size_t OutputData<T>::getAxisIndex(const std::string &axis_name) const
for (size_t i = 0; i < m_value_axes.size(); ++i) for (size_t i = 0; i < m_value_axes.size(); ++i)
if (m_value_axes[i]->getName() == axis_name) return i; if (m_value_axes[i]->getName() == axis_name) return i;
throw Exceptions::LogicErrorException( throw Exceptions::LogicErrorException(
"OutputData<T>::getAxisSerialNumber() -> " "OutputData<T>::getAxisIndex() -> "
"Error! Axis with given name not found '"+axis_name+std::string("'")); "Error! Axis with given name not found '"+axis_name+std::string("'"));
} }
template <class T>
bool OutputData<T>::axisNameExists(const std::string &axis_name) const
{
for (size_t i = 0; i < m_value_axes.size(); ++i)
if (m_value_axes[i]->getName() == axis_name) return true;
return false;
}
#endif // OUTPUTDATA_H #endif // OUTPUTDATA_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment