Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PluginFunctionsBaseIterator.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // Plugin Functions
56 //
57 //=============================================================================
58 
60 
61 #include "PluginFunctions.hh"
62 
63 namespace PluginFunctions {
64 
65 
67  pos_(0),
68  dataType_(_dataType),
69  restriction_(_restriction)
70 
71 {
72  // Start at the root Node
73  BaseObject* currentPos = objectRoot();
74 
75  currentPos = currentPos->next();
76 
77  while ( (currentPos != objectRoot()) ) {
78 
79  // Return only selected objects if requested
80  if (!restriction_.isEmpty ()) {
81  bool found = false;
82  foreach (QString rest, restriction_)
83  if (currentPos->flags().contains(rest))
84  {
85  found = true;
86  break;
87  }
88 
89  if (!found)
90  {
91  currentPos = currentPos->next();
92  continue;
93  }
94  }
95 
96  // Return only the right dataType
97  if ( _dataType != DATA_ALL )
98  if ( ! (currentPos->dataType( dataType_ ) ) ) {
99  currentPos = currentPos->next();
100  continue;
101  }
102 
103  // found a valid object
104  pos_ = dynamic_cast<BaseObject* > (currentPos);
105  break;
106  }
107 }
108 
110  pos_(pos),
111  dataType_(_data),
112  restriction_(_restriction)
113 {
114 };
115 
116 
118  return ( _rhs.pos_ == pos_ );
119 }
120 
122  return ( _rhs.pos_ != pos_ );
123 }
124 
126  pos_ = _rhs.pos_;
127  dataType_ = _rhs.dataType_;
128  restriction_ = _rhs.restriction_;
129  return *this;
130 }
131 
132 
134  return pos_;
135 }
136 
138 
139  // Convert our pointer to the basic one
140  BaseObject* currentPos = dynamic_cast< BaseObject* >(pos_);
141 
142  // Get the next objectData element in the tree
143  currentPos = currentPos->next();
144 
145  while ( (currentPos != objectRoot() ) ) {
146 
147  // Return only selected objects if requested
148  if (!restriction_.isEmpty ()) {
149  bool found = false;
150  foreach (QString rest, restriction_)
151  if (currentPos->flags().contains(rest))
152  {
153  found = true;
154  break;
155  }
156 
157  if (!found)
158  {
159  currentPos = currentPos->next();
160  continue;
161  }
162  }
163 
164  // Return only the right dataType
165  if ( ! (currentPos->dataType( dataType_ ) ) ) {
166  currentPos = currentPos->next();
167  continue;
168  }
169 
170  // found a valid object
171  pos_ = dynamic_cast<BaseObject* > (currentPos);
172  return *this;
173  }
174 
175  // No valid object found
176  pos_ = 0;
177  return *this;
178 }
179 
181  std::cerr << "TODO :--" << std::endl;
182  return *this;
183 }
184 
191  return pos_;
192 }
193 
196  return BaseObjectIterator(0);
197 }
198 
199 
200 }
BaseObjectIterator & operator=(const BaseObjectIterator &_rhs)
assign iterators
QStringList flags()
Definition: BaseObject.cc:341
BaseObject * operator*()
dereference the iterator
BaseObjectIterator(IteratorRestriction _restriction=ALL_OBJECTS, DataType _dataType=DATA_ALL)
Use this constructor for iterating through your data.
BaseObject * next()
Definition: BaseObject.cc:415
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
BaseObjectIterator & operator--()
last element
BaseObject *& objectRoot()
Get the root of the object structure.
DataType dataType_
returned data types of the iterator
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
bool operator!=(const BaseObjectIterator &_rhs)
compare iterators
bool operator==(const BaseObjectIterator &_rhs)
compare iterators
QStringList IteratorRestriction
Iterable object range.
Core Data Iterator used to iterate over all objects (Including groups)
Predefined datatypes.
Definition: DataTypes.hh:96
IteratorRestriction restriction_
Restriction of the iterator.
BaseObject * pos_
current position of the iterator
BaseObjectIterator & operator++()
next element