1 /*
2 ################################################################################
3 #  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
4 #  Read the zproject/README.md for information about making permanent changes. #
5 ################################################################################
6 */
7 
8 #include "QmlZhashx.h"
9 
10 
11 ///
12 //  Insert item into hash table with specified key and item.
13 //  If key is already present returns -1 and leaves existing item unchanged
14 //  Returns 0 on success.
insert(const void * key,void * item)15 int QmlZhashx::insert (const void *key, void *item) {
16     return zhashx_insert (self, key, item);
17 };
18 
19 ///
20 //  Update or insert item into hash table with specified key and item. If the
21 //  key is already present, destroys old item and inserts new one. If you set
22 //  a container item destructor, this is called on the old value. If the key
23 //  was not already present, inserts a new item. Sets the hash cursor to the
24 //  new item.
update(const void * key,void * item)25 void QmlZhashx::update (const void *key, void *item) {
26     zhashx_update (self, key, item);
27 };
28 
29 ///
30 //  Remove an item specified by key from the hash table. If there was no such
31 //  item, this function does nothing.
32 void QmlZhashx::delete (const void *key) {
33     zhashx_delete (self, key);
34 };
35 
36 ///
37 //  Delete all items from the hash table. If the key destructor is
38 //  set, calls it on every key. If the item destructor is set, calls
39 //  it on every item.
purge()40 void QmlZhashx::purge () {
41     zhashx_purge (self);
42 };
43 
44 ///
45 //  Return the item at the specified key, or null
lookup(const void * key)46 void *QmlZhashx::lookup (const void *key) {
47     return zhashx_lookup (self, key);
48 };
49 
50 ///
51 //  Reindexes an item from an old key to a new key. If there was no such
52 //  item, does nothing. Returns 0 if successful, else -1.
rename(const void * oldKey,const void * newKey)53 int QmlZhashx::rename (const void *oldKey, const void *newKey) {
54     return zhashx_rename (self, oldKey, newKey);
55 };
56 
57 ///
58 //  Set a free function for the specified hash table item. When the item is
59 //  destroyed, the free function, if any, is called on that item.
60 //  Use this when hash items are dynamically allocated, to ensure that
61 //  you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
62 //  Returns the item, or NULL if there is no such item.
freefn(const void * key,zhashx_free_fn freeFn)63 void *QmlZhashx::freefn (const void *key, zhashx_free_fn freeFn) {
64     return zhashx_freefn (self, key, freeFn);
65 };
66 
67 ///
68 //  Return the number of keys/items in the hash table
size()69 size_t QmlZhashx::size () {
70     return zhashx_size (self);
71 };
72 
73 ///
74 //  Return a zlistx_t containing the keys for the items in the
75 //  table. Uses the key_duplicator to duplicate all keys and sets the
76 //  key_destructor as destructor for the list.
keys()77 QmlZlistx *QmlZhashx::keys () {
78     QmlZlistx *retQ_ = new QmlZlistx ();
79     retQ_->self = zhashx_keys (self);
80     return retQ_;
81 };
82 
83 ///
84 //  Return a zlistx_t containing the values for the items in the
85 //  table. Uses the duplicator to duplicate all items and sets the
86 //  destructor as destructor for the list.
values()87 QmlZlistx *QmlZhashx::values () {
88     QmlZlistx *retQ_ = new QmlZlistx ();
89     retQ_->self = zhashx_values (self);
90     return retQ_;
91 };
92 
93 ///
94 //  Simple iterator; returns first item in hash table, in no given order,
95 //  or NULL if the table is empty. This method is simpler to use than the
96 //  foreach() method, which is deprecated. To access the key for this item
97 //  use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
first()98 void *QmlZhashx::first () {
99     return zhashx_first (self);
100 };
101 
102 ///
103 //  Simple iterator; returns next item in hash table, in no given order,
104 //  or NULL if the last item was already returned. Use this together with
105 //  zhashx_first() to process all items in a hash table. If you need the
106 //  items in sorted order, use zhashx_keys() and then zlistx_sort(). To
107 //  access the key for this item use zhashx_cursor(). NOTE: do NOT modify
108 //  the table while iterating.
next()109 void *QmlZhashx::next () {
110     return zhashx_next (self);
111 };
112 
113 ///
114 //  After a successful first/next method, returns the key for the item that
115 //  was returned. This is a constant string that you may not modify or
116 //  deallocate, and which lasts as long as the item in the hash. After an
117 //  unsuccessful first/next, returns NULL.
cursor()118 const void *QmlZhashx::cursor () {
119     return zhashx_cursor (self);
120 };
121 
122 ///
123 //  Add a comment to hash table before saving to disk. You can add as many
124 //  comment lines as you like. These comment lines are discarded when loading
125 //  the file. If you use a null format, all comments are deleted.
comment(const QString & format)126 void QmlZhashx::comment (const QString &format) {
127     zhashx_comment (self, "%s", format.toUtf8().data());
128 };
129 
130 ///
131 //  Save hash table to a text file in name=value format. Hash values must be
132 //  printable strings; keys may not contain '=' character. Returns 0 if OK,
133 //  else -1 if a file error occurred.
save(const QString & filename)134 int QmlZhashx::save (const QString &filename) {
135     return zhashx_save (self, filename.toUtf8().data());
136 };
137 
138 ///
139 //  Load hash table from a text file in name=value format; hash table must
140 //  already exist. Hash values must printable strings; keys may not contain
141 //  '=' character. Returns 0 if OK, else -1 if a file was not readable.
load(const QString & filename)142 int QmlZhashx::load (const QString &filename) {
143     return zhashx_load (self, filename.toUtf8().data());
144 };
145 
146 ///
147 //  When a hash table was loaded from a file by zhashx_load, this method will
148 //  reload the file if it has been modified since, and is "stable", i.e. not
149 //  still changing. Returns 0 if OK, -1 if there was an error reloading the
150 //  file.
refresh()151 int QmlZhashx::refresh () {
152     return zhashx_refresh (self);
153 };
154 
155 ///
156 //  Serialize hash table to a binary frame that can be sent in a message.
157 //  The packed format is compatible with the 'dictionary' type defined in
158 //  http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
159 //
160 //     ; A list of name/value pairs
161 //     dictionary      = dict-count *( dict-name dict-value )
162 //     dict-count      = number-4
163 //     dict-value      = longstr
164 //     dict-name       = string
165 //
166 //     ; Strings are always length + text contents
167 //     longstr         = number-4 *VCHAR
168 //     string          = number-1 *VCHAR
169 //
170 //     ; Numbers are unsigned integers in network byte order
171 //     number-1        = 1OCTET
172 //     number-4        = 4OCTET
173 //
174 //  Comments are not included in the packed data. Item values MUST be
175 //  strings.
pack()176 QmlZframe *QmlZhashx::pack () {
177     QmlZframe *retQ_ = new QmlZframe ();
178     retQ_->self = zhashx_pack (self);
179     return retQ_;
180 };
181 
182 ///
183 //  Same as pack but uses a user-defined serializer function to convert items
184 //  into longstr.
packOwn(zhashx_serializer_fn serializer)185 QmlZframe *QmlZhashx::packOwn (zhashx_serializer_fn serializer) {
186     QmlZframe *retQ_ = new QmlZframe ();
187     retQ_->self = zhashx_pack_own (self, serializer);
188     return retQ_;
189 };
190 
191 ///
192 //  Make a copy of the list; items are duplicated if you set a duplicator
193 //  for the list, otherwise not. Copying a null reference returns a null
194 //  reference. Note that this method's behavior changed slightly for CZMQ
195 //  v3.x, as it does not set nor respect autofree. It does however let you
196 //  duplicate any hash table safely. The old behavior is in zhashx_dup_v2.
dup()197 QmlZhashx *QmlZhashx::dup () {
198     QmlZhashx *retQ_ = new QmlZhashx ();
199     retQ_->self = zhashx_dup (self);
200     return retQ_;
201 };
202 
203 ///
204 //  Set a user-defined deallocator for hash items; by default items are not
205 //  freed when the hash is destroyed.
setDestructor(zhashx_destructor_fn destructor)206 void QmlZhashx::setDestructor (zhashx_destructor_fn destructor) {
207     zhashx_set_destructor (self, destructor);
208 };
209 
210 ///
211 //  Set a user-defined duplicator for hash items; by default items are not
212 //  copied when the hash is duplicated.
setDuplicator(zhashx_duplicator_fn duplicator)213 void QmlZhashx::setDuplicator (zhashx_duplicator_fn duplicator) {
214     zhashx_set_duplicator (self, duplicator);
215 };
216 
217 ///
218 //  Set a user-defined deallocator for keys; by default keys are freed
219 //  when the hash is destroyed using free().
setKeyDestructor(zhashx_destructor_fn destructor)220 void QmlZhashx::setKeyDestructor (zhashx_destructor_fn destructor) {
221     zhashx_set_key_destructor (self, destructor);
222 };
223 
224 ///
225 //  Set a user-defined duplicator for keys; by default keys are duplicated
226 //  using strdup.
setKeyDuplicator(zhashx_duplicator_fn duplicator)227 void QmlZhashx::setKeyDuplicator (zhashx_duplicator_fn duplicator) {
228     zhashx_set_key_duplicator (self, duplicator);
229 };
230 
231 ///
232 //  Set a user-defined comparator for keys; by default keys are
233 //  compared using strcmp.
234 //  The callback function should return zero (0) on matching
235 //  items.
setKeyComparator(zhashx_comparator_fn comparator)236 void QmlZhashx::setKeyComparator (zhashx_comparator_fn comparator) {
237     zhashx_set_key_comparator (self, comparator);
238 };
239 
240 ///
241 //  Set a user-defined hash function for keys; by default keys are
242 //  hashed by a modified Bernstein hashing function.
setKeyHasher(zhashx_hash_fn hasher)243 void QmlZhashx::setKeyHasher (zhashx_hash_fn hasher) {
244     zhashx_set_key_hasher (self, hasher);
245 };
246 
247 ///
248 //  Make copy of hash table; if supplied table is null, returns null.
249 //  Does not copy items themselves. Rebuilds new table so may be slow on
250 //  very large tables. NOTE: only works with item values that are strings
251 //  since there's no other way to know how to duplicate the item value.
dupV2()252 QmlZhashx *QmlZhashx::dupV2 () {
253     QmlZhashx *retQ_ = new QmlZhashx ();
254     retQ_->self = zhashx_dup_v2 (self);
255     return retQ_;
256 };
257 
258 
qmlAttachedProperties(QObject * object)259 QObject* QmlZhashx::qmlAttachedProperties(QObject* object) {
260     return new QmlZhashxAttached(object);
261 }
262 
263 
264 ///
265 //  Self test of this class.
test(bool verbose)266 void QmlZhashxAttached::test (bool verbose) {
267     zhashx_test (verbose);
268 };
269 
270 ///
271 //  Create a new, empty hash container
construct()272 QmlZhashx *QmlZhashxAttached::construct () {
273     QmlZhashx *qmlSelf = new QmlZhashx ();
274     qmlSelf->self = zhashx_new ();
275     return qmlSelf;
276 };
277 
278 ///
279 //  Unpack binary frame into a new hash table. Packed data must follow format
280 //  defined by zhashx_pack. Hash table is set to autofree. An empty frame
281 //  unpacks to an empty hash table.
unpack(QmlZframe * frame)282 QmlZhashx *QmlZhashxAttached::unpack (QmlZframe *frame) {
283     QmlZhashx *qmlSelf = new QmlZhashx ();
284     qmlSelf->self = zhashx_unpack (frame->self);
285     return qmlSelf;
286 };
287 
288 ///
289 //  Same as unpack but uses a user-defined deserializer function to convert
290 //  a longstr back into item format.
unpackOwn(QmlZframe * frame,zhashx_deserializer_fn deserializer)291 QmlZhashx *QmlZhashxAttached::unpackOwn (QmlZframe *frame, zhashx_deserializer_fn deserializer) {
292     QmlZhashx *qmlSelf = new QmlZhashx ();
293     qmlSelf->self = zhashx_unpack_own (frame->self, deserializer);
294     return qmlSelf;
295 };
296 
297 ///
298 //  Destroy a hash container and all items in it
destruct(QmlZhashx * qmlSelf)299 void QmlZhashxAttached::destruct (QmlZhashx *qmlSelf) {
300     zhashx_destroy (&qmlSelf->self);
301 };
302 
303 /*
304 ################################################################################
305 #  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
306 #  Read the zproject/README.md for information about making permanent changes. #
307 ################################################################################
308 */
309