add operator ==, < and > to SpectrumValue

This commit is contained in:
mrequena
2011-04-15 15:40:01 +02:00
parent 32943a52bc
commit a8be2795e5
2 changed files with 118 additions and 0 deletions

View File

@@ -649,6 +649,94 @@ SpectrumValue:: operator= (double rhs)
}
bool
SpectrumValue::operator== (const SpectrumValue& rhs) const
{
Values::const_iterator it1 = this->m_values.begin ();
Values::const_iterator it2 = rhs.m_values.begin ();
while ( it1 != this->m_values.end () && it2 != rhs.m_values.end () )
{
if ( *it1 != *it2 )
{
return false;
}
else
{
++it1;
++it2;
}
}
if ( it1 == this->m_values.end () && it2 == rhs.m_values.end () )
{
return true;
}
else
{
return false;
}
}
bool
SpectrumValue::operator< (const SpectrumValue &rhs) const
{
Values::const_iterator it1 = this->m_values.begin ();
Values::const_iterator it2 = rhs.m_values.begin ();
while ( it1 != this->m_values.end () && it2 != rhs.m_values.end () )
{
if ( *it1 >= *it2 )
{
return false;
}
else
{
++it1;
++it2;
}
}
if ( it1 == this->m_values.end () && it2 == rhs.m_values.end () )
{
return true;
}
else
{
return false;
}
}
bool
SpectrumValue::operator> (const SpectrumValue &rhs) const
{
Values::const_iterator it1 = this->m_values.begin ();
Values::const_iterator it2 = rhs.m_values.begin ();
while ( it1 != this->m_values.end () && it2 != rhs.m_values.end () )
{
if ( *it1 <= *it2 )
{
return false;
}
else
{
++it1;
++it2;
}
}
if ( it1 == this->m_values.end () && it2 == rhs.m_values.end () )
{
return true;
}
else
{
return false;
}
}
SpectrumValue
SpectrumValue:: operator<< (int n) const

View File

@@ -400,6 +400,36 @@ public:
/**
* Compare each component, one by one
*
* @param rhs Right Hand Side of the operator
*
* @return True if this == rhs
* False if this != rhs
*/
bool operator== (const SpectrumValue& rhs) const;
/**
* Compare each component, one by one
*
* @param rhs Right Hand Side of the operator
*
* @return True if this < rhs
* False if this >= rhs
*/
bool operator< (const SpectrumValue &rhs) const;
/**
* Compare each component, one by one
*
* @param rhs Right Hand Side of the operator
*
* @return True if this > rhs
* False if this <= rhs
*/
bool operator> (const SpectrumValue &rhs) const;
/**
*
* @param x the operand