summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Naming/Naming_Service_Container.h
blob: 2538197dee286b946cf8fc37803219bee072813a (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
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
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Naming_Service_Container.h
 *
 *  @author Bruce Trask <trask_b@ociweb.com>
 */
//=============================================================================

#ifndef NS_CONTAINER_H
#define NS_CONTAINER_H
#include /**/ "ace/pre.h"

#include "ace/ACE.h"

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

#include "tao/orbconf.h"

// Need by ACE_DLList_Node.
#include "ace/Containers.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL
class ACE_Allocator;
ACE_END_VERSIONED_NAMESPACE_DECL

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

template <class T> class ACE_Unbounded_List;
template <class T> class ACE_Unbounded_List_Iterator;

/**
 * @class ACE_NS_Node
 *
 * @brief Implementation element in a Queue, List, and Stack.
 */
template<class T>
class ACE_NS_Node
{
public:
  friend class ACE_Unbounded_List<T>;
  friend class ACE_Unbounded_List_Iterator<T>;

  ~ACE_NS_Node ();

private:
  ACE_NS_Node (const T &i, ACE_NS_Node<T> *n);
  ACE_NS_Node (ACE_NS_Node<T> *n = 0, int = 0);
  ACE_NS_Node (const ACE_NS_Node<T> &n);

  /// Pointer to next element in the list of <ACE_NS_Node>s.
  ACE_NS_Node<T> *next_;

  /// Current value of the item in this node.
  T item_;
};

/**
 * @class ACE_Unbounded_List_Iterator
 *
 * @brief Implement an iterator over an unbounded List.
 */
template <class T>
class ACE_Unbounded_List_Iterator
{
public:
  ACE_Unbounded_List_Iterator (ACE_Unbounded_List<T> &s, int end = 0);
  // = Iteration methods.

  /// Pass back the <next_item> that hasn't been seen in the List.
  /// Returns 0 when all items have been seen, else 1.
  int next (T *&next_item);

  /// Move forward by one element in the List.  Returns 0 when all the
  /// items in the List have been seen, else 1.
  int advance ();

  /// Move to the first element in the List.  Returns 0 if the
  /// List is empty, else 1.
  int first ();

  /// Returns 1 when all items have been seen, else 0.
  int done () const;

  /// Dump the state of an object.
  void dump () const;

  // = STL styled iteration, compare, and reference functions.

  /// Postfix advance.
  ACE_Unbounded_List_Iterator<T> operator++ (int);

  /// Prefix advance.
  ACE_Unbounded_List_Iterator<T>& operator++ ();

  /// Returns a reference to the interal element <this> is pointing to.
  T& operator* ();

  /// Check if two iterators point to the same position
  bool operator== (const ACE_Unbounded_List_Iterator<T> &) const;
  bool operator!= (const ACE_Unbounded_List_Iterator<T> &) const;

  /// Declare the dynamic allocation hooks.
  ACE_ALLOC_HOOK_DECLARE;

private:
  /// Pointer to the current node in the iteration.
  ACE_NS_Node<T> *current_;

  /// Pointer to the set we're iterating over.
  ACE_Unbounded_List<T> *set_;
};

/**
 * @class ACE_Unbounded_List
 *
 * @brief Implement a simple unordered set of <T> of unbounded size.
 *
 * This implementation of an unordered set uses a circular
 * linked list with a dummy node.  This implementation does not
 * allow duplicates, but it maintains FIFO ordering of insertions.
 */
template <class T>
class ACE_Unbounded_List
{
public:
  friend class ACE_Unbounded_List_Iterator<T>;

  // Trait definition.
  typedef ACE_Unbounded_List_Iterator<T> ITERATOR;
  typedef ACE_Unbounded_List_Iterator<T> iterator;

  /// Constructor.  Use user specified allocation strategy
  /// if specified.
  ACE_Unbounded_List (ACE_Allocator *alloc = 0);

  /// Copy constructor.
  ACE_Unbounded_List (const ACE_Unbounded_List<T> &);

  /// Assignment operator.
  void operator= (const ACE_Unbounded_List<T> &);

  /// Destructor.
  ~ACE_Unbounded_List ();

  // = Check boundary conditions.

  /// Returns 1 if the container is empty, otherwise returns 0.
  int is_empty () const;

  /// Returns 1 if the container is full, otherwise returns 0.
  int is_full () const;

  // = Classic unordered set operations.

  /**
   * Insert <new_item> into the set (doesn't allow duplicates).
   * Returns -1 if failures occur, 1 if item is already present, else
   * 0.
   */
  int insert (const T &new_item);

  /**
   * Remove first occurrence of <item> from the set.  Returns 0 if
   * it removes the item, -1 if it can't find the item, and -1 if a
   * failure occurs.
   */
  int remove (const T &item);

  /// Size of the set.
  size_t size () const;

  /// Dump the state of an object.
  void dump () const;

  /// Reset the <ACE_Unbounded_List> to be empty.
  void reset ();

  // = STL-styled unidirectional iterator factory.
  ACE_Unbounded_List_Iterator<T> begin ();
  ACE_Unbounded_List_Iterator<T> end ();

  /// Declare the dynamic allocation hooks.
  ACE_ALLOC_HOOK_DECLARE;

private:
  /// Insert <item> at the tail of the set (doesn't check for
  /// duplicates).
  int insert_tail (const T &item);

  /// Delete all the nodes in the List.
  void delete_nodes ();

  /// Copy nodes into this set.
  void copy_nodes (const ACE_Unbounded_List<T> &);

  /// Head of the linked list of NS_Nodes.
  ACE_NS_Node<T> *head_;

  /// Current size of the set.
  size_t cur_size_;

  /// Allocation strategy of the set.
  ACE_Allocator *allocator_;
};

TAO_END_VERSIONED_NAMESPACE_DECL

#include "orbsvcs/Naming/Naming_Service_Container.cpp"

#include /**/ "ace/post.h"
#endif /* NS_CONTAINERS_T_H */