Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PluginFunctionsIterator.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 
73  // Start at the root Node
74  BaseObject* currentPos = objectRoot();
75 
76  // Take the first element which is an baseObjectData
77  proceedToNextBaseObjectData(currentPos);
78 
79  while ( (currentPos != objectRoot()) ) {
80 
81  // Return only target objects if requested
82  if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) {
83  proceedToNextBaseObjectData(currentPos);
84  continue;
85  }
86 
87  // Return only source objects if requested
88  if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) {
89  proceedToNextBaseObjectData(currentPos);
90  continue;
91  }
92 
93  // Return only the right dataType
94  if ( _dataType != DATA_ALL )
95  if ( ! (currentPos->dataType( dataType_ ) ) ) {
96  proceedToNextBaseObjectData(currentPos);
97  continue;
98  }
99 
100  // found a valid object
101  pos_ = dynamic_cast<BaseObjectData* > (currentPos);
102  break;
103  }
104 }
105 
107  pos_(pos),
108  dataType_(_data),
109  restriction_(_restriction)
110 {
111 };
112 
113 
114 bool ObjectIterator::operator==( const ObjectIterator& _rhs) const {
115  return ( _rhs.pos_ == pos_ );
116 }
117 
118 bool ObjectIterator::operator!=( const ObjectIterator& _rhs) const {
119  return ( _rhs.pos_ != pos_ );
120 }
121 
123  pos_ = _rhs.pos_;
124  dataType_ = _rhs.dataType_;
125  restriction_ = _rhs.restriction_;
126  return *this;
127 }
128 
129 
131  return pos_;
132 }
133 
135 
136  // Convert our pointer to the basic one
137  BaseObject* currentPos = dynamic_cast< BaseObject* >(pos_);
138 
139  // Get the next objectData element in the tree
140  proceedToNextBaseObjectData(currentPos);
141 
142  while ( (currentPos != objectRoot() ) ) {
143 
144  // Return only target objects if requested
145  if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) {
146  proceedToNextBaseObjectData(currentPos);
147  continue;
148  }
149 
150  // Return only source objects if requested
151  if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) {
152  proceedToNextBaseObjectData(currentPos);
153  continue;
154  }
155 
156  // Return only the right dataType
157  if ( ! (currentPos->dataType( dataType_ ) ) ) {
158  proceedToNextBaseObjectData(currentPos);
159  continue;
160  }
161 
162  // found a valid object
163  pos_ = dynamic_cast<BaseObjectData* > (currentPos);
164  return *this;
165  }
166 
167  // No valid object found
168  pos_ = 0;
169  return *this;
170 }
171 
173  std::cerr << "TODO :--" << std::endl;
174  return *this;
175 }
176 
183  return pos_;
184 }
185 
188  return ObjectIterator(0);
189 }
190 
192 
193  _object = _object->next();
194 
195  // Go through the tree and stop at the root node or if we found a baseObjectData Object
196  while ( (_object != objectRoot()) && !dynamic_cast<BaseObjectData* > (_object) )
197  _object = _object->next();
198 }
199 
200 
201 
202 }
void proceedToNextBaseObjectData(BaseObject *&_object)
IteratorRestriction restriction_
Restriction of the iterator.
BaseObject * next()
Definition: BaseObject.cc:415
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
BaseObjectData * pos_
current position of the iterator
bool operator==(const ObjectIterator &_rhs) const
compare iterators
const QStringList TARGET_OBJECTS("target")
Iterable object range.
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
bool operator!=(const ObjectIterator &_rhs) const
compare iterators
bool source()
Definition: BaseObject.cc:302
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
BaseObject *& objectRoot()
Get the root of the object structure.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
ObjectIterator & operator++()
next element
BaseObjectData * operator*()
dereference the iterator
ObjectIterator & operator=(const ObjectIterator &_rhs)
assign iterators
QStringList IteratorRestriction
Iterable object range.
DataType dataType_
returned data types of the iterator
ObjectIterator(IteratorRestriction _restriction=ALL_OBJECTS, DataType _dataType=DATA_ALL)
Use this constructor for iterating through your data.
Predefined datatypes.
Definition: DataTypes.hh:96
bool target()
Definition: BaseObject.cc:284
ObjectIterator & operator--()
last element