1 #include "ace/OS_Memory.h"
2 #include "ace/Log_Msg.h"
3 #include "ace/Containers.h"
4 #include "DataElement.h"
9 // Illustrate the various ACE Queues.
13 // Illustrate the ACE unbounded queue
14 // that has copies of the data elements.
15 int runStackUnboundedQueue ();
17 // Illustrate the ACE unbounded queue
18 // with pointers to elements on the heap.
19 int runHeapUnboundedQueue ();
22 int QueueExample::run ()
24 ACE_TRACE ("QueueExample::run");
26 // Illustrate the queue with elements on the stack.
27 if (this->runStackUnboundedQueue () != 0)
32 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n# of live objects %d\n"),
33 DataElement::numOfActiveObjects ()));
35 // Illustrate the queue with elements on the heap.
36 if (this->runHeapUnboundedQueue () != 0)
41 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n# of live objects %d\n"),
42 DataElement::numOfActiveObjects ()));
47 // Listing 1 code/ch05
48 int QueueExample::runStackUnboundedQueue ()
50 ACE_TRACE ("QueueExample::runStackUnboundedQueue");
52 ACE_Unbounded_Queue
<DataElement
> queue
;
53 DataElement elem1
[10];
55 for (i
= 0; i
< 10; i
++)
57 elem1
[i
].setData (9-i
);
58 queue
.enqueue_head (elem1
[i
]);
61 DataElement elem2
[10];
62 for (i
= 0; i
< 10; i
++)
64 elem2
[i
].setData (i
+10);
65 queue
.enqueue_tail (elem2
[i
]);
68 for (ACE_Unbounded_Queue_Iterator
<DataElement
> iter (queue
);
72 DataElement
*elem
= 0;
74 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%d:"), elem
->getData ()));
80 // Listing 2 code/ch05
81 int QueueExample::runHeapUnboundedQueue ()
83 ACE_TRACE ("QueueExample::runHeapUnboundedQueue");
85 ACE_Unbounded_Queue
<DataElement
*> queue
;
86 for (int i
= 0; i
< 20; i
++)
89 ACE_NEW_RETURN(elem
, DataElement (i
), -1);
90 queue
.enqueue_head (elem
);
93 for (ACE_Unbounded_Queue_Iterator
<DataElement
*> iter
98 DataElement
**elem
= 0;
101 ((LM_DEBUG
, ACE_TEXT ("%d:"), (*elem
)->getData ()));
108 int ACE_TMAIN (int, ACE_TCHAR
*[])