PluginFunctionsBaseIterator.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6727 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 08:03:50 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  Plugin Functions
00049 //
00050 //=============================================================================
00051 
00052 #include <OpenFlipper/common/Types.hh>
00053 
00054 #include "PluginFunctions.hh"
00055 
00056 namespace PluginFunctions {
00057 
00058 
00059 BaseObjectIterator::BaseObjectIterator( IteratorRestriction _restriction , DataType _dataType) {
00060 
00061   // Initialize with invalid pos
00062   pos_ = 0;
00063 
00064   // Store the restriction for the operator ( Source/Target )
00065   restriction_ = _restriction;
00066 
00067   // Store the requested DataType
00068   dataType_ = _dataType;
00069 
00070   // Start at the root Node
00071   BaseObject* currentPos = objectRoot();
00072 
00073   currentPos = currentPos->next();
00074 
00075   while ( (currentPos != objectRoot()) ) {
00076 
00077     // Return only selected objects if requested
00078     if (!restriction_.isEmpty ()) {
00079       bool found = false;
00080       foreach (QString rest, restriction_)
00081         if (currentPos->flags().contains(rest))
00082         {
00083           found = true;
00084           break;
00085         }
00086 
00087       if (!found)
00088       {
00089         currentPos = currentPos->next();
00090         continue;
00091       }
00092     }
00093 
00094     // Return only the right dataType
00095     if ( _dataType != DATA_ALL )
00096       if ( ! (currentPos->dataType( dataType_ ) ) ) {
00097         currentPos = currentPos->next();
00098         continue;
00099       }
00100 
00101     // found a valid object
00102     pos_ = dynamic_cast<BaseObject* > (currentPos);
00103     break;
00104   }
00105 }
00106 
00107 BaseObjectIterator::BaseObjectIterator(BaseObject* pos, IteratorRestriction _restriction , DataType _data)
00108 {
00109    restriction_ = _restriction;
00110    pos_         = pos;
00111    dataType_    = _data;
00112 };
00113 
00114 
00115 bool BaseObjectIterator::operator==( const BaseObjectIterator& _rhs) {
00116    return ( _rhs.pos_ == pos_ );
00117 }
00118 
00119 bool BaseObjectIterator::operator!=( const BaseObjectIterator& _rhs) {
00120    return ( _rhs.pos_ != pos_ );
00121 }
00122 
00123 BaseObjectIterator& BaseObjectIterator::operator=( const BaseObjectIterator& _rhs) {
00124    pos_ = _rhs.pos_;
00125    return *this;
00126 }
00127 
00128 
00129 BaseObjectIterator::pointer BaseObjectIterator::operator->(){
00130    return pos_;
00131 }
00132 
00133 BaseObjectIterator& BaseObjectIterator::operator++() {
00134 
00135   // Convert our pointer to the basic one
00136   BaseObject* currentPos = dynamic_cast< BaseObject* >(pos_);
00137 
00138   // Get the next objectData element in the tree
00139   currentPos = currentPos->next();
00140 
00141   while ( (currentPos != objectRoot() ) ) {
00142 
00143     // Return only selected objects if requested
00144     if (!restriction_.isEmpty ()) {
00145       bool found = false;
00146       foreach (QString rest, restriction_)
00147         if (currentPos->flags().contains(rest))
00148         {
00149           found = true;
00150           break;
00151         }
00152 
00153       if (!found)
00154       {
00155         currentPos = currentPos->next();
00156         continue;
00157       }
00158     }
00159 
00160     // Return only the right dataType
00161     if ( ! (currentPos->dataType( dataType_ ) ) ) {
00162       currentPos = currentPos->next();
00163       continue;
00164     }
00165 
00166     // found a valid object
00167     pos_ = dynamic_cast<BaseObject* > (currentPos);
00168     return *this;
00169   }
00170 
00171   // No valid object found
00172   pos_ = 0;
00173   return *this;
00174 }
00175 
00176 BaseObjectIterator& BaseObjectIterator::operator--() {
00177    std::cerr << "TODO :--" << std::endl;
00178    return *this;
00179 }
00180 
00186 BaseObject* BaseObjectIterator::operator*() {
00187    return pos_;
00188 }
00189 
00191 BaseObjectIterator baseObjectsEnd() {
00192    return BaseObjectIterator(0);
00193 }
00194 
00195 
00196 }

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .