spectrum: Add ==, !=, Get/Set Values to SpectrumValue

spectrum: Add operator == and != to SpectrumValue
spectrum: Fix operator ==,!= (Thanks to Eduardo Almeida and Gabriel Ferreira)
spectrum: Add GetValues and SetValues functions to SpectrumValue
This commit is contained in:
Biljana Bojovic
2023-01-23 17:27:49 +01:00
parent 952b173a04
commit 81bd1e0bb4
2 changed files with 76 additions and 0 deletions

View File

@@ -411,6 +411,18 @@ operator+(const SpectrumValue& lhs, const SpectrumValue& rhs)
return res;
}
bool
operator==(const SpectrumValue& lhs, const SpectrumValue& rhs)
{
return (lhs.m_values == rhs.m_values);
}
bool
operator!=(const SpectrumValue& lhs, const SpectrumValue& rhs)
{
return (lhs.m_values != rhs.m_values);
}
SpectrumValue
operator+(const SpectrumValue& lhs, double rhs)
{

View File

@@ -159,6 +159,50 @@ class SpectrumValue : public SimpleRefCount<SpectrumValue>
*/
uint32_t GetValuesN() const;
/**
* Directly set the values using the std::vector<double>
* \param values a reference to the std::vector<double>
*/
inline void SetValues(Values& values)
{
NS_ASSERT_MSG(
values.size() == m_spectrumModel->GetNumBands(),
"Values size does not correspond to the SpectrumModel in use by this SpectrumValue.");
m_values = values;
}
/**
* Directly set the values by moving the values from the input std::vector<double>
* \param values a reference to the std::vector<double> to be moved
*/
inline void SetValues(Values&& values)
{
NS_ASSERT_MSG(
values.size() == m_spectrumModel->GetNumBands(),
"Values size does not correspond to the SpectrumModel in use by this SpectrumValue.");
m_values = std::move(values);
}
/**
* \brief Provides the direct access to the underlying std::vector<double>
* that stores the spectrum values.
* \return a reference to the stored values
*/
inline Values& GetValues()
{
return m_values;
}
/**
* \brief Provides the direct read-only access to the underlying std::vector<double>
* that stores the spectrum values.
* \return a const reference to the stored values
*/
inline const Values& GetValues() const
{
return m_values;
}
/**
* \brief Get the value element at the position
* \param pos position
@@ -286,6 +330,26 @@ class SpectrumValue : public SimpleRefCount<SpectrumValue>
*/
friend SpectrumValue operator/(double lhs, const SpectrumValue& rhs);
/**
* Compare two spectrum values
*
* @param lhs Left Hand Side of the operator
* @param rhs Right Hand Side of the operator
*
* @return true if lhs and rhs SpectruValues are equal
*/
friend bool operator==(const SpectrumValue& lhs, const SpectrumValue& rhs);
/**
* Compare two spectrum values
*
* @param lhs Left Hand Side of the operator
* @param rhs Right Hand Side of the operator
*
* @return true if lhs and rhs SpectruValues are not equal
*/
friend bool operator!=(const SpectrumValue& lhs, const SpectrumValue& rhs);
/**
* unary plus operator
*