Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
objiter.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2001 by Martin Geisse <mgeisse@gmx.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00023 #ifndef __CS_OBJITER_H__ 00024 #define __CS_OBJITER_H__ 00025 00026 #include "csextern.h" 00027 #include "csutil/ref.h" 00028 #include "iutil/object.h" 00029 00033 template<typename T> class csTypedObjectIterator 00034 { 00035 protected: 00036 scfInterfaceID scf_id; 00037 int scf_ver; 00038 csRef<iObjectIterator> iter; 00039 csRef<iBase> CurrentTypedObject; 00040 00041 void FetchObject() 00042 { 00043 CurrentTypedObject.Invalidate(); 00044 while (iter->HasNext()) 00045 { 00046 CurrentTypedObject = 00047 csPtr<iBase>((iBase*)(iter->Next()->QueryInterface(scf_id, scf_ver))); 00048 if (CurrentTypedObject.IsValid()) 00049 return; 00050 } 00051 } 00052 00053 public: 00055 csTypedObjectIterator(iObject* parent) 00056 { 00057 scf_id = scfInterface<T>::GetID(); 00058 scf_ver = scfInterface<T>::GetVersion(); 00059 iter = parent->GetIterator(); 00060 FetchObject(); 00061 } 00062 00064 ~csTypedObjectIterator() {} 00065 00067 T* Next() 00068 { 00069 iBase* cur = CurrentTypedObject; 00070 FetchObject(); 00071 return (T*)cur; 00072 } 00073 00075 void Reset() { iter->Reset(); FetchObject(); } 00076 00078 iObject* GetParentObj() const { return iter->GetParentObj(); } 00079 00081 bool HasNext() const { return CurrentTypedObject.IsValid(); } 00082 00084 T* FindName (const char* name) 00085 { 00086 iObject* obj = iter->FindName(name); 00087 if (obj != 0) 00088 CurrentTypedObject.AttachNew( 00089 (iBase*)(obj->QueryInterface(scf_id, scf_ver))); 00090 else 00091 CurrentTypedObject.Invalidate(); 00092 return (T*)(iBase*)CurrentTypedObject; 00093 } 00094 }; 00095 00096 #endif // __CS_OBJITER_H__
Generated for Crystal Space by doxygen 1.3.9.1