TeoCCl library  0.1.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
queue.h
Go to the documentation of this file.
1 /*
2  * The MIT License
3  *
4  * Copyright 2016-2018 Kirill Scherba <kirill@scherba.ru>.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
35 #ifndef QUEUE_H
36 #define QUEUE_H
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include <stddef.h>
43 
49 typedef struct teoQueueData {
50 
51  struct teoQueueData *prev;
52  struct teoQueueData *next;
53  size_t data_length;
54  char data[];
55 
56 } teoQueueData;
57 
58 typedef struct teoQueue {
59 
60  size_t length;
63 
64 } teoQueue;
65 
66 typedef struct teoQueueIterator {
67 
70 
72 
75 int teoQueueFree(teoQueue *q);
76 
77 teoQueueData *teoQueueNewData(void *data, size_t data_length);
78 
79 teoQueueData *teoQueueAdd(teoQueue *q, void *data, size_t data_length);
80 teoQueueData *teoQueueAddTop(teoQueue *q, void *data, size_t data_length);
81 teoQueueData *teoQueueAddAfter(teoQueue *q, void *data, size_t data_length,
82  teoQueueData *qd);
83 teoQueueData *teoQueueUpdate(teoQueue *q, void *data, size_t data_length,
84  teoQueueData *qd);
86 
93 size_t teoQueueSize(teoQueue *q);
94 
101 
102 typedef int (*teoQueueForeachFunction)(teoQueue *q, int idx, teoQueueData *data, void* user_data);
103 int teoQueueForeach(teoQueue *q, teoQueueForeachFunction callback, void *user_data);
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* QUEUE_H */
110 
teoQueueData * teoQueueIteratorNext(teoQueueIterator *it)
Get next element from Teo Queue iterator.
Definition: queue.c:421
teoQueueData * teoQueueMoveToEnd(teoQueue *q, teoQueueData *qd)
Move element from this queue to the end of queue.
Definition: queue.c:336
int teoQueueDeleteLast(teoQueue *q)
Delete last element from queue and free it.
Definition: queue.c:325
Definition: queue.h:58
struct teoQueueData * prev
Definition: queue.h:51
teoQueueData * qd
Definition: queue.h:69
teoQueueIterator * teoQueueIteratorNew(teoQueue *q)
Create new Teo Queue iterator.
Definition: queue.c:385
size_t data_length
Definition: queue.h:53
teoQueueData * teoQueueNewData(void *data, size_t data_length)
Create new teoQueueData buffer.
Definition: queue.c:135
struct teoQueueIterator teoQueueIterator
teoQueueData * teoQueueRemove(teoQueue *q, teoQueueData *qd)
Remove element from queue but not free it.
Definition: queue.c:274
int teoQueueFree(teoQueue *q)
Remove all elements from Teo queue.
Definition: queue.c:74
Definition: queue.h:66
teoQueueData * last
Definition: queue.h:62
teoQueueData * teoQueueUpdate(teoQueue *q, void *data, size_t data_length, teoQueueData *qd)
Update element: remove selected and set new one to it place.
Definition: queue.c:238
char data[]
Definition: queue.h:54
int(* teoQueueForeachFunction)(teoQueue *q, int idx, teoQueueData *data, void *user_data)
Definition: queue.h:102
teoQueueData * teoQueueAddTop(teoQueue *q, void *data, size_t data_length)
Add new element to the top of Teo queue.
Definition: queue.c:183
teoQueueData * teoQueueAdd(teoQueue *q, void *data, size_t data_length)
Add new element to the end of Teo queue.
Definition: queue.c:162
Queue module, linked list with data in body.
Definition: queue.h:49
int teoQueueForeach(teoQueue *q, teoQueueForeachFunction callback, void *user_data)
Loop through queue and call callback function with index and data in parameters.
Definition: queue.c:479
struct teoQueueData teoQueueData
Queue module, linked list with data in body.
teoQueueData * teoQueueIteratorElement(teoQueueIterator *it)
Get current Teo Queue iterator element.
Definition: queue.c:454
int teoQueueDeleteFirst(teoQueue *q)
Delete first element from queue and free it.
Definition: queue.c:315
struct teoQueueData * next
Definition: queue.h:52
teoQueueData * first
Definition: queue.h:61
teoQueue * teoQueueNew()
Create new Teo Queue.
Definition: queue.c:41
teoQueueData * teoQueueMoveToTop(teoQueue *q, teoQueueData *qd)
Move element from this queue to the top of queue.
Definition: queue.c:361
teoQueueData * teoQueuePut(teoQueue *q, teoQueueData *qd)
Put (add, copy) existing queue record to the end of selected queue.
Definition: queue.c:109
size_t length
Definition: queue.h:60
teoQueueData * teoQueueAddAfter(teoQueue *q, void *data, size_t data_length, teoQueueData *qd)
Add new element after selected in qd field.
Definition: queue.c:199
teoQueueData * teoQueueIteratorPrev(teoQueueIterator *it)
Get previous element from Teo Queue iterator.
Definition: queue.c:438
int teoQueueIteratorFree(teoQueueIterator *it)
Free (destroy) Teo Queue iterator.
Definition: queue.c:465
size_t teoQueueSize(teoQueue *q)
Get number of elements in Teo queue.
Definition: queue.c:97
teoQueueIterator * teoQueueIteratorReset(teoQueueIterator *it, teoQueue *q)
Reset iterator (or swith to new Queue)
Definition: queue.c:404
teoQueue * q
Definition: queue.h:68
struct teoQueue teoQueue
int teoQueueDelete(teoQueue *q, teoQueueData *qd)
Delete element from queue and free it.
Definition: queue.c:300
int teoQueueDestroy(teoQueue *q)
Destroy Teo Queue.
Definition: queue.c:57