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 
113  pos_ = _rhs.pos_;
114  dataType_ = _rhs.dataType_;
115  restriction_ = _rhs.restriction_;
116  return *this;
117 }
118 
119 
121  return pos_;
122 }
123 
125 
126  // Convert our pointer to the basic one
127  BaseObject* currentPos = dynamic_cast< BaseObject* >(pos_);
128 
129  // Get the next objectData element in the tree
130  proceedToNextBaseObjectData(currentPos);
131 
132  while ( (currentPos != objectRoot() ) ) {
133 
134  // Return only target objects if requested
135  if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) {
136  proceedToNextBaseObjectData(currentPos);
137  continue;
138  }
139 
140  // Return only source objects if requested
141  if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) {
142  proceedToNextBaseObjectData(currentPos);
143  continue;
144  }
145 
146  // Return only the right dataType
147  if ( ! (currentPos->dataType( dataType_ ) ) ) {
148  proceedToNextBaseObjectData(currentPos);
149  continue;
150  }
151 
152  // found a valid object
153  pos_ = dynamic_cast<BaseObjectData* > (currentPos);
154  return *this;
155  }
156 
157  // No valid object found
158  pos_ = 0;
159  return *this;
160 }
161 
163  std::cerr << "TODO :--" << std::endl;
164  return *this;
165 }
166 
173  return pos_;
174 }
175 
178  return ObjectIterator(0);
179 }
180 
182 
183  _object = _object->next();
184 
185  // Go through the tree and stop at the root node or if we found a baseObjectData Object
186  while ( (_object != objectRoot()) && !dynamic_cast<BaseObjectData* > (_object) )
187  _object = _object->next();
188 }
189 
190 
191 
192 }
ObjectIterator & operator=(const ObjectIterator &_rhs)
assign iterators
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
BaseObjectData * operator*()
dereference the iterator
bool source()
Definition: BaseObject.cc:291
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
IteratorRestriction restriction_
Restriction of the iterator.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
QStringList IteratorRestriction
Iterable object range.
ObjectIterator & operator--()
last element
bool target()
Definition: BaseObject.cc:273
BaseObject *& objectRoot()
Get the root of the object structure.
DataType dataType_
returned data types of the iterator
bool operator==(const ObjectIterator &_rhs) const
compare iterators
BaseObjectData * pos_
current position of the iterator
bool operator!=(const ObjectIterator &_rhs) const
compare iterators
Predefined datatypes.
Definition: DataTypes.hh:83
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
BaseObject * next()
Definition: BaseObject.cc:404
ObjectIterator & operator++()
next element
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.
void proceedToNextBaseObjectData(BaseObject *&_object)