Evoplex  0.2.1
Public Member Functions | List of all members
evoplex::Attributes Class Reference

A container of labeled values. More...

#include <attributes.h>

Public Member Functions

 Attributes (int size)
 Constructor. More...
 
 Attributes ()
 Constructor.
 
 ~Attributes ()
 Destructor.
 
void resize (int size)
 Resizes the container to the specified number of elements. More...
 
void reserve (int size)
 Attempt to preallocate enough memory for specified number of elements. More...
 
int size () const
 Gets the number of attributes in the container.
 
bool isEmpty () const
 Checks if the container is empty.
 
bool empty () const
 Checks if the container is empty. More...
 
int indexOf (const QString &name) const
 Returns the index position of name in the container. More...
 
bool contains (const QString &name) const
 Checks if the container contains name. More...
 
void replace (int id, QString newName, Value newValue)
 Replaces the item at index position id with newName and newValue. More...
 
void push_back (QString name, Value value)
 Appends the attribute name with the value value. More...
 
const std::vector< QString > & names () const
 Gets the name of all attributes.
 
const QString & name (int id) const
 Gets the name of the attribute at id. More...
 
const std::vector< Value > & values () const
 Gets the values of all attributes.
 
const Valuevalue (int id) const
 Gets the value of the attribute at id. More...
 
Value value (const QString &name, Value defaultValue=Value()) const
 Gets the value corresponding to name. More...
 
void setValue (int id, const Value &value)
 Sets the value at id. More...
 

Detailed Description

A container of labeled values.

It offers fixed time access to individual elements in any order by id and linear time by name.

Constructor & Destructor Documentation

◆ Attributes()

evoplex::Attributes::Attributes ( int  size)
inline

Constructor.

Parameters
sizeThe containers size.

Member Function Documentation

◆ contains()

bool evoplex::Attributes::contains ( const QString &  name) const
inline

Checks if the container contains name.

Parameters
nameThe attribute's name.
See also
indexOf(const QString&)

◆ empty()

bool evoplex::Attributes::empty ( ) const
inline

Checks if the container is empty.

◆ indexOf()

int evoplex::Attributes::indexOf ( const QString &  name) const
inline

Returns the index position of name in the container.

Parameters
nameThe attribute's name.
Returns
-1 if no item matched.
See also
contains(const QString&)

◆ name()

const QString & evoplex::Attributes::name ( int  id) const
inline

Gets the name of the attribute at id.

Exceptions
std::out_of_rangeif the id is not present.

◆ push_back()

void evoplex::Attributes::push_back ( QString  name,
Value  value 
)
inline

Appends the attribute name with the value value.

Parameters
nameThe attribute's name.
valueThe attribute's value.

◆ replace()

void evoplex::Attributes::replace ( int  id,
QString  newName,
Value  newValue 
)
inline

Replaces the item at index position id with newName and newValue.

Parameters
idThe attribute's id.
newNameThe new attribute's name.
newValueThe new attribute's value.
Exceptions
std::out_of_rangeif the id is not present.

◆ reserve()

void evoplex::Attributes::reserve ( int  size)
inline

Attempt to preallocate enough memory for specified number of elements.

This function attempts to reserve enough memory for the container to hold the specified number of elements. If the number requested is more than max_size(), length_error is thrown.

Parameters
sizeNumber of elements required.
Exceptions
std::length_errorIf size n exceeds maximum size.

◆ resize()

void evoplex::Attributes::resize ( int  size)
inline

Resizes the container to the specified number of elements.

This function will resize the container to the specified number of elements. If the number is smaller than the container's current size the container is truncated, otherwise default constructed elements, i.e., empty name and Value() are appended.

Parameters
sizeNumber of elements the container should contain.

◆ setValue()

void evoplex::Attributes::setValue ( int  id,
const Value value 
)
inline

Sets the value at id.

Parameters
idThe attribute's id.
valueThe new attribute's value.
Exceptions
std::out_of_rangeif the id is not present.

◆ value() [1/2]

const Value & evoplex::Attributes::value ( int  id) const
inline

Gets the value of the attribute at id.

Parameters
idThe attribute's id.
Exceptions
std::out_of_rangeif the id is not present.

◆ value() [2/2]

Value evoplex::Attributes::value ( const QString &  name,
Value  defaultValue = Value() 
) const
inline

Gets the value corresponding to name.

Parameters
nameThe attribute's name.
defaultValueA Value to be returned if name is not present.

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