Claw  1.7.3
binary_node.tpp
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
25 /**
26  * \file binary_node.tpp
27  * \brief The binary_node class implementation.
28  * \author Julien Jorge
29  */
30 
31 #include <cstddef>
32 
33 /*---------------------------------------------------------------------------*/
34 /**
35  * \brief Binary node constructor.
36  * \post (left==NULL) && (right==NULL)
37  */
38 template< class U >
39 claw::binary_node<U>::binary_node()
40  : left(NULL), right(NULL)
41 {
42 
43 } //binary_node()
44 
45 /*---------------------------------------------------------------------------*/
46 /**
47  * \brief Binary node copy constructor.
48  * \param that Node to copy from.
49  */
50 template< class U >
51 claw::binary_node<U>::binary_node( const binary_node& that )
52 {
53  if (that.left)
54  left = new U( * that.left );
55  else
56  left = NULL;
57 
58  if ( that.right )
59  right = new U( * that.right );
60  else
61  right = NULL;
62 } // binary_node() [copy constructor]
63 
64 /*---------------------------------------------------------------------------*/
65 /**
66  * \brief Clear right and left childs. Memory's not freed.
67  * \post this->left == NULL && this->right == NULL
68  */
69 template< class U >
70 void claw::binary_node<U>::clear()
71 {
72  left = NULL;
73  right = NULL;
74 } // clear()
75 
76 /*---------------------------------------------------------------------------*/
77 /**
78  * \brief Binary node destructor.
79  * Deletes the whole subtree.
80  */
81 template< class U >
82 claw::binary_node<U>::~binary_node()
83 {
84  if (left)
85  delete left;
86 
87  if (right)
88  delete right;
89 } // ~binary_node() [destructor]