Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | 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> 00034 class csTypedObjectIterator 00035 { 00036 protected: 00037 scfInterfaceID scf_id; 00038 int scf_ver; 00039 csRef<iObjectIterator> iter; 00040 csRef<T> CurrentTypedObject; 00041 00042 void FetchObject() 00043 { 00044 CurrentTypedObject.Invalidate(); 00045 while (iter->HasNext()) 00046 { 00047 CurrentTypedObject = 00048 csPtr<T>((T*)(iter->Next()->QueryInterface(scf_id, scf_ver))); 00049 if (CurrentTypedObject.IsValid()) 00050 return; 00051 } 00052 } 00053 00054 public: 00056 csTypedObjectIterator(iObject* parent) 00057 { 00058 scf_id = scfInterfaceTraits<T>::GetID(); 00059 scf_ver = scfInterfaceTraits<T>::GetVersion(); 00060 iter = parent->GetIterator(); 00061 FetchObject(); 00062 } 00063 00065 ~csTypedObjectIterator() {} 00066 00068 T* Next() 00069 { 00070 iBase* cur = CurrentTypedObject; 00071 FetchObject(); 00072 return (T*)cur; 00073 } 00074 00076 void Reset() { iter->Reset(); FetchObject(); } 00077 00079 iObject* GetParentObj() const { return iter->GetParentObj(); } 00080 00082 bool HasNext() const { return CurrentTypedObject.IsValid(); } 00083 00085 T* FindName (const char* name) 00086 { 00087 iObject* obj = iter->FindName(name); 00088 if (obj != 0) 00089 CurrentTypedObject.AttachNew( 00090 (T*)(obj->QueryInterface(scf_id, scf_ver))); 00091 else 00092 CurrentTypedObject.Invalidate(); 00093 return (T*)CurrentTypedObject; 00094 } 00095 }; 00096 00097 #endif // __CS_OBJITER_H__
Generated for Crystal Space by doxygen 1.4.4