summaryrefslogtreecommitdiff
path: root/examples/Smart_Pointers/Widget_Impl.cpp
blob: 2d3ab404804a7f9ddaf77dae36b2b81406e87b59 (plain)
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
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file    Widget_Impl.cpp
 *
 *  $Id$
 *
 *  @author Christopher Kohlhoff <chris@kohlhoff.com>
 */
//=============================================================================

#include "Widget_Impl.h"
#include "ace/Log_Msg.h"

Widget_Impl::Widget_Impl (void)
{
  ACE_DEBUG ((LM_DEBUG, "Widget_Impl constructor\n"));
}

Widget_Impl::~Widget_Impl (void)
{
  ACE_DEBUG ((LM_DEBUG, "Widget_Impl destructor\n"));
}

void Widget_Impl::add_part (Widget_Part *part)
{
  // Take ownership of the part object using a ACE_Refcounted_Auto_Ptr.
  ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> new_part (part);

  parts_.enqueue_tail (new_part);
}

Widget_Part *Widget_Impl::remove_part (void)
{
  ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> removed_part;
  if (parts_.dequeue_head (removed_part) == -1)
    return 0;

  // Ownership of the part object is released and transferred to the caller.
  return removed_part.release();
}

void Widget_Impl::list_parts (void)
{
  ACE_Unbounded_Queue_Iterator<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> > iter (parts_);
  ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> *current_part;
  while (iter.next (current_part))
    {
      (*current_part)->print_info ();
      iter.advance ();
    }
}