45 #include <Bpp/Clonable.h> 46 #include <Bpp/Utils/MapTools.h> 47 #include <Bpp/BppString.h> 48 #include <Bpp/Numeric/Number.h> 132 Node(
const std::string& name) :
145 Node(
int id,
const std::string& name) :
214 std::vector<int> sonsId(
sons_.size());
215 for (
size_t i = 0; i <
sons_.size(); i++)
217 sonsId[i] =
sons_[i]->getId();
250 name_ =
new std::string(name);
286 throw NodePException(
"Node::getDistanceToFather: Node has no distance.",
this);
358 throw NullPointerException(
"Node::setFather(). Empty node given as input.");
360 if (find(node->sons_.begin(), node->sons_.end(),
this) == node->sons_.end())
361 node->
sons_.push_back(
this);
363 std::cerr <<
"DEVEL warning: Node::setFather. Son node already registered! No pb here, but could be a bug in your implementation..." << std::endl;
395 virtual const Node*
getSon(
size_t pos)
const throw (IndexOutOfBoundsException)
397 if (pos >=
sons_.size())
throw IndexOutOfBoundsException(
"Node::getSon().", pos, 0,
sons_.size() - 1);
401 virtual Node*
getSon(
size_t pos)
throw (IndexOutOfBoundsException)
403 if (pos >=
sons_.size())
throw IndexOutOfBoundsException(
"Node::getSon().", pos, 0,
sons_.size() - 1);
410 throw NullPointerException(
"Node::addSon(). Empty node given as input.");
412 sons_.insert(
sons_.begin() +
static_cast<ptrdiff_t
>(pos), node);
414 std::cerr <<
"DEVEL warning: Node::addSon. Son node already registered! No pb here, but could be a bug in your implementation..." << std::endl;
416 node->father_ =
this;
422 throw NullPointerException(
"Node::addSon(). Empty node given as input.");
424 sons_.push_back(node);
426 throw NodePException(
"Node::addSon. Trying to add a node which is already present.");
427 node->father_ =
this;
433 throw NullPointerException(
"Node::setSon(). Empty node given as input.");
434 if (pos >=
sons_.size())
435 throw IndexOutOfBoundsException(
"Node::setSon(). Invalid node position.", pos, 0,
sons_.size() - 1);
436 std::vector<Node*>::iterator search = find(
sons_.begin(),
sons_.end(), node);
437 if (search ==
sons_.end() || search ==
sons_.begin() +
static_cast<ptrdiff_t
>(pos))
440 throw NodePException(
"Node::setSon. Trying to set a node which is already present.");
441 node->father_ =
this;
446 if (pos >=
sons_.size())
447 throw IndexOutOfBoundsException(
"Node::removeSon(). Invalid node position.", pos, 0,
sons_.size() - 1);
449 sons_.erase(
sons_.begin() +
static_cast<ptrdiff_t
>(pos));
457 throw NullPointerException(
"Node::removeSon(). Empty node given as input.");
458 for (
size_t i = 0; i <
sons_.size(); i++)
460 if (
sons_[i] == node)
462 sons_.erase(
sons_.begin() +
static_cast<ptrdiff_t
>(i));
463 node->removeFather();
472 while (
sons_.size() != 0)
476 virtual void swap(
size_t branch1,
size_t branch2)
throw (IndexOutOfBoundsException);
688 virtual
bool operator==(const
Node& node)
const {
return id_ == node.id_; }
virtual void addSon(size_t pos, Node *node)
virtual std::vector< std::string > getBranchPropertyNames() const
virtual bool hasNodeProperty(const std::string &name) const
virtual std::string getName() const
Get the name associated to this node, if there is one, otherwise throw a NodeException.
virtual void removeSons()
virtual bool hasName() const
Tell is this node has a name.
virtual void deleteBranchProperties()
Delete all branch properties.
virtual Clonable * removeBranchProperty(const std::string &name)
virtual std::vector< int > getSonsId() const
virtual void deleteNodeProperty(const std::string &name)
virtual void setSon(size_t pos, Node *node)
virtual Clonable * getBranchProperty(const std::string &name)
std::vector< Node * > sons_
virtual const Node * getSon(size_t pos) const
virtual bool hasDistanceToFather() const
Tell is this node has a distance to the father.
virtual const Clonable * getBranchProperty(const std::string &name) const
Node(const std::string &name)
Build a new Node with specified name.
virtual const Node * getFather() const
Get the father of this node is there is one.
virtual int getFatherId() const
virtual void removeNodeProperties()
Remove all node properties.
virtual bool hasBootstrapValue() const
virtual void deleteBranchProperty(const std::string &name)
virtual void setName(const std::string &name)
Give a name or update the name associated to the node.
virtual void deleteNodeProperties()
Delete all node properties.
Node & operator=(const Node &node)
Assignation operator.
double * distanceToFather_
virtual void addSon(Node *node)
virtual bool hasFather() const
Tell if this node has a father node.
virtual bool isLeaf() const
virtual double getDistanceToFather() const
Get the distance to the father node is there is one, otherwise throw a NodeException.
Node(int id)
Build a new Node with specified id.
virtual int getId() const
Get the node's id.
virtual Node * removeFather()
Remove the father of this node.
std::vector< const Node * > getNeighbors() const
virtual Node * removeSon(size_t pos)
std::map< std::string, Clonable * > nodeProperties_
std::map< std::string, Clonable * > branchProperties_
virtual size_t getSonPosition(const Node *son) const
Exception thrown when something is wrong with a particular node.
virtual void removeSon(Node *node)
The phylogenetic node class.
virtual void setId(int id)
Set this node's id.
virtual Clonable * getNodeProperty(const std::string &name)
virtual void swap(size_t branch1, size_t branch2)
Node(int id, const std::string &name)
Build a new Node with specified id and name.
General exception thrown if a property could not be found.
virtual void setDistanceToFather(double distance)
Set or update the distance toward the father node.
virtual size_t getNumberOfSons() const
virtual const Clonable * getNodeProperty(const std::string &name) const
virtual void setFather(Node *node)
Set the father node of this node.
virtual Node * getSon(size_t pos)
General exception thrown when something is wrong with a particular node.
virtual std::vector< Node * > & getSons()
const Node * operator[](int i) const
virtual void deleteName()
Delete the name associated to this node (do nothing if there is no name).
virtual size_t degree() const
virtual void removeBranchProperties()
Remove all branch properties.
Node()
Build a new void Node object.
virtual Clonable * removeNodeProperty(const std::string &name)
virtual void deleteDistanceToFather()
Delete the distance to the father node.
virtual Node * getFather()
Get the father of this node is there is one.
virtual std::vector< std::string > getNodePropertyNames() const
virtual bool hasBranchProperty(const std::string &name) const
virtual void setBranchProperty(const std::string &name, const Clonable &property)
Set/add a branch property.
virtual void setNodeProperty(const std::string &name, const Clonable &property)
Set/add a node property.
virtual double getBootstrapValue() const