solarpowerlog trunk
/home/tobi/workspace/solarpowerlog/src/Inverters/interfaces/CNestedCapaIterator.cpp
Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  solarpowerlog
00003  Copyright (C) 2009  Tobias Frost
00004 
00005  This file is part of solarpowerlog.
00006 
00007  Solarpowerlog is free software; However, it is dual-licenced
00008  as described in the file "COPYING".
00009 
00010  For this file (CNestedCapaIterator.cpp), the license terms are:
00011 
00012  You can redistribute it and/or modify it under the terms of the GNU
00013  General Public License as published by the Free Software Foundation; either
00014  version 3 of the License, or (at your option) any later version.
00015 
00016  This program is distributed in the hope that it will be useful, but
00017  WITHOUT ANY WARRANTY; without even the implied warranty of
00018  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  Lesser General Public License for more details.
00020 
00021  You should have received a copy of the GNU Library General Public
00022  License along with this proramm; if not, see
00023  <http://www.gnu.org/licenses/>.
00024  ----------------------------------------------------------------------------
00025  */
00026 
00033 #ifdef HAVE_CONFIG_H
00034 #include "config.h"
00035 #endif
00036 
00037 #include <memory>
00038 
00039 #include "Inverters/interfaces/CNestedCapaIterator.h"
00040 
00041 CNestedCapaIterator::CNestedCapaIterator( IInverterBase *b,
00042      IInverterBase* parent ) :
00043      ICapaIterator(b, parent)
00044 {
00045      topmost = b;
00046      // TODO Auto-generated constructor stub
00047 }
00048 
00049 CNestedCapaIterator::~CNestedCapaIterator()
00050 {
00051      // TODO Auto-generated destructor stub
00052 }
00053 
00059 bool CNestedCapaIterator::HasNext()
00060 {
00061      CCapability *c;
00062      pair<string, CCapability*> p;
00063      if (ICapaIterator::HasNext()) {
00064           p = GetElement();
00065           // Check if we had to filter that one out.
00066           if (p.second == (c = topmost->GetConcreteCapability(p.first))) {
00067                // yes, not filtered.
00068                return true;
00069           } else {
00070                // that one is to be filtered.
00071                // Filter and then recurse.
00072                ICapaIterator::GetNext();
00073                return HasNext();
00074           }
00075      }
00076      // appearantly, the curent base is out of capabilities.
00077      // descent one level deeper.
00078 
00079      if (parent) {
00080           // Set the parent as new base, and ask the parent for its parent
00081           // via getting the information in its iterator.
00082           this->SetBase(parent);
00083           auto_ptr<ICapaIterator> p(parent->GetCapaNewIterator());
00084           this->setParent(p->getParent());
00085      } else {
00086           return false;
00087      }
00088      return ICapaIterator::HasNext();
00089 }
00090 
00095 pair<string, CCapability*> CNestedCapaIterator::GetNext()
00096 {
00097      // HasNext() already set up everything we need to know...
00098      return ICapaIterator::GetNext();
00099 }