Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
59 #include <OpenFlipper/common/Types.hh>
60
61 #include "PluginFunctions.hh"
62
63 namespace PluginFunctions {
64
65
66 BaseObjectIterator::BaseObjectIterator( IteratorRestriction _restriction , DataType _dataType) :
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
109 BaseObjectIterator::BaseObjectIterator(BaseObject* pos, IteratorRestriction _restriction , DataType _data) :
110 pos_(pos),
111 dataType_(_data),
112 restriction_(_restriction)
113 {
114 };
115
116
117 bool BaseObjectIterator::operator==( const BaseObjectIterator& _rhs) {
118 return ( _rhs.pos_ == pos_ );
119 }
120
121 bool BaseObjectIterator::operator!=( const BaseObjectIterator& _rhs) {
122 return ( _rhs.pos_ != pos_ );
123 }
124
125 BaseObjectIterator& BaseObjectIterator::operator=( const BaseObjectIterator& _rhs) {
126 pos_ = _rhs.pos_;
127 dataType_ = _rhs.dataType_;
128 restriction_ = _rhs.restriction_;
129 return *this;
130 }
131
132
133 BaseObjectIterator::pointer BaseObjectIterator::operator->(){
134 return pos_;
135 }
136
137 BaseObjectIterator& BaseObjectIterator::operator++() {
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
180 BaseObjectIterator& BaseObjectIterator::operator--() {
181 std::cerr << "TODO :--" << std::endl;
182 return *this;
183 }
184
190 BaseObject* BaseObjectIterator::operator*() {
191 return pos_;
192 }
193
195 BaseObjectIterator baseObjectsEnd() {
196 return BaseObjectIterator(0);
197 }
198
199
200 }
PluginFunctions::BaseObjectIterator::operator=
BaseObjectIterator & operator=(const BaseObjectIterator &_rhs)
assign iterators
Definition: PluginFunctionsBaseIterator.cc:125
BaseObject::flags
QStringList flags()
Definition: BaseObject.cc:341
PluginFunctions::BaseObjectIterator::operator*
BaseObject * operator*()
dereference the iterator
Definition: PluginFunctionsBaseIterator.cc:190
PluginFunctions::BaseObjectIterator::BaseObjectIterator
BaseObjectIterator(IteratorRestriction _restriction=ALL_OBJECTS, DataType _dataType=DATA_ALL)
Use this constructor for iterating through your data.
Definition: PluginFunctionsBaseIterator.cc:66
PluginFunctions
Definition: PluginFunctionsBSplineCurve.cc:69
BaseObject::next
BaseObject * next()
Definition: BaseObject.cc:415
PluginFunctions::baseObjectsEnd
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
Definition: PluginFunctionsBaseIterator.cc:195
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
PluginFunctions::BaseObjectIterator::operator->
pointer operator->()
dereference
Definition: PluginFunctionsBaseIterator.cc:133
PluginFunctions::BaseObjectIterator::operator--
BaseObjectIterator & operator--()
last element
Definition: PluginFunctionsBaseIterator.cc:180
BaseObject
Definition: BaseObject.hh:94
PluginFunctions::objectRoot
BaseObject *& objectRoot()
Get the root of the object structure.
Definition: PluginFunctions.cc:1103
PluginFunctions::BaseObjectIterator::dataType_
DataType dataType_
returned data types of the iterator
Definition: PluginFunctions.hh:746
DATA_ALL
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
PluginFunctions::BaseObjectIterator::operator!=
bool operator!=(const BaseObjectIterator &_rhs)
compare iterators
Definition: PluginFunctionsBaseIterator.cc:121
PluginFunctions::BaseObjectIterator::operator==
bool operator==(const BaseObjectIterator &_rhs)
compare iterators
Definition: PluginFunctionsBaseIterator.cc:117
PluginFunctions::IteratorRestriction
QStringList IteratorRestriction
Iterable object range.
Definition: PluginFunctions.hh:439
PluginFunctions::BaseObjectIterator
Core Data Iterator used to iterate over all objects (Including groups)
Definition: PluginFunctions.hh:686
PluginFunctions.hh
DataType
Predefined datatypes.
Definition: DataTypes.hh:96
Types.hh
PluginFunctions::BaseObjectIterator::restriction_
IteratorRestriction restriction_
Restriction of the iterator.
Definition: PluginFunctions.hh:749
PluginFunctions::BaseObjectIterator::pos_
BaseObject * pos_
current position of the iterator
Definition: PluginFunctions.hh:739
PluginFunctions::BaseObjectIterator::operator++
BaseObjectIterator & operator++()
next element
Definition: PluginFunctionsBaseIterator.cc:137