Back to index

salome-kernel  6.5.0
DF_ChildIterator.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "DF_ChildIterator.hxx"
00021 
00022 //Constructor
00023 DF_ChildIterator::DF_ChildIterator(const DF_Label& theLabel, bool allLevels)
00024   :_root(NULL), _current(NULL)
00025 {
00026   Init(theLabel, allLevels);
00027 }
00028 
00029 DF_ChildIterator::DF_ChildIterator()
00030   :_root(NULL), _current(NULL)
00031 {
00032 }
00033 
00034 DF_ChildIterator::~DF_ChildIterator() 
00035 {
00036   _root = NULL;
00037   _current = NULL;
00038 }
00039 
00040 //Initializes the iterator
00041 void DF_ChildIterator::Init(const DF_Label& theLabel, bool allLevels)
00042 {
00043   _root = theLabel._node;
00044   _allLevels = allLevels;
00045   if(_root) _current = _root->_firstChild;
00046 }
00047 
00048 //Returns a current Label
00049 DF_Label DF_ChildIterator::Value()
00050 {
00051   return DF_Label(_current);
00052 }
00053 
00054 //Returns true if there is a current Label
00055 bool DF_ChildIterator::More()
00056 {
00057   return _current!=0;
00058 }
00059 
00060 //Moves to the next Label
00061 void DF_ChildIterator::Next()
00062 {
00063   if(!_allLevels) {
00064     _current = _current->_next; //Move to the next brother
00065     return;
00066   }
00067   else {
00068     if(_current->_firstChild) { //Go down to the first child
00069       _current = _current->_firstChild;
00070     }
00071     else {
00072       if(_current->_next) { //Next Brother
00073         _current = _current->_next;
00074       }
00075       else {
00076         if(_current->_father && _current->_father != _root) {
00077           DF_LabelNode *father = _current->_father;
00078           _current = father->_next;
00079           if(!_current) {
00080             while(father && father != _root) {
00081               father = father->_father;
00082               if(father->_next) break;
00083             } 
00084             if(father == _root) father = NULL;
00085             if(father) _current = father->_next;
00086             else _current = NULL;
00087           }
00088         }
00089         else {
00090           _current = NULL; //We iterate the whole sub tree
00091         }
00092       }
00093     }
00094   }
00095 }
00096