2012-12-06 04:36:45 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* System.Collections.Specialized.ListDictionary
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-02-01 03:27:58 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2012-12-06 04:36:45 +04:00
|
|
|
#include <winpr/collections.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* C equivalent of the C# ListDictionary Class:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/system.collections.specialized.listdictionary.aspx
|
2013-07-06 02:23:26 +04:00
|
|
|
*
|
|
|
|
* Internal implementation uses a singly-linked list
|
2012-12-06 04:36:45 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Properties
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the number of key/value pairs contained in the ListDictionary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ListDictionary_Count(wListDictionary* listDictionary)
|
|
|
|
{
|
2013-07-06 02:23:26 +04:00
|
|
|
int count = 0;
|
|
|
|
wListDictionaryItem* item;
|
|
|
|
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return -1;
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
EnterCriticalSection(&listDictionary->lock);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->head)
|
2013-07-06 02:23:26 +04:00
|
|
|
{
|
2013-08-13 01:48:32 +04:00
|
|
|
item = listDictionary->head;
|
|
|
|
|
|
|
|
while (item)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
item = item->next;
|
|
|
|
}
|
2013-07-06 02:23:26 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
|
|
|
|
2013-07-06 02:23:26 +04:00
|
|
|
return count;
|
2012-12-06 04:36:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a value indicating whether the ListDictionary has a fixed size.
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL ListDictionary_IsFixedSized(wListDictionary* listDictionary)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a value indicating whether the ListDictionary is read-only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL ListDictionary_IsReadOnly(wListDictionary* listDictionary)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a value indicating whether the ListDictionary is synchronized (thread safe).
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL ListDictionary_IsSynchronized(wListDictionary* listDictionary)
|
|
|
|
{
|
|
|
|
return listDictionary->synchronized;
|
|
|
|
}
|
|
|
|
|
2014-04-06 01:15:17 +04:00
|
|
|
/**
|
|
|
|
* Lock access to the ListDictionary
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ListDictionary_Lock(wListDictionary* listDictionary)
|
|
|
|
{
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return;
|
|
|
|
|
2014-04-06 01:15:17 +04:00
|
|
|
EnterCriticalSection(&listDictionary->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlock access to the ListDictionary
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ListDictionary_Unlock(wListDictionary* listDictionary)
|
|
|
|
{
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return;
|
|
|
|
|
2014-04-06 01:15:17 +04:00
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
|
|
|
}
|
|
|
|
|
2012-12-06 04:36:45 +04:00
|
|
|
/**
|
|
|
|
* Methods
|
|
|
|
*/
|
|
|
|
|
2013-10-18 00:30:36 +04:00
|
|
|
/**
|
|
|
|
* Gets the list of keys as an array
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
int count;
|
2014-11-17 01:43:18 +03:00
|
|
|
ULONG_PTR* pKeys = NULL;
|
2013-10-18 00:30:36 +04:00
|
|
|
wListDictionaryItem* item;
|
|
|
|
|
2015-04-03 17:21:01 +03:00
|
|
|
if (!ppKeys || !listDictionary)
|
2013-10-18 00:30:36 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (listDictionary->synchronized)
|
|
|
|
EnterCriticalSection(&listDictionary->lock);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
if (listDictionary->head)
|
|
|
|
{
|
|
|
|
item = listDictionary->head;
|
|
|
|
|
|
|
|
while (item)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-17 01:43:18 +03:00
|
|
|
if (count)
|
2015-04-03 17:21:01 +03:00
|
|
|
{
|
|
|
|
pKeys = (ULONG_PTR *) calloc(count, sizeof(ULONG_PTR));
|
|
|
|
if (!pKeys)
|
|
|
|
{
|
|
|
|
if (listDictionary->synchronized)
|
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2013-10-18 00:30:36 +04:00
|
|
|
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
if (listDictionary->head)
|
|
|
|
{
|
|
|
|
item = listDictionary->head;
|
|
|
|
|
|
|
|
while (item)
|
|
|
|
{
|
|
|
|
pKeys[index++] = (ULONG_PTR) item->key;
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppKeys = pKeys;
|
|
|
|
|
|
|
|
if (listDictionary->synchronized)
|
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-12-06 04:36:45 +04:00
|
|
|
/**
|
|
|
|
* Adds an entry with the specified key and value into the ListDictionary.
|
|
|
|
*/
|
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
BOOL ListDictionary_Add(wListDictionary* listDictionary, void* key, void* value)
|
2012-12-06 04:36:45 +04:00
|
|
|
{
|
2013-07-06 02:23:26 +04:00
|
|
|
wListDictionaryItem* item;
|
|
|
|
wListDictionaryItem* lastItem;
|
2015-04-03 17:21:01 +03:00
|
|
|
BOOL ret = FALSE;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
EnterCriticalSection(&listDictionary->lock);
|
|
|
|
|
2013-07-06 02:23:26 +04:00
|
|
|
item = (wListDictionaryItem*) malloc(sizeof(wListDictionaryItem));
|
2014-04-18 20:26:04 +04:00
|
|
|
if (!item)
|
2015-04-03 17:21:01 +03:00
|
|
|
goto out_error;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
|
|
|
item->key = key;
|
|
|
|
item->value = value;
|
2012-12-06 04:36:45 +04:00
|
|
|
|
2013-07-06 02:23:26 +04:00
|
|
|
item->next = NULL;
|
|
|
|
|
|
|
|
if (!listDictionary->head)
|
|
|
|
{
|
|
|
|
listDictionary->head = item;
|
|
|
|
}
|
2013-08-13 01:48:32 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
lastItem = listDictionary->head;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
while (lastItem->next)
|
|
|
|
lastItem = lastItem->next;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
lastItem->next = item;
|
|
|
|
}
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2015-04-03 17:21:01 +03:00
|
|
|
ret = TRUE;
|
|
|
|
out_error:
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
2014-12-11 19:25:34 +03:00
|
|
|
|
2015-04-03 17:21:01 +03:00
|
|
|
return ret;
|
2012-12-06 04:36:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all entries from the ListDictionary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ListDictionary_Clear(wListDictionary* listDictionary)
|
|
|
|
{
|
2013-07-06 02:23:26 +04:00
|
|
|
wListDictionaryItem* item;
|
|
|
|
wListDictionaryItem* nextItem;
|
|
|
|
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return;
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
EnterCriticalSection(&listDictionary->lock);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->head)
|
2013-07-06 02:23:26 +04:00
|
|
|
{
|
2013-08-13 01:48:32 +04:00
|
|
|
item = listDictionary->head;
|
|
|
|
|
|
|
|
while (item)
|
|
|
|
{
|
|
|
|
nextItem = item->next;
|
2014-12-12 01:08:22 +03:00
|
|
|
|
|
|
|
if (listDictionary->objectKey.fnObjectFree)
|
|
|
|
listDictionary->objectKey.fnObjectFree(item->key);
|
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
if (listDictionary->objectValue.fnObjectFree)
|
|
|
|
listDictionary->objectValue.fnObjectFree(item->value);
|
2014-12-12 01:08:22 +03:00
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
free(item);
|
|
|
|
item = nextItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
listDictionary->head = NULL;
|
2013-07-06 02:23:26 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
2012-12-06 04:36:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether the ListDictionary contains a specific key.
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL ListDictionary_Contains(wListDictionary* listDictionary, void* key)
|
|
|
|
{
|
2013-07-06 02:23:26 +04:00
|
|
|
wListDictionaryItem* item;
|
2014-04-18 20:26:04 +04:00
|
|
|
OBJECT_EQUALS_FN keyEquals;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
2015-02-01 00:56:25 +03:00
|
|
|
EnterCriticalSection(&(listDictionary->lock));
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
keyEquals = listDictionary->objectKey.fnObjectEquals;
|
|
|
|
item = listDictionary->head;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
while (item)
|
|
|
|
{
|
|
|
|
if (keyEquals(item->key, key))
|
|
|
|
break;
|
2013-08-13 01:48:32 +04:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
item = item->next;
|
2013-07-06 02:23:26 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
2015-02-01 00:56:25 +03:00
|
|
|
LeaveCriticalSection(&(listDictionary->lock));
|
2013-08-13 01:48:32 +04:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
return (item) ? TRUE : FALSE;
|
2012-12-06 04:36:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the entry with the specified key from the ListDictionary.
|
|
|
|
*/
|
|
|
|
|
2013-10-18 01:27:47 +04:00
|
|
|
void* ListDictionary_Remove(wListDictionary* listDictionary, void* key)
|
2012-12-06 04:36:45 +04:00
|
|
|
{
|
2013-10-18 01:27:47 +04:00
|
|
|
void* value = NULL;
|
2013-07-06 02:23:26 +04:00
|
|
|
wListDictionaryItem* item;
|
|
|
|
wListDictionaryItem* prevItem;
|
2014-04-18 20:26:04 +04:00
|
|
|
OBJECT_EQUALS_FN keyEquals;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return NULL;
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
EnterCriticalSection(&listDictionary->lock);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
keyEquals = listDictionary->objectKey.fnObjectEquals;
|
|
|
|
|
|
|
|
item = listDictionary->head;
|
|
|
|
prevItem = NULL;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
while (item)
|
|
|
|
{
|
|
|
|
if (keyEquals(item->key, key))
|
2013-07-06 02:23:26 +04:00
|
|
|
{
|
2014-04-18 20:26:04 +04:00
|
|
|
if (!prevItem)
|
|
|
|
listDictionary->head = item->next;
|
|
|
|
else
|
|
|
|
prevItem->next = item->next;
|
2013-10-15 16:11:14 +04:00
|
|
|
value = item->value;
|
2013-07-06 02:23:26 +04:00
|
|
|
free(item);
|
2014-04-18 20:26:04 +04:00
|
|
|
break;
|
2013-07-06 02:23:26 +04:00
|
|
|
}
|
2014-04-18 20:26:04 +04:00
|
|
|
|
|
|
|
prevItem = item;
|
|
|
|
item = item->next;
|
2013-07-06 02:23:26 +04:00
|
|
|
}
|
2013-08-13 01:48:32 +04:00
|
|
|
|
|
|
|
if (listDictionary->synchronized)
|
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
2013-10-18 01:27:47 +04:00
|
|
|
|
2013-10-15 16:11:14 +04:00
|
|
|
return value;
|
2013-07-06 02:23:26 +04:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:15:44 +04:00
|
|
|
/**
|
|
|
|
* Removes the first (head) entry from the list
|
|
|
|
*/
|
|
|
|
|
|
|
|
void *ListDictionary_Remove_Head(wListDictionary* listDictionary)
|
|
|
|
{
|
|
|
|
wListDictionaryItem* item;
|
|
|
|
void *value = NULL;
|
|
|
|
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-15 18:15:44 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
EnterCriticalSection(&listDictionary->lock);
|
|
|
|
|
|
|
|
if (listDictionary->head)
|
|
|
|
{
|
|
|
|
item = listDictionary->head;
|
|
|
|
listDictionary->head = listDictionary->head->next;
|
|
|
|
value = item->value;
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listDictionary->synchronized)
|
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2013-07-06 02:23:26 +04:00
|
|
|
/**
|
|
|
|
* Get an item value using key
|
|
|
|
*/
|
|
|
|
|
|
|
|
void* ListDictionary_GetItemValue(wListDictionary* listDictionary, void* key)
|
|
|
|
{
|
2013-08-13 01:48:32 +04:00
|
|
|
void* value = NULL;
|
2013-08-30 16:19:50 +04:00
|
|
|
wListDictionaryItem* item = NULL;
|
2014-04-18 20:26:04 +04:00
|
|
|
OBJECT_EQUALS_FN keyEquals;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return NULL;
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
EnterCriticalSection(&listDictionary->lock);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
keyEquals = listDictionary->objectKey.fnObjectEquals;
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->head)
|
2013-07-06 02:23:26 +04:00
|
|
|
{
|
2013-08-13 01:48:32 +04:00
|
|
|
item = listDictionary->head;
|
|
|
|
|
|
|
|
while (item)
|
|
|
|
{
|
2014-04-18 20:26:04 +04:00
|
|
|
if (keyEquals(item->key, key))
|
2013-08-13 01:48:32 +04:00
|
|
|
break;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
item = item->next;
|
|
|
|
}
|
2013-07-06 02:23:26 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
value = (item) ? item->value : NULL;
|
|
|
|
|
|
|
|
if (listDictionary->synchronized)
|
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
|
|
|
|
|
|
|
return value;
|
2013-07-06 02:23:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an item value using key
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, void* key, void* value)
|
|
|
|
{
|
2013-08-13 01:48:32 +04:00
|
|
|
BOOL status = FALSE;
|
2013-07-06 02:23:26 +04:00
|
|
|
wListDictionaryItem* item;
|
2014-04-18 20:26:04 +04:00
|
|
|
OBJECT_EQUALS_FN keyEquals;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2016-04-26 10:34:12 +03:00
|
|
|
if (!listDictionary)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
EnterCriticalSection(&listDictionary->lock);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
keyEquals = listDictionary->objectKey.fnObjectEquals;
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->head)
|
2013-07-06 02:23:26 +04:00
|
|
|
{
|
2013-08-13 01:48:32 +04:00
|
|
|
item = listDictionary->head;
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
while (item)
|
|
|
|
{
|
2014-04-18 20:26:04 +04:00
|
|
|
if (keyEquals(item->key, key))
|
2013-08-13 01:48:32 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item)
|
2014-04-18 20:26:04 +04:00
|
|
|
{
|
|
|
|
if (listDictionary->objectValue.fnObjectFree)
|
|
|
|
listDictionary->objectValue.fnObjectFree(item->value);
|
2013-08-13 01:48:32 +04:00
|
|
|
item->value = value;
|
2014-04-18 20:26:04 +04:00
|
|
|
}
|
2013-08-13 01:48:32 +04:00
|
|
|
|
|
|
|
status = (item) ? TRUE : FALSE;
|
2013-07-06 02:23:26 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
if (listDictionary->synchronized)
|
|
|
|
LeaveCriticalSection(&listDictionary->lock);
|
2013-07-06 02:23:26 +04:00
|
|
|
|
2013-08-13 01:48:32 +04:00
|
|
|
return status;
|
2012-12-06 04:36:45 +04:00
|
|
|
}
|
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
static BOOL default_equal_function(void *obj1, void *obj2)
|
|
|
|
{
|
|
|
|
return (obj1 == obj2);
|
|
|
|
}
|
2012-12-06 04:36:45 +04:00
|
|
|
/**
|
|
|
|
* Construction, Destruction
|
|
|
|
*/
|
|
|
|
|
|
|
|
wListDictionary* ListDictionary_New(BOOL synchronized)
|
|
|
|
{
|
|
|
|
wListDictionary* listDictionary = NULL;
|
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
listDictionary = (wListDictionary*) calloc(1, sizeof(wListDictionary));
|
2015-02-01 00:56:25 +03:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
if (!listDictionary)
|
|
|
|
return NULL;
|
2013-08-13 01:48:32 +04:00
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
listDictionary->synchronized = synchronized;
|
2013-11-04 05:46:40 +04:00
|
|
|
|
2015-02-01 00:56:25 +03:00
|
|
|
if (!InitializeCriticalSectionAndSpinCount(&(listDictionary->lock), 4000))
|
2014-04-18 20:26:04 +04:00
|
|
|
{
|
|
|
|
free(listDictionary);
|
|
|
|
return NULL;
|
2012-12-06 04:36:45 +04:00
|
|
|
}
|
|
|
|
|
2014-04-18 20:26:04 +04:00
|
|
|
listDictionary->objectKey.fnObjectEquals = default_equal_function;
|
|
|
|
listDictionary->objectValue.fnObjectEquals = default_equal_function;
|
2015-02-01 00:56:25 +03:00
|
|
|
|
2012-12-06 04:36:45 +04:00
|
|
|
return listDictionary;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListDictionary_Free(wListDictionary* listDictionary)
|
|
|
|
{
|
2013-07-06 02:23:26 +04:00
|
|
|
if (listDictionary)
|
|
|
|
{
|
|
|
|
ListDictionary_Clear(listDictionary);
|
2013-08-13 01:48:32 +04:00
|
|
|
DeleteCriticalSection(&listDictionary->lock);
|
2013-07-06 02:23:26 +04:00
|
|
|
free(listDictionary);
|
|
|
|
}
|
2012-12-06 04:36:45 +04:00
|
|
|
}
|
|
|
|
|