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
|
// $Id$
#ifndef CIAO_OBJECT_SET_T_C
#define CIAO_OBJECT_SET_T_C
#include "Object_Set_T.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#if !defined (__ACE_INLINE__)
#include "Object_Set_T.inl"
#endif /* __ACE_INLINE__ */
ACE_RCSID(ciao, Object_Set_T, "$Id$")
template <class T, class T_var>
CIAO::Object_Set<T, T_var>::Object_Set (CORBA::ULong init_capacity,
CORBA::ULong step)
: capacity_ (init_capacity),
size_ (0),
step_ (step)
{
this->buffer_ = new T_var [this->capacity_];
}
template <class T, class T_var>
CIAO::Object_Set<T, T_var>::~Object_Set ()
{
delete[] this->buffer_;
}
template <class T, class T_var> void
CIAO::Object_Set<T, T_var>::release ()
{
CORBA::ULong i = 0;
for (; i < this->size_; ++i)
{
this->buffer_[i] = T::_nil ();
}
}
template <class T, class T_var> CORBA::Long
CIAO::Object_Set<T, T_var>::add (T *objref)
{
if (this->size_ == this->capacity_)
this->grow ();
this->buffer_[this->size_] = T::_duplicate (objref);
return this->size_++;
}
template<class T, class T_var> CORBA::Long
CIAO::Object_Set<T, T_var>::remove (T *objref)
{
if (CORBA::is_nil (objref))
return -1;
CORBA::ULong i = 0;
for (; i < this->size_; ++i)
if (objref->_is_equivalent (this->buffer_[i].in ())) // _is_equivalent could be unreliable?
{
--this->size_;
if (i != this->size_)
this->buffer_[i] = this->buffer_[this->size_];
this->buffer_[this->size_] = T::_nil ();
return 0;
}
return -1; // not found.
}
template <class T, class T_var> void
CIAO::Object_Set<T, T_var>::grow (void)
{
this->capacity_ += this->step_;
T_var *newbuf = new T_var [this->capacity_];
CORBA::ULong i = 0;
for (; i < this->size_; ++i)
newbuf[i] = this->buffer_[i]; // this will hijack the object ownership
delete[] this->buffer_;
this->buffer_ = newbuf;
}
template <class T, class T_var> CORBA::ULong
CIAO::Object_Set<T, T_var>::copy (CORBA::ULong len,
T **buf)
{
if (buf == 0)
return 0;
if (len > this->size_)
len = this->size_;
CORBA::ULong i = 0;
for (; i < len; ++i)
buf[i] = T::_duplicate (this->buffer_[i].in ());
return len;
}
template <class T, class T_var> int
CIAO::Object_Set<T, T_var>::object_in_set (T *objref)
{
if (CORBA::is_nil (objref)) // Don't count nil objref
return 0;
CORBA::ULong i = 0;
for (; i < this->size_; ++i)
if (objref->_is_equivalent (this->buffer_[i].in ())) // _is_equivalent could be unreliable?
return -1;
return 0;
}
#endif /* CIAO_OBJECT_SET_T_C */
|