arzmq-sys 0.6.3

Low-level bindings to the zeromq library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569

#include "protoQueue.h"

ProtoQueue::ProtoQueue(bool usePool)
 : container_pool(usePool ? &builtin_container_pool : NULL)
{
}

ProtoQueue::ProtoQueue(ContainerPool* containerPool)
 : container_pool(containerPool)
{
}

ProtoQueue::~ProtoQueue()
{
   // Note the original plan was to call the Empty()
    // method here so that when a ProtoQueue is deleted
    // it removes any queued Containers so they aren't left
    // with a bad pointer.  But, you can't call virtual methods
    // from a destructor in C++. So, the derived classes 
    // MUST call Empty() in their destructors!
    builtin_container_pool.Destroy();
}


ProtoQueue::Container::Container()
 : item(NULL), queue(NULL), entry(*this)
{
}

ProtoQueue::Container::~Container()
{
    // Derived Container class destructors MUST
    // also call "Cleanup()" so there is no danger
    // of an indirect call to a virtual function
    // (See the longer note in ProtoQueue::Item::~Item()
    //  below)
    Cleanup();
}

void ProtoQueue::Container::Cleanup()
{
    if (NULL != item) 
    {
        ASSERT(NULL != queue);
        queue->Remove(*item);   
    }
}

ProtoQueue::Container::Entry::Entry(Container& theContainer)
 : container(theContainer)
{
}

ProtoQueue::Item::Item()
{
}

ProtoQueue::Item::~Item()
{
    // If the call to Cleanup() causes some sort of core dump,
    // it is likely the case that the derived ProtoQueue depends
    // upon some extension of the base Item class for its data
    // organization.  So, derived Item types SHOULD/MUST call
    // Cleanup() themselves so the Cleanup() call here doesn't do 
    // anything harmful.  (the derived class' destructor() call to Cleanup()
    // will be called first and be safer.  In fact, perhaps it would be better to
    // not call Cleanup() here at all and require programmers that create
    // derived Item subclasses to call Cleanup().  The way to help force
    // this may be to make the Cleanup() a pure virtual function in
    // the base class so that subclasses must implement it?  There is still
    // some leftover safety issue here where further derivations are performed ...
    // (This is the same issue as the note for the Empty() method above.)
    // Perhaps there is a better design that avoids this C++ issue!
    Cleanup();
}

void ProtoQueue::Item::Cleanup()
{
    while (!container_list.IsEmpty())
    {
        Container::Entry*entry = static_cast<Container::Entry*>(container_list.GetRoot());
        ProtoQueue* theQueue = entry->GetContainer().GetQueue();
        ASSERT(NULL != theQueue);
        theQueue->Remove(*this);
    }
}  // end ProtoQueue::Item::Cleanup()

bool ProtoQueue::Item::IsInOtherQueue(const ProtoQueue& queue)
{
    ProtoTree::Iterator iterator(container_list);
    const ProtoQueue::Container::Entry* entry;
    while (NULL != (entry = static_cast<const Container::Entry*>(iterator.GetNextItem())))
    {
        if (&queue != entry->GetContainer().GetQueue())
            return true;
    }
    return false;
}  // end ProtoQueue::IsInOtherQueue()

ProtoQueue::ContainerPool::ContainerPool()
{
}

ProtoQueue::ContainerPool::~ContainerPool()
{
    Destroy();
}

void ProtoQueue::ContainerPool::Destroy()
{
    Container* container;
    while (NULL != (container = Get()))
        delete container;
}  // end ProtoQueue::ContainerPool::Destroy()

ProtoSimpleQueue::ProtoSimpleQueue(bool usePool)
 : ProtoQueue(usePool)
{
}

ProtoSimpleQueue::ProtoSimpleQueue(ContainerPool* containerPool)
 : ProtoQueue(containerPool)
{
}

ProtoSimpleQueue::~ProtoSimpleQueue()
{
    Empty();
}

bool ProtoSimpleQueue::Append(Item& theItem)
{
    Container* theContainer = GetContainerFromPool();
    if (NULL == theContainer) theContainer = CreateContainer();
    if (NULL == theContainer) return false;
    Associate(theItem, *theContainer);
    item_list.Append(*theContainer);
    return true;
}  // end ProtoSimpleQueue::Append()

bool ProtoSimpleQueue::Prepend(ProtoQueue::Item& theItem)
{
    Container* theContainer = GetContainerFromPool();
    if (NULL == theContainer) theContainer = CreateContainer();
    if (NULL == theContainer) return false;
    Associate(theItem, *theContainer);
    item_list.Prepend(*theContainer);
    return true;
}  // end ProtoSimpleQueue::Prepend()

