| <large>libXpertMassCore and libXpertMassGui Developer Documentation</large>

- libXpertMassCore
- MassCollection

# MsXpS::libXpertMassCore::MassCollection Class

class MsXpS::libXpertMassCore::MassCollection

The MassCollection class provides a container for masses (as double values) and for text representing thoses values. More...

Header: | `#include <MassCollection.hpp>`

- List of all members, including inherited members
- MassCollection is part of libXpertMassCore Utilities.

## Public Functions

| MassCollection(const QString &name)
| MassCollection(const QString &name, const QString &mass_text)
| MassCollection(const QString &name, const std::vector<double> &masses)
| MassCollection(const MsXpS::libXpertMassCore::MassCollection &other)
| ~MassCollection()
void | addMass(double mass)
const QString & | getComment() const
double | getMassAtIndex(std::size_t index) const
const std::vector<double> & | getMassesCstRef() const
std::vector<double> & | getMassesRef()
const QString & | getName() const
bool | isValid() const
QString | massesToText()
void | removeLessThan(double threshold)
void | setComment(const QString &comment)
void | setName(const QString &name)
std::size_t | size() const
void | sortAscending()
void | sortDescending()
int | textToMasses(const QString &text, MsXpS::libXpertMassCore::ErrorList *error_list_p)
bool | validate(MsXpS::libXpertMassCore::ErrorList *error_list_p) const
MsXpS::libXpertMassCore::MassCollection & | operator=(const MsXpS::libXpertMassCore::MassCollection &other)

## Protected Variables

QString | m_comment
std::vector<double> | m_masses
QString | m_name

## Detailed Description

The MassCollection class provides a container for masses (as double values) and for text representing thoses values. Methods allow to create numerical mass values starting for a text string representing mass values separated by newline characters and, reciprocally, create a text string starting from all the mass values.

The mass values are stored in a container (m_masses) and the text string is stored in m_massText.

## Member Function Documentation

### MassCollection::MassCollection(const QString &name)

Constructs a MassCollection with name.

The instance is created in an invalid state.

### MassCollection::MassCollection(const QString &name, const QString &mass_text)

Constructs a MassCollection with name and mass_text.

The mass_text is the textual representation of the mass double values that is parsed and converted to mass double values. After the parsing, this instance is validated, and the result is set to m_isValid.

### MassCollection::MassCollection(const QString &name, const std::vector<double> &masses)

Constructs a MassCollection with name and masses.

The masses are copied to the member container without check. If the masses container is non-empty, the m_isValid status is set to true, else to false.

### MassCollection::MassCollection(const MsXpS::libXpertMassCore::MassCollection &other)

Constructs a MassCollection as a copy of other. If the masses container is non-empty, the m_isValid status is set to true, else to false.

### `[noexcept]` MassCollection::~MassCollection()

Destructs this MassCollection.

### void MassCollection::addMass(double mass)

Adds mass to each mass in the container.

### const QString &MassCollection::getComment() const

Returns the comment.

### double MassCollection::getMassAtIndex(std::size_t index) const

Returns the mass at the index in the container.

An out of bounds index is fatal.

### const std::vector<double> &MassCollection::getMassesCstRef() const

Returns a const reference to the container of masses.

### std::vector<double> &MassCollection::getMassesRef()

Returns a reference to the container of masses.

### const QString &MassCollection::getName() const

Returns the name.

### bool MassCollection::isValid() const

Returns the validity status of this MassCollection.

### QString MassCollection::massesToText()

Returns a text string representing the mass double values in the container all separated with a newline character.

### void MassCollection::removeLessThan(double threshold)

Removes from the container all mass values strictly below threshold.

### void MassCollection::setComment(const QString &comment)

Sets the comment to comment.

### void MassCollection::setName(const QString &name)

Sets the name to name.

### std::size_t MassCollection::size() const

Returns the size of the container of masses.

### void MassCollection::sortAscending()

Sorts the masses in the container in ascending order.

### void MassCollection::sortDescending()

Sorts the masses in the container in descending order.

### int MassCollection::textToMasses(const QString &text, MsXpS::libXpertMassCore::ErrorList *error_list_p)

Returns the count of masses successfully obtained by converting the text to double values.

The text is first split at newline characters and each obtained string is converted to a double value that is added to the container.

The mass container is first emptied and the validity status of the MassCollection is set to false.

If the text is empty, this function returns 0.

If a conversion error is encountered, the faulty text element is appended to error_list_p, the mass container is cleared, m_isValid is set to false and -1 is returned.

If the container of masses is non-empty at the end of the conversion (without error), then m_isValid is set to true and the container size is returned.

### bool MassCollection::validate(MsXpS::libXpertMassCore::ErrorList *error_list_p) const

Validates this MassCollection and returns true if successful or false otherwise.

Upon validation, error messages are set to error_list_p (not emptied).

If validation is successful, the m_isValid validity status is set to true, to false otherwise.

### MsXpS::libXpertMassCore::MassCollection &MassCollection::operator=(const MsXpS::libXpertMassCore::MassCollection &other)

Assigns other to this MassCollection and returns a reference to this object. If the masses are non-empty, the m_isValid status is set to true, else to false.

## Member Variable Documentation

### QString MassCollection::m_comment

This variable holds the comment associated to the MassCollection.

### std::vector<double> MassCollection::m_masses

This variable holds the container of mass double values.

### QString MassCollection::m_name

This variable holds the name associated to the MassCollection.