bpp-phyl3  3.0.0
NodeTemplate.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_PHYL_TREE_NODETEMPLATE_H
6 #define BPP_PHYL_TREE_NODETEMPLATE_H
7 
8 
9 #include "Node.h"
10 
11 namespace bpp
12 {
36 template<class NodeInfos>
37 class NodeTemplate :
38  public Node
39 {
40  friend class TreeTemplateTools;
41 
42 private:
43  NodeInfos infos_;
44 
45 public:
49  NodeTemplate() : Node(), infos_() {}
50 
54  NodeTemplate(int id) : Node(id), infos_() {}
55 
59  NodeTemplate(const std::string& name) : Node(name), infos_() {}
60 
64  NodeTemplate(int id, const std::string& name) : Node(id, name), infos_() {}
65 
66 protected:
72  NodeTemplate(const Node& node) : Node(node), infos_() {}
73 
80  Node(node), infos_(node.infos_)
81  {}
82 
90  {
91  Node::operator=(node);
92  infos_ = node.infos_;
93  return *this;
94  }
95 
96  NodeTemplate<NodeInfos>* clone() const { return new NodeTemplate<NodeInfos>(*this); }
97 
98 public:
99  virtual ~NodeTemplate() {}
100 
101 public:
102  const NodeTemplate<NodeInfos>* getFather() const { return dynamic_cast<const NodeTemplate<NodeInfos>*>(father_); }
103 
105 
107 
108  const NodeTemplate<NodeInfos>* getSon(size_t i) const { return dynamic_cast<NodeTemplate<NodeInfos>*>(sons_[i]); }
109 
110  NodeTemplate<NodeInfos>* getSon(size_t i) { return dynamic_cast<NodeTemplate<NodeInfos>*>(sons_[i]); }
111 
112  std::vector<const NodeTemplate<NodeInfos>*> getNeighbors() const
113  {
114  std::vector<const Node*> neighbors = Node::getNeighbors();
115  std::vector<const NodeTemplate<NodeInfos>*> neighbors2(neighbors.size());
116  for (size_t i = 0; i < neighbors.size(); i++)
117  {
118  neighbors2[i] = dynamic_cast<const NodeTemplate<NodeInfos>*>(neighbors[i]);
119  }
120  return neighbors2;
121  }
122 
123  std::vector<NodeTemplate<NodeInfos>*> getNeighbors()
124  {
125  std::vector<Node*> neighbors = Node::getNeighbors();
126  std::vector<NodeTemplate<NodeInfos>*> neighbors2(neighbors.size());
127  for (size_t i = 0; i < neighbors.size(); i++)
128  {
129  neighbors2[i] = dynamic_cast<NodeTemplate<NodeInfos>*>(neighbors[i]);
130  }
131  return neighbors2;
132  }
133 
134  NodeTemplate<NodeInfos>* operator[](int i) { return dynamic_cast<NodeTemplate<NodeInfos>*>((i < 0) ? father_ : sons_[i]); }
135 
136  const NodeTemplate<NodeInfos>* operator[](int i) const { return dynamic_cast<const NodeTemplate<NodeInfos>*>((i < 0) ? father_ : sons_[i]); }
137 
138 
139  // Specific methods:
140 
144  virtual const NodeInfos& getInfos() const { return infos_; }
145 
149  virtual NodeInfos& getInfos() { return infos_; }
150 
156  virtual void setInfos(const NodeInfos& infos) { infos_ = infos; }
157 };
158 } // end of namespace bpp.
159 #endif // BPP_PHYL_TREE_NODETEMPLATE_H
The NodeTemplate class.
Definition: NodeTemplate.h:39
NodeTemplate< NodeInfos > * getFather()
Get the father of this node is there is one.
Definition: NodeTemplate.h:104
NodeInfos infos_
Definition: NodeTemplate.h:43
virtual NodeInfos & getInfos()
Definition: NodeTemplate.h:149
virtual ~NodeTemplate()
Definition: NodeTemplate.h:99
NodeTemplate< NodeInfos > * clone() const
Definition: NodeTemplate.h:96
NodeTemplate< NodeInfos > * getSon(size_t i)
Definition: NodeTemplate.h:110
const NodeTemplate< NodeInfos > * operator[](int i) const
Definition: NodeTemplate.h:136
std::vector< const NodeTemplate< NodeInfos > * > getNeighbors() const
Definition: NodeTemplate.h:112
NodeTemplate(const NodeTemplate< NodeInfos > &node)
Copy constructor.
Definition: NodeTemplate.h:79
NodeTemplate(int id)
Build a new NodeTemplate with specified id.
Definition: NodeTemplate.h:54
std::vector< NodeTemplate< NodeInfos > * > getNeighbors()
Definition: NodeTemplate.h:123
virtual void setInfos(const NodeInfos &infos)
Set the information to be associated to this node.
Definition: NodeTemplate.h:156
NodeTemplate< NodeInfos > * operator[](int i)
Definition: NodeTemplate.h:134
NodeTemplate< NodeInfos > & operator=(const NodeTemplate< NodeInfos > &node)
Assignation operator.
Definition: NodeTemplate.h:89
const NodeTemplate< NodeInfos > * getSon(size_t i) const
Definition: NodeTemplate.h:108
NodeTemplate(const std::string &name)
Build a new NodeTemplate with specified name.
Definition: NodeTemplate.h:59
NodeTemplate()
Build a new void NodeTemplate object.
Definition: NodeTemplate.h:49
NodeTemplate(int id, const std::string &name)
Build a new NodeTemplate with specified id and name.
Definition: NodeTemplate.h:64
const NodeTemplate< NodeInfos > * getFather() const
Get the father of this node is there is one.
Definition: NodeTemplate.h:102
NodeTemplate(const Node &node)
Copy constructor.
Definition: NodeTemplate.h:72
NodeTemplate< NodeInfos > * removeFather()
Remove the father of this node.
Definition: NodeTemplate.h:106
virtual const NodeInfos & getInfos() const
Definition: NodeTemplate.h:144
The phylogenetic node class.
Definition: Node.h:59
Node * father_
Definition: Node.h:64
Node & operator=(const Node &node)
Assignation operator.
Definition: Node.cpp:42
std::vector< Node * > sons_
Definition: Node.h:63
std::vector< const Node * > getNeighbors() const
Definition: Node.cpp:127
Utilitary methods working with TreeTemplate and Node objects.
Defines the basic types of data flow nodes.