A library for working with phylogenetic and population genetic data.
v0.32.0
BaseNodeData Class Reference

#include <genesis/tree/tree/node_data.hpp>

Inherited by CommonNodeData.

Detailed Description

Base class for storing data on Nodes of a Tree.

This class provides the start point for the class hierarchy of node data classes. In order to correctly achieve polymorphic behaviour, and with its use case in a Tree in mind, this class and its derived classes are supposed to be used via unique pointers to their instances. Although this yields automatic memory management, it unfortunately disallows covariant return types.

The class thus provides a static create() function instead of a default constructor. This needs to be reimplemented in derived classes in order to allow creation of objects of the exact derived type. For similar reasons, instead of a copy constructor, it provides a clone() function.

Furthermore, the class provides a virtual recreate() function that default-constructs an object of the same derived type as it was called on. This is allows to create new data instances for a Tree without the need to know the exact derived type. For example, this can be used when adding new Nodes to a Tree, in order to fill them with default-constructed data of the same type of some other Nodes of the Tree.

It is recommended that derived classes follow the same access rules for its constructors. See CommonNodeData for an example.

This class does not contain any data itself. See BaseEdgeData for its "partner" class.

Definition at line 66 of file node_data.hpp.

Public Member Functions

 BaseNodeData (BaseNodeData &&)=delete
 Deleted move constructor. More...
 
virtual ~BaseNodeData ()=default
 Virtual destructor. Needed for polymorphism. More...
 
virtual std::unique_ptr< BaseNodeDataclone () const
 Polymorphically copy an instance of this class. Use instead of copy constructor. More...
 
BaseNodeDataoperator= (BaseNodeData &&)=delete
 Deleted move assignment. More...
 
virtual std::unique_ptr< BaseNodeDatarecreate () const
 Polymorphically create a default-constructed instance of this class with the same derived type as it was called on. More...
 

Static Public Member Functions

static std::unique_ptr< BaseNodeDatacreate ()
 Create a new instance of this class. Use instead of default constructor. More...
 

Protected Member Functions

 BaseNodeData ()=default
 Protected default constructor. Called from the create() function. More...
 
 BaseNodeData (BaseNodeData const &)=default
 Protected copy constructor. Called from the clone() function. More...
 
BaseNodeDataoperator= (BaseNodeData const &)=default
 Protected copy assignment. Not used right now. More...
 

Constructor & Destructor Documentation

◆ ~BaseNodeData()

virtual ~BaseNodeData ( )
virtualdefault

Virtual destructor. Needed for polymorphism.

◆ BaseNodeData() [1/3]

BaseNodeData ( BaseNodeData &&  )
delete

Deleted move constructor.

Not viable with polymorphism. Also, we don't need it. The data is held by pointer (in order to allow polymorphism in the first place), so we can simply move the pointer instead.

◆ BaseNodeData() [2/3]

BaseNodeData ( )
protecteddefault

Protected default constructor. Called from the create() function.

◆ BaseNodeData() [3/3]

BaseNodeData ( BaseNodeData const &  )
protecteddefault

Protected copy constructor. Called from the clone() function.

Member Function Documentation

◆ clone()

virtual std::unique_ptr< BaseNodeData > clone ( ) const
inlinevirtual

Polymorphically copy an instance of this class. Use instead of copy constructor.

Reimplemented in SimpleNewickNodeData, MassTreeNodeData, AttributeTreeNodeData, PlacementNodeData, LayoutNodeData, and CommonNodeData.

Definition at line 134 of file node_data.hpp.

◆ create()

static std::unique_ptr< BaseNodeData > create ( )
inlinestatic

Create a new instance of this class. Use instead of default constructor.

Definition at line 117 of file node_data.hpp.

◆ operator=() [1/2]

BaseNodeData& operator= ( BaseNodeData &&  )
delete

Deleted move assignment.

Not viable with polymorphism. Also, we don't need it. The data is held by pointer (in order to allow polymorphism in the first place), so we can simply move the pointer instead.

◆ operator=() [2/2]

BaseNodeData& operator= ( BaseNodeData const &  )
protecteddefault

Protected copy assignment. Not used right now.

◆ recreate()

virtual std::unique_ptr< BaseNodeData > recreate ( ) const
inlinevirtual

Polymorphically create a default-constructed instance of this class with the same derived type as it was called on.

Reimplemented in SimpleNewickNodeData, MassTreeNodeData, AttributeTreeNodeData, PlacementNodeData, LayoutNodeData, and CommonNodeData.

Definition at line 126 of file node_data.hpp.


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