bpp-phyl3 3.0.0
AwareNode.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#include <Bpp/Exceptions.h>
7
8#include "AwareNode.h"
9
10using namespace bpp;
11using namespace std;
12
15AwareNode::AwareNode(const AwareNode& node) :
16 id_(node.id_),
17 sons_(), father_(),
18 distanceToFather_(node.distanceToFather_)
19{}
20
24{
25 id_ = node.id_;
26 father_ = 0;
28 sons_.clear();
29
30 return *this;
31}
32
35void AwareNode::swap(size_t branch1, size_t branch2)
36{
37 if (branch1 > branch2)
38 {
39 size_t tmp = branch1;
40 branch1 = branch2;
41 branch2 = tmp;
42 }
43 AwareNode* node1 = getSon(branch1);
44 AwareNode* node2 = getSon(branch2);
45 removeSon(node1);
46 removeSon(node2);
47 addSon(branch1, node2);
48 addSon(branch2, node1);
49}
50
51size_t AwareNode::getSonPosition(const AwareNode* son) const
52{
53 if (!son)
54 throw NullPointerException("Node::getSonPosition(). Empty node given as input.");
55 for (size_t i = 0; i < sons_.size(); i++)
56 {
57 if (sons_[i] == son)
58 return i;
59 }
60 throw Exception("Son not found: " + TextTools::toString(son->getId()));
61}
62
63/******************************************************************************/
A node class aware of its neighbours.
Definition: AwareNode.h:43
AwareNode & operator=(const AwareNode &node)
Assignation operator.
Definition: AwareNode.cpp:23
AwareNode * father_
Definition: AwareNode.h:47
virtual const AwareNode * getSon(size_t pos) const
Definition: AwareNode.h:239
virtual size_t getSonPosition(const AwareNode *son) const
Definition: AwareNode.cpp:51
unsigned int id_
Definition: AwareNode.h:45
virtual void removeSon(size_t pos)
Definition: AwareNode.h:284
virtual void swap(size_t branch1, size_t branch2)
Definition: AwareNode.cpp:35
double distanceToFather_
Definition: AwareNode.h:48
std::vector< AwareNode * > sons_
Definition: AwareNode.h:46
virtual unsigned int getId() const
Get the node's id.
Definition: AwareNode.h:121
virtual void addSon(size_t pos, AwareNode *node)
Definition: AwareNode.h:251
std::string toString(T t)
Defines the basic types of data flow nodes.