bool ProtoSimpleQueue::Insert(ProtoQueue::Item& theItem, ProtoQueue::Item& nextItem)
{
    Container* theContainer = GetContainerFromPool();
    if (NULL == theContainer) theContainer = CreateContainer();
    if (NULL == theContainer) return false;
    Associate(theItem, *theContainer);
    Container* nextContainer = static_cast<Container*>(nextItem.GetContainer(*this));
    if (NULL == nextContainer)
    {
        PLOG(PL_ERROR, "ProtoSimpleQueue::Insert() error: nextItem not in this queue?!\n");
        Disassociate(theItem, *theContainer);
        if (NULL != container_pool)
            container_pool->Put(*theContainer);
        else
            delete theContainer;
        return false;
    }    
    item_list.Insert(*theContainer, *nextContainer);
    return true;
}  // end ProtoSimpleQueue::Insert()

bool ProtoSimpleQueue::InsertAfter(ProtoQueue::Item& theItem, ProtoQueue::Item& nextItem)
{
    Container* theContainer = GetContainerFromPool();
    if (NULL == theContainer) theContainer = CreateContainer();
    if (NULL == theContainer) return false;
    Associate(theItem, *theContainer);
    Container* nextContainer = static_cast<Container*>(nextItem.GetContainer(*this));
    if (NULL == nextContainer)
    {
        PLOG(PL_ERROR, "ProtoSimpleQueue::Insert() error: nextItem not in this queue?!\n");
        Disassociate(theItem, *theContainer);
        if (NULL != container_pool)
            container_pool->Put(*theContainer);
        else
            delete theContainer;
        return false;
    }    
    item_list.InsertAfter(*theContainer, *nextContainer);
    return true;
}  // end ProtoSimpleQueue::Insert()

void ProtoSimpleQueue::Remove(Item& theItem)
{
    Container* theContainer = static_cast<Container*>(ProtoQueue::GetContainer(theItem));
    if (NULL != theContainer) RemoveContainer(theContainer, theItem);
}  // end ProtoSimpleQueue::Remove()

ProtoSimpleQueue::Item* ProtoSimpleQueue::RemoveHead()
{
    Container* container = item_list.GetHead();
    if (NULL != container) 
    {
        Item* item = container->GetItem();
        ASSERT(NULL != item);
        RemoveContainer(container, *item);
        return item;
    }
    else
    {
        return NULL;
    }
}  // end ProtoSimpleQueue::RemoveHead()

ProtoSimpleQueue::Item* ProtoSimpleQueue::RemoveTail()
{
    Container* container = item_list.GetTail();
    if (NULL != container) 
    {
        Item* item = container->GetItem();
        ASSERT(NULL != item);
        RemoveContainer(container, *item);
        return item;
    }
    else
    {
        return NULL;
    }
}  // end ProtoSimpleQueue::RemoveTail()

void ProtoSimpleQueue::RemoveContainer(Container* theContainer, Item& theItem)
{
    ASSERT(NULL != theContainer);
    item_list.Remove(*theContainer);
    Disassociate(theItem, *theContainer);
    if (NULL != container_pool)
        container_pool->Put(*theContainer);
    else
        delete theContainer;
}  // end ProtoSimpleQueue::RemoveContainer()

void ProtoSimpleQueue::Empty()
{
    Container* nextContainer;
    while (NULL != (nextContainer = item_list.RemoveHead()))
    {
        ProtoQueue::Item* nextItem = nextContainer->GetItem();
        ASSERT(NULL != nextItem);
        Disassociate(*nextItem, *nextContainer);
        if (NULL != container_pool)
            container_pool->Put(*nextContainer);
        else
            delete nextContainer;
    }
}  // end ProtoSimpleQueue::Empty()

void ProtoSimpleQueue::Destroy()
{
    Container* nextContainer;
    while (NULL != (nextContainer = item_list.RemoveHead()))
    {
        ProtoQueue::Item* nextItem = nextContainer->GetItem();
        ASSERT(NULL != nextItem);
        Disassociate(*nextItem, *nextContainer);
        delete nextItem;
        if (NULL != container_pool)
            container_pool->Put(*nextContainer);
        else
            delete nextContainer;
    }
}  // end ProtoSimpleQueue::Destroy()

ProtoSimpleQueue::Iterator::Iterator(ProtoSimpleQueue& theQueue, bool reverse)
 : ProtoList::Iterator(theQueue.item_list, reverse)
{
}

ProtoSimpleQueue::Iterator::~Iterator()
{
}

ProtoSimpleQueue::Container::Container()
{
}

ProtoSimpleQueue::Container::~Container()
{
    Cleanup();
}

ProtoIndexedQueue::ProtoIndexedQueue(bool usePool)
 : ProtoQueue(usePool)
{
}

