Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #ifndef __CS_OBJITER_H__
00024 #define __CS_OBJITER_H__
00025
00026 #include "csextern.h"
00027 #include "csutil/scf.h"
00028 #include "csutil/ref.h"
00029 #include "iutil/object.h"
00030
00034 template<typename T>
00035 class csTypedObjectIterator
00036 {
00037 protected:
00038 csRef<iObjectIterator> iter;
00039 csRef<T> CurrentTypedObject;
00040
00041 void FetchObject()
00042 {
00043 CurrentTypedObject.Invalidate();
00044 while (iter->HasNext())
00045 {
00046 CurrentTypedObject = scfQueryInterface<T> (iter->Next());
00047 if (CurrentTypedObject.IsValid())
00048 return;
00049 }
00050 }
00051
00052 public:
00054 csTypedObjectIterator(iObject* parent)
00055 {
00056 iter = parent->GetIterator();
00057 FetchObject();
00058 }
00059
00061 ~csTypedObjectIterator() {}
00062
00064 T* Next()
00065 {
00066 T* cur = CurrentTypedObject;
00067 FetchObject();
00068 return (T*)cur;
00069 }
00070
00072 void Reset() { iter->Reset(); FetchObject(); }
00073
00075 iObject* GetParentObj() const { return iter->GetParentObj(); }
00076
00078 bool HasNext() const { return CurrentTypedObject.IsValid(); }
00079
00081 T* FindName (const char* name)
00082 {
00083 iObject* obj = iter->FindName(name);
00084 if (obj != 0)
00085 CurrentTypedObject = scfQueryInterface<T> (obj);
00086 else
00087 CurrentTypedObject.Invalidate();
00088 return (T*)CurrentTypedObject;
00089 }
00090 };
00091
00092 #endif // __CS_OBJITER_H__