blob: bdfdbbc49fa60a428d0bed624170f7606e4a3229 (
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
|
// $Id$
/**
* @file Object_Set_T.h
*
* Helper template classes for maintaining and managing object
* reference sets.
*
* @author Nanbor Wang <nanbor@cs.wustl.edu>
*/
#ifndef CIAO_OBJECT_SET_T_H
#define CIAO_OBJECT_SET_T_H
#include /**/ "ace/pre.h"
#include "tao/ORB_Constants.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
namespace CIAO
{
/**
* @class Object_Set
*
* @brief A helper template class for maintaining and managing a set
* of object reference.
*
* This class provides a naive implementation of an object reference
* set. It is naive because it simply keeps object references in an
* objref_var array without checking for duplication. More
* importantly, it takes O(n) to to look for an object reference and
* return it. What we really need is a thread-safe hash_set<> like
* class here. Since this is mostly used only during setup/assemble
* time for a CIAO application, i.e., not on critical path, this
* class serves as a place holder for later, more efficient
* implementation.
*/
template <class T, class T_var>
class Object_Set
{
public:
/**
* Default contructor that also allows initializing the initial
* capacity of the set and the increment step.
*/
Object_Set (CORBA::ULong init_capacity = 10,
CORBA::ULong step = 10);
/// Default destructor.
~Object_Set (void);
/// Adding a new object reference to the set. Return -1 if error
/// occurred.
CORBA::Long add (T *objref);
/// Removing an object from the set. Return -1 if error occurred.
CORBA::Long remove (T *objref);
/// Removing all objects from the set. Return -1 if error occurred.
CORBA::Long remove_all (void);
/// Access the underlying T_var array directly. This is added to
/// get around a bug in TAO's sequence of object C++ mapping.
T_var &at (CORBA::ULong index);
/**
* Get a copy of the object reference set into the incoming array
* @c buffer with capacity of @c size. @c buffer is usually
* allocated using a sequence's @c allocbuf method. Notice that
* caller is responsible to release the object references in
* buffer.
*
* @retval actual number of objrefs copied into @c buffer.
*/
CORBA::ULong copy (CORBA::ULong size, T **buffer);
/**
* Check if an object is in the set. Return 0 if false.
*/
int object_in_set (T *objref);
/// Query the current size the set contains.
CORBA::ULong size (void) const;
/// Query the current capacity the set.
CORBA::ULong capacity (void) const;
/**
* Release all object references.
*/
void release (void);
protected:
/// Grow the internal array holding the object references.
void grow (void);
/// Pointer to the dynamically allocated buffer that holds the
/// object references.
T_var *buffer_;
/// Maximun capacity of this->buffer_;
CORBA::ULong capacity_;
/// Current size in the set.
CORBA::ULong size_;
/// How many more slots to add each time we expand the capacity of
/// this set.
CORBA::ULong step_;
};
}
#if defined (__ACE_INLINE__)
#include "Object_Set_T.inl"
#endif /* !defined INLINE */
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "Object_Set_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Object_Set_T.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
#include /**/ "ace/post.h"
#endif /* CIAO_OBJECT_SET_T_H */
|