#include <genesis/taxonomy/taxon.hpp>
Inherits Taxonomy.
Store a Taxon, i.e., an element in a Taxonomy, with its name, rank and sub-taxa.
This class models a taxon within the hierarchy of a Taxonomy. Each such taxon can have a name assigned to it, a taxonomic rank, and an arbitrarily nested set of sub-taxa. The name and the rank are both free-form strings which can have any value.
The name is one part of a taxonomic path string. For example, given the string
Animalia;Vertebrata;Mammalia;Carnivora
a Taxon could have the name "Mammalia", and contain a Taxon with the name "Carnivora" as child. See Taxonomy for details, see Taxopath for the taxonomic path string format.
Each taxon is itself also a Taxonomy, in terms of class inheritance. This also makes some biological sense, as a taxon can be seen as the taxonomy of its sub-taxa. We however only consider the Taxonomy as the top level of the hierarchy. For more information, see there. The class inheritance is mainly due to software design descisions, in order to make working with Taxonomies and Taxa as easy and straight forward as possible.
Public Member Functions | |
Taxon () | |
Default constructor. Does nothing. More... | |
Taxon (std::string const &name) | |
Constructor that uses the given name for the Taxon. More... | |
Taxon (Taxon const &) | |
Copy constructor. More... | |
Taxon (Taxon &&) | |
Move constructor. More... | |
virtual | ~Taxon ()=default |
template<class TaxonDataType > | |
TaxonDataType & | data () |
template<class TaxonDataType > | |
TaxonDataType const & | data () const |
template<class TaxonDataType > | |
TaxonDataType * | data_cast () |
template<class TaxonDataType > | |
TaxonDataType const * | data_cast () const |
BaseTaxonData * | data_ptr () |
Return a pointer to the data. More... | |
BaseTaxonData const * | data_ptr () const |
Return a const pointer to the data. More... | |
bool | has_data () const |
Return true if the Taxon has a data object assigned to it. More... | |
std::string const & | name () const |
Return the name of this taxon. More... | |
void | name (std::string const &value) |
Set the name of this taxon. More... | |
Taxon & | operator= (Taxon const &) |
Copy assignment operator. More... | |
Taxon & | operator= (Taxon &&) |
Move assignment operator. More... | |
Taxon const * | parent () const |
Return a pointer to the parent of this taxon, or a nullptr if this is the top level taxon. More... | |
Taxon * | parent () |
Return a pointer to the parent of this taxon, or a nullptr if this is the top level taxon. More... | |
std::string const & | rank () const |
Return the rank of this taxon. More... | |
void | rank (std::string const &value) |
Set the rank of this taxon. More... | |
Taxon & | reset_data (std::unique_ptr< BaseTaxonData > data) |
Reset the data pointer of this Taxon. More... | |
![]() | |
Taxonomy ()=default | |
Taxonomy (Taxonomy const &) | |
Copy constructor. More... | |
Taxonomy (Taxonomy &&) | |
Move constructor. More... | |
virtual | ~Taxonomy ()=default |
Taxon & | add_child (Taxon const &child) |
Add a child Taxon as a copy of a given Taxon and return it. More... | |
Taxon & | add_child (std::string const &name) |
Add a child Taxon by creating a new one with the given name and return it. More... | |
Taxon const & | at (size_t index) const |
Return the child Taxon at the given index. More... | |
Taxon & | at (size_t index) |
Return the child Taxon at the given index. More... | |
iterator | begin () |
Return an iterator to the beginning of the child taxa. More... | |
const_iterator | begin () const |
Return a const iterator to the beginning of the child taxa. More... | |
const_iterator | cbegin () const |
Return a const iterator to the beginning of the child taxa. More... | |
const_iterator | cend () const |
Return a const iterator to the end of the child taxa. More... | |
void | clear_children () |
Remove all children. More... | |
iterator | end () |
Return an iterator to the end of the child taxa. More... | |
const_iterator | end () const |
Return a const iterator to the end of the child taxa. More... | |
Taxon const & | get_child (std::string name) const |
Return the child Taxon with a given name if it exists, or throw otherwise. More... | |
Taxon & | get_child (std::string name) |
Return the child Taxon with a given name if it exists, or throw otherwise. More... | |
bool | has_child (std::string name) const |
Return whether an immediate child Taxon with the given name exists. More... | |
size_t | index_of (std::string const &name) const |
Taxonomy & | operator= (Taxonomy const &) |
Copy assigment operator. More... | |
Taxonomy & | operator= (Taxonomy &&) |
Move assignment operator. More... | |
Taxon const & | operator[] (std::string name) const |
Return the child Taxon with a given name if it exists, or throw otherwise. More... | |
Taxon & | operator[] (std::string name) |
Return the child Taxon with a given name if it exists, or throw otherwise. More... | |
Taxon const & | operator[] (size_t index) const |
Return the child Taxon at the given index. More... | |
Taxon & | operator[] (size_t index) |
Return the child Taxon at the given index. More... | |
void | remove_child (std::string const &name) |
Remove a child Taxon with a certain name. More... | |
size_t | size () const |
Return the number of immediate child Taxa. More... | |
Public Attributes | |
friend | Taxonomy |
Taxonomy is a friend, as it needs access to parent_ in order to ensure consistency. More... | |
Protected Member Functions | |
Taxon & | add_child_ (Taxon const &child) override |
Virtual implementation function for adding a child taxon. More... | |
![]() | |
void | reset_parent_pointers_ (Taxon *parent) |
Internal helper function that resets the parent pointer of all stored Taxa. More... | |
Friends | |
void | swap (Taxon &lhs, Taxon &rhs) |
Swapperator for Taxon. More... | |
Additional Inherited Members | |
![]() | |
typedef std::vector< Taxon > ::const_iterator | const_iterator |
typedef std::vector< Taxon > ::iterator | iterator |
Taxon | ( | std::string const & | name | ) |
|
virtualdefault |
Copy constructor.
We need a custom version of this in order to set the Taxon::parent() pointers of all children correctly when copying and to copy the data.
Copying first sets the parent() pointer to nullptr
. This is because we might want to get a 'blank' copy, i.e., a Taxon that is not attached to a Taxonomy. This way, the functions expecting a parent pointer don't get a potentially invalid pointer.
If however we copy a Taxon into a Taxonomy (or into some other Taxon), reset_parent_pointers_() is called later anyway, which then sets the parent pointer to the correct value.
Move constructor.
We need a custom version of this in order to set the Taxon::parent() pointers of all children correctly, and to treat the data correctlty when copying.
Virtual implementation function for adding a child taxon.
See Taxonomy::add_child_() for details. In addition to the base class implementation, this function also sets the parent pointer of the Taxon.
Reimplemented from Taxonomy.
BaseTaxonData * data_ptr | ( | ) |
BaseTaxonData const * data_ptr | ( | ) | const |
bool has_data | ( | ) | const |
std::string const & name | ( | ) | const |
void name | ( | std::string const & | value | ) |
Copy assignment operator.
We need a custom version of this in order to set the Taxon::parent() pointers of all children correctly, and to treat the data correctlty when copying.
See the move constructor for details.
Move assignment operator.
We need a custom version of this in order to set the Taxon::parent() pointers of all children correctly, and to treat the data correctlty when copying.
Taxon const * parent | ( | ) | const |
Taxon * parent | ( | ) |
std::string const & rank | ( | ) | const |
void rank | ( | std::string const & | value | ) |
Taxon & reset_data | ( | std::unique_ptr< BaseTaxonData > | data | ) |
Reset the data pointer of this Taxon.
Using this function, a Taxon can be assigend new data. It is also possible to change the data type completely (as long as it derives from BaseTaxonData). Be however aware that many functions that work with a Taxonomy expect a certain data type. Thus, changing it might break those functions and lead to exceptions and other errors.
friend Taxonomy |