bpp-phyl  2.1.0
 All Classes Namespaces Files Functions Variables Friends Pages
NodeTemplate.h
Go to the documentation of this file.
1 //
2 // File: NodeTemplate.h
3 // Created by: Vincent Ranwez
4 // Julien Dutheil
5 // Created on: Thu Jun 28 18:11 2005
6 //
7 
8 /*
9 Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
10 
11 This software is a computer program whose purpose is to provide classes
12 for phylogenetic data analysis.
13 
14 This software is governed by the CeCILL license under French law and
15 abiding by the rules of distribution of free software. You can use,
16 modify and/ or redistribute the software under the terms of the CeCILL
17 license as circulated by CEA, CNRS and INRIA at the following URL
18 "http://www.cecill.info".
19 
20 As a counterpart to the access to the source code and rights to copy,
21 modify and redistribute granted by the license, users are provided only
22 with a limited warranty and the software's author, the holder of the
23 economic rights, and the successive licensors have only limited
24 liability.
25 
26 In this respect, the user's attention is drawn to the risks associated
27 with loading, using, modifying and/or developing or reproducing the
28 software by the user in light of its specific status of free software,
29 that may mean that it is complicated to manipulate, and that also
30 therefore means that it is reserved for developers and experienced
31 professionals having in-depth computer knowledge. Users are therefore
32 encouraged to load and test the software's suitability as regards their
33 requirements in conditions enabling the security of their systems and/or
34 data to be ensured and, more generally, to use and operate it in the
35 same conditions as regards security.
36 
37 The fact that you are presently reading this means that you have had
38 knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef _NODETEMPLATE_H_
42 #define _NODETEMPLATE_H_
43 
44 #include "Node.h"
45 
46 namespace bpp
47 {
48 
72 template<class NodeInfos>
73 class NodeTemplate :
74  public Node
75 {
76  friend class TreeTemplateTools;
77 
78  private:
79 
80  NodeInfos infos_;
81 
82  public:
83 
87  NodeTemplate() : Node(), infos_() {}
88 
92  NodeTemplate(int id) : Node(id), infos_() {}
93 
97  NodeTemplate(const std::string& name) : Node(name), infos_() {}
98 
102  NodeTemplate(int id, const std::string& name) : Node(id, name), infos_() {}
103 
104  protected:
110  NodeTemplate(const Node& node) : Node(node), infos_() {}
111 
118  Node(node), infos_(node.infos_)
119  {}
120 
128  {
129  Node::operator=(node);
130  infos_ = node.infos_;
131  return *this;
132  }
133 
134  NodeTemplate<NodeInfos>* clone() const { return new NodeTemplate<NodeInfos>(*this); }
135 
136  public:
137  virtual ~NodeTemplate() {}
138 
139  public:
140 
141  const NodeTemplate<NodeInfos>* getFather() const { return dynamic_cast<const NodeTemplate<NodeInfos> *>(father_); }
142 
144 
146 
147  const NodeTemplate<NodeInfos>* getSon(size_t i) const throw (IndexOutOfBoundsException) { return dynamic_cast<NodeTemplate<NodeInfos> *>(sons_[i]); }
148 
149  NodeTemplate<NodeInfos>* getSon(size_t i) throw (IndexOutOfBoundsException) { return dynamic_cast<NodeTemplate<NodeInfos> *>(sons_[i]); }
150 
151  std::vector<const NodeTemplate<NodeInfos>*> getNeighbors() const
152  {
153  std::vector<const Node*> neighbors = Node::getNeighbors();
154  std::vector<const NodeTemplate<NodeInfos>*> neighbors2(neighbors.size());
155  for (size_t i = 0; i < neighbors.size(); i++)
156  neighbors2[i] = dynamic_cast<const NodeTemplate<NodeInfos>*>(neighbors[i]);
157  return neighbors2;
158  }
159 
160  std::vector<NodeTemplate<NodeInfos>*> getNeighbors()
161  {
162  std::vector<Node*> neighbors = Node::getNeighbors();
163  std::vector<NodeTemplate<NodeInfos>*> neighbors2(neighbors.size());
164  for (size_t i = 0; i < neighbors.size(); i++)
165  neighbors2[i] = dynamic_cast<NodeTemplate<NodeInfos>*>(neighbors[i]);
166  return neighbors2;
167  }
168 
169  NodeTemplate<NodeInfos>* operator[](int i) { return dynamic_cast<NodeTemplate<NodeInfos>*>((i < 0) ? father_ : sons_[i]); }
170 
171  const NodeTemplate<NodeInfos>* operator[](int i) const { return dynamic_cast<const NodeTemplate<NodeInfos> *>((i < 0) ? father_ : sons_[i]); }
172 
173 
174  // Specific methods:
175 
179  virtual const NodeInfos& getInfos() const { return infos_; }
180 
184  virtual NodeInfos& getInfos() { return infos_; }
185 
191  virtual void setInfos(const NodeInfos& infos) { infos_ = infos; }
192 
193 };
194 
195 } //end of namespace bpp.
196 
197 #endif //_NODETEMPLATE_H_
198