libwinpr-utils: stubbed Queue, Stack and ArrayList
This commit is contained in:
parent
0fcd7ea243
commit
c06c0fe665
104
winpr/include/winpr/collections.h
Normal file
104
winpr/include/winpr/collections.h
Normal file
@ -0,0 +1,104 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Collections
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_COLLECTIONS_H
|
||||
#define WINPR_COLLECTIONS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <winpr/winpr.h>
|
||||
#include <winpr/wtypes.h>
|
||||
|
||||
/* System.Collections.Queue */
|
||||
|
||||
struct _wQueue
|
||||
{
|
||||
BOOL bSynchronized;
|
||||
};
|
||||
typedef struct _wQueue wQueue;
|
||||
|
||||
WINPR_API int Queue_Count(wQueue* queue);
|
||||
WINPR_API BOOL Queue_IsSynchronized(wQueue* queue);
|
||||
|
||||
WINPR_API void Queue_Clear(wQueue* queue);
|
||||
WINPR_API BOOL Queue_Contains(wQueue* queue, void* obj);
|
||||
|
||||
WINPR_API void Queue_Enqueue(wQueue* queue, void* obj);
|
||||
WINPR_API void* Queue_Dequeue(wQueue* queue);
|
||||
|
||||
WINPR_API void* Queue_Peek(wQueue* queue);
|
||||
|
||||
WINPR_API wQueue* Queue_New(BOOL bSynchronized);
|
||||
WINPR_API void Queue_Free(wQueue* queue);
|
||||
|
||||
/* System.Collections.Stack */
|
||||
|
||||
struct _wStack
|
||||
{
|
||||
BOOL bSynchronized;
|
||||
};
|
||||
typedef struct _wStack wStack;
|
||||
|
||||
WINPR_API int Stack_Count(wStack* stack);
|
||||
WINPR_API BOOL Stack_IsSynchronized(wStack* stack);
|
||||
|
||||
WINPR_API void Stack_Clear(wStack* stack);
|
||||
WINPR_API BOOL Stack_Contains(wStack* stack, void* obj);
|
||||
|
||||
WINPR_API void Stack_Push(wStack* stack, void* obj);
|
||||
WINPR_API void* Stack_Pop(wStack* stack);
|
||||
|
||||
WINPR_API void* Stack_Peek(wStack* stack);
|
||||
|
||||
WINPR_API wStack* Stack_New(BOOL bSynchronized);
|
||||
WINPR_API void Stack_Free(wStack* stack);
|
||||
|
||||
/* System.Collections.ArrayList */
|
||||
|
||||
struct _wArrayList
|
||||
{
|
||||
BOOL bSynchronized;
|
||||
};
|
||||
typedef struct _wArrayList wArrayList;
|
||||
|
||||
WINPR_API int ArrayList_Capacity(wArrayList* arrayList);
|
||||
WINPR_API int ArrayList_Count(wArrayList* arrayList);
|
||||
WINPR_API BOOL ArrayList_IsFixedSized(wArrayList* arrayList);
|
||||
WINPR_API BOOL ArrayList_IsReadOnly(wArrayList* arrayList);
|
||||
WINPR_API BOOL ArrayList_IsSynchronized(wArrayList* arrayList);
|
||||
WINPR_API void* ArrayList_Item(wArrayList* arrayList, int index, void* obj);
|
||||
|
||||
WINPR_API void ArrayList_Clear(wArrayList* arrayList);
|
||||
WINPR_API BOOL ArrayList_Contains(wArrayList* arrayList, void* obj);
|
||||
|
||||
WINPR_API int ArrayList_Add(wArrayList* arrayList, void* obj);
|
||||
WINPR_API void ArrayList_Insert(wArrayList* arrayList, int index, void* obj);
|
||||
|
||||
WINPR_API void ArrayList_Remove(wArrayList* arrayList, void* obj);
|
||||
WINPR_API void ArrayList_RemoveAt(wArrayList* arrayList, int index, void* obj);
|
||||
|
||||
WINPR_API int ArrayList_IndexOf(wArrayList* arrayList, void* obj, int startIndex, int count);
|
||||
WINPR_API int ArrayList_LastIndexOf(wArrayList* arrayList, void* obj, int startIndex, int count);
|
||||
|
||||
WINPR_API wArrayList* ArrayList_New(BOOL bSynchronized);
|
||||
WINPR_API void ArrayList_Free(wArrayList* arrayList);
|
||||
|
||||
#endif /* WINPR_COLLECTIONS_H */
|
@ -18,6 +18,11 @@
|
||||
set(MODULE_NAME "winpr-utils")
|
||||
set(MODULE_PREFIX "WINPR_UTILS")
|
||||
|
||||
set(${MODULE_PREFIX}_COLLECTIONS_SRCS
|
||||
collections/Queue.c
|
||||
collections/Stack.c
|
||||
collections/ArrayList.c)
|
||||
|
||||
set(${MODULE_PREFIX}_SRCS
|
||||
sam.c
|
||||
ntlm.c
|
||||
@ -25,6 +30,9 @@ set(${MODULE_PREFIX}_SRCS
|
||||
stream.c
|
||||
cmdline.c)
|
||||
|
||||
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS}
|
||||
${${MODULE_PREFIX}_COLLECTIONS_SRCS})
|
||||
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
|
||||
|
240
winpr/libwinpr/utils/collections/ArrayList.c
Normal file
240
winpr/libwinpr/utils/collections/ArrayList.c
Normal file
@ -0,0 +1,240 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* System.Collections.ArrayList
|
||||
*
|
||||
* 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
|
||||
|
||||
#include <winpr/collections.h>
|
||||
|
||||
/**
|
||||
* C equivalent of the C# ArrayList Class:
|
||||
* http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx
|
||||
*/
|
||||
|
||||
/**
|
||||
* Properties
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets or sets the number of elements that the ArrayList can contain.
|
||||
*/
|
||||
|
||||
int ArrayList_Capacity(wArrayList* arrayList)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of elements actually contained in the ArrayList.
|
||||
*/
|
||||
|
||||
int ArrayList_Count(wArrayList* arrayList)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether the ArrayList has a fixed size.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_IsFixedSized(wArrayList* arrayList)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether the ArrayList is read-only.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_IsReadOnly(wArrayList* arrayList)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether access to the ArrayList is synchronized (thread safe).
|
||||
*/
|
||||
|
||||
BOOL ArrayList_IsSynchronized(wArrayList* arrayList)
|
||||
{
|
||||
return arrayList->bSynchronized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or sets the element at the specified index.
|
||||
*/
|
||||
|
||||
void* ArrayList_Item(wArrayList* arrayList, int index, void* obj)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Removes all elements from the ArrayList.
|
||||
*/
|
||||
|
||||
void ArrayList_Clear(wArrayList* arrayList)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an element is in the ArrayList.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_Contains(wArrayList* arrayList, void* obj)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an object to the end of the ArrayList.
|
||||
*/
|
||||
|
||||
int ArrayList_Add(wArrayList* arrayList, void* obj)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Inserts an element into the ArrayList at the specified index.
|
||||
*/
|
||||
|
||||
void ArrayList_Insert(wArrayList* arrayList, int index, void* obj)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the first occurrence of a specific object from the ArrayList.
|
||||
*/
|
||||
|
||||
void ArrayList_Remove(wArrayList* arrayList, void* obj)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the element at the specified index of the ArrayList.
|
||||
*/
|
||||
|
||||
void ArrayList_RemoveAt(wArrayList* arrayList, int index, void* obj)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the specified Object and returns the zero-based index of the first occurrence within the entire ArrayList.
|
||||
*
|
||||
* Searches for the specified Object and returns the zero-based index of the last occurrence within the range of elements
|
||||
* in the ArrayList that extends from the first element to the specified index.
|
||||
*
|
||||
* Searches for the specified Object and returns the zero-based index of the last occurrence within the range of elements
|
||||
* in the ArrayList that contains the specified number of elements and ends at the specified index.
|
||||
*/
|
||||
|
||||
int ArrayList_IndexOf(wArrayList* arrayList, void* obj, int startIndex, int count)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the specified Object and returns the zero-based index of the last occurrence within the entire ArrayList.
|
||||
*
|
||||
* Searches for the specified Object and returns the zero-based index of the last occurrence within the range of elements
|
||||
* in the ArrayList that extends from the first element to the specified index.
|
||||
*
|
||||
* Searches for the specified Object and returns the zero-based index of the last occurrence within the range of elements
|
||||
* in the ArrayList that contains the specified number of elements and ends at the specified index.
|
||||
*/
|
||||
|
||||
int ArrayList_LastIndexOf(wArrayList* arrayList, void* obj, int startIndex, int count)
|
||||
{
|
||||
if (arrayList->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construction, Destruction
|
||||
*/
|
||||
|
||||
wArrayList* ArrayList_New(BOOL bSynchronized)
|
||||
{
|
||||
wArrayList* arrayList = NULL;
|
||||
|
||||
arrayList = (wArrayList*) malloc(sizeof(wArrayList));
|
||||
|
||||
if (arrayList)
|
||||
{
|
||||
arrayList->bSynchronized = bSynchronized;
|
||||
}
|
||||
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
void ArrayList_Free(wArrayList* arrayList)
|
||||
{
|
||||
free(arrayList);
|
||||
}
|
149
winpr/libwinpr/utils/collections/Queue.c
Normal file
149
winpr/libwinpr/utils/collections/Queue.c
Normal file
@ -0,0 +1,149 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* System.Collections.Queue
|
||||
*
|
||||
* 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
|
||||
|
||||
#include <winpr/collections.h>
|
||||
|
||||
/**
|
||||
* C equivalent of the C# Queue Class:
|
||||
* http://msdn.microsoft.com/en-us/library/system.collections.queue.aspx
|
||||
*/
|
||||
|
||||
/**
|
||||
* Properties
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the number of elements contained in the Queue.
|
||||
*/
|
||||
|
||||
int Queue_Count(wQueue* queue)
|
||||
{
|
||||
if (queue->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether access to the Queue is synchronized (thread safe).
|
||||
*/
|
||||
|
||||
BOOL Queue_IsSynchronized(wQueue* queue)
|
||||
{
|
||||
return queue->bSynchronized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Removes all objects from the Queue.
|
||||
*/
|
||||
|
||||
void Queue_Clear(wQueue* queue)
|
||||
{
|
||||
if (queue->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an element is in the Queue.
|
||||
*/
|
||||
|
||||
BOOL Queue_Contains(wQueue* queue, void* obj)
|
||||
{
|
||||
if (queue->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an object to the end of the Queue.
|
||||
*/
|
||||
|
||||
void Queue_Enqueue(wQueue* queue, void* obj)
|
||||
{
|
||||
if (queue->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and returns the object at the beginning of the Queue.
|
||||
*/
|
||||
|
||||
void* Queue_Dequeue(wQueue* queue)
|
||||
{
|
||||
if (queue->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object at the beginning of the Queue without removing it.
|
||||
*/
|
||||
|
||||
void* Queue_Peek(wQueue* queue)
|
||||
{
|
||||
if (queue->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construction, Destruction
|
||||
*/
|
||||
|
||||
wQueue* Queue_New(BOOL bSynchronized)
|
||||
{
|
||||
wQueue* queue = NULL;
|
||||
|
||||
queue = (wQueue*) malloc(sizeof(wQueue));
|
||||
|
||||
if (queue)
|
||||
{
|
||||
queue->bSynchronized = bSynchronized;
|
||||
}
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
void Queue_Free(wQueue* queue)
|
||||
{
|
||||
free(queue);
|
||||
}
|
149
winpr/libwinpr/utils/collections/Stack.c
Normal file
149
winpr/libwinpr/utils/collections/Stack.c
Normal file
@ -0,0 +1,149 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* System.Collections.Stack
|
||||
*
|
||||
* 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
|
||||
|
||||
#include <winpr/collections.h>
|
||||
|
||||
/**
|
||||
* C equivalent of the C# Stack Class:
|
||||
* http://msdn.microsoft.com/en-us/library/system.collections.stack.aspx
|
||||
*/
|
||||
|
||||
/**
|
||||
* Properties
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the number of elements contained in the Stack.
|
||||
*/
|
||||
|
||||
int Stack_Count(wStack* stack)
|
||||
{
|
||||
if (stack->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether access to the Stack is synchronized (thread safe).
|
||||
*/
|
||||
|
||||
BOOL Stack_IsSynchronized(wStack* stack)
|
||||
{
|
||||
return stack->bSynchronized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Removes all objects from the Stack.
|
||||
*/
|
||||
|
||||
void Stack_Clear(wStack* stack)
|
||||
{
|
||||
if (stack->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an element is in the Stack.
|
||||
*/
|
||||
|
||||
BOOL Stack_Contains(wStack* stack, void* obj)
|
||||
{
|
||||
if (stack->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts an object at the top of the Stack.
|
||||
*/
|
||||
|
||||
void Stack_Push(wStack* stack, void* obj)
|
||||
{
|
||||
if (stack->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and returns the object at the top of the Stack.
|
||||
*/
|
||||
|
||||
void* Stack_Pop(wStack* stack)
|
||||
{
|
||||
if (stack->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object at the top of the Stack without removing it.
|
||||
*/
|
||||
|
||||
void* Stack_Peek(wStack* stack)
|
||||
{
|
||||
if (stack->bSynchronized)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construction, Destruction
|
||||
*/
|
||||
|
||||
wStack* Stack_New(BOOL bSynchronized)
|
||||
{
|
||||
wStack* stack = NULL;
|
||||
|
||||
stack = (wStack*) malloc(sizeof(wStack));
|
||||
|
||||
if (stack)
|
||||
{
|
||||
stack->bSynchronized = bSynchronized;
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
void Stack_Free(wStack* stack)
|
||||
{
|
||||
free(stack);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user