blob: 220c5f752fc67ab5ab96bc229dbe3a33957a1ac2 (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// -*- C++ -*-
//=============================================================================
/**
* @file Widget_Impl.h
*
* @author Christopher Kohlhoff <chris@kohlhoff.com>
*/
//=============================================================================
#ifndef WIDGET_IMPL_H
#define WIDGET_IMPL_H
#include "Widget.h"
#include "Widget_Part.h"
#include "ace/Unbounded_Queue.h"
#include "ace/Refcounted_Auto_Ptr.h"
#include "ace/Synch_Traits.h"
#include "ace/Thread_Mutex.h"
/**
* @class Widget_Impl
*
* @brief An implementation of the Widget interface.
*/
class Widget_Impl : public Widget
{
public:
/// Constructor.
Widget_Impl ();
/// Destructor.
virtual ~Widget_Impl ();
/// Add a new part to the widget. The widget takes ownership of the part
/// object.
virtual void add_part (Widget_Part *part);
/// Remove a random part from the widget. Ownership of the part is returned
/// to the caller.
virtual Widget_Part *remove_part ();
/// Ask the widget to print information about the parts that it contains.
virtual void list_parts ();
private:
/// The parts which make up this widget. The set actually contains instances
/// of ACE_Refcounted_Auto_Ptr to automatically manage the lifetimes of the
/// constituent parts.
///
/// Some things to note about the choice of ACE_Refcounted_Auto_Ptr:
/// - We cannot use auto_ptr to manage the objects, since auto_ptr does not
/// support the copying and assignment semantics necessary for storage in
/// a container.
/// - The ACE_Strong_Bound_Ptr reference counted pointer could be used to
/// store objects in a container, however (for reasons of safety) it
/// provides no way to release ownership of the object from the smart
/// pointer. We need to be able to release ownership to implement the
/// remove_part method.
/// - ACE_Refcounted_Ptr can both be stored in containers and allows us to
/// release ownership of the pointer that it contains.
ACE_Unbounded_Queue<ACE_Refcounted_Auto_Ptr<Widget_Part, ACE_SYNCH_MUTEX> > parts_;
};
#endif /* WIDGET_IMPL_H */
|