tizen 2.3 release
[external/buxton.git] / src / shared / buxtonarray.h
1 /*
2  * This file is part of buxton.
3  *
4  * Copyright (C) 2013 Intel Corporation
5  *
6  * buxton is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as
8  * published by the Free Software Foundation; either version 2.1
9  * of the License, or (at your option) any later version.
10  */
11
12 #pragma once
13
14 #ifdef HAVE_CONFIG_H
15         #include "config.h"
16 #endif
17
18 #include <stdint.h>
19 #include <stdbool.h>
20
21 #include "buxtondata.h"
22
23 /**
24  * A dynamic array
25  * Represents daemon's reply to client
26  */
27 typedef struct BuxtonArray {
28         void **data; /**<Dynamic array contents */
29         uint len; /**<Length of the array */
30 } BuxtonArray;
31
32
33 /**
34  * Valid function prototype for 'free' method
35  * @param p Pointer to free
36  */
37 typedef void (*buxton_free_func) (void* p);
38
39 /**
40  * Create a new BuxtonArray
41  * @returns BuxtonArray a newly allocated BuxtonArray
42  */
43 BuxtonArray *buxton_array_new(void)
44         __attribute__((warn_unused_result));
45
46 /**
47  * Append data to BuxtonArray
48  * @param array Valid BuxtonArray
49  * @param data Pointer to add to this array
50  * @returns bool true if the data was added to the array
51  */
52 bool buxton_array_add(BuxtonArray *array,
53                       void *data)
54         __attribute__((warn_unused_result));
55
56 /**
57  * Free an array, and optionally its members
58  * @param array valid BuxtonArray reference
59  * @param free_func Function to call to free all members, or NULL to leave allocated
60  */
61 void buxton_array_free(BuxtonArray **array,
62                        buxton_free_func free_method);
63
64
65 /**
66  * Retrieve a BuxtonData from the array by index
67  * @param array valid BuxtonArray reference
68  * @param index index of the element in the array
69  * @return a data pointer refered to by index, or NULL
70  */
71 void *buxton_array_get(BuxtonArray *array, uint16_t index)
72         __attribute__((warn_unused_result));
73
74 /*
75  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
76  *
77  * Local variables:
78  * c-basic-offset: 8
79  * tab-width: 8
80  * indent-tabs-mode: t
81  * End:
82  *
83  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
84  * :indentSize=8:tabSize=8:noTabs=false:
85  */