27 # include <dds/toc_util.h> 28 # if defined(COREDX_DDS_SEQ_EX) 49 template <
class T,u
int32_t bound>
class bounded_seq;
77 this->
resize(x.core_seq._length);
78 for (
unsigned int i = 0; i < this->core_seq._length; i++)
79 this->core_seq._buffer[i] = x.core_seq._buffer[i];
85 uint32_t
size()
const;
105 void size(uint32_t n);
145 const T&
at (uint32_t n)
const;
149 const T&
front ()
const;
153 const T&
back ()
const;
174 typedef struct CoreSeqType
177 unsigned int _maximum;
178 unsigned int _length;
181 unsigned int _item_size;
184 CoreSeqType_t core_seq;
186 template <
class TY,u
int32_t BOUND>
friend class bounded_sequence;
193 INIT_SEQ(this->core_seq);
194 this->core_seq._item_size =
sizeof(T);
200 INIT_SEQ(this->core_seq);
201 this->core_seq._item_size =
sizeof(T);
214 return this->core_seq._size;
219 return this->core_seq._length;
224 return this->core_seq._length;
230 this->core_seq._maximum = n;
235 return this->core_seq._maximum;
241 return (this->core_seq._length == 0)?
true:
false;
252 T * tmpbuf =
static_cast<T*
>(0);
255 if ( ( this->core_seq._maximum == 0 ) ||
256 ( this->core_seq._maximum >= n ) )
258 T * newbuf =
new T[n];
261 this->core_seq._size = n;
262 if (this->core_seq._length > n)
263 this->core_seq._length = n;
265 if (this->core_seq._buffer)
266 for (uint32_t i = 0;i < this->core_seq._length; i++)
267 newbuf[i] = this->core_seq._buffer[i];
268 tmpbuf = this->core_seq._buffer;
269 this->core_seq._buffer = newbuf;
279 this->core_seq._size = 0;
280 this->core_seq._length = 0;
281 tmpbuf = this->core_seq._buffer;
282 this->core_seq._buffer = 0;
293 if (this->core_seq._size == n)
294 this->core_seq._length = n;
300 if (this->core_seq._size >= n)
301 this->core_seq._length = n;
307 resize(this->core_seq._length);
314 #if defined(COREDX_DDS_SEQ_EX) 315 if ( n >= this->core_seq._size )
316 throw std::out_of_range(
"n");
318 return this->core_seq._buffer[n];
324 #if defined(COREDX_DDS_SEQ_EX) 325 if ( n >= this->core_seq._size )
326 throw std::out_of_range(
"n");
328 return this->core_seq._buffer[n];
332 #if defined(COREDX_DDS_SEQ_EX) 333 if ( n >= this->core_seq._size )
334 throw std::out_of_range(
"n");
339 #if defined(COREDX_DDS_SEQ_EX) 340 if ( n >= this->core_seq._size )
341 throw std::out_of_range(
"n");
346 #if defined(COREDX_DDS_SEQ_EX) 347 if ( this->core_seq._size == 0 )
348 throw std::out_of_range(
"index");
353 #if defined(COREDX_DDS_SEQ_EX) 354 if ( this->core_seq._size == 0 )
355 throw std::out_of_range(
"index");
361 #if defined(COREDX_DDS_SEQ_EX) 362 if ( this->core_seq._length == 0 )
363 throw std::out_of_range(
"index");
365 return (*
this)[this->core_seq._length-1];
368 #if defined(COREDX_DDS_SEQ_EX) 369 if ( this->core_seq._length == 0 )
370 throw std::out_of_range(
"index");
372 return (*
this)[this->core_seq._length-1];
375 return this->core_seq._buffer;
387 this->core_seq._buffer[this->
size()] = v;
388 this->core_seq._length ++;
397 if (this->core_seq._length > 0) this->core_seq._length--;
402 tmp = this->core_seq;
403 this->core_seq = x.core_seq;
408 delete[] this->core_seq._buffer;
409 this->core_seq._buffer = 0;
410 this->core_seq._length = 0;
411 this->core_seq._size = 0;
416 delete[] this->core_seq._buffer;
417 this->core_seq._buffer = buf;
418 this->core_seq._length = n;
419 this->core_seq._size = n;
424 T* retval = this->core_seq._buffer;
425 this->core_seq._buffer = NULL;
426 this->core_seq._length = 0;
427 this->core_seq._size = 0;
432 template <
class T,u
int32_t BOUND>
class bounded_sequence :
public sequence<T> {
437 template<
class T,u
int32_t BOUND>
438 bounded_sequence<T, BOUND>::bounded_sequence() :
sequence<T>() {
439 this->core_seq._maximum = BOUND;
444 # define CPP_DECLARE_UNBOUNDED_SEQ( type, name ) typedef DDS::sequence<type> name 445 # define DECLARE_CPP_UNBOUNDED_SEQ( type, name ) typedef DDS::sequence<type> name 447 # define CPP_DECLARE_BOUNDED_SEQ( type, bound, name ) typedef DDS::bounded_sequence<type,bound> name 448 # define DECLARE_CPP_BOUNDED_SEQ( type, bound, name ) typedef DDS::bounded_sequence<type,bound> name T & front()
Definition: dds_seq.hh:345
T * release()
Release current sequence contents, caller takes ownership of the memory. If successful, the sequence is empty after this operation.
Definition: dds_seq.hh:423
void assign(T *buffer, uint32_t n)
Caller provides an array of elements of size 'n'. The Sequence takes ownership of the memory...
Definition: dds_seq.hh:415
uint32_t maximum() const
set the 'maximum' length of the sequence
Definition: dds_seq.hh:234
uint32_t size() const
Returns the current size (number of elements) of the sequence.
Definition: dds_seq.hh:218
T & back()
Definition: dds_seq.hh:360
uint32_t length() const
alias for size()
Definition: dds_seq.hh:223
Sequence data type.
Definition: dds_seq.hh:61
void clear()
Definition: dds_seq.hh:407
T & operator[](uint32_t n)
Definition: dds_seq.hh:313
~sequence()
destroy the sequence and release resources. Destroys sequence contents.
Definition: dds_seq.hh:206
sequence & operator=(const sequence &x)
assignment operator Copies seqeuence contents.
Definition: dds_seq.hh:76
void pop_back()
Definition: dds_seq.hh:396
Provides the DDS infrastructure.
Definition: dds_builtin_basic.hh:27
void shrink_to_fit()
reduce 'capacity' to match 'size'
Definition: dds_seq.hh:306
bool resize(uint32_t n)
Set the 'capacity' and 'size' of the sequence.
Definition: dds_seq.hh:290
bool reserve(uint32_t n)
Set the capacity of the sequence.
Definition: dds_seq.hh:250
sequence()
construct an empty sequence
Definition: dds_seq.hh:192
T & at(uint32_t n)
Definition: dds_seq.hh:331
bool empty() const
test if the sequence is empty
Definition: dds_seq.hh:240
bool push_back(const T &v)
Definition: dds_seq.hh:379
uint32_t capacity() const
Returns the current capacity (number of elements) of the sequence. The equation "size <= capacity" is...
Definition: dds_seq.hh:213
const T * buffer() const
Definition: dds_seq.hh:374
void swap(sequence &x)
Definition: dds_seq.hh:400