Developer Documentation
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 //
45 // Plugin Functions
46 //
47 //=============================================================================
48 
50 
51 #include "PluginFunctions.hh"
52 
53 namespace PluginFunctions {
54 
55 
57  pos_(0),
58  dataType_(_dataType),
59  restriction_(_restriction)
60 {
61 
62 
63  // Start at the root Node
64  BaseObject* currentPos = objectRoot();
65 
66  // Take the first element which is an baseObjectData
67  proceedToNextBaseObjectData(currentPos);
68 
69  while ( (currentPos != objectRoot()) ) {
70 
71  // Return only target objects if requested
72  if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) {
73  proceedToNextBaseObjectData(currentPos);
74  continue;
75  }
76 
77  // Return only source objects if requested
78  if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) {
79  proceedToNextBaseObjectData(currentPos);
80  continue;
81  }
82 
83  // Return only the right dataType
84  if ( _dataType != DATA_ALL )
85  if ( ! (currentPos->dataType( dataType_ ) ) ) {
86  proceedToNextBaseObjectData(currentPos);
87  continue;
88  }
89 
90  // found a valid object
91  pos_ = dynamic_cast<BaseObjectData* > (currentPos);
92  break;
93  }
94 }
95 
97  pos_(pos),
98  dataType_(_data),
99  restriction_(_restriction)
100 {
101 };
102 
103 
104 bool ObjectIterator::operator==( const ObjectIterator& _rhs) const {
105  return ( _rhs.pos_ == pos_ );
106 }
107 
108 bool ObjectIterator::operator!=( const ObjectIterator& _rhs) const {
109  return ( _rhs.pos_ != pos_ );
110 }
111 
112 
114  return pos_;
115 }
116 
118 
119  // Convert our pointer to the basic one
120  BaseObject* currentPos = dynamic_cast< BaseObject* >(pos_);
121 
122  // Get the next objectData element in the tree
123  proceedToNextBaseObjectData(currentPos);
124 
125  while ( (currentPos != objectRoot() ) ) {
126 
127  // Return only target objects if requested
128  if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) {
129  proceedToNextBaseObjectData(currentPos);
130  continue;
131  }
132 
133  // Return only source objects if requested
134  if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) {
135  proceedToNextBaseObjectData(currentPos);
136  continue;
137  }
138 
139  // Return only the right dataType
140  if ( ! (currentPos->dataType( dataType_ ) ) ) {
141  proceedToNextBaseObjectData(currentPos);
142  continue;
143  }
144 
145  // found a valid object
146  pos_ = dynamic_cast<BaseObjectData* > (currentPos);
147  return *this;
148  }
149 
150  // No valid object found
151  pos_ = 0;
152  return *this;
153 }
154 
156  std::cerr << "TODO :--" << std::endl;
157  return *this;
158 }
159 
166  return pos_;
167 }
168 
171  return ObjectIterator(0);
172 }
173 
175 
176  _object = _object->next();
177 
178  // Go through the tree and stop at the root node or if we found a baseObjectData Object
179  while ( (_object != objectRoot()) && !dynamic_cast<BaseObjectData* > (_object) )
180  _object = _object->next();
181 }
182 
183 
184 
185 }
BaseObjectData * operator*()
dereference the iterator
bool source()
Definition: BaseObject.cc:291
bool operator!=(const ObjectIterator &_rhs) const
compare iterators
bool operator==(const ObjectIterator &_rhs) const
compare iterators
BaseObject *& objectRoot()
Get the root of the object structure.
bool target()
Definition: BaseObject.cc:273
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
Predefined datatypes.
Definition: DataTypes.hh:83
BaseObjectData * pos_
current position of the iterator
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
BaseObject * next()
Definition: BaseObject.cc:404
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
IteratorRestriction restriction_
Restriction of the iterator.
ObjectIterator & operator--()
last element
QStringList IteratorRestriction
Iterable object range.
void proceedToNextBaseObjectData(BaseObject *&_object)
ObjectIterator & operator++()
next element
const QStringList TARGET_OBJECTS("target")
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.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.