csutil/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 "iutil/object.h" 00027 00033 #define CS_DECLARE_OBJECT_ITERATOR(NAME,INTERFACE) \ 00034 class NAME : public csTypedObjectIterator \ 00035 { \ 00036 protected: \ 00037 virtual void GetRequestedInterface (scfInterfaceID &id, \ 00038 int &ver) const \ 00039 { id = scfInterface<INTERFACE>::GetID(); \ 00040 ver = scfInterface<INTERFACE>::GetVersion(); } \ 00041 public: \ 00042 inline NAME (iObject *Parent) : csTypedObjectIterator (Parent) \ 00043 { } \ 00044 inline INTERFACE *Next () \ 00045 { return (INTERFACE*)(iBase*)csTypedObjectIterator::Next (); } \ 00046 }; 00047 00051 class csTypedObjectIterator 00052 { 00053 protected: 00054 csRef<iObjectIterator> iter; 00055 csRef<iBase> CurrentTypedObject; 00056 bool fetched; 00057 00058 void FetchObject (); 00059 iBase* GetCurrentObject(); 00060 virtual void GetRequestedInterface (scfInterfaceID &id, int &ver) const = 0; 00061 00062 public: 00064 csTypedObjectIterator (iObject *Parent); 00066 virtual ~csTypedObjectIterator (); 00067 00069 iBase* Next() 00070 { 00071 iBase* cur = GetCurrentObject(); 00072 FetchObject (); 00073 return cur; 00074 } 00076 void Reset () { iter->Reset (); fetched = false; } 00078 iObject *GetParentObj() const { return iter->GetParentObj (); } 00080 bool HasNext () const 00081 { return const_cast<csTypedObjectIterator*>(this)->GetCurrentObject() != 0; } 00083 iBase* FindName (const char* name); 00084 }; 00085 00086 #endif // __CS_OBJITER_H__
Generated for Crystal Space by doxygen 1.2.18