Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 164 lines (144 sloc) 6.201 kb
2f8cb1d Refactoring and finished rewriting libbenc
cjdelisle authored
1 /*
2 * You may redistribute this program and/or modify it under the terms of
3 * the GNU General Public License as published by the Free Software Foundation,
4 * either version 3 of the License, or (at your option) any later version.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
547f4a3 Cleaned up a bunch of files, added a codestyle validator and some inf…
cjdelisle authored
14 #ifndef Dict_H
15 #define Dict_H
2f8cb1d Refactoring and finished rewriting libbenc
cjdelisle authored
16
17 #include "memory/Allocator.h"
18 #include "benc/Object.h"
19
20 struct Dict_Entry;
21 struct Dict_Entry {
22 struct Dict_Entry* next;
23 const String* key;
24 Object* val;
25 };
26
27 /**
28 * Remove an entry from the dictionary.
29 *
30 * @param dictionary the dictionary to remove the entry from.
31 * @param key the key which the entry is entered under.
32 * @return 1 if there was an entry removed, 0 if there was not.
33 */
34 int32_t Dict_remove(Dict* dictionary, const String* key);
35
36 /*----------------------- Size Functions -----------------------*/
37
38 /**
39 * Get the number of entries in a dictionary.
40 *
41 * @param a dictionary
42 * @return the number of entries in the dictionary or -1 if the dictionary argument is NULL.
43 */
44 int32_t Dict_size(const Dict* dictionary);
45
46
47 /*----------------------- Dictionary Lookup Functions -----------------------*/
48
49 /**
50 * Lookup an integer value from a dictionary, if the value is not present
51 * or is not an integer type then NULL is returned.
52 *
53 * @param dictionary the dictionary to look the entry up in.
54 * @param key the key to look the entry up with.
55 * @return an integer which is in the dictionary under the given key or else NULL.
56 */
57 int64_t* Dict_getInt(const Dict* dictionary, const String* key);
58
59 /**
60 * Lookup a string value from a dictionary, if the value is not present
61 * or is not a string type then NULL is returned.
62 *
63 * @param dictionary the dictionary to look the entry up in.
64 * @param key the key to look the entry up with.
65 * @return a string which is in the dictionary under the given key or else NULL.
66 */
67 String* Dict_getString(const Dict* dictionary, const String* key);
68
69 /**
70 * Lookup a dictionary value from another dictionary, if the value is not present
71 * or is not a dictionary type then NULL is returned.
72 *
73 * @param dictionary the dictionary to look the entry up in.
74 * @param key the key to look the entry up with.
75 * @return a dictionary which is in the dictionary under the given key or else NULL.
76 */
77 Dict* Dict_getDict(const Dict* dictionary, const String* key);
78
79 /**
80 * Lookup a list value from a dictionary, if the value is not present
81 * or is not a list type then NULL is returned.
82 *
83 * @param dictionary the dictionary to look the entry up in.
84 * @param key the key to look the entry up with.
85 * @return a list which is in the dictionary under the given key or else NULL.
86 */
87 List* Dict_getList(const Dict* dictionary, const String* key);
88
89 /*----------------------- Dictionary Put Functions -----------------------*/
90
91 /**
92 * Insert an integer into a dictionary.
93 *
94 * @param putIntoThis the dictionary to insert an entry into.
95 * @param key the reference key to use for putting the entry in the dictionary.
96 * @param value the integer to insert. int64_t is an alias to int64_t.
97 * @param allocator the means to get memory for storing the dictionary entry wrapper.
98 * @return if the key already exists in the dictionary then the value which was
99 * displaced by the put, otherwise NULL.
100 */
101 Object* Dict_putInt(Dict* putIntoThis,
102 const String* key,
103 int64_t value,
104 const struct Allocator* allocator);
105
106 /**
107 * Insert a String object into another dictionary.
108 * NOTE: This will not copy the given object, only add a pointer to it in the dictionary.
109 *
110 * @param putIntoThis the dictionary to insert an entry into.
111 * @param key the reference key to use for putting the entry in the dictionary.
112 * @param value the string to insert.
113 * @param allocator the means to get memory for storing the dictionary entry wrapper.
114 * @return if the key already exists in the dictionary then the value which was
115 * displaced by the put, otherwise NULL.
116 */
117 Object* Dict_putString(Dict* putIntoThis,
118 const String* key,
119 String* value,
120 const struct Allocator* allocator);
121
122 /**
123 * Insert a Dictionary object into another dictionary.
124 * NOTE: This will not copy the given object, only add a pointer to it in the dictionary.
125 *
126 * @param putIntoThis the dictionary to insert an entry into.
127 * @param key the reference key to use for putting the entry in the dictionary.
128 * @param value the value to insert.
129 * @param allocator the memory allocator to use for getting memory for the entry.
130 * @return if the key already exists in the dictionary then the value which was
131 * displaced by the put, otherwise NULL.
132 */
133 Object* Dict_putDict(Dict* putIntoThis,
134 const String* key,
135 Dict* value,
136 const struct Allocator* allocator);
137
138 /**
139 * Insert a List object into a dictionary.
140 * NOTE: This will not copy the given object, only add a pointer to it in the dictionary.
141 *
142 * @param putIntoThis the dictionary to insert an entry into.
143 * @param key the reference key to use for putting the entry in the dictionary.
144 * @param value the list to insert.
145 * @param allocator the memory allocator to use for getting memory for the entry.
146 * @return if the key already exists in the dictionary then the value which was
147 * displaced by the put, otherwise NULL.
148 */
149 Object* Dict_putList(Dict* putIntoThis,
150 const String* key,
151 List* value,
152 const struct Allocator* allocator);
153
154 /*----------------------- Constructors -----------------------*/
155
156 /**
157 * Create a new bencoded dictionary type.
158 *
159 * @param allocator the place to allocate the memory for storing the dictionary.
160 */
161 Dict* Dict_new(const struct Allocator* allocator);
162
163 #endif
Something went wrong with that request. Please try again.