Developer Documentation
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 //=============================================================================
45 //
46 // Plugin Functions
47 //
48 //=============================================================================
49 
51 
52 #include "PluginFunctions.hh"
53 
54 namespace PluginFunctions {
55 
56 
58  pos_(0),
59  dataType_(_dataType),
60  restriction_(_restriction)
61 
62 {
63  // Start at the root Node
64  BaseObject* currentPos = objectRoot();
65 
66  currentPos = currentPos->next();
67 
68  while ( (currentPos != objectRoot()) ) {
69 
70  // Return only selected objects if requested
71  if (!restriction_.isEmpty ()) {
72  bool found = false;
73  foreach (QString rest, restriction_)
74  if (currentPos->flags().contains(rest))
75  {
76  found = true;
77  break;
78  }
79 
80  if (!found)
81  {
82  currentPos = currentPos->next();
83  continue;
84  }
85  }
86 
87  // Return only the right dataType
88  if ( _dataType != DATA_ALL )
89  if ( ! (currentPos->dataType( dataType_ ) ) ) {
90  currentPos = currentPos->next();
91  continue;
92  }
93 
94  // found a valid object
95  pos_ = dynamic_cast<BaseObject* > (currentPos);
96  break;
97  }
98 }
99 
101  pos_(pos),
102  dataType_(_data),
103  restriction_(_restriction)
104 {
105 };
106 
107 
109  return ( _rhs.pos_ == pos_ );
110 }
111 
113  return ( _rhs.pos_ != pos_ );
114 }
115 
117  pos_ = _rhs.pos_;
118  dataType_ = _rhs.dataType_;
119  restriction_ = _rhs.restriction_;
120  return *this;
121 }
122 
123 
125  return pos_;
126 }
127 
129 
130  // Convert our pointer to the basic one
131  BaseObject* currentPos = dynamic_cast< BaseObject* >(pos_);
132 
133  // Get the next objectData element in the tree
134  currentPos = currentPos->next();
135 
136  while ( (currentPos != objectRoot() ) ) {
137 
138  // Return only selected objects if requested
139  if (!restriction_.isEmpty ()) {
140  bool found = false;
141  foreach (QString rest, restriction_)
142  if (currentPos->flags().contains(rest))
143  {
144  found = true;
145  break;
146  }
147 
148  if (!found)
149  {
150  currentPos = currentPos->next();
151  continue;
152  }
153  }
154 
155  // Return only the right dataType
156  if ( ! (currentPos->dataType( dataType_ ) ) ) {
157  currentPos = currentPos->next();
158  continue;
159  }
160 
161  // found a valid object
162  pos_ = dynamic_cast<BaseObject* > (currentPos);
163  return *this;
164  }
165 
166  // No valid object found
167  pos_ = 0;
168  return *this;
169 }
170 
172  std::cerr << "TODO :--" << std::endl;
173  return *this;
174 }
175 
182  return pos_;
183 }
184 
187  return BaseObjectIterator(0);
188 }
189 
190 
191 }
BaseObject * operator*()
dereference the iterator
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
bool operator!=(const BaseObjectIterator &_rhs)
compare iterators
BaseObjectIterator & operator=(const BaseObjectIterator &_rhs)
assign iterators
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
QStringList IteratorRestriction
Iterable object range.
BaseObjectIterator(IteratorRestriction _restriction=ALL_OBJECTS, DataType _dataType=DATA_ALL)
Use this constructor for iterating through your data.
QStringList flags()
Definition: BaseObject.cc:330
BaseObject * pos_
current position of the iterator
bool operator==(const BaseObjectIterator &_rhs)
compare iterators
BaseObject *& objectRoot()
Get the root of the object structure.
BaseObjectIterator & operator--()
last element
DataType dataType_
returned data types of the iterator
IteratorRestriction restriction_
Restriction of the iterator.
Predefined datatypes.
Definition: DataTypes.hh:83
BaseObject * next()
Definition: BaseObject.cc:404
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
Core Data Iterator used to iterate over all objects (Including groups)
BaseObjectIterator & operator++()
next element