## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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 "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__