Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ObjectIterator.cpp

00001 /*************************************************************************** 00002 * This file is part of OpenCAL: Open Computer Animation Library * 00003 * I created OpenCAL as my master's thesis Computer Science (multimedia) * 00004 * at the tUL university in Diepenbeek, Belgium * 00005 * * 00006 * Copyright (C) 2003-2004 by Jeroen Dierckx * 00007 * jeroen.dierckx@student.luc.ac.be * 00008 * * 00009 ***************************************************************************/ 00010 00011 // Includes 00012 #include "ObjectIterator.h" 00013 #include <OpenCAL/System.h> 00014 #include <OpenCAL/Object.h> 00015 using namespace OpenCAL; 00016 00017 using namespace std; 00018 00019 00020 /****************************** 00021 * Constructors and destructor * 00022 ******************************/ 00023 00024 ObjectIterator::ObjectIterator(System *system) 00025 : m_system(system) 00026 { 00028 reset(); 00029 } 00030 00031 ObjectIterator::~ObjectIterator() 00032 { 00033 } 00034 00035 00036 /************************ 00037 * Get and set functions * 00038 ************************/ 00039 00040 00041 /********************* 00042 * Operator functions * 00043 *********************/ 00044 00051 ObjectIterator &ObjectIterator::operator++() 00052 { 00053 if(!m_currentObject) return *this; 00054 00055 m_currentObject = 0; 00056 System *system = m_currentSystem; 00057 00058 if(m_objectIndex < (system->numObjects() - 1)) 00059 { 00060 m_currentObject = system->getObject(++m_objectIndex); 00061 } 00062 else if(system->numSystems() > 0) 00063 { 00064 for(unsigned int i = 0; i < system->numSystems(); ++i) 00065 { 00066 m_systemStack.push_back(i); 00067 if(gotoFirstObject(system->getSystem(i))) 00068 break; 00069 m_systemStack.pop_back(); 00070 } 00071 } 00072 else if(!m_systemStack.empty()) 00073 { 00074 while(!m_currentObject && !m_systemStack.empty()) 00075 { 00076 unsigned int index = m_systemStack.back(); 00077 m_systemStack.pop_back(); 00078 m_currentSystem = m_currentSystem->getParent(); 00079 system = m_currentSystem; 00080 for(unsigned int i = index + 1; i < system->numSystems(); ++i) 00081 { 00082 m_systemStack.push_back(i); 00083 if(gotoFirstObject(system->getSystem(i))) 00084 break; 00085 m_systemStack.pop_back(); 00086 } 00087 } 00088 } 00089 else 00090 { 00091 m_currentObject = 0; 00092 } 00093 00094 return *this; 00095 } 00096 00097 const ObjectIterator ObjectIterator::operator++(int) 00098 { 00099 ObjectIterator current = *this; 00100 operator++(); 00101 return current; 00102 } 00103 00104 00105 /****************** 00106 * Other functions * 00107 ******************/ 00108 00109 void ObjectIterator::reset() 00110 { 00111 m_systemStack.clear(); 00112 gotoFirstObject(m_system); 00113 } 00114 00115 00116 /********************** 00117 * Protected functions * 00118 **********************/ 00119 00120 Object *ObjectIterator::gotoFirstObject(System *system) 00121 { 00122 // If we find an object, it will always be the first one of a system 00123 m_objectIndex = 0; 00124 00125 m_currentObject = 0; 00126 m_currentSystem = system; 00127 00128 // If the system has objects in it, return the first one 00129 if(system->numObjects() > 0) 00130 { 00131 m_currentObject = system->getObject(0); 00132 return m_currentObject; 00133 } 00134 00135 // If the system hasn't any objects, look if the child systems have any 00136 for(unsigned int i = 0; i < system->numSystems(); ++i) 00137 { 00138 m_systemStack.push_back(i); 00139 if(gotoFirstObject(system->getSystem(i))) 00140 return m_currentObject; 00141 m_systemStack.pop_back(); 00142 } 00143 00144 return 0; 00145 }

Generated on Sun Aug 15 19:19:22 2004 for OpenCAL: Open Computer Animation Library by doxygen 1.3.8