ProtoIndexedQueue::ProtoIndexedQueue(ContainerPool* containerPool)
 : ProtoQueue(containerPool)
{
}

ProtoIndexedQueue::~ProtoIndexedQueue()
{
    Empty();
}

bool ProtoIndexedQueue::Insert(Item& theItem)
{
    Container* theContainer = GetContainerFromPool();
    if (NULL == theContainer) theContainer = CreateContainer();
    if (NULL == theContainer) return false;
    Associate(theItem, *theContainer);
    //return item_tree.Insert(*theContainer);
    //bunny Brian should we always return true here seems wrong...I'll let you do the update above or not.
    item_tree.Insert(*theContainer);
    return true;
}  // end ProtoIndexedQueue::Insert()

void ProtoIndexedQueue::Remove(Item& theItem)
{
    Container* theContainer = static_cast<Container*>(ProtoQueue::GetContainer(theItem));
    if (NULL != theContainer)
    {
        item_tree.Remove(*theContainer);
        Disassociate(theItem, *theContainer);
        if (NULL != container_pool)
            container_pool->Put(*theContainer);
        else
            delete theContainer;
    }
}  // end ProtoIndexedQueue::Remove()

void ProtoIndexedQueue::Empty()
{
    // We use the "SimpleIterator here because it is safe
    // to call from the destructor
    Container* nextContainer;
    Tree::SimpleIterator sit(item_tree);
    // We have to defer container deletion until after item_tree traversal
    // so we use this "tmpPool" (this is so the item virtuals aren't accessed)
    ContainerPool tmpPool; 
    while (NULL != (nextContainer = sit.GetNextItem()))
    {
        ProtoQueue::Item* nextItem = nextContainer->GetItem();
        ASSERT(NULL != nextItem);
        Disassociate(*nextItem, *nextContainer);
        if (NULL != container_pool)
            container_pool->Put(*nextContainer);
        else
            tmpPool.Put(*nextContainer);
    }
    tmpPool.Destroy();
    item_tree.Empty();  // sets the item_tree.root to NULL
}  // end ProtoIndexedQueue::Empty()

// "Destroy" is same as "Empty", except items are deleted
void ProtoIndexedQueue::Destroy()
{
    // We use the "SimpleIterator here because it is safe
    // to call from the destructor
    Container* nextContainer;
    Tree::SimpleIterator sit(item_tree);
    // We have to defer container deletion until after item_tree traversal
    // so we use this "tmpPool" (this is so the item virtuals aren't accessed)
    // The "trick" here is we stick the "container" directly into a pool
    // without a "Remove" from the tree (where virtuals would be invoked).
    // This is safe with the "SimpleIterator" we're using.
    ContainerPool tmpPool; 
    while (NULL != (nextContainer = sit.GetNextItem()))
    {
        ProtoQueue::Item* nextItem = nextContainer->GetItem();
        ASSERT(NULL != nextItem);
        Disassociate(*nextItem, *nextContainer);
        delete nextItem;
        if (NULL != container_pool)
            container_pool->Put(*nextContainer);
        else
            tmpPool.Put(*nextContainer);
    }
    tmpPool.Destroy();
    item_tree.Empty();  // sets the item_tree.root to NULL
}  // end ProtoIndexedQueue::Destroy()

        
ProtoIndexedQueue::Iterator::Iterator(ProtoIndexedQueue& theQueue, bool reverse)
 : ProtoTree::Iterator(theQueue.item_tree, reverse)
{
}

ProtoIndexedQueue::Iterator::~Iterator()
{
}

ProtoIndexedQueue::Container::Container()
{
}

ProtoIndexedQueue::Container::~Container()
{
    Cleanup();
}

const char* ProtoIndexedQueue::Container::GetKey() const
{
    ProtoQueue::Item* item = GetItem();
    ASSERT(NULL != item);
    ProtoIndexedQueue* iq = static_cast<ProtoIndexedQueue*>(GetQueue());
    return (iq->GetKey(*item));
}  // end ProtoIndexedQueue::Container::GetKey()

unsigned int ProtoIndexedQueue::Container::GetKeysize() const
{
    ProtoQueue::Item* item = GetItem();
    ASSERT(NULL != item);
    ProtoIndexedQueue* iq = static_cast<ProtoIndexedQueue*>(GetQueue());
    return (iq->GetKeysize(*item));
}  // end ProtoIndexedQueue::Container::GetKeysize()
                



ProtoSortedQueue::ProtoSortedQueue(bool usePool)
 : ProtoQueue(usePool)
{
}

ProtoSortedQueue::ProtoSortedQueue(ContainerPool* containerPool)
 : ProtoQueue(containerPool)
{
}

