wintrust/tests: Add tests for WVTAsn1SpcIndirectDataContentDecode.
[wine.git] / dlls / windows.media.speech / vector.c
blobc23fb9dc56e196121cb7ce766a943136d1412bbb
1 /* WinRT Windows.Media.Speech implementation
3 * Copyright 2022 Bernhard Kölbl for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "private.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(speech);
28 * IIterator<HSTRING>
32 struct iterator_hstring
34 IIterator_HSTRING IIterator_HSTRING_iface;
35 LONG ref;
37 IVectorView_HSTRING *view;
38 UINT32 index;
39 UINT32 size;
42 static inline struct iterator_hstring *impl_from_IIterator_HSTRING( IIterator_HSTRING *iface )
44 return CONTAINING_RECORD(iface, struct iterator_hstring, IIterator_HSTRING_iface);
47 static HRESULT WINAPI iterator_hstring_QueryInterface( IIterator_HSTRING *iface, REFIID iid, void **out )
49 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
51 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
53 if (IsEqualGUID(iid, &IID_IUnknown) ||
54 IsEqualGUID(iid, &IID_IInspectable) ||
55 IsEqualGUID(iid, &IID_IAgileObject) ||
56 IsEqualGUID(iid, &IID_IIterator_HSTRING))
58 IInspectable_AddRef((*out = &impl->IIterator_HSTRING_iface));
59 return S_OK;
62 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
63 *out = NULL;
64 return E_NOINTERFACE;
67 static ULONG WINAPI iterator_hstring_AddRef( IIterator_HSTRING *iface )
69 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
70 ULONG ref = InterlockedIncrement(&impl->ref);
71 TRACE("iface %p increasing refcount to %lu.\n", iface, ref);
72 return ref;
75 static ULONG WINAPI iterator_hstring_Release( IIterator_HSTRING *iface )
77 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
78 ULONG ref = InterlockedDecrement(&impl->ref);
80 TRACE("iface %p decreasing refcount to %lu.\n", iface, ref);
82 if (!ref)
84 IVectorView_HSTRING_Release(impl->view);
85 free(impl);
88 return ref;
91 static HRESULT WINAPI iterator_hstring_GetIids( IIterator_HSTRING *iface, ULONG *iid_count, IID **iids )
93 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
94 return E_NOTIMPL;
97 static HRESULT WINAPI iterator_hstring_GetRuntimeClassName( IIterator_HSTRING *iface, HSTRING *class_name )
99 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
100 return E_NOTIMPL;
103 static HRESULT WINAPI iterator_hstring_GetTrustLevel( IIterator_HSTRING *iface, TrustLevel *trust_level )
105 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
106 return E_NOTIMPL;
109 static HRESULT WINAPI iterator_hstring_get_Current( IIterator_HSTRING *iface, HSTRING *value )
111 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
112 TRACE("iface %p, value %p.\n", iface, value);
113 return IVectorView_HSTRING_GetAt(impl->view, impl->index, value);
116 static HRESULT WINAPI iterator_hstring_get_HasCurrent( IIterator_HSTRING *iface, BOOL *value )
118 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
120 TRACE("iface %p, value %p.\n", iface, value);
122 *value = impl->index < impl->size;
123 return S_OK;
126 static HRESULT WINAPI iterator_hstring_MoveNext( IIterator_HSTRING *iface, BOOL *value )
128 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
130 TRACE("iface %p, value %p.\n", iface, value);
132 if (impl->index < impl->size) impl->index++;
133 return IIterator_HSTRING_get_HasCurrent(iface, value);
136 static HRESULT WINAPI iterator_hstring_GetMany( IIterator_HSTRING *iface, UINT32 items_size,
137 HSTRING *items, UINT *count )
139 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
140 TRACE("iface %p, items_size %u, items %p, count %p.\n", iface, items_size, items, count);
141 return IVectorView_HSTRING_GetMany(impl->view, impl->index, items_size, items, count);
144 static const IIterator_HSTRINGVtbl iterator_hstring_vtbl =
146 /* IUnknown methods */
147 iterator_hstring_QueryInterface,
148 iterator_hstring_AddRef,
149 iterator_hstring_Release,
150 /* IInspectable methods */
151 iterator_hstring_GetIids,
152 iterator_hstring_GetRuntimeClassName,
153 iterator_hstring_GetTrustLevel,
154 /* IIterator<HSTRING> methods */
155 iterator_hstring_get_Current,
156 iterator_hstring_get_HasCurrent,
157 iterator_hstring_MoveNext,
158 iterator_hstring_GetMany,
163 * IVectorView<HSTRING>
167 struct vector_view_hstring
169 IVectorView_HSTRING IVectorView_HSTRING_iface;
170 IIterable_HSTRING IIterable_HSTRING_iface;
171 LONG ref;
173 UINT32 size;
174 HSTRING elements[];
177 C_ASSERT(sizeof(struct vector_view_hstring) == offsetof(struct vector_view_hstring, elements[0]));
179 static inline struct vector_view_hstring *impl_from_IVectorView_HSTRING( IVectorView_HSTRING *iface )
181 return CONTAINING_RECORD(iface, struct vector_view_hstring, IVectorView_HSTRING_iface);
184 static HRESULT WINAPI vector_view_hstring_QueryInterface( IVectorView_HSTRING *iface, REFIID iid, void **out )
186 struct vector_view_hstring *impl = impl_from_IVectorView_HSTRING(iface);
188 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
190 if (IsEqualGUID(iid, &IID_IUnknown) ||
191 IsEqualGUID(iid, &IID_IInspectable) ||
192 IsEqualGUID(iid, &IID_IAgileObject) ||
193 IsEqualGUID(iid, &IID_IVectorView_HSTRING))
195 IInspectable_AddRef((*out = &impl->IVectorView_HSTRING_iface));
196 return S_OK;
199 if (IsEqualGUID(iid, &IID_IIterable_HSTRING))
201 IInspectable_AddRef((*out = &impl->IIterable_HSTRING_iface));
202 return S_OK;
205 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
206 *out = NULL;
207 return E_NOINTERFACE;
210 static ULONG WINAPI vector_view_hstring_AddRef( IVectorView_HSTRING *iface )
212 struct vector_view_hstring *impl = impl_from_IVectorView_HSTRING(iface);
213 ULONG ref = InterlockedIncrement(&impl->ref);
214 TRACE("iface %p increasing refcount to %lu.\n", iface, ref);
215 return ref;
218 static ULONG WINAPI vector_view_hstring_Release( IVectorView_HSTRING *iface )
220 struct vector_view_hstring *impl = impl_from_IVectorView_HSTRING(iface);
221 ULONG i, ref = InterlockedDecrement(&impl->ref);
223 TRACE("iface %p decreasing refcount to %lu.\n", iface, ref);
225 if (!ref)
227 for (i = 0; i < impl->size; ++i) WindowsDeleteString(impl->elements[i]);
228 free(impl);
231 return ref;
234 static HRESULT WINAPI vector_view_hstring_GetIids( IVectorView_HSTRING *iface, ULONG *iid_count, IID **iids )
236 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
237 return E_NOTIMPL;
240 static HRESULT WINAPI vector_view_hstring_GetRuntimeClassName( IVectorView_HSTRING *iface, HSTRING *class_name )
242 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
243 return E_NOTIMPL;
246 static HRESULT WINAPI vector_view_hstring_GetTrustLevel( IVectorView_HSTRING *iface, TrustLevel *trust_level )
248 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
249 return E_NOTIMPL;
252 static HRESULT WINAPI vector_view_hstring_GetAt( IVectorView_HSTRING *iface, UINT32 index, HSTRING *value )
254 struct vector_view_hstring *impl = impl_from_IVectorView_HSTRING(iface);
256 TRACE("iface %p, index %u, value %p.\n", iface, index, value);
258 *value = NULL;
259 if (index >= impl->size) return E_BOUNDS;
261 return WindowsDuplicateString(impl->elements[index], value);
264 static HRESULT WINAPI vector_view_hstring_get_Size( IVectorView_HSTRING *iface, UINT32 *value )
266 struct vector_view_hstring *impl = impl_from_IVectorView_HSTRING(iface);
268 TRACE("iface %p, value %p.\n", iface, value);
270 *value = impl->size;
271 return S_OK;
274 static HRESULT WINAPI vector_view_hstring_IndexOf( IVectorView_HSTRING *iface, HSTRING element,
275 UINT32 *index, BOOLEAN *found )
277 struct vector_view_hstring *impl = impl_from_IVectorView_HSTRING(iface);
278 ULONG i;
280 TRACE("iface %p, element %p, index %p, found %p.\n", iface, element, index, found);
282 for (i = 0; i < impl->size; ++i) if (impl->elements[i] == element) break;
283 if ((*found = (i < impl->size))) *index = i;
284 else *index = 0;
286 return S_OK;
289 static HRESULT WINAPI vector_view_hstring_GetMany( IVectorView_HSTRING *iface, UINT32 start_index,
290 UINT32 items_size, HSTRING *items, UINT *count )
292 struct vector_view_hstring *impl = impl_from_IVectorView_HSTRING(iface);
293 HRESULT hr;
294 UINT32 i;
296 TRACE( "iface %p, start_index %u, items_size %u, items %p, count %p.\n",
297 iface, start_index, items_size, items, count );
299 if (start_index >= impl->size) return E_BOUNDS;
301 for (i = start_index; i < impl->size; ++i)
303 if (i - start_index >= items_size) break;
304 if (FAILED(hr = WindowsDuplicateString(impl->elements[i], &items[i - start_index]))) goto error;
306 *count = i - start_index;
308 return S_OK;
310 error:
311 *count = 0;
312 while (i-- > start_index) WindowsDeleteString(items[i-start_index]);
313 return hr;
316 static const struct IVectorView_HSTRINGVtbl vector_view_hstring_vtbl =
318 /* IUnknown methods */
319 vector_view_hstring_QueryInterface,
320 vector_view_hstring_AddRef,
321 vector_view_hstring_Release,
322 /* IInspectable methods */
323 vector_view_hstring_GetIids,
324 vector_view_hstring_GetRuntimeClassName,
325 vector_view_hstring_GetTrustLevel,
326 /* IVectorView<HSTRING> methods */
327 vector_view_hstring_GetAt,
328 vector_view_hstring_get_Size,
329 vector_view_hstring_IndexOf,
330 vector_view_hstring_GetMany,
335 * IIterable<HSTRING>
339 DEFINE_IINSPECTABLE_(iterable_view_hstring, IIterable_HSTRING, struct vector_view_hstring, view_impl_from_IIterable_HSTRING,
340 IIterable_HSTRING_iface, &impl->IVectorView_HSTRING_iface)
342 static HRESULT WINAPI iterable_view_hstring_First( IIterable_HSTRING *iface, IIterator_HSTRING **value )
344 struct vector_view_hstring *impl = view_impl_from_IIterable_HSTRING(iface);
345 struct iterator_hstring *iter;
347 TRACE("iface %p, value %p.\n", iface, value);
349 if (!(iter = calloc(1, sizeof(*iter)))) return E_OUTOFMEMORY;
350 iter->IIterator_HSTRING_iface.lpVtbl = &iterator_hstring_vtbl;
351 iter->ref = 1;
353 IVectorView_HSTRING_AddRef((iter->view = &impl->IVectorView_HSTRING_iface));
354 iter->size = impl->size;
356 *value = &iter->IIterator_HSTRING_iface;
357 return S_OK;
360 static const struct IIterable_HSTRINGVtbl iterable_view_hstring_vtbl =
362 /* IUnknown methods */
363 iterable_view_hstring_QueryInterface,
364 iterable_view_hstring_AddRef,
365 iterable_view_hstring_Release,
366 /* IInspectable methods */
367 iterable_view_hstring_GetIids,
368 iterable_view_hstring_GetRuntimeClassName,
369 iterable_view_hstring_GetTrustLevel,
370 /* IIterable<HSTRING> methods */
371 iterable_view_hstring_First,
376 * IVector<HSTRING>
380 struct vector_hstring
382 IVector_HSTRING IVector_HSTRING_iface;
383 IIterable_HSTRING IIterable_HSTRING_iface;
384 LONG ref;
386 UINT32 size;
387 UINT32 capacity;
388 HSTRING *elements;
391 static inline struct vector_hstring *impl_from_IVector_HSTRING( IVector_HSTRING *iface )
393 return CONTAINING_RECORD(iface, struct vector_hstring, IVector_HSTRING_iface);
396 static HRESULT WINAPI vector_hstring_QueryInterface( IVector_HSTRING *iface, REFIID iid, void **out )
398 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
400 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
402 if (IsEqualGUID(iid, &IID_IUnknown) ||
403 IsEqualGUID(iid, &IID_IInspectable) ||
404 IsEqualGUID(iid, &IID_IAgileObject) ||
405 IsEqualGUID(iid, &IID_IVector_HSTRING))
407 IInspectable_AddRef((*out = &impl->IVector_HSTRING_iface));
408 return S_OK;
411 if (IsEqualGUID(iid, &IID_IIterable_HSTRING))
413 IInspectable_AddRef((*out = &impl->IIterable_HSTRING_iface));
414 return S_OK;
417 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
418 *out = NULL;
419 return E_NOINTERFACE;
422 static ULONG WINAPI vector_hstring_AddRef( IVector_HSTRING *iface )
424 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
425 ULONG ref = InterlockedIncrement(&impl->ref);
426 TRACE("iface %p, ref %lu.\n", iface, ref);
427 return ref;
430 static ULONG WINAPI vector_hstring_Release( IVector_HSTRING *iface )
432 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
433 ULONG ref = InterlockedDecrement(&impl->ref);
435 TRACE("iface %p, ref %lu.\n", iface, ref);
437 if (!ref)
439 IVector_HSTRING_Clear(iface);
440 free(impl);
443 return ref;
446 static HRESULT WINAPI vector_hstring_GetIids( IVector_HSTRING *iface, ULONG *iid_count, IID **iids )
448 FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids );
449 return E_NOTIMPL;
452 static HRESULT WINAPI vector_hstring_GetRuntimeClassName( IVector_HSTRING *iface, HSTRING *class_name )
454 FIXME( "iface %p, class_name %p stub!\n", iface, class_name );
455 return E_NOTIMPL;
458 static HRESULT WINAPI vector_hstring_GetTrustLevel( IVector_HSTRING *iface, TrustLevel *trust_level )
460 FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level );
461 return E_NOTIMPL;
464 static HRESULT WINAPI vector_hstring_GetAt( IVector_HSTRING *iface, UINT32 index, HSTRING *value )
466 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
468 TRACE( "iface %p, index %u, value %p.\n", iface, index, value );
470 *value = NULL;
471 if (index >= impl->size) return E_BOUNDS;
473 return WindowsDuplicateString(impl->elements[index], value);
476 static HRESULT WINAPI vector_hstring_get_Size( IVector_HSTRING *iface, UINT32 *value )
478 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
479 TRACE( "iface %p, value %p.\n", iface, value );
480 *value = impl->size;
481 return S_OK;
484 static HRESULT WINAPI vector_hstring_GetView( IVector_HSTRING *iface, IVectorView_HSTRING **value )
486 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
487 struct vector_view_hstring *view;
488 HRESULT hr;
489 ULONG i;
491 TRACE("iface %p, value %p.\n", iface, value);
493 if (!(view = calloc(1, offsetof(struct vector_view_hstring, elements[impl->size])))) return E_OUTOFMEMORY;
494 view->IVectorView_HSTRING_iface.lpVtbl = &vector_view_hstring_vtbl;
495 view->IIterable_HSTRING_iface.lpVtbl = &iterable_view_hstring_vtbl;
496 view->ref = 1;
498 for (i = 0; i < impl->size; ++i)
499 if (FAILED(hr = WindowsDuplicateString(impl->elements[i], &view->elements[view->size++]))) goto error;
501 *value = &view->IVectorView_HSTRING_iface;
502 return S_OK;
504 error:
505 while (i-- > 0) WindowsDeleteString(view->elements[i]);
506 free(view);
507 return hr;
510 static HRESULT WINAPI vector_hstring_IndexOf( IVector_HSTRING *iface, HSTRING element, UINT32 *index, BOOLEAN *found )
512 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
513 ULONG i;
515 TRACE("iface %p, element %p, index %p, found %p.\n", iface, element, index, found);
517 for (i = 0; i < impl->size; ++i) if (impl->elements[i] == element) break;
518 if ((*found = (i < impl->size))) *index = i;
519 else *index = 0;
521 return S_OK;
524 static HRESULT WINAPI vector_hstring_SetAt( IVector_HSTRING *iface, UINT32 index, HSTRING value )
526 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
527 HSTRING tmp;
528 HRESULT hr;
530 TRACE( "iface %p, index %u, value %p.\n", iface, index, value );
532 if (index >= impl->size) return E_BOUNDS;
534 if (FAILED(hr = WindowsDuplicateString(value, &tmp))) return hr;
536 WindowsDeleteString(impl->elements[index]);
537 impl->elements[index] = tmp;
538 return S_OK;
541 static HRESULT WINAPI vector_hstring_InsertAt( IVector_HSTRING *iface, UINT32 index, HSTRING value )
543 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
544 HSTRING tmp, *tmp2 = impl->elements;
545 HRESULT hr;
547 TRACE( "iface %p, index %u, value %p.\n", iface, index, value );
549 if (FAILED(hr = WindowsDuplicateString(value, &tmp))) return hr;
551 if (impl->size == impl->capacity)
553 impl->capacity = max(32, impl->capacity * 3 / 2);
554 if (!(impl->elements = realloc(impl->elements, impl->capacity * sizeof(*impl->elements))))
556 impl->elements = tmp2;
557 return E_OUTOFMEMORY;
561 memmove(impl->elements + index + 1, impl->elements + index, (impl->size++ - index) * sizeof(*impl->elements));
562 impl->elements[index] = tmp;
563 return S_OK;
566 static HRESULT WINAPI vector_hstring_RemoveAt( IVector_HSTRING *iface, UINT32 index )
568 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
570 TRACE("iface %p, index %u.\n", iface, index);
572 if (index >= impl->size) return E_BOUNDS;
574 WindowsDeleteString(impl->elements[index]);
575 memmove(impl->elements + index, impl->elements + index + 1, (--impl->size - index) * sizeof(*impl->elements));
576 return S_OK;
579 static HRESULT WINAPI vector_hstring_Append( IVector_HSTRING *iface, HSTRING value )
581 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
583 TRACE("iface %p, value %p.\n", iface, value);
585 return IVector_HSTRING_InsertAt(iface, impl->size, value);
588 static HRESULT WINAPI vector_hstring_RemoveAtEnd( IVector_HSTRING *iface )
590 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
592 TRACE("iface %p.\n", iface);
594 if (impl->size) WindowsDeleteString(impl->elements[--impl->size]);
595 return S_OK;
598 static HRESULT WINAPI vector_hstring_Clear( IVector_HSTRING *iface )
600 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
602 TRACE("iface %p.\n", iface);
604 while (impl->size) IVector_HSTRING_RemoveAtEnd(iface);
605 free(impl->elements);
606 impl->capacity = 0;
607 impl->elements = NULL;
609 return S_OK;
612 static HRESULT WINAPI vector_hstring_GetMany( IVector_HSTRING *iface, UINT32 start_index,
613 UINT32 items_size, HSTRING *items, UINT32 *count )
615 struct vector_hstring *impl = impl_from_IVector_HSTRING(iface);
616 HRESULT hr;
617 UINT32 i;
619 TRACE("iface %p, start_index %u, items_size %u, items %p, count %p.\n", iface, start_index, items_size, items, count);
621 if (start_index >= impl->size) return E_BOUNDS;
623 for (i = start_index; i < impl->size; ++i)
625 if (i - start_index >= items_size) break;
626 if (FAILED(hr = WindowsDuplicateString(impl->elements[i], &items[i-start_index]))) goto error;
628 *count = i - start_index;
630 return S_OK;
632 error:
633 *count = 0;
634 while (i-- > start_index) WindowsDeleteString(items[i-start_index]);
635 return hr;
638 static HRESULT WINAPI vector_hstring_ReplaceAll( IVector_HSTRING *iface, UINT32 count, HSTRING *items )
640 HRESULT hr;
641 ULONG i;
643 TRACE("iface %p, count %u, items %p.\n", iface, count, items);
645 hr = IVector_HSTRING_Clear(iface);
646 for (i = 0; i < count && SUCCEEDED(hr); ++i) hr = IVector_HSTRING_Append(iface, items[i]);
647 return hr;
650 static const struct IVector_HSTRINGVtbl vector_hstring_vtbl =
652 /* IUnknown methods */
653 vector_hstring_QueryInterface,
654 vector_hstring_AddRef,
655 vector_hstring_Release,
656 /* IInspectable methods */
657 vector_hstring_GetIids,
658 vector_hstring_GetRuntimeClassName,
659 vector_hstring_GetTrustLevel,
660 /* IVector<HSTRING> methods */
661 vector_hstring_GetAt,
662 vector_hstring_get_Size,
663 vector_hstring_GetView,
664 vector_hstring_IndexOf,
665 vector_hstring_SetAt,
666 vector_hstring_InsertAt,
667 vector_hstring_RemoveAt,
668 vector_hstring_Append,
669 vector_hstring_RemoveAtEnd,
670 vector_hstring_Clear,
671 vector_hstring_GetMany,
672 vector_hstring_ReplaceAll,
677 * IIterable<HSTRING>
681 DEFINE_IINSPECTABLE(iterable_hstring, IIterable_HSTRING, struct vector_hstring, IVector_HSTRING_iface)
683 static HRESULT WINAPI iterable_hstring_First( IIterable_HSTRING *iface, IIterator_HSTRING **value )
685 struct vector_hstring *impl = impl_from_IIterable_HSTRING(iface);
686 IIterable_HSTRING *iterable;
687 IVectorView_HSTRING *view;
688 HRESULT hr;
690 TRACE("iface %p, value %p.\n", iface, value);
692 if (FAILED(hr = IVector_HSTRING_GetView(&impl->IVector_HSTRING_iface, &view))) return hr;
694 hr = IVectorView_HSTRING_QueryInterface(view, &IID_IIterable_HSTRING, (void **)&iterable);
695 IVectorView_HSTRING_Release(view);
696 if (FAILED(hr)) return hr;
698 hr = IIterable_HSTRING_First(iterable, value);
699 IIterable_HSTRING_Release(iterable);
700 return hr;
703 static const struct IIterable_HSTRINGVtbl iterable_hstring_vtbl =
705 /* IUnknown methods */
706 iterable_hstring_QueryInterface,
707 iterable_hstring_AddRef,
708 iterable_hstring_Release,
709 /* IInspectable methods */
710 iterable_hstring_GetIids,
711 iterable_hstring_GetRuntimeClassName,
712 iterable_hstring_GetTrustLevel,
713 /* IIterable<HSTRING> methods */
714 iterable_hstring_First,
717 HRESULT vector_hstring_create( IVector_HSTRING **out )
719 struct vector_hstring *impl;
721 TRACE("out %p.\n", out);
723 if (!(impl = calloc(1, sizeof(*impl)))) return E_OUTOFMEMORY;
724 impl->IVector_HSTRING_iface.lpVtbl = &vector_hstring_vtbl;
725 impl->IIterable_HSTRING_iface.lpVtbl = &iterable_hstring_vtbl;
726 impl->ref = 1;
728 *out = &impl->IVector_HSTRING_iface;
729 TRACE("created %p\n", *out);
730 return S_OK;
733 HRESULT vector_hstring_create_copy( IIterable_HSTRING *iterable, IVector_HSTRING **out )
735 struct vector_hstring *impl;
736 IIterator_HSTRING *iterator;
737 UINT32 capacity = 0;
738 BOOL available;
739 HRESULT hr;
741 TRACE("iterable %p, out %p.\n", iterable, out);
743 if (FAILED(hr = vector_hstring_create(out))) return hr;
744 if (FAILED(hr = IIterable_HSTRING_First(iterable, &iterator))) goto error;
746 for (IIterator_HSTRING_get_HasCurrent(iterator, &available); available; IIterator_HSTRING_MoveNext(iterator, &available))
747 capacity++;
749 IIterator_HSTRING_Release(iterator);
751 impl = impl_from_IVector_HSTRING(*out);
752 impl->size = 0;
753 impl->capacity = capacity;
754 if (!(impl->elements = realloc(impl->elements, impl->capacity * sizeof(*impl->elements)))) goto error;
756 if (FAILED(hr = IIterable_HSTRING_First(iterable, &iterator))) goto error;
758 for (IIterator_HSTRING_get_HasCurrent(iterator, &available); available; IIterator_HSTRING_MoveNext(iterator, &available))
760 HSTRING str;
761 if (FAILED(hr = IIterator_HSTRING_get_Current(iterator, &str))) goto error;
762 if (FAILED(hr = WindowsDuplicateString(str, &impl->elements[impl->size]))) goto error;
763 WindowsDeleteString(str);
764 impl->size++;
767 IIterator_HSTRING_Release(iterator);
769 TRACE("created %p\n", *out);
770 return S_OK;
772 error:
773 IVector_HSTRING_Release(*out);
774 return hr;
779 * IIterator<Inspectable*>
783 struct iterator_inspectable
785 IIterator_IInspectable IIterator_IInspectable_iface;
786 const GUID *iid;
787 LONG ref;
789 IVectorView_IInspectable *view;
790 UINT32 index;
791 UINT32 size;
794 static inline struct iterator_inspectable *impl_from_IIterator_IInspectable( IIterator_IInspectable *iface )
796 return CONTAINING_RECORD(iface, struct iterator_inspectable, IIterator_IInspectable_iface);
799 static HRESULT WINAPI iterator_inspectable_QueryInterface( IIterator_IInspectable *iface, REFIID iid, void **out )
801 struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface);
803 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
805 if (IsEqualGUID(iid, &IID_IUnknown) ||
806 IsEqualGUID(iid, &IID_IInspectable) ||
807 IsEqualGUID(iid, &IID_IAgileObject) ||
808 IsEqualGUID(iid, impl->iid))
810 IInspectable_AddRef((*out = &impl->IIterator_IInspectable_iface));
811 return S_OK;
814 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
815 *out = NULL;
816 return E_NOINTERFACE;
819 static ULONG WINAPI iterator_inspectable_AddRef( IIterator_IInspectable *iface )
821 struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface);
822 ULONG ref = InterlockedIncrement(&impl->ref);
823 TRACE("iface %p increasing refcount to %lu.\n", iface, ref);
824 return ref;
827 static ULONG WINAPI iterator_inspectable_Release( IIterator_IInspectable *iface )
829 struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface);
830 ULONG ref = InterlockedDecrement(&impl->ref);
832 TRACE("iface %p decreasing refcount to %lu.\n", iface, ref);
834 if (!ref)
836 IVectorView_IInspectable_Release(impl->view);
837 free(impl);
840 return ref;
843 static HRESULT WINAPI iterator_inspectable_GetIids( IIterator_IInspectable *iface, ULONG *iid_count, IID **iids )
845 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
846 return E_NOTIMPL;
849 static HRESULT WINAPI iterator_inspectable_GetRuntimeClassName( IIterator_IInspectable *iface, HSTRING *class_name )
851 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
852 return E_NOTIMPL;
855 static HRESULT WINAPI iterator_inspectable_GetTrustLevel( IIterator_IInspectable *iface, TrustLevel *trust_level )
857 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
858 return E_NOTIMPL;
861 static HRESULT WINAPI iterator_inspectable_get_Current( IIterator_IInspectable *iface, IInspectable **value )
863 struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface);
864 TRACE("iface %p, value %p.\n", iface, value);
865 return IVectorView_IInspectable_GetAt(impl->view, impl->index, value);
868 static HRESULT WINAPI iterator_inspectable_get_HasCurrent( IIterator_IInspectable *iface, BOOL *value )
870 struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface);
872 TRACE("iface %p, value %p.\n", iface, value);
874 *value = impl->index < impl->size;
875 return S_OK;
878 static HRESULT WINAPI iterator_inspectable_MoveNext( IIterator_IInspectable *iface, BOOL *value )
880 struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface);
882 TRACE("iface %p, value %p.\n", iface, value);
884 if (impl->index < impl->size) impl->index++;
885 return IIterator_IInspectable_get_HasCurrent(iface, value);
888 static HRESULT WINAPI iterator_inspectable_GetMany( IIterator_IInspectable *iface, UINT32 items_size,
889 IInspectable **items, UINT *count )
891 struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface);
892 TRACE("iface %p, items_size %u, items %p, count %p.\n", iface, items_size, items, count);
893 return IVectorView_IInspectable_GetMany(impl->view, impl->index, items_size, items, count);
896 static const IIterator_IInspectableVtbl iterator_inspectable_vtbl =
898 /* IUnknown methods */
899 iterator_inspectable_QueryInterface,
900 iterator_inspectable_AddRef,
901 iterator_inspectable_Release,
902 /* IInspectable methods */
903 iterator_inspectable_GetIids,
904 iterator_inspectable_GetRuntimeClassName,
905 iterator_inspectable_GetTrustLevel,
906 /* IIterator<IInspectable*> methods */
907 iterator_inspectable_get_Current,
908 iterator_inspectable_get_HasCurrent,
909 iterator_inspectable_MoveNext,
910 iterator_inspectable_GetMany
915 * IVectorView<Inspectable*>
919 struct vector_view_inspectable
921 IVectorView_IInspectable IVectorView_IInspectable_iface;
922 IIterable_IInspectable IIterable_IInspectable_iface;
923 struct vector_iids iids;
924 LONG ref;
926 UINT32 size;
927 IInspectable *elements[];
930 C_ASSERT(sizeof(struct vector_view_inspectable) == offsetof(struct vector_view_inspectable, elements[0]));
932 static inline struct vector_view_inspectable *impl_from_IVectorView_IInspectable( IVectorView_IInspectable *iface )
934 return CONTAINING_RECORD(iface, struct vector_view_inspectable, IVectorView_IInspectable_iface);
937 static HRESULT WINAPI vector_view_inspectable_QueryInterface( IVectorView_IInspectable *iface, REFIID iid, void **out )
939 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
941 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
943 if (IsEqualGUID(iid, &IID_IUnknown) ||
944 IsEqualGUID(iid, &IID_IInspectable) ||
945 IsEqualGUID(iid, &IID_IAgileObject) ||
946 IsEqualGUID(iid, impl->iids.view))
948 IInspectable_AddRef((*out = &impl->IVectorView_IInspectable_iface));
949 return S_OK;
952 if (IsEqualGUID(iid, impl->iids.iterable))
954 IInspectable_AddRef((*out = &impl->IIterable_IInspectable_iface));
955 return S_OK;
958 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
959 *out = NULL;
960 return E_NOINTERFACE;
963 static ULONG WINAPI vector_view_inspectable_AddRef( IVectorView_IInspectable *iface )
965 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
966 ULONG ref = InterlockedIncrement(&impl->ref);
967 TRACE("iface %p increasing refcount to %lu.\n", iface, ref);
968 return ref;
971 static ULONG WINAPI vector_view_inspectable_Release( IVectorView_IInspectable *iface )
973 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
974 ULONG i, ref = InterlockedDecrement(&impl->ref);
976 TRACE("iface %p decreasing refcount to %lu.\n", iface, ref);
978 if (!ref)
980 for (i = 0; i < impl->size; ++i) IInspectable_Release(impl->elements[i]);
981 free(impl);
984 return ref;
987 static HRESULT WINAPI vector_view_inspectable_GetIids( IVectorView_IInspectable *iface, ULONG *iid_count, IID **iids )
989 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
990 return E_NOTIMPL;
993 static HRESULT WINAPI vector_view_inspectable_GetRuntimeClassName( IVectorView_IInspectable *iface, HSTRING *class_name )
995 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
996 return E_NOTIMPL;
999 static HRESULT WINAPI vector_view_inspectable_GetTrustLevel( IVectorView_IInspectable *iface, TrustLevel *trust_level )
1001 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
1002 return E_NOTIMPL;
1005 static HRESULT WINAPI vector_view_inspectable_GetAt( IVectorView_IInspectable *iface, UINT32 index, IInspectable **value )
1007 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
1009 TRACE("iface %p, index %u, value %p.\n", iface, index, value);
1011 *value = NULL;
1012 if (index >= impl->size) return E_BOUNDS;
1014 IInspectable_AddRef((*value = impl->elements[index]));
1015 return S_OK;
1018 static HRESULT WINAPI vector_view_inspectable_get_Size( IVectorView_IInspectable *iface, UINT32 *value )
1020 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
1022 TRACE("iface %p, value %p.\n", iface, value);
1024 *value = impl->size;
1025 return S_OK;
1028 static HRESULT WINAPI vector_view_inspectable_IndexOf( IVectorView_IInspectable *iface, IInspectable *element,
1029 UINT32 *index, BOOLEAN *found )
1031 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
1032 ULONG i;
1034 TRACE("iface %p, element %p, index %p, found %p.\n", iface, element, index, found);
1036 for (i = 0; i < impl->size; ++i) if (impl->elements[i] == element) break;
1037 if ((*found = (i < impl->size))) *index = i;
1038 else *index = 0;
1040 return S_OK;
1043 static HRESULT WINAPI vector_view_inspectable_GetMany( IVectorView_IInspectable *iface, UINT32 start_index,
1044 UINT32 items_size, IInspectable **items, UINT *count )
1046 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
1047 UINT32 i;
1049 TRACE("iface %p, start_index %u, items_size %u, items %p, count %p.\n",
1050 iface, start_index, items_size, items, count);
1052 if (start_index >= impl->size) return E_BOUNDS;
1054 for (i = start_index; i < impl->size; ++i)
1056 if (i - start_index >= items_size) break;
1057 IInspectable_AddRef((items[i - start_index] = impl->elements[i]));
1059 *count = i - start_index;
1061 return S_OK;
1064 static const struct IVectorView_IInspectableVtbl vector_view_inspectable_vtbl =
1066 /* IUnknown methods */
1067 vector_view_inspectable_QueryInterface,
1068 vector_view_inspectable_AddRef,
1069 vector_view_inspectable_Release,
1070 /* IInspectable methods */
1071 vector_view_inspectable_GetIids,
1072 vector_view_inspectable_GetRuntimeClassName,
1073 vector_view_inspectable_GetTrustLevel,
1074 /* IVectorView<IInspectable*> methods */
1075 vector_view_inspectable_GetAt,
1076 vector_view_inspectable_get_Size,
1077 vector_view_inspectable_IndexOf,
1078 vector_view_inspectable_GetMany
1083 * IIterable<Inspectable*>
1087 DEFINE_IINSPECTABLE_(iterable_view_inspectable, IIterable_IInspectable, struct vector_view_inspectable,
1088 view_impl_from_IIterable_IInspectable, IIterable_IInspectable_iface, &impl->IVectorView_IInspectable_iface)
1090 static HRESULT WINAPI iterable_view_inspectable_First( IIterable_IInspectable *iface, IIterator_IInspectable **value )
1092 struct vector_view_inspectable *impl = view_impl_from_IIterable_IInspectable(iface);
1093 struct iterator_inspectable *iter;
1095 TRACE("iface %p, value %p.\n", iface, value);
1097 if (!(iter = calloc(1, sizeof(struct iterator_inspectable)))) return E_OUTOFMEMORY;
1098 iter->IIterator_IInspectable_iface.lpVtbl = &iterator_inspectable_vtbl;
1099 iter->iid = impl->iids.iterator;
1100 iter->ref = 1;
1102 IVectorView_IInspectable_AddRef((iter->view = &impl->IVectorView_IInspectable_iface));
1103 iter->size = impl->size;
1105 *value = &iter->IIterator_IInspectable_iface;
1106 return S_OK;
1109 static const struct IIterable_IInspectableVtbl iterable_view_inspectable_vtbl =
1111 /* IUnknown methods */
1112 iterable_view_inspectable_QueryInterface,
1113 iterable_view_inspectable_AddRef,
1114 iterable_view_inspectable_Release,
1115 /* IInspectable methods */
1116 iterable_view_inspectable_GetIids,
1117 iterable_view_inspectable_GetRuntimeClassName,
1118 iterable_view_inspectable_GetTrustLevel,
1119 /* IIterable<IInspectable*> methods */
1120 iterable_view_inspectable_First
1125 * IVector<Inspectable*>
1129 struct vector_inspectable
1131 IVector_IInspectable IVector_IInspectable_iface;
1132 IIterable_IInspectable IIterable_IInspectable_iface;
1133 struct vector_iids iids;
1134 LONG ref;
1136 UINT32 size;
1137 UINT32 capacity;
1138 IInspectable **elements;
1141 static inline struct vector_inspectable *impl_from_IVector_IInspectable( IVector_IInspectable *iface )
1143 return CONTAINING_RECORD(iface, struct vector_inspectable, IVector_IInspectable_iface);
1146 static HRESULT WINAPI vector_inspectable_QueryInterface( IVector_IInspectable *iface, REFIID iid, void **out )
1148 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1150 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
1152 if (IsEqualGUID(iid, &IID_IUnknown) ||
1153 IsEqualGUID(iid, &IID_IInspectable) ||
1154 IsEqualGUID(iid, &IID_IAgileObject) ||
1155 IsEqualGUID(iid, impl->iids.vector))
1157 IInspectable_AddRef((*out = &impl->IVector_IInspectable_iface));
1158 return S_OK;
1161 if (IsEqualGUID(iid, impl->iids.iterable))
1163 IInspectable_AddRef((*out = &impl->IIterable_IInspectable_iface));
1164 return S_OK;
1167 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
1168 *out = NULL;
1169 return E_NOINTERFACE;
1172 static ULONG WINAPI vector_inspectable_AddRef( IVector_IInspectable *iface )
1174 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1175 ULONG ref = InterlockedIncrement(&impl->ref);
1176 TRACE("iface %p increasing refcount to %lu.\n", iface, ref);
1177 return ref;
1180 static ULONG WINAPI vector_inspectable_Release( IVector_IInspectable *iface )
1182 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1183 ULONG ref = InterlockedDecrement(&impl->ref);
1185 TRACE("iface %p decreasing refcount to %lu.\n", iface, ref);
1187 if (!ref)
1189 IVector_IInspectable_Clear(iface);
1190 free(impl);
1193 return ref;
1196 static HRESULT WINAPI vector_inspectable_GetIids( IVector_IInspectable *iface, ULONG *iid_count, IID **iids )
1198 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
1199 return E_NOTIMPL;
1202 static HRESULT WINAPI vector_inspectable_GetRuntimeClassName( IVector_IInspectable *iface, HSTRING *class_name )
1204 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
1205 return E_NOTIMPL;
1208 static HRESULT WINAPI vector_inspectable_GetTrustLevel( IVector_IInspectable *iface, TrustLevel *trust_level )
1210 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
1211 return E_NOTIMPL;
1214 static HRESULT WINAPI vector_inspectable_GetAt( IVector_IInspectable *iface, UINT32 index, IInspectable **value )
1216 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1218 TRACE("iface %p, index %u, value %p.\n", iface, index, value);
1220 *value = NULL;
1221 if (index >= impl->size) return E_BOUNDS;
1223 IInspectable_AddRef((*value = impl->elements[index]));
1224 return S_OK;
1227 static HRESULT WINAPI vector_inspectable_get_Size( IVector_IInspectable *iface, UINT32 *value )
1229 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1230 TRACE("iface %p, value %p.\n", iface, value);
1231 *value = impl->size;
1232 return S_OK;
1235 static HRESULT WINAPI vector_inspectable_GetView( IVector_IInspectable *iface, IVectorView_IInspectable **value )
1237 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1238 struct vector_view_inspectable *view;
1239 ULONG i;
1241 TRACE("iface %p, value %p.\n", iface, value);
1243 if (!(view = calloc(1, offsetof(struct vector_view_inspectable, elements[impl->size])))) return E_OUTOFMEMORY;
1244 view->IVectorView_IInspectable_iface.lpVtbl = &vector_view_inspectable_vtbl;
1245 view->IIterable_IInspectable_iface.lpVtbl = &iterable_view_inspectable_vtbl;
1246 view->iids = impl->iids;
1247 view->ref = 1;
1249 for (i = 0; i < impl->size; ++i) IInspectable_AddRef((view->elements[view->size++] = impl->elements[i]));
1251 *value = &view->IVectorView_IInspectable_iface;
1252 return S_OK;
1255 static HRESULT WINAPI vector_inspectable_IndexOf( IVector_IInspectable *iface,
1256 IInspectable *element, UINT32 *index, BOOLEAN *found )
1258 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1259 ULONG i;
1261 TRACE("iface %p, element %p, index %p, found %p.\n", iface, element, index, found);
1263 for (i = 0; i < impl->size; ++i) if (impl->elements[i] == element) break;
1264 if ((*found = (i < impl->size))) *index = i;
1265 else *index = 0;
1267 return S_OK;
1270 static HRESULT WINAPI vector_inspectable_SetAt( IVector_IInspectable *iface, UINT32 index, IInspectable *value )
1272 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1274 TRACE("iface %p, index %u, value %p.\n", iface, index, value);
1276 if (index >= impl->size) return E_BOUNDS;
1277 IInspectable_Release(impl->elements[index]);
1278 IInspectable_AddRef((impl->elements[index] = value));
1279 return S_OK;
1282 static HRESULT WINAPI vector_inspectable_InsertAt( IVector_IInspectable *iface, UINT32 index, IInspectable *value )
1284 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1285 IInspectable **tmp = impl->elements;
1287 TRACE("iface %p, index %u, value %p.\n", iface, index, value);
1289 if (impl->size == impl->capacity)
1291 impl->capacity = max(32, impl->capacity * 3 / 2);
1292 if (!(impl->elements = realloc(impl->elements, impl->capacity * sizeof(*impl->elements))))
1294 impl->elements = tmp;
1295 return E_OUTOFMEMORY;
1299 memmove(impl->elements + index + 1, impl->elements + index, (impl->size++ - index) * sizeof(*impl->elements));
1300 IInspectable_AddRef((impl->elements[index] = value));
1301 return S_OK;
1304 static HRESULT WINAPI vector_inspectable_RemoveAt( IVector_IInspectable *iface, UINT32 index )
1306 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1308 TRACE("iface %p, index %u.\n", iface, index);
1310 if (index >= impl->size) return E_BOUNDS;
1311 IInspectable_Release(impl->elements[index]);
1312 memmove(impl->elements + index, impl->elements + index + 1, (--impl->size - index) * sizeof(*impl->elements));
1313 return S_OK;
1316 static HRESULT WINAPI vector_inspectable_Append( IVector_IInspectable *iface, IInspectable *value )
1318 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1320 TRACE("iface %p, value %p.\n", iface, value);
1322 return IVector_IInspectable_InsertAt(iface, impl->size, value);
1325 static HRESULT WINAPI vector_inspectable_RemoveAtEnd( IVector_IInspectable *iface )
1327 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1329 TRACE("iface %p.\n", iface);
1331 if (impl->size) IInspectable_Release(impl->elements[--impl->size]);
1332 return S_OK;
1335 static HRESULT WINAPI vector_inspectable_Clear( IVector_IInspectable *iface )
1337 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1339 TRACE("iface %p.\n", iface);
1341 while (impl->size) IVector_IInspectable_RemoveAtEnd(iface);
1342 free(impl->elements);
1343 impl->capacity = 0;
1344 impl->elements = NULL;
1346 return S_OK;
1349 static HRESULT WINAPI vector_inspectable_GetMany( IVector_IInspectable *iface, UINT32 start_index,
1350 UINT32 items_size, IInspectable **items, UINT *count )
1352 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1353 UINT32 i;
1355 TRACE("iface %p, start_index %u, items_size %u, items %p, count %p.\n",
1356 iface, start_index, items_size, items, count);
1358 if (start_index >= impl->size) return E_BOUNDS;
1360 for (i = start_index; i < impl->size; ++i)
1362 if (i - start_index >= items_size) break;
1363 IInspectable_AddRef((items[i - start_index] = impl->elements[i]));
1365 *count = i - start_index;
1367 return S_OK;
1370 static HRESULT WINAPI vector_inspectable_ReplaceAll( IVector_IInspectable *iface, UINT32 count, IInspectable **items )
1372 HRESULT hr;
1373 ULONG i;
1375 TRACE("iface %p, count %u, items %p.\n", iface, count, items);
1377 hr = IVector_IInspectable_Clear(iface);
1378 for (i = 0; i < count && SUCCEEDED(hr); ++i) hr = IVector_IInspectable_Append(iface, items[i]);
1379 return hr;
1382 static const struct IVector_IInspectableVtbl vector_inspectable_vtbl =
1384 /* IUnknown methods */
1385 vector_inspectable_QueryInterface,
1386 vector_inspectable_AddRef,
1387 vector_inspectable_Release,
1388 /* IInspectable methods */
1389 vector_inspectable_GetIids,
1390 vector_inspectable_GetRuntimeClassName,
1391 vector_inspectable_GetTrustLevel,
1392 /* IVector<IInspectable*> methods */
1393 vector_inspectable_GetAt,
1394 vector_inspectable_get_Size,
1395 vector_inspectable_GetView,
1396 vector_inspectable_IndexOf,
1397 vector_inspectable_SetAt,
1398 vector_inspectable_InsertAt,
1399 vector_inspectable_RemoveAt,
1400 vector_inspectable_Append,
1401 vector_inspectable_RemoveAtEnd,
1402 vector_inspectable_Clear,
1403 vector_inspectable_GetMany,
1404 vector_inspectable_ReplaceAll
1409 * IIterable<Inspectable*>
1413 DEFINE_IINSPECTABLE(iterable_inspectable, IIterable_IInspectable, struct vector_inspectable, IVector_IInspectable_iface)
1415 static HRESULT WINAPI iterable_inspectable_First( IIterable_IInspectable *iface, IIterator_IInspectable **value )
1417 struct vector_inspectable *impl = impl_from_IIterable_IInspectable(iface);
1418 IIterable_IInspectable *iterable;
1419 IVectorView_IInspectable *view;
1420 HRESULT hr;
1422 TRACE("iface %p, value %p.\n", iface, value);
1424 if (FAILED(hr = IVector_IInspectable_GetView(&impl->IVector_IInspectable_iface, &view))) return hr;
1426 hr = IVectorView_IInspectable_QueryInterface(view, impl->iids.iterable, (void **)&iterable);
1427 IVectorView_IInspectable_Release(view);
1428 if (FAILED(hr)) return hr;
1430 hr = IIterable_IInspectable_First(iterable, value);
1431 IIterable_IInspectable_Release(iterable);
1432 return hr;
1435 static const struct IIterable_IInspectableVtbl iterable_inspectable_vtbl =
1437 /* IUnknown methods */
1438 iterable_inspectable_QueryInterface,
1439 iterable_inspectable_AddRef,
1440 iterable_inspectable_Release,
1441 /* IInspectable methods */
1442 iterable_inspectable_GetIids,
1443 iterable_inspectable_GetRuntimeClassName,
1444 iterable_inspectable_GetTrustLevel,
1445 /* IIterable<IInspectable*> methods */
1446 iterable_inspectable_First
1449 HRESULT vector_inspectable_create( const struct vector_iids *iids, IVector_IInspectable **out )
1451 struct vector_inspectable *impl;
1453 TRACE("iid %s, out %p.\n", debugstr_guid(iids->vector), out);
1455 if (!(impl = calloc(1, sizeof(*impl)))) return E_OUTOFMEMORY;
1456 impl->IVector_IInspectable_iface.lpVtbl = &vector_inspectable_vtbl;
1457 impl->IIterable_IInspectable_iface.lpVtbl = &iterable_inspectable_vtbl;
1458 impl->iids = *iids;
1459 impl->ref = 1;
1461 *out = &impl->IVector_IInspectable_iface;
1462 TRACE("created %p\n", *out);
1463 return S_OK;