windows.media.speech: Add IIterable<IInspectable*> stubs.
[wine.git] / dlls / windows.media.speech / vector.c
blob5b6a4b1c98449ce5adc871bc73b58a940e6e6cd6
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 * IVectorView<Inspectable*>
783 struct vector_view_inspectable
785 IVectorView_IInspectable IVectorView_IInspectable_iface;
786 IIterable_IInspectable IIterable_IInspectable_iface;
787 struct vector_iids iids;
788 LONG ref;
790 UINT32 size;
791 IInspectable *elements[];
794 C_ASSERT(sizeof(struct vector_view_inspectable) == offsetof(struct vector_view_inspectable, elements[0]));
796 static inline struct vector_view_inspectable *impl_from_IVectorView_IInspectable( IVectorView_IInspectable *iface )
798 return CONTAINING_RECORD(iface, struct vector_view_inspectable, IVectorView_IInspectable_iface);
801 static HRESULT WINAPI vector_view_inspectable_QueryInterface( IVectorView_IInspectable *iface, REFIID iid, void **out )
803 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
805 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
807 if (IsEqualGUID(iid, &IID_IUnknown) ||
808 IsEqualGUID(iid, &IID_IInspectable) ||
809 IsEqualGUID(iid, &IID_IAgileObject) ||
810 IsEqualGUID(iid, impl->iids.view))
812 IInspectable_AddRef((*out = &impl->IVectorView_IInspectable_iface));
813 return S_OK;
816 if (IsEqualGUID(iid, impl->iids.iterable))
818 IInspectable_AddRef((*out = &impl->IIterable_IInspectable_iface));
819 return S_OK;
822 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
823 *out = NULL;
824 return E_NOINTERFACE;
827 static ULONG WINAPI vector_view_inspectable_AddRef( IVectorView_IInspectable *iface )
829 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
830 ULONG ref = InterlockedIncrement(&impl->ref);
831 TRACE("iface %p increasing refcount to %lu.\n", iface, ref);
832 return ref;
835 static ULONG WINAPI vector_view_inspectable_Release( IVectorView_IInspectable *iface )
837 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
838 ULONG i, ref = InterlockedDecrement(&impl->ref);
840 TRACE("iface %p decreasing refcount to %lu.\n", iface, ref);
842 if (!ref)
844 for (i = 0; i < impl->size; ++i) IInspectable_Release(impl->elements[i]);
845 free(impl);
848 return ref;
851 static HRESULT WINAPI vector_view_inspectable_GetIids( IVectorView_IInspectable *iface, ULONG *iid_count, IID **iids )
853 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
854 return E_NOTIMPL;
857 static HRESULT WINAPI vector_view_inspectable_GetRuntimeClassName( IVectorView_IInspectable *iface, HSTRING *class_name )
859 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
860 return E_NOTIMPL;
863 static HRESULT WINAPI vector_view_inspectable_GetTrustLevel( IVectorView_IInspectable *iface, TrustLevel *trust_level )
865 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
866 return E_NOTIMPL;
869 static HRESULT WINAPI vector_view_inspectable_GetAt( IVectorView_IInspectable *iface, UINT32 index, IInspectable **value )
871 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
873 TRACE("iface %p, index %u, value %p.\n", iface, index, value);
875 *value = NULL;
876 if (index >= impl->size) return E_BOUNDS;
878 IInspectable_AddRef((*value = impl->elements[index]));
879 return S_OK;
882 static HRESULT WINAPI vector_view_inspectable_get_Size( IVectorView_IInspectable *iface, UINT32 *value )
884 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
886 TRACE("iface %p, value %p.\n", iface, value);
888 *value = impl->size;
889 return S_OK;
892 static HRESULT WINAPI vector_view_inspectable_IndexOf( IVectorView_IInspectable *iface, IInspectable *element,
893 UINT32 *index, BOOLEAN *found )
895 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
896 ULONG i;
898 TRACE("iface %p, element %p, index %p, found %p.\n", iface, element, index, found);
900 for (i = 0; i < impl->size; ++i) if (impl->elements[i] == element) break;
901 if ((*found = (i < impl->size))) *index = i;
902 else *index = 0;
904 return S_OK;
907 static HRESULT WINAPI vector_view_inspectable_GetMany( IVectorView_IInspectable *iface, UINT32 start_index,
908 UINT32 items_size, IInspectable **items, UINT *count )
910 struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface);
911 UINT32 i;
913 TRACE("iface %p, start_index %u, items_size %u, items %p, count %p.\n",
914 iface, start_index, items_size, items, count);
916 if (start_index >= impl->size) return E_BOUNDS;
918 for (i = start_index; i < impl->size; ++i)
920 if (i - start_index >= items_size) break;
921 IInspectable_AddRef((items[i - start_index] = impl->elements[i]));
923 *count = i - start_index;
925 return S_OK;
928 static const struct IVectorView_IInspectableVtbl vector_view_inspectable_vtbl =
930 /* IUnknown methods */
931 vector_view_inspectable_QueryInterface,
932 vector_view_inspectable_AddRef,
933 vector_view_inspectable_Release,
934 /* IInspectable methods */
935 vector_view_inspectable_GetIids,
936 vector_view_inspectable_GetRuntimeClassName,
937 vector_view_inspectable_GetTrustLevel,
938 /* IVectorView<IInspectable*> methods */
939 vector_view_inspectable_GetAt,
940 vector_view_inspectable_get_Size,
941 vector_view_inspectable_IndexOf,
942 vector_view_inspectable_GetMany
947 * IIterable<Inspectable*>
951 DEFINE_IINSPECTABLE_(iterable_view_inspectable, IIterable_IInspectable, struct vector_view_inspectable,
952 view_impl_from_IIterable_IInspectable, IIterable_IInspectable_iface, &impl->IVectorView_IInspectable_iface)
954 static HRESULT WINAPI iterable_view_inspectable_First( IIterable_IInspectable *iface, IIterator_IInspectable **value )
956 FIXME("iface %p, value %p stub!\n", iface, value);
957 return E_NOTIMPL;
960 static const struct IIterable_IInspectableVtbl iterable_view_inspectable_vtbl =
962 /* IUnknown methods */
963 iterable_view_inspectable_QueryInterface,
964 iterable_view_inspectable_AddRef,
965 iterable_view_inspectable_Release,
966 /* IInspectable methods */
967 iterable_view_inspectable_GetIids,
968 iterable_view_inspectable_GetRuntimeClassName,
969 iterable_view_inspectable_GetTrustLevel,
970 /* IIterable<IInspectable*> methods */
971 iterable_view_inspectable_First
976 * IVector<Inspectable*>
980 struct vector_inspectable
982 IVector_IInspectable IVector_IInspectable_iface;
983 IIterable_IInspectable IIterable_IInspectable_iface;
984 struct vector_iids iids;
985 LONG ref;
987 UINT32 size;
988 UINT32 capacity;
989 IInspectable **elements;
992 static inline struct vector_inspectable *impl_from_IVector_IInspectable( IVector_IInspectable *iface )
994 return CONTAINING_RECORD(iface, struct vector_inspectable, IVector_IInspectable_iface);
997 static HRESULT WINAPI vector_inspectable_QueryInterface( IVector_IInspectable *iface, REFIID iid, void **out )
999 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1001 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
1003 if (IsEqualGUID(iid, &IID_IUnknown) ||
1004 IsEqualGUID(iid, &IID_IInspectable) ||
1005 IsEqualGUID(iid, &IID_IAgileObject) ||
1006 IsEqualGUID(iid, impl->iids.vector))
1008 IInspectable_AddRef((*out = &impl->IVector_IInspectable_iface));
1009 return S_OK;
1012 if (IsEqualGUID(iid, impl->iids.iterable))
1014 IInspectable_AddRef((*out = &impl->IIterable_IInspectable_iface));
1015 return S_OK;
1018 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
1019 *out = NULL;
1020 return E_NOINTERFACE;
1023 static ULONG WINAPI vector_inspectable_AddRef( IVector_IInspectable *iface )
1025 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1026 ULONG ref = InterlockedIncrement(&impl->ref);
1027 TRACE("iface %p increasing refcount to %lu.\n", iface, ref);
1028 return ref;
1031 static ULONG WINAPI vector_inspectable_Release( IVector_IInspectable *iface )
1033 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1034 ULONG ref = InterlockedDecrement(&impl->ref);
1036 TRACE("iface %p decreasing refcount to %lu.\n", iface, ref);
1038 if (!ref)
1040 IVector_IInspectable_Clear(iface);
1041 free(impl);
1044 return ref;
1047 static HRESULT WINAPI vector_inspectable_GetIids( IVector_IInspectable *iface, ULONG *iid_count, IID **iids )
1049 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
1050 return E_NOTIMPL;
1053 static HRESULT WINAPI vector_inspectable_GetRuntimeClassName( IVector_IInspectable *iface, HSTRING *class_name )
1055 FIXME("iface %p, class_name %p stub!\n", iface, class_name);
1056 return E_NOTIMPL;
1059 static HRESULT WINAPI vector_inspectable_GetTrustLevel( IVector_IInspectable *iface, TrustLevel *trust_level )
1061 FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
1062 return E_NOTIMPL;
1065 static HRESULT WINAPI vector_inspectable_GetAt( IVector_IInspectable *iface, UINT32 index, IInspectable **value )
1067 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1069 TRACE("iface %p, index %u, value %p.\n", iface, index, value);
1071 *value = NULL;
1072 if (index >= impl->size) return E_BOUNDS;
1074 IInspectable_AddRef((*value = impl->elements[index]));
1075 return S_OK;
1078 static HRESULT WINAPI vector_inspectable_get_Size( IVector_IInspectable *iface, UINT32 *value )
1080 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1081 TRACE("iface %p, value %p.\n", iface, value);
1082 *value = impl->size;
1083 return S_OK;
1086 static HRESULT WINAPI vector_inspectable_GetView( IVector_IInspectable *iface, IVectorView_IInspectable **value )
1088 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1089 struct vector_view_inspectable *view;
1090 ULONG i;
1092 TRACE("iface %p, value %p.\n", iface, value);
1094 if (!(view = calloc(1, offsetof(struct vector_view_inspectable, elements[impl->size])))) return E_OUTOFMEMORY;
1095 view->IVectorView_IInspectable_iface.lpVtbl = &vector_view_inspectable_vtbl;
1096 view->IIterable_IInspectable_iface.lpVtbl = &iterable_view_inspectable_vtbl;
1097 view->iids = impl->iids;
1098 view->ref = 1;
1100 for (i = 0; i < impl->size; ++i) IInspectable_AddRef((view->elements[view->size++] = impl->elements[i]));
1102 *value = &view->IVectorView_IInspectable_iface;
1103 return S_OK;
1106 static HRESULT WINAPI vector_inspectable_IndexOf( IVector_IInspectable *iface,
1107 IInspectable *element, UINT32 *index, BOOLEAN *found )
1109 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1110 ULONG i;
1112 TRACE("iface %p, element %p, index %p, found %p.\n", iface, element, index, found);
1114 for (i = 0; i < impl->size; ++i) if (impl->elements[i] == element) break;
1115 if ((*found = (i < impl->size))) *index = i;
1116 else *index = 0;
1118 return S_OK;
1121 static HRESULT WINAPI vector_inspectable_SetAt( IVector_IInspectable *iface, UINT32 index, IInspectable *value )
1123 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1125 TRACE("iface %p, index %u, value %p.\n", iface, index, value);
1127 if (index >= impl->size) return E_BOUNDS;
1128 IInspectable_Release(impl->elements[index]);
1129 IInspectable_AddRef((impl->elements[index] = value));
1130 return S_OK;
1133 static HRESULT WINAPI vector_inspectable_InsertAt( IVector_IInspectable *iface, UINT32 index, IInspectable *value )
1135 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1136 IInspectable **tmp = impl->elements;
1138 TRACE("iface %p, index %u, value %p.\n", iface, index, value);
1140 if (impl->size == impl->capacity)
1142 impl->capacity = max(32, impl->capacity * 3 / 2);
1143 if (!(impl->elements = realloc(impl->elements, impl->capacity * sizeof(*impl->elements))))
1145 impl->elements = tmp;
1146 return E_OUTOFMEMORY;
1150 memmove(impl->elements + index + 1, impl->elements + index, (impl->size++ - index) * sizeof(*impl->elements));
1151 IInspectable_AddRef((impl->elements[index] = value));
1152 return S_OK;
1155 static HRESULT WINAPI vector_inspectable_RemoveAt( IVector_IInspectable *iface, UINT32 index )
1157 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1159 TRACE("iface %p, index %u.\n", iface, index);
1161 if (index >= impl->size) return E_BOUNDS;
1162 IInspectable_Release(impl->elements[index]);
1163 memmove(impl->elements + index, impl->elements + index + 1, (--impl->size - index) * sizeof(*impl->elements));
1164 return S_OK;
1167 static HRESULT WINAPI vector_inspectable_Append( IVector_IInspectable *iface, IInspectable *value )
1169 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1171 TRACE("iface %p, value %p.\n", iface, value);
1173 return IVector_IInspectable_InsertAt(iface, impl->size, value);
1176 static HRESULT WINAPI vector_inspectable_RemoveAtEnd( IVector_IInspectable *iface )
1178 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1180 TRACE("iface %p.\n", iface);
1182 if (impl->size) IInspectable_Release(impl->elements[--impl->size]);
1183 return S_OK;
1186 static HRESULT WINAPI vector_inspectable_Clear( IVector_IInspectable *iface )
1188 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1190 TRACE("iface %p.\n", iface);
1192 while (impl->size) IVector_IInspectable_RemoveAtEnd(iface);
1193 free(impl->elements);
1194 impl->capacity = 0;
1195 impl->elements = NULL;
1197 return S_OK;
1200 static HRESULT WINAPI vector_inspectable_GetMany( IVector_IInspectable *iface, UINT32 start_index,
1201 UINT32 items_size, IInspectable **items, UINT *count )
1203 struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface);
1204 UINT32 i;
1206 TRACE("iface %p, start_index %u, items_size %u, items %p, count %p.\n",
1207 iface, start_index, items_size, items, count);
1209 if (start_index >= impl->size) return E_BOUNDS;
1211 for (i = start_index; i < impl->size; ++i)
1213 if (i - start_index >= items_size) break;
1214 IInspectable_AddRef((items[i - start_index] = impl->elements[i]));
1216 *count = i - start_index;
1218 return S_OK;
1221 static HRESULT WINAPI vector_inspectable_ReplaceAll( IVector_IInspectable *iface, UINT32 count, IInspectable **items )
1223 HRESULT hr;
1224 ULONG i;
1226 TRACE("iface %p, count %u, items %p.\n", iface, count, items);
1228 hr = IVector_IInspectable_Clear(iface);
1229 for (i = 0; i < count && SUCCEEDED(hr); ++i) hr = IVector_IInspectable_Append(iface, items[i]);
1230 return hr;
1233 static const struct IVector_IInspectableVtbl vector_inspectable_vtbl =
1235 /* IUnknown methods */
1236 vector_inspectable_QueryInterface,
1237 vector_inspectable_AddRef,
1238 vector_inspectable_Release,
1239 /* IInspectable methods */
1240 vector_inspectable_GetIids,
1241 vector_inspectable_GetRuntimeClassName,
1242 vector_inspectable_GetTrustLevel,
1243 /* IVector<IInspectable*> methods */
1244 vector_inspectable_GetAt,
1245 vector_inspectable_get_Size,
1246 vector_inspectable_GetView,
1247 vector_inspectable_IndexOf,
1248 vector_inspectable_SetAt,
1249 vector_inspectable_InsertAt,
1250 vector_inspectable_RemoveAt,
1251 vector_inspectable_Append,
1252 vector_inspectable_RemoveAtEnd,
1253 vector_inspectable_Clear,
1254 vector_inspectable_GetMany,
1255 vector_inspectable_ReplaceAll
1260 * IIterable<Inspectable*>
1264 DEFINE_IINSPECTABLE(iterable_inspectable, IIterable_IInspectable, struct vector_inspectable, IVector_IInspectable_iface)
1266 static HRESULT WINAPI iterable_inspectable_First( IIterable_IInspectable *iface, IIterator_IInspectable **value )
1268 FIXME("iface %p, value %p stub!\n", iface, value);
1269 return E_NOTIMPL;
1272 static const struct IIterable_IInspectableVtbl iterable_inspectable_vtbl =
1274 /* IUnknown methods */
1275 iterable_inspectable_QueryInterface,
1276 iterable_inspectable_AddRef,
1277 iterable_inspectable_Release,
1278 /* IInspectable methods */
1279 iterable_inspectable_GetIids,
1280 iterable_inspectable_GetRuntimeClassName,
1281 iterable_inspectable_GetTrustLevel,
1282 /* IIterable<IInspectable*> methods */
1283 iterable_inspectable_First
1286 HRESULT vector_inspectable_create( const struct vector_iids *iids, IVector_IInspectable **out )
1288 struct vector_inspectable *impl;
1290 TRACE("iid %s, out %p.\n", debugstr_guid(iids->vector), out);
1292 if (!(impl = calloc(1, sizeof(*impl)))) return E_OUTOFMEMORY;
1293 impl->IVector_IInspectable_iface.lpVtbl = &vector_inspectable_vtbl;
1294 impl->IIterable_IInspectable_iface.lpVtbl = &iterable_inspectable_vtbl;
1295 impl->iids = *iids;
1296 impl->ref = 1;
1298 *out = &impl->IVector_IInspectable_iface;
1299 TRACE("created %p\n", *out);
1300 return S_OK;