ProtoSortedQueue::~ProtoSortedQueue()
{
    Empty();
}

bool ProtoSortedQueue::Insert(Item& theItem)
{
    Container* theContainer = GetContainerFromPool();
    if (NULL == theContainer) theContainer = CreateContainer();
    if (NULL == theContainer) return false;
    Associate(theItem, *theContainer);
    item_tree.Insert(*theContainer);
    return true;
}  // end ProtoSortedQueue::Insert()

void ProtoSortedQueue::Remove(Item& theItem)
{
    Container* theContainer = static_cast<Container*>(ProtoQueue::GetContainer(theItem));
    if (NULL != theContainer)
    {
        item_tree.Remove(*theContainer);
        Disassociate(theItem, *theContainer);
        if (NULL != container_pool)
            container_pool->Put(*theContainer);
        else
            delete theContainer;
    }
}  // end ProtoSortedQueue::Remove()

void ProtoSortedQueue::Empty()
{
    Container* nextContainer;
    ProtoSortedTree::Iterator iterator(item_tree);
    while (NULL != (nextContainer = static_cast<Container*>(iterator.GetNextItem())))
    {
        ProtoQueue::Item* nextItem = nextContainer->GetItem();
        ASSERT(NULL != nextItem);
        Disassociate(*nextItem, *nextContainer);
        if (NULL != container_pool)
            container_pool->Put(*nextContainer);
        else
            delete nextContainer;
    }
    item_tree.Empty();
}  // end ProtoSortedQueue::Empty()

void ProtoSortedQueue::Destroy()
{
    Container* nextContainer;
    ProtoSortedTree::Iterator iterator(item_tree);
    while (NULL != (nextContainer = static_cast<Container*>(iterator.GetNextItem())))
    {
        ProtoQueue::Item* nextItem = nextContainer->GetItem();
        ASSERT(NULL != nextItem);
        Disassociate(*nextItem, *nextContainer);
        delete nextItem;
        if (NULL != container_pool)
            container_pool->Put(*nextContainer);
        else
            delete nextContainer;
    }
    item_tree.Empty();
}  // end ProtoSortedQueue::Destroy()

ProtoTree::Endian ProtoSortedQueue::GetEndian() const
{
    return ProtoTree::ENDIAN_BIG;  // BIG ENDIAN by default
}

bool ProtoSortedQueue::UseComplement2() const
{
    return true;
}  // end ProtoSortedQueue::UseComplement2()

bool ProtoSortedQueue::UseSignBit() const
{
    return false;
}  // end ProtoSortedQueue::UseSignBit()

ProtoSortedQueue::Iterator::Iterator(ProtoSortedQueue&    theQueue, 
                                     bool                       reverse,
                                     const char*                keyMin,
                                     unsigned int               keysize)
 : ProtoSortedTree::Iterator(theQueue.item_tree, reverse, keyMin, keysize)
{
}

ProtoSortedQueue::Iterator::~Iterator()
{
}

ProtoSortedQueue::Container::Container()
{
}

ProtoSortedQueue::Container::~Container()
{
    Cleanup();
}

const char* ProtoSortedQueue::Container::GetKey() const
{
    ProtoQueue::Item* item = GetItem();
    ASSERT(NULL != item);
    ProtoSortedQueue* sq = static_cast<ProtoSortedQueue*>(GetQueue());
    return (sq->GetKey(*item));
}  // end ProtoSortedQueue::Container::GetKey()

unsigned int ProtoSortedQueue::Container::GetKeysize() const
{
    ProtoQueue::Item* item = GetItem();
    ASSERT(NULL != item);
    ProtoSortedQueue* sq = static_cast<ProtoSortedQueue*>(GetQueue());
    return (sq->GetKeysize(*item));
}  // end ProtoSortedQueue::Container::GetKeysize()
                                

ProtoTree::Endian ProtoSortedQueue::Container::GetEndian() const
{
    ProtoSortedQueue* sq = static_cast<ProtoSortedQueue*>(GetQueue());
    ASSERT(NULL != sq);
    return (sq->GetEndian());
}  // end ProtoSortedQueue::Container::GetEndian()

bool ProtoSortedQueue::Container::UseComplement2() const
{
    ProtoSortedQueue* sq = static_cast<ProtoSortedQueue*>(GetQueue());
    ASSERT(NULL != sq);
    return (sq->UseComplement2());
}  // end ProtoSortedQueue::Container::UseComplement2()

bool ProtoSortedQueue::Container::UseSignBit() const
{
    ProtoSortedQueue* sq = static_cast<ProtoSortedQueue*>(GetQueue());
    ASSERT(NULL != sq);
    return (sq->UseSignBit());
}  // end ProtoSortedQueue::Container::UseSignBit()