2 * IEnum* implementation
4 * Copyright 2006 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/list.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ole);
36 struct tagEnumSTATPROPSETSTG_impl
46 /************************************************************************
47 * enumx_QueryInterface
49 HRESULT WINAPI enumx_QueryInterface(
54 if ( (This==0) || (ppvObject==0) )
59 if (IsEqualGUID(&IID_IUnknown, riid) ||
60 IsEqualGUID(&This->riid, riid))
62 IUnknown_AddRef(((IUnknown*)This));
70 /************************************************************************
73 ULONG WINAPI enumx_AddRef(enumx_impl *This)
75 return InterlockedIncrement(&This->ref);
78 /************************************************************************
81 ULONG WINAPI enumx_Release(enumx_impl *This)
85 ref = InterlockedDecrement(&This->ref);
88 while (!list_empty(&This->elements))
90 struct list *x = list_head(&This->elements);
92 HeapFree(GetProcessHeap(), 0, x);
94 HeapFree(GetProcessHeap(), 0, This);
99 /************************************************************************
102 HRESULT WINAPI enumx_Next(enumx_impl *This, ULONG celt,
103 void *rgelt, ULONG *pceltFetched)
108 TRACE("%p %u %p\n", This, celt, pceltFetched);
110 if (This->current == NULL)
111 This->current = list_head(&This->elements);
113 while (count < celt && This->current && This->current != &This->elements)
115 memcpy(p, &This->current[1], This->elem_size);
116 p += This->elem_size;
117 This->current = This->current->next;
121 *pceltFetched = count;
127 /************************************************************************
130 HRESULT WINAPI enumx_Skip(enumx_impl *This, ULONG celt)
134 TRACE("%p %u\n", This, celt);
136 if (This->current == NULL)
137 This->current = list_head(&This->elements);
139 while (count < celt && This->current && This->current != &This->elements)
145 /************************************************************************
148 HRESULT WINAPI enumx_Reset(enumx_impl *This)
152 This->current = NULL;
156 /************************************************************************
159 HRESULT WINAPI enumx_Clone(
167 /************************************************************************
170 * Allocate a generic enumerator
172 enumx_impl *enumx_allocate(REFIID riid, const void *vtbl, ULONG elem_size)
176 enumx = HeapAlloc(GetProcessHeap(), 0, sizeof *enumx);
181 enumx->current = NULL;
182 enumx->elem_size = elem_size;
184 list_init(&enumx->elements);
190 /************************************************************************
193 * Add an element to the enumeration.
195 void *enumx_add_element(enumx_impl *enumx, const void *data)
197 struct list *element;
199 element = HeapAlloc(GetProcessHeap(), 0, sizeof *element + enumx->elem_size);
202 memcpy(&element[1], data, enumx->elem_size);
203 list_add_tail(&enumx->elements, element);