Commit fa755c35 authored by Jan Möbius's avatar Jan Möbius
Browse files

Cleanup the ObjectIterator a bit

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4052 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 05727679
...@@ -513,6 +513,11 @@ class DLLEXPORT ObjectIterator { ...@@ -513,6 +513,11 @@ class DLLEXPORT ObjectIterator {
/// Restriction of the iterator /// Restriction of the iterator
IteratorRestriction restriction_; IteratorRestriction restriction_;
/** Takes an object and goes through the object tree to the next BaseObjectData
* It stops at the root node.
*/
inline void proceedToNextBaseObjectData(BaseObject*& _object);
}; };
// /// Return Iterator to Mesh End // /// Return Iterator to Mesh End
......
...@@ -57,42 +57,29 @@ ObjectIterator::ObjectIterator( IteratorRestriction _restriction , DataType _dat ...@@ -57,42 +57,29 @@ ObjectIterator::ObjectIterator( IteratorRestriction _restriction , DataType _dat
dataType_ = _dataType; dataType_ = _dataType;
// Start at the root Node // Start at the root Node
BaseObject* currentPos = objectRoot()->next(); BaseObject* currentPos = objectRoot();
// Go through the tree and stop at the root node or if we found a baseObjectData Object // Take the first element which is an baseObjectData
while ( (currentPos != objectRoot()) && !dynamic_cast<BaseObjectData* > (currentPos) ) proceedToNextBaseObjectData(currentPos);
currentPos = currentPos->next();
while ( (currentPos != objectRoot()) ) { while ( (currentPos != objectRoot()) ) {
// Return only target objects if requested // Return only target objects if requested
if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) { if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) {
proceedToNextBaseObjectData(currentPos);
// Go through the tree and stop at the root node or if we found a baseObjectData Object
while ( (currentPos != objectRoot()) && !dynamic_cast<BaseObjectData* > (currentPos) )
currentPos = currentPos->next();
continue; continue;
} }
// Return only source objects if requested // Return only source objects if requested
if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) { if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) {
proceedToNextBaseObjectData(currentPos);
// Go through the tree and stop at the root node or if we found a baseObjectData Object
while ( (currentPos != objectRoot()) && !dynamic_cast<BaseObjectData* > (currentPos) )
currentPos = currentPos->next();
continue; continue;
} }
// Return only the right dataType // Return only the right dataType
if ( _dataType != DATA_ALL ) if ( _dataType != DATA_ALL )
if ( ! (currentPos->dataType( dataType_ ) ) ) { if ( ! (currentPos->dataType( dataType_ ) ) ) {
proceedToNextBaseObjectData(currentPos);
// Go through the tree and stop at the root node or if we found a baseObjectData Object
while ( (currentPos != objectRoot()) && !dynamic_cast<BaseObjectData* > (currentPos) )
currentPos = currentPos->next();
continue; continue;
} }
...@@ -134,42 +121,26 @@ ObjectIterator& ObjectIterator::operator++() { ...@@ -134,42 +121,26 @@ ObjectIterator& ObjectIterator::operator++() {
// Convert our pointer to the basic one // Convert our pointer to the basic one
BaseObject* currentPos = dynamic_cast< BaseObject* >(pos_); BaseObject* currentPos = dynamic_cast< BaseObject* >(pos_);
// Get the next element in the tree // Get the next objectData element in the tree
currentPos = currentPos->next(); proceedToNextBaseObjectData(currentPos);
// Go through the tree and stop at the root node or if we found a baseObjectData Object
while ( (currentPos != objectRoot()) && !dynamic_cast<BaseObjectData* > (currentPos) )
currentPos = currentPos->next();
while ( (currentPos != objectRoot() ) ) { while ( (currentPos != objectRoot() ) ) {
// Return only target objects if requested // Return only target objects if requested
if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) { if ( (restriction_ == TARGET_OBJECTS) && (! currentPos->target() ) ) {
proceedToNextBaseObjectData(currentPos);
// Go through the tree and stop at the root node or if we found a baseObjectData Object
while ( (currentPos != objectRoot()) && !dynamic_cast<BaseObjectData* > (currentPos) )
currentPos = currentPos->next();
continue; continue;
} }
// Return only source objects if requested // Return only source objects if requested
if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) { if ( (restriction_ == SOURCE_OBJECTS) && (! currentPos->source() ) ) {
proceedToNextBaseObjectData(currentPos);
// Go through the tree and stop at the root node or if we found a baseObjectData Object
while ( (currentPos != objectRoot()) && !dynamic_cast<BaseObjectData* > (currentPos) )
currentPos = currentPos->next();
continue; continue;
} }
// Return only the right dataType // Return only the right dataType
if ( ! (currentPos->dataType( dataType_ ) ) ) { if ( ! (currentPos->dataType( dataType_ ) ) ) {
proceedToNextBaseObjectData(currentPos);
// Go through the tree and stop at the root node or if we found a baseObjectData Object
while ( (currentPos != objectRoot()) && !dynamic_cast<BaseObjectData* > (currentPos) )
currentPos = currentPos->next();
continue; continue;
} }
...@@ -200,7 +171,16 @@ BaseObjectData* ObjectIterator::operator*() { ...@@ -200,7 +171,16 @@ BaseObjectData* ObjectIterator::operator*() {
/// Return Iterator to Object End /// Return Iterator to Object End
ObjectIterator objects_end() { ObjectIterator objects_end() {
return ObjectIterator(0); return ObjectIterator(0);
}; }
void ObjectIterator::proceedToNextBaseObjectData(BaseObject*& _object) {
_object = _object->next();
// Go through the tree and stop at the root node or if we found a baseObjectData Object
while ( (_object != objectRoot()) && !dynamic_cast<BaseObjectData* > (_object) )
_object = _object->next();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment