summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/ESF/ESF_Proxy_RB_Tree.h
blob: 089f7caaf714c6c143895caa47ff4d1e9499b212 (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
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
// -*- C++ -*-

/**
 *  @file   ESF_Proxy_RB_Tree.h
 *
 *  @author Carlos O'Ryan (coryan@cs.wustl.edu)
 *
 *  http://doc.ece.uci.edu/~coryan/EC/index.html
 */

#ifndef TAO_ESF_PROXY_RB_TREE_H
#define TAO_ESF_PROXY_RB_TREE_H

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include /**/ "tao/Versioned_Namespace.h"

#include "ace/RB_Tree.h"
#include "ace/Null_Mutex.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

/// Iterator class for a ACE_ESF_RB_Tree
template<class PROXY>
class TAO_ESF_Proxy_RB_Tree_Iterator
{
public:
  typedef ACE_RB_Tree_Iterator<PROXY *,
                               int,
                               ACE_Less_Than<PROXY*>,
                               ACE_Null_Mutex>
    Implementation;

  TAO_ESF_Proxy_RB_Tree_Iterator (const Implementation &i);

  bool operator == (const TAO_ESF_Proxy_RB_Tree_Iterator<PROXY> &rhs) const;
  bool operator != (const TAO_ESF_Proxy_RB_Tree_Iterator<PROXY> &rhs) const;
  TAO_ESF_Proxy_RB_Tree_Iterator<PROXY>& operator++ ();
  TAO_ESF_Proxy_RB_Tree_Iterator<PROXY> operator++ (int);
  PROXY *operator *();

private:
  Implementation impl_;
};

// ****************************************************************

/// Concrete Proxy collection based on ACE_RB_Tree
/**
 * The Event Service Framework provides several alternatives for the
 * underlying proxy collections.
 * This version is based on Red-Black trees that offer good insertion,
 * removal and lookup performance, but the iteration is slightly
 * degraded.
 */
template<class PROXY>
class TAO_ESF_Proxy_RB_Tree
{
public:
  /// A typedef for the underlying implementaiton class
  typedef ACE_RB_Tree<PROXY*,int,ACE_Less_Than<PROXY*>,ACE_Null_Mutex> Implementation;

  /// A typedef for the underlying iterator
  typedef TAO_ESF_Proxy_RB_Tree_Iterator<PROXY> Iterator;

  /// Constructor
  TAO_ESF_Proxy_RB_Tree ();

  /// Return the first element in the collection, or end() if there
  /// are none
  TAO_ESF_Proxy_RB_Tree_Iterator<PROXY> begin ();

  /// Return one past the last element in the collection
  TAO_ESF_Proxy_RB_Tree_Iterator<PROXY> end ();

  /// Return the number of elements in the collection
  size_t size () const;

  /// Insert a new element to the collection
  void connected (PROXY *);

  /// Insert a new element that could be there already.
  void reconnected (PROXY *);
  /// Remove an element from the collection
  void disconnected (PROXY *);

  /// Shutdown the collection, i.e. remove all elements and release
  /// resources
  void shutdown ();

private:
  /// The underlying implementation object
  Implementation impl_;
};

TAO_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
#include "orbsvcs/ESF/ESF_Proxy_RB_Tree.inl"
#endif /* __ACE_INLINE__ */

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "orbsvcs/ESF/ESF_Proxy_RB_Tree.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("ESF_Proxy_RB_Tree.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#endif /* TAO_ESF_PROXY_RB_TREE_H */