1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkCollectionIterator.cxx 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 #include "vtkCollectionIterator.h" 16 #include "vtkCollection.h" 17 #include "vtkObjectFactory.h" 18 19 vtkStandardNewMacro(vtkCollectionIterator); 20 21 //------------------------------------------------------------------------------ vtkCollectionIterator()22vtkCollectionIterator::vtkCollectionIterator() 23 { 24 this->Element = nullptr; 25 this->Collection = nullptr; 26 } 27 28 //------------------------------------------------------------------------------ ~vtkCollectionIterator()29vtkCollectionIterator::~vtkCollectionIterator() 30 { 31 this->SetCollection(nullptr); 32 } 33 34 //------------------------------------------------------------------------------ PrintSelf(ostream & os,vtkIndent indent)35void vtkCollectionIterator::PrintSelf(ostream& os, vtkIndent indent) 36 { 37 this->Superclass::PrintSelf(os, indent); 38 if (this->Collection) 39 { 40 os << indent << "Collection: " << this->Collection << "\n"; 41 } 42 else 43 { 44 os << indent << "Collection: (none)\n"; 45 } 46 } 47 48 //------------------------------------------------------------------------------ SetCollection(vtkCollection * collection)49void vtkCollectionIterator::SetCollection(vtkCollection* collection) 50 { 51 vtkSetObjectBodyMacro(Collection, vtkCollection, collection); 52 this->GoToFirstItem(); 53 } 54 55 //------------------------------------------------------------------------------ GoToFirstItem()56void vtkCollectionIterator::GoToFirstItem() 57 { 58 if (this->Collection) 59 { 60 this->Element = this->Collection->Top; 61 } 62 else 63 { 64 this->Element = nullptr; 65 } 66 } 67 68 //------------------------------------------------------------------------------ GoToNextItem()69void vtkCollectionIterator::GoToNextItem() 70 { 71 if (this->Element) 72 { 73 this->Element = this->Element->Next; 74 } 75 } 76 77 //------------------------------------------------------------------------------ IsDoneWithTraversal()78int vtkCollectionIterator::IsDoneWithTraversal() 79 { 80 return (this->Element ? 0 : 1); 81 } 82 83 //------------------------------------------------------------------------------ GetCurrentObject()84vtkObject* vtkCollectionIterator::GetCurrentObject() 85 { 86 if (this->Element) 87 { 88 return this->Element->Item; 89 } 90 return nullptr; 91 } 92