summaryrefslogtreecommitdiff
path: root/TAO/tao/sequence.i
blob: f4b2b6d5968b661eabf062e57e946726866acda0 (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
/* -*- C++ -*- */

// ============================================================================
//
// = LIBRARY
//    TAO
// 
// = FILENAME
//    sequence.i
//
// = AUTHOR
//    Copyright 1994-1995 by Sun Microsystems Inc.
//
//    Aniruddha Gokhale
// 
// ============================================================================

// operations on the unbounded sequence class

template <class T> ACE_INLINE
TAO_UnboundedSeq<T>::TAO_UnboundedSeq (void)
  : maximum_ (0),
    length_ (0),
    release_ (0),
    buffer_ (0)
{
}

template <class T> ACE_INLINE
TAO_UnboundedSeq<T>::TAO_UnboundedSeq (CORBA::ULong max)
  : maximum_ (max),
    length_ (0),
    release_ (1) // we own it
{
  buffer_ = TAO_UnboundedSeq<T>::allocbuf (max);
}

template <class T> ACE_INLINE
TAO_UnboundedSeq<T>::TAO_UnboundedSeq (CORBA::ULong max, CORBA::ULong length, T
                                    *data, CORBA::Boolean release)
  : maxium_ (max),
    length_ (length),
    buffer_ (data),
    release_ (release)
{
}

template <class T> ACE_INLINE
TAO_UnboundedSeq<T>::TAO_UnboundedSeq (const TAO_UnboundedSeq<T> &seq)
  : maximum_ (seq.maximum ()),
    length_ (seq.length ()),
    release_ (1) // we own this
{
  this->buffer_ = TAO_UnboundedSeq<T>::allocbuf (this->maximum_);
  for (CORBA::ULong i=0; i < this->length_; i++)
    this->buffer_[i] = seq[i];
}

template <class T> ACE_INLINE
TAO_UnboundedSeq<T>::~TAO_UnboundedSeq (void)
{
  if (this->release_)
    TAO_UnboundedSeq<T>::freebuf (this->buffer_);

}

template <class T> ACE_INLINE TAO_UnboundedSeq<T> &
TAO_UnboundedSeq<T>::operator= (const TAO_UnboundedSeq<T> &seq)
{
  this->maximum_ = seq.maximum_;
  this->length_ = seq.length_;
  this->release_ = 1;
  this->buffer_ = TAO_UnboundedSeq<T>::allocbuf (this->maximum_);
  for (CORBA::ULong i=0; i < this->length_; i++)
    this->buffer_[i] = seq[i];
}

template <class T> ACE_INLINE CORBA::ULong
TAO_UnboundedSeq<T>::maximum (void) const
{
  return this->maximum_;
}

template <class T> ACE_INLINE void
TAO_UnboundedSeq<T>::length (CORBA::ULong length)
{
  this->length_ = length;
}

template <class T> ACE_INLINE CORBA::ULong
TAO_UnboundedSeq<T>::length (void) const
{
  return this->length_;
}

template <class T> ACE_INLINE T &
TAO_UnboundedSeq<T>::operator[] (CORBA::ULong i)
{
  ACE_ASSERT (i < this->length_);
  return this->buffer_[i];
}

template <class T> ACE_INLINE const T &
TAO_UnboundedSeq<T>::operator[] (CORBA::ULong i) const
{
  ACE_ASSERT (i < this->length_);
  return this->buffer_[i];
}

template <class T> ACE_INLINE T *
TAO_UnboundedSeq<T>::allocbuf (CORBA::ULong size)
{
  return new T[size];
}

template <class T> ACE_INLINE void
TAO_UnboundedSeq<T>::freebuf (T *buffer)
{
  delete [] buffer;
}


// operations on the Bounded sequence class

template <class T, CORBA::ULong size> ACE_INLINE
TAO_BoundedSeq<T,size>::TAO_BoundedSeq (void)
  : length_ (0),
    release_ (0),
    buffer_ (0)
{
}

template <class T, CORBA::ULong size> ACE_INLINE
TAO_BoundedSeq<T,size>::TAO_BoundedSeq (CORBA::ULong length, T *data, CORBA::Boolean
                                   release) 
  : length_ (length),
    buffer_ (data),
    release_ (release)
{
}

template <class T, CORBA::ULong size> ACE_INLINE
TAO_BoundedSeq<T,size>::TAO_BoundedSeq (const TAO_BoundedSeq<T,size> &seq)
  : length_ (seq.length ()),
    release_ (1) // we own this
{
  this->buffer_ = TAO_BoundedSeq<T,size>::allocbuf (this->length_);
  for (CORBA::ULong i=0; i < this->length_; i++)
    this->buffer_[i] = seq[i];
}

template <class T, CORBA::ULong size> ACE_INLINE
TAO_BoundedSeq<T,size>::~TAO_BoundedSeq (void)
{
  if (this->release_)
    TAO_BoundedSeq<T,size>::freebuf (this->buffer_);

}

template <class T, CORBA::ULong size> ACE_INLINE TAO_BoundedSeq<T,size> &
TAO_BoundedSeq<T,size>::operator= (const TAO_BoundedSeq<T,size> &seq)
{
  this->length_ = seq.length_;
  this->release_ = 1;
  this->buffer_ = TAO_BoundedSeq<T,size>::allocbuf (this->length_);
  for (CORBA::ULong i=0; i < this->length_; i++)
    this->buffer_[i] = seq[i];
}

template <class T, CORBA::ULong size> ACE_INLINE CORBA::ULong
TAO_BoundedSeq<T,size>::maximum (void) const
{
  return this->length_;
}

template <class T, CORBA::ULong size> ACE_INLINE void
TAO_BoundedSeq<T,size>::length (CORBA::ULong length)
{
  this->length_ = length;
}

template <class T, CORBA::ULong size> ACE_INLINE CORBA::ULong
TAO_BoundedSeq<T,size>::length (void) const
{
  return this->length_;
}

template <class T, CORBA::ULong size> ACE_INLINE T &
TAO_BoundedSeq<T,size>::operator[] (CORBA::ULong i)
{
  ACE_ASSERT (i < this->length_);
  return this->buffer_[i];
}

template <class T, CORBA::ULong size> ACE_INLINE const T &
TAO_BoundedSeq<T,size>::operator[] (CORBA::ULong i) const
{
  ACE_ASSERT (i < this->length_);
  return this->buffer_[i];
}

template <class T, CORBA::ULong size> ACE_INLINE T *
TAO_BoundedSeq<T,size>::allocbuf (CORBA::ULong size)
{
  return new T[size];
}

template <class T, CORBA::ULong size> ACE_INLINE void
TAO_BoundedSeq<T,size>::freebuf (T *buffer)
{
  delete [] buffer;
}