2012-09-20 06:02:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Alistair Leslie-Hughes
|
2015-02-27 16:25:06 +01:00
|
|
|
* Copyright 2015 Nikolay Sivov for CodeWeavers
|
2012-09-20 06:02:16 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2019-06-20 09:09:09 +02:00
|
|
|
#include <math.h>
|
2012-09-20 06:02:16 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "ole2.h"
|
2015-02-24 22:22:00 +01:00
|
|
|
#include "olectl.h"
|
2012-09-20 06:02:16 +02:00
|
|
|
#include "dispex.h"
|
|
|
|
#include "scrrun.h"
|
|
|
|
#include "scrrun_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2018-02-03 00:17:54 +01:00
|
|
|
#include "wine/heap.h"
|
2015-02-27 16:00:28 +01:00
|
|
|
#include "wine/list.h"
|
2012-09-20 06:02:16 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(scrrun);
|
|
|
|
|
2015-03-21 21:30:56 +01:00
|
|
|
#define BUCKET_COUNT 509
|
|
|
|
#define DICT_HASH_MOD 1201
|
2015-02-27 16:00:28 +01:00
|
|
|
|
2015-03-17 20:18:27 +01:00
|
|
|
/* Implementation details
|
|
|
|
|
|
|
|
Dictionary contains one list that links all pairs, this way
|
|
|
|
order in which they were added is preserved. Each bucket has
|
|
|
|
its own list to hold all pairs in this bucket. Initially all
|
|
|
|
bucket lists are zeroed and we init them once we about to add
|
|
|
|
first pair.
|
|
|
|
|
|
|
|
When pair is removed it's unlinked from both lists; if it was
|
|
|
|
a last pair in a bucket list it stays empty in initialized state.
|
|
|
|
|
|
|
|
Preserving pair order is important for enumeration, so far testing
|
|
|
|
indicates that pairs are not reordered basing on hash value.
|
|
|
|
*/
|
|
|
|
|
2015-02-27 16:00:28 +01:00
|
|
|
struct keyitem_pair {
|
2015-03-17 20:18:27 +01:00
|
|
|
struct list entry;
|
|
|
|
struct list bucket;
|
2015-02-27 16:00:28 +01:00
|
|
|
DWORD hash;
|
|
|
|
VARIANT key;
|
|
|
|
VARIANT item;
|
|
|
|
};
|
|
|
|
|
2012-09-20 06:02:16 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2016-12-07 11:33:58 +01:00
|
|
|
struct provideclassinfo classinfo;
|
2012-09-20 06:02:16 +02:00
|
|
|
IDictionary IDictionary_iface;
|
|
|
|
LONG ref;
|
2015-02-24 09:28:41 +01:00
|
|
|
|
|
|
|
CompareMethod method;
|
2015-02-26 15:27:02 +01:00
|
|
|
LONG count;
|
2015-02-27 16:00:28 +01:00
|
|
|
struct list pairs;
|
2015-03-17 20:18:27 +01:00
|
|
|
struct list buckets[BUCKET_COUNT];
|
2015-03-18 13:11:32 +01:00
|
|
|
struct list notifier;
|
2012-09-20 06:02:16 +02:00
|
|
|
} dictionary;
|
|
|
|
|
2015-03-17 20:49:17 +01:00
|
|
|
struct dictionary_enum {
|
|
|
|
IEnumVARIANT IEnumVARIANT_iface;
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
dictionary *dict;
|
2015-03-18 13:11:32 +01:00
|
|
|
struct list *cur;
|
|
|
|
struct list notify;
|
2015-03-17 20:49:17 +01:00
|
|
|
};
|
|
|
|
|
2012-09-20 06:02:16 +02:00
|
|
|
static inline dictionary *impl_from_IDictionary(IDictionary *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, dictionary, IDictionary_iface);
|
|
|
|
}
|
|
|
|
|
2015-03-17 20:49:17 +01:00
|
|
|
static inline struct dictionary_enum *impl_from_IEnumVARIANT(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dictionary_enum, IEnumVARIANT_iface);
|
|
|
|
}
|
|
|
|
|
2015-03-17 20:18:27 +01:00
|
|
|
static inline struct list *get_bucket_head(dictionary *dict, DWORD hash)
|
2015-02-27 16:00:28 +01:00
|
|
|
{
|
2015-03-17 20:18:27 +01:00
|
|
|
return &dict->buckets[hash % BUCKET_COUNT];
|
2015-02-27 16:00:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL is_string_key(const VARIANT *key)
|
|
|
|
{
|
|
|
|
return V_VT(key) == VT_BSTR || V_VT(key) == (VT_BSTR|VT_BYREF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only for VT_BSTR or VT_BSTR|VT_BYREF types */
|
|
|
|
static inline WCHAR *get_key_strptr(const VARIANT *key)
|
|
|
|
{
|
|
|
|
if (V_VT(key) == VT_BSTR)
|
|
|
|
return V_BSTR(key);
|
|
|
|
|
|
|
|
if (V_BSTRREF(key))
|
|
|
|
return *V_BSTRREF(key);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* should be used only when both keys are of string type, it's not checked */
|
|
|
|
static inline int strcmp_key(const dictionary *dict, const VARIANT *key1, const VARIANT *key2)
|
|
|
|
{
|
|
|
|
const WCHAR *str1, *str2;
|
|
|
|
|
|
|
|
str1 = get_key_strptr(key1);
|
|
|
|
str2 = get_key_strptr(key2);
|
2019-06-20 09:09:09 +02:00
|
|
|
return dict->method == BinaryCompare ? wcscmp(str1, str2) : wcsicmp(str1, str2);
|
2015-02-27 16:00:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL is_matching_key(const dictionary *dict, const struct keyitem_pair *pair, const VARIANT *key, DWORD hash)
|
|
|
|
{
|
|
|
|
if (is_string_key(key) && is_string_key(&pair->key)) {
|
|
|
|
if (hash != pair->hash)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return strcmp_key(dict, key, &pair->key) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((is_string_key(key) && !is_string_key(&pair->key)) ||
|
|
|
|
(!is_string_key(key) && is_string_key(&pair->key)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* for numeric keys only check hash */
|
|
|
|
return hash == pair->hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct keyitem_pair *get_keyitem_pair(dictionary *dict, VARIANT *key)
|
|
|
|
{
|
|
|
|
struct keyitem_pair *pair;
|
2015-03-17 20:18:27 +01:00
|
|
|
struct list *head, *entry;
|
2015-02-27 16:00:28 +01:00
|
|
|
VARIANT hash;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IDictionary_get_HashVal(&dict->IDictionary_iface, key, &hash);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return NULL;
|
|
|
|
|
2015-04-11 08:58:48 +02:00
|
|
|
head = get_bucket_head(dict, V_I4(&hash));
|
2015-03-17 20:18:27 +01:00
|
|
|
if (!head->next || list_empty(head))
|
2015-02-27 16:00:28 +01:00
|
|
|
return NULL;
|
|
|
|
|
2015-04-11 08:58:48 +02:00
|
|
|
entry = list_head(head);
|
2015-02-27 16:00:28 +01:00
|
|
|
do {
|
2015-03-17 20:18:27 +01:00
|
|
|
pair = LIST_ENTRY(entry, struct keyitem_pair, bucket);
|
2015-02-27 16:00:28 +01:00
|
|
|
if (is_matching_key(dict, pair, key, V_I4(&hash))) return pair;
|
2015-03-17 20:18:27 +01:00
|
|
|
} while ((entry = list_next(head, entry)));
|
2015-02-27 16:00:28 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT add_keyitem_pair(dictionary *dict, VARIANT *key, VARIANT *item)
|
|
|
|
{
|
2015-03-17 20:18:27 +01:00
|
|
|
struct keyitem_pair *pair;
|
|
|
|
struct list *head;
|
2015-02-27 16:00:28 +01:00
|
|
|
VARIANT hash;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IDictionary_get_HashVal(&dict->IDictionary_iface, key, &hash);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
pair = heap_alloc(sizeof(*pair));
|
|
|
|
if (!pair)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
pair->hash = V_I4(&hash);
|
|
|
|
VariantInit(&pair->key);
|
|
|
|
VariantInit(&pair->item);
|
|
|
|
|
|
|
|
hr = VariantCopyInd(&pair->key, key);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
hr = VariantCopyInd(&pair->item, item);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
head = get_bucket_head(dict, pair->hash);
|
2015-03-17 20:18:27 +01:00
|
|
|
if (!head->next)
|
|
|
|
/* this only happens once per bucket */
|
|
|
|
list_init(head);
|
2015-02-27 16:00:28 +01:00
|
|
|
|
2015-03-17 20:18:27 +01:00
|
|
|
/* link to bucket list and to full list */
|
|
|
|
list_add_tail(head, &pair->bucket);
|
|
|
|
list_add_tail(&dict->pairs, &pair->entry);
|
2015-02-27 16:00:28 +01:00
|
|
|
dict->count++;
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
VariantClear(&pair->key);
|
|
|
|
VariantClear(&pair->item);
|
|
|
|
heap_free(pair);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_keyitem_pair(struct keyitem_pair *pair)
|
|
|
|
{
|
|
|
|
VariantClear(&pair->key);
|
|
|
|
VariantClear(&pair->item);
|
|
|
|
heap_free(pair);
|
|
|
|
}
|
|
|
|
|
2015-03-17 20:49:17 +01:00
|
|
|
static HRESULT WINAPI dict_enum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
struct dictionary_enum *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IEnumVARIANT) || IsEqualIID(riid, &IID_IUnknown)) {
|
|
|
|
*obj = iface;
|
|
|
|
IEnumVARIANT_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
WARN("interface not supported %s\n", debugstr_guid(riid));
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dict_enum_AddRef(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
struct dictionary_enum *This = impl_from_IEnumVARIANT(iface);
|
2016-12-07 11:33:57 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
TRACE("(%p)->(%u)\n", This, ref);
|
|
|
|
return ref;
|
2015-03-17 20:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dict_enum_Release(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
struct dictionary_enum *This = impl_from_IEnumVARIANT(iface);
|
2016-12-07 11:33:57 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
2015-03-17 20:49:17 +01:00
|
|
|
|
2016-12-07 11:33:57 +01:00
|
|
|
TRACE("(%p)->(%u)\n", This, ref);
|
2015-03-17 20:49:17 +01:00
|
|
|
|
2016-12-07 11:33:57 +01:00
|
|
|
if (!ref) {
|
2015-03-18 13:11:32 +01:00
|
|
|
list_remove(&This->notify);
|
2015-03-17 20:49:17 +01:00
|
|
|
IDictionary_Release(&This->dict->IDictionary_iface);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dict_enum_Next(IEnumVARIANT *iface, ULONG count, VARIANT *keys, ULONG *fetched)
|
|
|
|
{
|
|
|
|
struct dictionary_enum *This = impl_from_IEnumVARIANT(iface);
|
2015-03-18 13:11:32 +01:00
|
|
|
struct keyitem_pair *pair;
|
|
|
|
ULONG i = 0;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u %p %p)\n", This, count, keys, fetched);
|
|
|
|
|
|
|
|
if (fetched)
|
|
|
|
*fetched = 0;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
while (This->cur && i < count) {
|
|
|
|
pair = LIST_ENTRY(This->cur, struct keyitem_pair, entry);
|
|
|
|
VariantCopy(&keys[i], &pair->key);
|
|
|
|
This->cur = list_next(&This->dict->pairs, This->cur);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fetched)
|
|
|
|
*fetched = i;
|
|
|
|
|
|
|
|
return i < count ? S_FALSE : S_OK;
|
2015-03-17 20:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dict_enum_Skip(IEnumVARIANT *iface, ULONG count)
|
|
|
|
{
|
|
|
|
struct dictionary_enum *This = impl_from_IEnumVARIANT(iface);
|
2015-03-18 13:11:32 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%u)\n", This, count);
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (!This->cur)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
This->cur = list_next(&This->dict->pairs, This->cur);
|
|
|
|
if (!This->cur) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count == 0 ? S_OK : S_FALSE;
|
2015-03-17 20:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dict_enum_Reset(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
struct dictionary_enum *This = impl_from_IEnumVARIANT(iface);
|
2015-03-18 13:11:32 +01:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
This->cur = list_head(&This->dict->pairs);
|
|
|
|
return S_OK;
|
2015-03-17 20:49:17 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 13:11:32 +01:00
|
|
|
static HRESULT create_dict_enum(dictionary*, IUnknown**);
|
|
|
|
|
2015-03-17 20:49:17 +01:00
|
|
|
static HRESULT WINAPI dict_enum_Clone(IEnumVARIANT *iface, IEnumVARIANT **cloned)
|
|
|
|
{
|
|
|
|
struct dictionary_enum *This = impl_from_IEnumVARIANT(iface);
|
2015-03-18 13:11:32 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, cloned);
|
|
|
|
return create_dict_enum(This->dict, (IUnknown**)cloned);
|
2015-03-17 20:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumVARIANTVtbl dictenumvtbl = {
|
|
|
|
dict_enum_QueryInterface,
|
|
|
|
dict_enum_AddRef,
|
|
|
|
dict_enum_Release,
|
|
|
|
dict_enum_Next,
|
|
|
|
dict_enum_Skip,
|
|
|
|
dict_enum_Reset,
|
|
|
|
dict_enum_Clone
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT create_dict_enum(dictionary *dict, IUnknown **ret)
|
|
|
|
{
|
|
|
|
struct dictionary_enum *This;
|
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
|
|
|
|
This = heap_alloc(sizeof(*This));
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IEnumVARIANT_iface.lpVtbl = &dictenumvtbl;
|
|
|
|
This->ref = 1;
|
2015-03-18 13:11:32 +01:00
|
|
|
This->cur = list_head(&dict->pairs);
|
|
|
|
list_add_tail(&dict->notifier, &This->notify);
|
2015-03-17 20:49:17 +01:00
|
|
|
This->dict = dict;
|
|
|
|
IDictionary_AddRef(&dict->IDictionary_iface);
|
|
|
|
|
|
|
|
*ret = (IUnknown*)&This->IEnumVARIANT_iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-18 13:11:32 +01:00
|
|
|
static void notify_remove_pair(struct list *notifier, struct list *pair)
|
|
|
|
{
|
|
|
|
struct dictionary_enum *dict_enum;
|
|
|
|
struct list *cur;
|
|
|
|
|
|
|
|
LIST_FOR_EACH(cur, notifier) {
|
|
|
|
dict_enum = LIST_ENTRY(cur, struct dictionary_enum, notify);
|
|
|
|
if (!pair)
|
|
|
|
dict_enum->cur = list_head(&dict_enum->dict->pairs);
|
|
|
|
else if (dict_enum->cur == pair) {
|
|
|
|
dict_enum->cur = list_next(&dict_enum->dict->pairs, dict_enum->cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-20 06:02:16 +02:00
|
|
|
static HRESULT WINAPI dictionary_QueryInterface(IDictionary *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IDispatch) ||
|
|
|
|
IsEqualIID(riid, &IID_IDictionary))
|
|
|
|
{
|
|
|
|
*obj = &This->IDictionary_iface;
|
|
|
|
}
|
2016-12-07 11:33:58 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IProvideClassInfo))
|
|
|
|
{
|
|
|
|
*obj = &This->classinfo.IProvideClassInfo_iface;
|
|
|
|
}
|
2012-09-20 06:02:16 +02:00
|
|
|
else if ( IsEqualGUID( riid, &IID_IDispatchEx ))
|
|
|
|
{
|
|
|
|
TRACE("Interface IDispatchEx not supported - returning NULL\n");
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
else if ( IsEqualGUID( riid, &IID_IObjectWithSite ))
|
|
|
|
{
|
|
|
|
TRACE("Interface IObjectWithSite not supported - returning NULL\n");
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-21 05:29:02 +02:00
|
|
|
WARN("interface %s not implemented\n", debugstr_guid(riid));
|
2012-09-20 06:02:16 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2016-12-07 11:33:58 +01:00
|
|
|
IUnknown_AddRef((IUnknown*)*obj);
|
2012-09-20 06:02:16 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dictionary_AddRef(IDictionary *iface)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
2016-12-07 11:33:57 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2016-12-07 11:33:57 +01:00
|
|
|
TRACE("(%p)->(%u)\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dictionary_Release(IDictionary *iface)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
2016-12-07 11:33:57 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2016-12-07 11:33:57 +01:00
|
|
|
TRACE("(%p)->(%u)\n", This, ref);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2016-12-07 11:33:57 +01:00
|
|
|
if (!ref) {
|
2015-02-27 16:00:28 +01:00
|
|
|
IDictionary_RemoveAll(iface);
|
2012-11-10 15:47:17 +01:00
|
|
|
heap_free(This);
|
2015-02-27 16:00:28 +01:00
|
|
|
}
|
2012-09-20 06:02:16 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dictionary_GetTypeInfoCount(IDictionary *iface, UINT *pctinfo)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
2016-12-07 11:33:57 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, pctinfo);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
|
|
|
*pctinfo = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dictionary_GetTypeInfo(IDictionary *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
|
|
|
|
return get_typeinfo(IDictionary_tid, ppTInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dictionary_GetIDsOfNames(IDictionary *iface, REFIID riid, LPOLESTR *rgszNames,
|
|
|
|
UINT cNames, LCID lcid, DISPID *rgDispId)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
ITypeInfo *typeinfo;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
|
|
|
|
|
|
|
|
hr = get_typeinfo(IDictionary_tid, &typeinfo);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
|
|
|
|
ITypeInfo_Release(typeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dictionary_Invoke(IDictionary *iface, DISPID dispIdMember, REFIID riid,
|
|
|
|
LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
|
|
|
|
EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
ITypeInfo *typeinfo;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
|
|
|
|
lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
|
|
|
|
hr = get_typeinfo(IDictionary_tid, &typeinfo);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
2012-09-21 02:53:51 +02:00
|
|
|
hr = ITypeInfo_Invoke(typeinfo, &This->IDictionary_iface, dispIdMember, wFlags,
|
2012-09-20 06:02:16 +02:00
|
|
|
pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
ITypeInfo_Release(typeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dictionary_putref_Item(IDictionary *iface, VARIANT *Key, VARIANT *pRetItem)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%p %p)\n", This, Key, pRetItem);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2015-02-27 16:13:04 +01:00
|
|
|
static HRESULT WINAPI dictionary_put_Item(IDictionary *iface, VARIANT *key, VARIANT *item)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
2015-02-27 16:13:04 +01:00
|
|
|
struct keyitem_pair *pair;
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:13:04 +01:00
|
|
|
TRACE("(%p)->(%s %s)\n", This, debugstr_variant(key), debugstr_variant(item));
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:13:04 +01:00
|
|
|
if ((pair = get_keyitem_pair(This, key)))
|
|
|
|
return VariantCopyInd(&pair->item, item);
|
|
|
|
|
|
|
|
return IDictionary_Add(iface, key, item);
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 16:13:04 +01:00
|
|
|
static HRESULT WINAPI dictionary_get_Item(IDictionary *iface, VARIANT *key, VARIANT *item)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
2015-02-27 16:13:04 +01:00
|
|
|
struct keyitem_pair *pair;
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:13:04 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_variant(key), item);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:13:04 +01:00
|
|
|
if ((pair = get_keyitem_pair(This, key)))
|
|
|
|
VariantCopy(item, &pair->item);
|
|
|
|
else {
|
|
|
|
VariantInit(item);
|
|
|
|
return IDictionary_Add(iface, key, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 16:00:28 +01:00
|
|
|
static HRESULT WINAPI dictionary_Add(IDictionary *iface, VARIANT *key, VARIANT *item)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
2015-02-27 16:00:28 +01:00
|
|
|
TRACE("(%p)->(%s %s)\n", This, debugstr_variant(key), debugstr_variant(item));
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:00:28 +01:00
|
|
|
if (get_keyitem_pair(This, key))
|
|
|
|
return CTL_E_KEY_ALREADY_EXISTS;
|
|
|
|
|
|
|
|
return add_keyitem_pair(This, key, item);
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 15:27:02 +01:00
|
|
|
static HRESULT WINAPI dictionary_get_Count(IDictionary *iface, LONG *count)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
2015-02-26 15:27:02 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, count);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-26 15:27:02 +01:00
|
|
|
*count = This->count;
|
2012-09-20 06:02:16 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-27 16:18:13 +01:00
|
|
|
static HRESULT WINAPI dictionary_Exists(IDictionary *iface, VARIANT *key, VARIANT_BOOL *exists)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
2015-02-27 16:18:13 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_variant(key), exists);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:18:13 +01:00
|
|
|
if (!exists)
|
|
|
|
return CTL_E_ILLEGALFUNCTIONCALL;
|
|
|
|
|
|
|
|
*exists = get_keyitem_pair(This, key) != NULL ? VARIANT_TRUE : VARIANT_FALSE;
|
|
|
|
return S_OK;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 16:22:32 +01:00
|
|
|
static HRESULT WINAPI dictionary_Items(IDictionary *iface, VARIANT *items)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
2015-02-27 16:22:32 +01:00
|
|
|
struct keyitem_pair *pair;
|
|
|
|
SAFEARRAYBOUND bound;
|
|
|
|
SAFEARRAY *sa;
|
|
|
|
VARIANT *v;
|
|
|
|
HRESULT hr;
|
|
|
|
LONG i;
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:22:32 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, items);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:22:32 +01:00
|
|
|
if (!items)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
bound.lLbound = 0;
|
|
|
|
bound.cElements = This->count;
|
|
|
|
sa = SafeArrayCreate(VT_VARIANT, 1, &bound);
|
|
|
|
if (!sa)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = SafeArrayAccessData(sa, (void**)&v);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
SafeArrayDestroy(sa);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY(pair, &This->pairs, struct keyitem_pair, entry) {
|
|
|
|
VariantCopy(&v[i], &pair->item);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
SafeArrayUnaccessData(sa);
|
|
|
|
|
|
|
|
V_VT(items) = VT_ARRAY|VT_VARIANT;
|
|
|
|
V_ARRAY(items) = sa;
|
|
|
|
return S_OK;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 16:25:06 +01:00
|
|
|
static HRESULT WINAPI dictionary_put_Key(IDictionary *iface, VARIANT *key, VARIANT *newkey)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
2015-02-27 16:25:06 +01:00
|
|
|
struct keyitem_pair *pair;
|
|
|
|
VARIANT empty;
|
|
|
|
HRESULT hr;
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:25:06 +01:00
|
|
|
TRACE("(%p)->(%s %s)\n", This, debugstr_variant(key), debugstr_variant(newkey));
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:25:06 +01:00
|
|
|
if ((pair = get_keyitem_pair(This, key))) {
|
|
|
|
/* found existing pair for a key, add new pair with new key
|
|
|
|
and old item and remove old pair after that */
|
|
|
|
|
|
|
|
hr = IDictionary_Add(iface, newkey, &pair->item);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
return IDictionary_Remove(iface, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantInit(&empty);
|
|
|
|
return IDictionary_Add(iface, newkey, &empty);
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 16:22:32 +01:00
|
|
|
static HRESULT WINAPI dictionary_Keys(IDictionary *iface, VARIANT *keys)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
2015-02-27 16:22:32 +01:00
|
|
|
struct keyitem_pair *pair;
|
|
|
|
SAFEARRAYBOUND bound;
|
|
|
|
SAFEARRAY *sa;
|
|
|
|
VARIANT *v;
|
|
|
|
HRESULT hr;
|
|
|
|
LONG i;
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:22:32 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, keys);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:22:32 +01:00
|
|
|
if (!keys)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
bound.lLbound = 0;
|
|
|
|
bound.cElements = This->count;
|
|
|
|
sa = SafeArrayCreate(VT_VARIANT, 1, &bound);
|
|
|
|
if (!sa)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = SafeArrayAccessData(sa, (void**)&v);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
SafeArrayDestroy(sa);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY(pair, &This->pairs, struct keyitem_pair, entry) {
|
|
|
|
VariantCopy(&v[i], &pair->key);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
SafeArrayUnaccessData(sa);
|
|
|
|
|
|
|
|
V_VT(keys) = VT_ARRAY|VT_VARIANT;
|
|
|
|
V_ARRAY(keys) = sa;
|
|
|
|
return S_OK;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 16:15:10 +01:00
|
|
|
static HRESULT WINAPI dictionary_Remove(IDictionary *iface, VARIANT *key)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
2015-02-27 16:15:10 +01:00
|
|
|
struct keyitem_pair *pair;
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-03-24 10:02:45 +01:00
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_variant(key));
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:15:10 +01:00
|
|
|
if (!(pair = get_keyitem_pair(This, key)))
|
|
|
|
return CTL_E_ELEMENT_NOT_FOUND;
|
|
|
|
|
2015-03-18 13:11:32 +01:00
|
|
|
notify_remove_pair(&This->notifier, &pair->entry);
|
2015-02-27 16:15:10 +01:00
|
|
|
list_remove(&pair->entry);
|
2015-03-17 20:18:27 +01:00
|
|
|
list_remove(&pair->bucket);
|
2015-02-27 16:15:10 +01:00
|
|
|
This->count--;
|
|
|
|
|
|
|
|
free_keyitem_pair(pair);
|
|
|
|
return S_OK;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dictionary_RemoveAll(IDictionary *iface)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
2015-02-27 16:00:28 +01:00
|
|
|
struct keyitem_pair *pair, *pair2;
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:00:28 +01:00
|
|
|
TRACE("(%p)\n", This);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-27 16:00:28 +01:00
|
|
|
if (This->count == 0)
|
|
|
|
return S_OK;
|
|
|
|
|
2015-03-18 13:11:32 +01:00
|
|
|
notify_remove_pair(&This->notifier, NULL);
|
2015-02-27 16:00:28 +01:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(pair, pair2, &This->pairs, struct keyitem_pair, entry) {
|
|
|
|
list_remove(&pair->entry);
|
2015-03-17 20:18:27 +01:00
|
|
|
list_remove(&pair->bucket);
|
2015-02-27 16:00:28 +01:00
|
|
|
free_keyitem_pair(pair);
|
|
|
|
}
|
|
|
|
This->count = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-24 09:28:41 +01:00
|
|
|
static HRESULT WINAPI dictionary_put_CompareMode(IDictionary *iface, CompareMethod method)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
2015-02-24 09:28:41 +01:00
|
|
|
TRACE("(%p)->(%d)\n", This, method);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-26 15:27:02 +01:00
|
|
|
if (This->count)
|
|
|
|
return CTL_E_ILLEGALFUNCTIONCALL;
|
|
|
|
|
2015-02-24 09:28:41 +01:00
|
|
|
This->method = method;
|
|
|
|
return S_OK;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-24 09:28:41 +01:00
|
|
|
static HRESULT WINAPI dictionary_get_CompareMode(IDictionary *iface, CompareMethod *method)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
2015-02-24 09:28:41 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, method);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-24 09:28:41 +01:00
|
|
|
*method = This->method;
|
|
|
|
return S_OK;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-03-17 20:49:17 +01:00
|
|
|
static HRESULT WINAPI dictionary__NewEnum(IDictionary *iface, IUnknown **ret)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
2015-03-17 20:49:17 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, ret);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-03-17 20:49:17 +01:00
|
|
|
return create_dict_enum(This, ret);
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-24 21:27:17 +01:00
|
|
|
static DWORD get_str_hash(const WCHAR *str, CompareMethod method)
|
2012-09-20 06:02:16 +02:00
|
|
|
{
|
2015-02-24 21:27:17 +01:00
|
|
|
DWORD hash = 0;
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2015-02-24 21:27:17 +01:00
|
|
|
if (str) {
|
|
|
|
while (*str) {
|
|
|
|
WCHAR ch;
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2019-06-20 09:09:09 +02:00
|
|
|
ch = (method == TextCompare || method == DatabaseCompare) ? towlower(*str) : *str;
|
2015-02-24 21:27:17 +01:00
|
|
|
|
|
|
|
hash += (hash << 4) + ch;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 21:30:56 +01:00
|
|
|
return hash % DICT_HASH_MOD;
|
2012-09-20 06:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-24 22:22:00 +01:00
|
|
|
static DWORD get_num_hash(FLOAT num)
|
|
|
|
{
|
2015-03-21 21:30:56 +01:00
|
|
|
return (*((DWORD*)&num)) % DICT_HASH_MOD;
|
|
|
|
}
|
|
|
|
|
2015-03-23 06:18:30 +01:00
|
|
|
static HRESULT get_flt_hash(FLOAT flt, LONG *hash)
|
|
|
|
{
|
|
|
|
if (isinf(flt)) {
|
|
|
|
*hash = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else if (!isnan(flt)) {
|
|
|
|
*hash = get_num_hash(flt);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NaN case */
|
|
|
|
*hash = ~0u;
|
|
|
|
return CTL_E_ILLEGALFUNCTIONCALL;
|
|
|
|
}
|
|
|
|
|
2015-03-21 21:30:56 +01:00
|
|
|
static DWORD get_ptr_hash(void *ptr)
|
|
|
|
{
|
|
|
|
return PtrToUlong(ptr) % DICT_HASH_MOD;
|
2015-02-24 22:22:00 +01:00
|
|
|
}
|
|
|
|
|
2015-02-24 21:27:17 +01:00
|
|
|
static HRESULT WINAPI dictionary_get_HashVal(IDictionary *iface, VARIANT *key, VARIANT *hash)
|
|
|
|
{
|
|
|
|
dictionary *This = impl_from_IDictionary(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_variant(key), hash);
|
|
|
|
|
|
|
|
V_VT(hash) = VT_I4;
|
|
|
|
switch (V_VT(key))
|
|
|
|
{
|
2015-02-27 16:01:48 +01:00
|
|
|
case VT_BSTR|VT_BYREF:
|
2015-02-24 21:27:17 +01:00
|
|
|
case VT_BSTR:
|
2015-02-27 16:01:48 +01:00
|
|
|
V_I4(hash) = get_str_hash(get_key_strptr(key), This->method);
|
2015-02-24 21:27:17 +01:00
|
|
|
break;
|
2015-03-23 06:19:12 +01:00
|
|
|
case VT_UI1|VT_BYREF:
|
2015-02-24 22:22:00 +01:00
|
|
|
case VT_UI1:
|
2015-03-23 06:19:12 +01:00
|
|
|
V_I4(hash) = get_num_hash(V_VT(key) & VT_BYREF ? *V_UI1REF(key) : V_UI1(key));
|
2015-02-24 22:22:00 +01:00
|
|
|
break;
|
2015-03-23 06:19:12 +01:00
|
|
|
case VT_I2|VT_BYREF:
|
2015-02-24 22:22:00 +01:00
|
|
|
case VT_I2:
|
2015-03-23 06:19:12 +01:00
|
|
|
V_I4(hash) = get_num_hash(V_VT(key) & VT_BYREF ? *V_I2REF(key) : V_I2(key));
|
2015-02-24 22:22:00 +01:00
|
|
|
break;
|
2015-03-23 06:19:12 +01:00
|
|
|
case VT_I4|VT_BYREF:
|
2015-02-24 22:22:00 +01:00
|
|
|
case VT_I4:
|
2015-03-23 06:19:12 +01:00
|
|
|
V_I4(hash) = get_num_hash(V_VT(key) & VT_BYREF ? *V_I4REF(key) : V_I4(key));
|
2015-02-24 22:22:00 +01:00
|
|
|
break;
|
2015-03-21 21:30:56 +01:00
|
|
|
case VT_UNKNOWN|VT_BYREF:
|
|
|
|
case VT_DISPATCH|VT_BYREF:
|
|
|
|
case VT_UNKNOWN:
|
|
|
|
case VT_DISPATCH:
|
|
|
|
{
|
|
|
|
IUnknown *src = (V_VT(key) & VT_BYREF) ? *V_UNKNOWNREF(key) : V_UNKNOWN(key);
|
|
|
|
IUnknown *unk = NULL;
|
|
|
|
|
|
|
|
if (!src) {
|
|
|
|
V_I4(hash) = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_QueryInterface(src, &IID_IUnknown, (void**)&unk);
|
|
|
|
if (!unk) {
|
|
|
|
V_I4(hash) = ~0u;
|
|
|
|
return CTL_E_ILLEGALFUNCTIONCALL;
|
|
|
|
}
|
|
|
|
V_I4(hash) = get_ptr_hash(unk);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
break;
|
|
|
|
}
|
2015-03-23 06:18:30 +01:00
|
|
|
case VT_DATE|VT_BYREF:
|
|
|
|
case VT_DATE:
|
|
|
|
return get_flt_hash(V_VT(key) & VT_BYREF ? *V_DATEREF(key) : V_DATE(key), &V_I4(hash));
|
|
|
|
case VT_R4|VT_BYREF:
|
2015-02-25 06:11:15 +01:00
|
|
|
case VT_R4:
|
2015-03-23 06:18:30 +01:00
|
|
|
return get_flt_hash(V_VT(key) & VT_BYREF ? *V_R4REF(key) : V_R4(key), &V_I4(hash));
|
|
|
|
case VT_R8|VT_BYREF:
|
2015-02-25 06:11:15 +01:00
|
|
|
case VT_R8:
|
2015-03-23 06:18:30 +01:00
|
|
|
return get_flt_hash(V_VT(key) & VT_BYREF ? *V_R8REF(key) : V_R8(key), &V_I4(hash));
|
2015-02-24 22:22:00 +01:00
|
|
|
case VT_INT:
|
|
|
|
case VT_UINT:
|
|
|
|
case VT_I1:
|
|
|
|
case VT_I8:
|
|
|
|
case VT_UI2:
|
|
|
|
case VT_UI4:
|
|
|
|
V_I4(hash) = ~0u;
|
|
|
|
return CTL_E_ILLEGALFUNCTIONCALL;
|
2015-02-24 21:27:17 +01:00
|
|
|
default:
|
|
|
|
FIXME("not implemented for type %d\n", V_VT(key));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-09-20 06:02:16 +02:00
|
|
|
|
|
|
|
static const struct IDictionaryVtbl dictionary_vtbl =
|
|
|
|
{
|
|
|
|
dictionary_QueryInterface,
|
|
|
|
dictionary_AddRef,
|
|
|
|
dictionary_Release,
|
|
|
|
dictionary_GetTypeInfoCount,
|
|
|
|
dictionary_GetTypeInfo,
|
|
|
|
dictionary_GetIDsOfNames,
|
|
|
|
dictionary_Invoke,
|
|
|
|
dictionary_putref_Item,
|
|
|
|
dictionary_put_Item,
|
|
|
|
dictionary_get_Item,
|
|
|
|
dictionary_Add,
|
|
|
|
dictionary_get_Count,
|
|
|
|
dictionary_Exists,
|
|
|
|
dictionary_Items,
|
|
|
|
dictionary_put_Key,
|
|
|
|
dictionary_Keys,
|
|
|
|
dictionary_Remove,
|
|
|
|
dictionary_RemoveAll,
|
|
|
|
dictionary_put_CompareMode,
|
|
|
|
dictionary_get_CompareMode,
|
|
|
|
dictionary__NewEnum,
|
|
|
|
dictionary_get_HashVal
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI Dictionary_CreateInstance(IClassFactory *factory,IUnknown *outer,REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
dictionary *This;
|
|
|
|
|
2016-12-07 11:33:57 +01:00
|
|
|
TRACE("(%p, %p, %s, %p)\n", factory, outer, debugstr_guid(riid), obj);
|
2012-09-20 06:02:16 +02:00
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
|
2012-11-10 15:47:17 +01:00
|
|
|
This = heap_alloc(sizeof(*This));
|
2012-09-20 06:02:16 +02:00
|
|
|
if(!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IDictionary_iface.lpVtbl = &dictionary_vtbl;
|
|
|
|
This->ref = 1;
|
2015-02-24 09:28:41 +01:00
|
|
|
This->method = BinaryCompare;
|
2015-02-26 15:27:02 +01:00
|
|
|
This->count = 0;
|
2015-02-27 16:00:28 +01:00
|
|
|
list_init(&This->pairs);
|
2015-03-18 13:11:32 +01:00
|
|
|
list_init(&This->notifier);
|
2015-02-27 16:00:28 +01:00
|
|
|
memset(This->buckets, 0, sizeof(This->buckets));
|
2012-09-20 06:02:16 +02:00
|
|
|
|
2016-12-07 11:33:58 +01:00
|
|
|
init_classinfo(&CLSID_Dictionary, (IUnknown *)&This->IDictionary_iface, &This->classinfo);
|
2012-09-20 06:02:16 +02:00
|
|
|
*obj = &This->IDictionary_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|