mirror of https://github.com/FreeRDP/FreeRDP
[winpr,collections] ListDictionary
This commit is contained in:
parent
0669cfe483
commit
f27076ab82
|
@ -178,42 +178,11 @@ extern "C"
|
||||||
|
|
||||||
/* System.Collections.DictionaryBase */
|
/* System.Collections.DictionaryBase */
|
||||||
|
|
||||||
/* WARNING: Do not access structs directly, the API will be reworked
|
|
||||||
* to make this opaque. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
BOOL synchronized;
|
|
||||||
CRITICAL_SECTION lock;
|
|
||||||
} wDictionary;
|
|
||||||
|
|
||||||
/* System.Collections.Specialized.ListDictionary */
|
/* System.Collections.Specialized.ListDictionary */
|
||||||
|
typedef struct s_wListDictionary wListDictionary;
|
||||||
|
|
||||||
typedef struct s_wListDictionaryItem wListDictionaryItem;
|
WINPR_API wObject* ListDictionary_KeyObject(wListDictionary* _dictionary);
|
||||||
|
WINPR_API wObject* ListDictionary_ValueObject(wListDictionary* _dictionary);
|
||||||
/* WARNING: Do not access structs directly, the API will be reworked
|
|
||||||
* to make this opaque. */
|
|
||||||
struct s_wListDictionaryItem
|
|
||||||
{
|
|
||||||
void* key;
|
|
||||||
void* value;
|
|
||||||
|
|
||||||
wListDictionaryItem* next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* WARNING: Do not access structs directly, the API will be reworked
|
|
||||||
* to make this opaque. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
BOOL synchronized;
|
|
||||||
CRITICAL_SECTION lock;
|
|
||||||
|
|
||||||
wListDictionaryItem* head;
|
|
||||||
wObject objectKey;
|
|
||||||
wObject objectValue;
|
|
||||||
} wListDictionary;
|
|
||||||
|
|
||||||
#define ListDictionary_KeyObject(_dictionary) (&_dictionary->objectKey)
|
|
||||||
#define ListDictionary_ValueObject(_dictionary) (&_dictionary->objectValue)
|
|
||||||
|
|
||||||
WINPR_API size_t ListDictionary_Count(wListDictionary* listDictionary);
|
WINPR_API size_t ListDictionary_Count(wListDictionary* listDictionary);
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,31 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <winpr/config.h>
|
#include <winpr/config.h>
|
||||||
|
#include <winpr/assert.h>
|
||||||
#include <winpr/crt.h>
|
#include <winpr/crt.h>
|
||||||
|
|
||||||
#include <winpr/collections.h>
|
#include <winpr/collections.h>
|
||||||
|
|
||||||
|
typedef struct s_wListDictionaryItem wListDictionaryItem;
|
||||||
|
|
||||||
|
struct s_wListDictionaryItem
|
||||||
|
{
|
||||||
|
void* key;
|
||||||
|
void* value;
|
||||||
|
|
||||||
|
wListDictionaryItem* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct s_wListDictionary
|
||||||
|
{
|
||||||
|
BOOL synchronized;
|
||||||
|
CRITICAL_SECTION lock;
|
||||||
|
|
||||||
|
wListDictionaryItem* head;
|
||||||
|
wObject objectKey;
|
||||||
|
wObject objectValue;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C equivalent of the C# ListDictionary Class:
|
* C equivalent of the C# ListDictionary Class:
|
||||||
* http://msdn.microsoft.com/en-us/library/system.collections.specialized.listdictionary.aspx
|
* http://msdn.microsoft.com/en-us/library/system.collections.specialized.listdictionary.aspx
|
||||||
|
@ -30,6 +50,18 @@
|
||||||
* Internal implementation uses a singly-linked list
|
* Internal implementation uses a singly-linked list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
WINPR_API wObject* ListDictionary_KeyObject(wListDictionary* _dictionary)
|
||||||
|
{
|
||||||
|
WINPR_ASSERT(_dictionary);
|
||||||
|
return &_dictionary->objectKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
WINPR_API wObject* ListDictionary_ValueObject(wListDictionary* _dictionary)
|
||||||
|
{
|
||||||
|
WINPR_ASSERT(_dictionary);
|
||||||
|
return &_dictionary->objectValue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties
|
* Properties
|
||||||
*/
|
*/
|
||||||
|
@ -70,8 +102,7 @@ size_t ListDictionary_Count(wListDictionary* listDictionary)
|
||||||
|
|
||||||
void ListDictionary_Lock(wListDictionary* listDictionary)
|
void ListDictionary_Lock(wListDictionary* listDictionary)
|
||||||
{
|
{
|
||||||
if (!listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
return;
|
|
||||||
|
|
||||||
EnterCriticalSection(&listDictionary->lock);
|
EnterCriticalSection(&listDictionary->lock);
|
||||||
}
|
}
|
||||||
|
@ -82,8 +113,7 @@ void ListDictionary_Lock(wListDictionary* listDictionary)
|
||||||
|
|
||||||
void ListDictionary_Unlock(wListDictionary* listDictionary)
|
void ListDictionary_Unlock(wListDictionary* listDictionary)
|
||||||
{
|
{
|
||||||
if (!listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
return;
|
|
||||||
|
|
||||||
LeaveCriticalSection(&listDictionary->lock);
|
LeaveCriticalSection(&listDictionary->lock);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +130,8 @@ size_t ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKey
|
||||||
{
|
{
|
||||||
ULONG_PTR* pKeys = NULL;
|
ULONG_PTR* pKeys = NULL;
|
||||||
|
|
||||||
if (!ppKeys || !listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
|
if (!ppKeys)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (listDictionary->synchronized)
|
if (listDictionary->synchronized)
|
||||||
|
@ -163,8 +194,7 @@ BOOL ListDictionary_Add(wListDictionary* listDictionary, const void* key, void*
|
||||||
wListDictionaryItem* lastItem;
|
wListDictionaryItem* lastItem;
|
||||||
BOOL ret = FALSE;
|
BOOL ret = FALSE;
|
||||||
|
|
||||||
if (!listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (listDictionary->synchronized)
|
if (listDictionary->synchronized)
|
||||||
EnterCriticalSection(&listDictionary->lock);
|
EnterCriticalSection(&listDictionary->lock);
|
||||||
|
@ -218,8 +248,7 @@ void ListDictionary_Clear(wListDictionary* listDictionary)
|
||||||
wListDictionaryItem* item;
|
wListDictionaryItem* item;
|
||||||
wListDictionaryItem* nextItem;
|
wListDictionaryItem* nextItem;
|
||||||
|
|
||||||
if (!listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
return;
|
|
||||||
|
|
||||||
if (listDictionary->synchronized)
|
if (listDictionary->synchronized)
|
||||||
EnterCriticalSection(&listDictionary->lock);
|
EnterCriticalSection(&listDictionary->lock);
|
||||||
|
@ -258,8 +287,7 @@ BOOL ListDictionary_Contains(wListDictionary* listDictionary, const void* key)
|
||||||
wListDictionaryItem* item;
|
wListDictionaryItem* item;
|
||||||
OBJECT_EQUALS_FN keyEquals;
|
OBJECT_EQUALS_FN keyEquals;
|
||||||
|
|
||||||
if (!listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (listDictionary->synchronized)
|
if (listDictionary->synchronized)
|
||||||
EnterCriticalSection(&(listDictionary->lock));
|
EnterCriticalSection(&(listDictionary->lock));
|
||||||
|
@ -292,8 +320,7 @@ void* ListDictionary_Remove(wListDictionary* listDictionary, const void* key)
|
||||||
wListDictionaryItem* prevItem;
|
wListDictionaryItem* prevItem;
|
||||||
OBJECT_EQUALS_FN keyEquals;
|
OBJECT_EQUALS_FN keyEquals;
|
||||||
|
|
||||||
if (!listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (listDictionary->synchronized)
|
if (listDictionary->synchronized)
|
||||||
EnterCriticalSection(&listDictionary->lock);
|
EnterCriticalSection(&listDictionary->lock);
|
||||||
|
@ -335,8 +362,7 @@ void* ListDictionary_Remove_Head(wListDictionary* listDictionary)
|
||||||
wListDictionaryItem* item;
|
wListDictionaryItem* item;
|
||||||
void* value = NULL;
|
void* value = NULL;
|
||||||
|
|
||||||
if (!listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (listDictionary->synchronized)
|
if (listDictionary->synchronized)
|
||||||
EnterCriticalSection(&listDictionary->lock);
|
EnterCriticalSection(&listDictionary->lock);
|
||||||
|
@ -365,8 +391,7 @@ void* ListDictionary_GetItemValue(wListDictionary* listDictionary, const void* k
|
||||||
wListDictionaryItem* item = NULL;
|
wListDictionaryItem* item = NULL;
|
||||||
OBJECT_EQUALS_FN keyEquals;
|
OBJECT_EQUALS_FN keyEquals;
|
||||||
|
|
||||||
if (!listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (listDictionary->synchronized)
|
if (listDictionary->synchronized)
|
||||||
EnterCriticalSection(&listDictionary->lock);
|
EnterCriticalSection(&listDictionary->lock);
|
||||||
|
@ -404,8 +429,7 @@ BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, const void* ke
|
||||||
wListDictionaryItem* item;
|
wListDictionaryItem* item;
|
||||||
OBJECT_EQUALS_FN keyEquals;
|
OBJECT_EQUALS_FN keyEquals;
|
||||||
|
|
||||||
if (!listDictionary)
|
WINPR_ASSERT(listDictionary);
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (listDictionary->synchronized)
|
if (listDictionary->synchronized)
|
||||||
EnterCriticalSection(&listDictionary->lock);
|
EnterCriticalSection(&listDictionary->lock);
|
||||||
|
@ -451,8 +475,7 @@ static BOOL default_equal_function(const void* obj1, const void* obj2)
|
||||||
|
|
||||||
wListDictionary* ListDictionary_New(BOOL synchronized)
|
wListDictionary* ListDictionary_New(BOOL synchronized)
|
||||||
{
|
{
|
||||||
wListDictionary* listDictionary = NULL;
|
wListDictionary* listDictionary = (wListDictionary*)calloc(1, sizeof(wListDictionary));
|
||||||
listDictionary = (wListDictionary*)calloc(1, sizeof(wListDictionary));
|
|
||||||
|
|
||||||
if (!listDictionary)
|
if (!listDictionary)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue