2
// File: NodeTemplate.h
3
// Created by: Vincent Ranwez
5
// Created on: Thu Jun 28 18:11 2005
9
Copyright or © or Copr. Julien Dutheil, (November 16, 2004)
11
Julien.Dutheil@univ-montp2.fr
13
This software is a computer program whose purpose is to provide classes
14
for phylogenetic data analysis.
16
This software is governed by the CeCILL license under French law and
17
abiding by the rules of distribution of free software. You can use,
18
modify and/ or redistribute the software under the terms of the CeCILL
19
license as circulated by CEA, CNRS and INRIA at the following URL
20
"http://www.cecill.info".
22
As a counterpart to the access to the source code and rights to copy,
23
modify and redistribute granted by the license, users are provided only
24
with a limited warranty and the software's author, the holder of the
25
economic rights, and the successive licensors have only limited
28
In this respect, the user's attention is drawn to the risks associated
29
with loading, using, modifying and/or developing or reproducing the
30
software by the user in light of its specific status of free software,
31
that may mean that it is complicated to manipulate, and that also
32
therefore means that it is reserved for developers and experienced
33
professionals having in-depth computer knowledge. Users are therefore
34
encouraged to load and test the software's suitability as regards their
35
requirements in conditions enabling the security of their systems and/or
36
data to be ensured and, more generally, to use and operate it in the
37
same conditions as regards security.
39
The fact that you are presently reading this means that you have had
40
knowledge of the CeCILL license and that you accept its terms.
43
#ifndef _NODETEMPLATE_H_
44
#define _NODETEMPLATE_H_
52
* @brief The NodeTemplate class.
54
* This class inherits from the Node class.
55
* Its is a generic way to store any information to a node.
56
* A NodeTemplate only add the setInfos and getInfos methods,
57
* which set and retrieve a NodeInfo, whose type is given as a template
59
* This class is mainly for computation conveniency, one may define a NodeInfo
60
* class with several results attached.
61
* An example is provided in the PGMA class.
62
* Another way is to use a map<Node *, NodeInfos>, with the limitation of the
64
* One may also wish to use the property system of the Node class, but
65
* properties are stored as in a map<string, Clonable *>, with the drawbacks
66
* of the slow map access and the systematic use of dynamic_cast<NodeInfo *> to
67
* convert from Clonable *.
69
* This class redefines all constructors and access methods (get*) with return
70
* types as NodeTemplate and not Node (using covariant returns).
72
* @see Node, TreeTemplate
74
template<class NodeInfos>
75
class NodeTemplate : public Node
85
* @brief Build a new void NodeTemplate object.
87
NodeTemplate() : Node(), infos_() {}
90
* @brief Build a new NodeTemplate with specified id.
92
NodeTemplate(int id) : Node(id), infos_() {}
95
* @brief Build a new NodeTemplate with specified name.
97
NodeTemplate(const std::string& name) : Node(name), infos_() {}
100
* @brief Build a new NodeTemplate with specified id and name.
102
NodeTemplate(int id, const std::string& name) : Node(id, name), infos_() {}
105
* @brief Copy constructor.
107
* @param node The node to copy.
109
NodeTemplate(const Node& node) : Node(node), infos_() {}
112
* @brief Copy constructor.
114
* @param node The node to copy.
116
NodeTemplate(const NodeTemplate<NodeInfos>& node):
117
Node(node), infos_(node.infos_)
121
* @brief Assignation operator.
123
* @param node the node to copy.
124
* @return A reference toward this node.
126
NodeTemplate<NodeInfos>& operator=(const NodeTemplate<NodeInfos>& node)
128
Node::operator=(node);
129
infos_ = node.infos_;
133
virtual ~NodeTemplate() {}
135
NodeTemplate<NodeInfos>* clone() const { return new NodeTemplate<NodeInfos>(*this); }
139
const NodeTemplate<NodeInfos>* getFather() const { return dynamic_cast<const NodeTemplate<NodeInfos> *>(father_); }
141
NodeTemplate<NodeInfos>* getFather() { return dynamic_cast<NodeTemplate<NodeInfos> *>(father_); }
143
NodeTemplate<NodeInfos>* removeFather() { NodeTemplate<NodeInfos> * f = dynamic_cast<NodeTemplate<NodeInfos> *>(father_); father_ = 0; return f; }
145
const NodeTemplate<NodeInfos>* getSon(unsigned int i) const throw (IndexOutOfBoundsException) { return dynamic_cast<NodeTemplate<NodeInfos> *>(sons_[i]); }
147
NodeTemplate<NodeInfos>* getSon(unsigned int i) throw (IndexOutOfBoundsException) { return dynamic_cast<NodeTemplate<NodeInfos> *>(sons_[i]); }
149
std::vector<const NodeTemplate<NodeInfos>*> getNeighbors() const
151
std::vector<const Node*> neighbors = Node::getNeighbors();
152
std::vector<const NodeTemplate<NodeInfos>*> neighbors2(neighbors.size());
153
for (unsigned int i = 0; i < neighbors.size(); i++)
154
neighbors2[i] = dynamic_cast<const NodeTemplate<NodeInfos>*>(neighbors[i]);
158
std::vector<NodeTemplate<NodeInfos>*> getNeighbors()
160
std::vector<Node*> neighbors = Node::getNeighbors();
161
std::vector<NodeTemplate<NodeInfos>*> neighbors2(neighbors.size());
162
for (unsigned int i = 0; i < neighbors.size(); i++)
163
neighbors2[i] = dynamic_cast<NodeTemplate<NodeInfos>*>(neighbors[i]);
167
NodeTemplate<NodeInfos>* operator[](int i) { return dynamic_cast<NodeTemplate<NodeInfos>*>((i < 0) ? father_ : sons_[i]); }
169
const NodeTemplate<NodeInfos>* operator[](int i) const { return dynamic_cast<const NodeTemplate<NodeInfos> *>((i < 0) ? father_ : sons_[i]); }
175
* @return A reference toward the information object associated to this node.
177
virtual const NodeInfos& getInfos() const { return infos_; }
180
* @return A reference toward the information object associated to this node.
182
virtual NodeInfos& getInfos() { return infos_; }
185
* @brief Set the information to be associated to this node.
187
* @param infos An information object.
189
virtual void setInfos(const NodeInfos& infos) { infos_ = infos; }
193
} //end of namespace bpp.
195
#endif //_NODETEMPLATE_H_