tree.tpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00031 /*----------------------------------------------------------------------------*/
00035 template<typename T>
00036 claw::tree<T>::tree()
00037   : value()
00038 {
00039 
00040 } // tree::tree()
00041 
00042 /*----------------------------------------------------------------------------*/
00047 template<typename T>
00048 claw::tree<T>::tree( const T& v )
00049   : value(v)
00050 {
00051 
00052 } // tree::tree()
00053 
00054 /*----------------------------------------------------------------------------*/
00059 template<typename T>
00060 bool claw::tree<T>::operator==( const self_type& that ) const
00061 {
00062   bool result = ( value == that.value );
00063 
00064   if (result)
00065     {
00066       typename child_list::const_iterator it_me = m_child.begin();
00067       typename child_list::const_iterator it_him = that.m_child.begin();
00068       typename child_list::const_iterator eit_me = m_child.end();
00069       typename child_list::const_iterator eit_him = that.m_child.end();
00070   
00071       while ( result && (it_me!=eit_me) && (it_him!=eit_him) )
00072         result = (*it_me == *it_him);
00073 
00074       if ( (it_me!=eit_me) || (it_him!=eit_him) )
00075         result = false;
00076     }
00077 
00078   return result;
00079 } // tree::operator==()
00080 
00081 /*----------------------------------------------------------------------------*/
00085 template<typename T>
00086 bool claw::tree<T>::is_leaf() const
00087 {
00088   return m_child.empty();
00089 } // tree::is_leaf()
00090 
00091 /*----------------------------------------------------------------------------*/
00096 template<typename T>
00097 typename claw::tree<T>::self_type& claw::tree<T>::add_child( const T& v )
00098 {
00099   m_child.push_back( self_type(v) );
00100   return m_child.back();
00101 } // tree::add_child()
00102 
00103 /*----------------------------------------------------------------------------*/
00108 template<typename T>
00109 typename claw::tree<T>::self_type&
00110 claw::tree<T>::add_child( const self_type& v )
00111 {
00112   m_child.push_back( v );
00113 } // tree::add_child()
00114 
00115 /*----------------------------------------------------------------------------*/
00120 template<typename T>
00121 typename claw::tree<T>::iterator claw::tree<T>::find( const T& v )
00122 {
00123   typename child_list::iterator it;
00124   bool found = false;
00125 
00126   for ( it=m_child.begin(); !found && (it!=end()) ; )
00127     if ( it->value == v )
00128       found = true;
00129     else
00130       ++it;
00131 
00132   return iterator( it );
00133 } // tree::find()
00134 
00135 /*----------------------------------------------------------------------------*/
00140 template<typename T>
00141 typename claw::tree<T>::const_iterator claw::tree<T>::find( const T& v ) const
00142 {
00143   typename child_list::const_iterator it;
00144   bool found = false;
00145 
00146   for ( it=m_child.begin(); !found && (it!=end()) ; )
00147     if ( it->value == v )
00148       found = true;
00149     else
00150       ++it;
00151 
00152   return const_iterator( it );
00153 } // tree::find()
00154 
00155 /*----------------------------------------------------------------------------*/
00159 template<typename T>
00160 typename claw::tree<T>::iterator claw::tree<T>::begin()
00161 {
00162   return iterator( m_child.begin() );
00163 } // tree::begin()()
00164 
00165 /*----------------------------------------------------------------------------*/
00169 template<typename T>
00170 typename claw::tree<T>::iterator claw::tree<T>::end()
00171 {
00172   return iterator( m_child.end() );
00173 } // tree::end()
00174 
00175 /*----------------------------------------------------------------------------*/
00179 template<typename T>
00180 typename claw::tree<T>::const_iterator claw::tree<T>::begin() const
00181 {
00182   return const_iterator( m_child.begin() );
00183 } // tree::begin()
00184 
00185 /*----------------------------------------------------------------------------*/
00189 template<typename T>
00190 typename claw::tree<T>::const_iterator claw::tree<T>::end() const
00191 {
00192   return const_iterator( m_child.end() );
00193 } // tree::end()

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1