|
objiter.h00001 /* 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 00019 #ifndef __OBJITER_H__ 00020 #define __OBJITER_H__ 00021 00022 #include "iutil/object.h" 00023 00028 #define CS_DECLARE_OBJECT_ITERATOR(NAME,INTERFACE) \ 00029 class NAME : public csTypedObjectIterator \ 00030 { \ 00031 protected: \ 00032 virtual void GetRequestedInterface (scfInterfaceID &id, int &ver) const \ 00033 { id = scfGetID_##INTERFACE (); ver = VERSION_##INTERFACE; } \ 00034 public: \ 00035 inline NAME (iObject *Parent) : csTypedObjectIterator (Parent) \ 00036 { FetchObject (); } \ 00037 inline INTERFACE *Get () \ 00038 { return (INTERFACE*)CurrentTypedObject; } \ 00039 }; 00040 00041 class csTypedObjectIterator 00042 { 00043 protected: 00044 iObjectIterator *iter; 00045 iBase *CurrentTypedObject; 00046 00047 void FetchObject (); 00048 virtual void GetRequestedInterface (scfInterfaceID &id, int &ver) const = 0; 00049 00050 public: 00051 // constructor 00052 csTypedObjectIterator (iObject *Parent); 00053 // destructor 00054 virtual ~csTypedObjectIterator (); 00055 00056 // Move forward 00057 inline bool Next(); 00058 // Reset the iterator to the beginning 00059 inline void Reset(); 00060 // Get the object we are pointing at 00061 inline iObject *GetObject () const; 00062 // Get the parent object 00063 inline iObject *GetParentObj() const; 00064 // Check if we have any children of requested type 00065 inline bool IsFinished () const; 00066 // Find the object with the given name 00067 inline bool FindName (const char* name); 00068 }; 00069 00070 inline bool csTypedObjectIterator::Next() 00071 { bool r = iter->Next (); FetchObject (); return r; } 00072 inline void csTypedObjectIterator::Reset() 00073 { iter->Reset (); FetchObject (); } 00074 inline iObject *csTypedObjectIterator::GetObject () const 00075 { return iter->GetObject (); } 00076 inline iObject *csTypedObjectIterator::GetParentObj() const 00077 { return iter->GetParentObj (); } 00078 inline bool csTypedObjectIterator::IsFinished () const 00079 { return iter->IsFinished (); } 00080 inline bool csTypedObjectIterator::FindName (const char* name) 00081 { bool r = iter->FindName (name); FetchObject (); return r; } 00082 00083 #endif // __OBJITER_H__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |