20 #ifndef reda_sequence_gen_h
21 #define reda_sequence_gen_h
24 #include "osapi/osapi_dll.h"
29 #ifndef reda_sequence_h
30 #include "reda/reda_sequence.h"
33 #define concatenate(A, B) A ## B
39 #if defined(T_copy) && !defined(T_initialize)
40 #error "T_copy defined without T_initialize"
43 #if defined(T_compare) && !defined(T_initialize)
44 #error "T_compare defined without T_initialize"
47 #if defined(TSeq_isStringType) && (!defined(T_initialize) || !defined(T_finalize) || !defined(T_copy))
48 #error "TSeq_isStringType defined without T_initialize/T_finalize/T_copy"
51 #if defined(T_initialize) || defined(T_finalize) || defined(T_copy)
53 #define _map(TSeq) concatenate(TSeq, _map)
54 #define TSeq_map _map(TSeq)
56 TSeq_map(
struct TSeq *seq,
RTI_BOOL(*map)(T*),RTI_INT32 begin, RTI_INT32 end)
60 for (i = begin; i <= end; i++)
62 if (!map(&seq->_contiguous_buffer[i]))
71 #ifdef TSeq_isStringType
72 #ifndef TSeq_map_w_length
73 #define _map_w_length(TSeq) concatenate(TSeq, _map_w_length)
74 #define TSeq_map_w_length _map_w_length(TSeq)
76 TSeq_map_w_length(
struct TSeq *seq,
RTI_BOOL(*map)(T*, RTI_UINT32),RTI_INT32 begin, RTI_INT32 end, RTI_UINT32 max_str_len)
80 for (i = begin; i <= end; i++)
82 if (!map(&seq->_contiguous_buffer[i], max_str_len))
95 #ifndef TSeq_initialize
96 #define _initialize(TSeq) concatenate(TSeq, _initialize)
97 #define TSeq_initialize _initialize(TSeq)
99 TSeq_initialize(
struct TSeq *
self)
101 return REDA_Sequence_initialize((
struct REDA_Sequence*)
self,
sizeof(T));
104 #undef TSeq_initialize
107 #ifndef TSeq_finalize
108 #define _finalize(TSeq) concatenate(TSeq, _finalize)
109 #define TSeq_finalize _finalize(TSeq)
111 TSeq_finalize(
struct TSeq *
self)
115 result = TSeq_map(
self,T_finalize,0,self->_maximum-1);
120 return REDA_Sequence_finalize((
struct REDA_Sequence*)
self);
122 return REDA_Sequence_finalize((
struct REDA_Sequence*)
self);
130 #ifndef TSeq_get_maximum
131 #define _get_maximum(TSeq) concatenate(TSeq, _get_maximum)
132 #define TSeq_get_maximum _get_maximum(TSeq)
134 TSeq_get_maximum(
const struct TSeq *
self)
136 return REDA_Sequence_get_maximum((
const struct REDA_Sequence *)
self);
139 #undef TSeq_get_maximum
143 #ifndef TSeq_set_maximum
144 #define _set_maximum(TSeq) concatenate(TSeq, _set_maximum)
145 #define TSeq_set_maximum _set_maximum(TSeq)
146 #ifndef TSeq_isStringType
148 TSeq_set_maximum(
struct TSeq *
self, RTI_INT32 new_max)
151 struct TSeq seq_copy;
155 OSAPI_LOG_PRECONDITION(
self == NULL,
157 (OSAPI_LOG_PRECONDITION_PARAM,
"self=%p",
self))
162 seq_copy.copy(*
self);
165 result = REDA_Sequence_set_maximum((
struct REDA_Sequence*)
self,
172 result = TSeq_map(
self,T_initialize,0,self->_maximum-1);
178 if (self->_length > 0)
182 for (i = 0; i < (new_max < seq_copy._length ? new_max : seq_copy._length); ++i)
184 if (!T_copy(&self->_contiguous_buffer[i],
185 (
const T*) &seq_copy._contiguous_buffer[i]))
192 if (seq_copy._contiguous_buffer != NULL)
194 result = TSeq_map(&seq_copy,T_finalize,0,seq_copy._maximum-1);
201 return REDA_Sequence_set_maximum((
struct REDA_Sequence*)
self, new_max,RTI_TRUE);
206 TSeq_set_maximum(
struct TSeq *
self, RTI_INT32 new_max, RTI_UINT32 max_str_len)
208 struct TSeq seq_copy;
210 RTI_INT32 i, old_max;
212 OSAPI_LOG_PRECONDITION(
self == NULL,
214 (OSAPI_LOG_PRECONDITION_PARAM,
"self=%p",
self))
218 old_max = REDA_Sequence_get_maximum((const struct REDA_Sequence *)self);
221 if (old_max == new_max) {
227 result = REDA_Sequence_set_maximum((
struct REDA_Sequence*)
self,
235 for (i = 0; i < ((old_max < new_max) ? old_max : new_max); i++)
237 self->_contiguous_buffer[i] = seq_copy._contiguous_buffer[i];
241 result = TSeq_map_w_length(
self,T_initialize,old_max,new_max-1,max_str_len);
249 if (seq_copy._contiguous_buffer != NULL)
251 result = TSeq_map(&seq_copy,T_finalize,new_max,old_max-1);
260 #undef TSeq_set_maximum
263 #ifndef TSeq_get_length
264 #define _get_length(TSeq) concatenate(TSeq, _get_length)
265 #define TSeq_get_length _get_length(TSeq)
267 TSeq_get_length(
const struct TSeq *
self)
269 return REDA_Sequence_get_length((
const struct REDA_Sequence *)
self);
272 #undef TSeq_get_length
276 #ifndef TSeq_set_length
277 #define _set_length(TSeq) concatenate(TSeq, _set_length)
278 #define TSeq_set_length _set_length(TSeq)
280 TSeq_set_length(
struct TSeq *
self, RTI_INT32 new_length)
282 return REDA_Sequence_set_length((
struct REDA_Sequence *)
self, new_length);
285 #undef TSeq_set_length
289 #ifndef TSeq_get_reference
290 #define _get_reference(TSeq) concatenate(TSeq, _get_reference)
291 #define TSeq_get_reference _get_reference(TSeq)
293 TSeq_get_reference(
const struct TSeq *
self, RTI_INT32 i)
295 return (T*)REDA_Sequence_get_reference((
const struct REDA_Sequence*)
self,i);
297 #undef _get_reference
298 #undef TSeq_get_reference
304 #define _copy(TSeq) concatenate(TSeq, _copy)
305 #define TSeq_copy _copy(TSeq)
306 #ifndef TSeq_isStringType
308 TSeq_copy(
struct TSeq *
self,
const struct TSeq *src)
313 struct TSeq seq_copy;
315 OSAPI_LOG_PRECONDITION(
self == NULL,
317 (OSAPI_LOG_PRECONDITION_PARAM,
"self=%p",
self));
326 seq_copy._contiguous_buffer =
self->_contiguous_buffer;
327 seq_copy._maximum =
self->_maximum;
328 seq_copy._length =
self->_length;
329 seq_copy._element_size =
self->_element_size;
330 seq_copy._flags =
self->_flags;
331 seq_copy._token1 =
self->_token1;
332 seq_copy._token2 =
self->_token2;
335 if (REDA_Sequence_copy((
struct REDA_Sequence *)
self,
336 (
const struct REDA_Sequence *)src,
343 if (self->_contiguous_buffer != seq_copy._contiguous_buffer)
345 result = TSeq_map(
self,T_initialize,0,self->_maximum-1);
353 for (i = 0; i < src->_length; i++)
355 if (!T_copy(&self->_contiguous_buffer[i],
356 (
const T*) &src->_contiguous_buffer[i]))
364 if ((seq_copy._contiguous_buffer != NULL) &&
365 (seq_copy._contiguous_buffer != self->_contiguous_buffer))
367 result = TSeq_map(&seq_copy,T_finalize,0,seq_copy._maximum-1);
379 return (
struct TSeq*)REDA_Sequence_copy((
struct REDA_Sequence *)
self,
380 (
const struct REDA_Sequence *)src,
386 TSeq_copy(
struct TSeq *
self,
const struct TSeq *src, RTI_UINT32 max_str_len)
390 struct TSeq seq_copy;
399 seq_copy._contiguous_buffer =
self->_contiguous_buffer;
400 seq_copy._maximum =
self->_maximum;
401 seq_copy._length =
self->_length;
402 seq_copy._element_size =
self->_element_size;
403 seq_copy._flags =
self->_flags;
404 seq_copy._token1 =
self->_token1;
405 seq_copy._token2 =
self->_token2;
407 OSAPI_LOG_PRECONDITION(
self == NULL,
409 (OSAPI_LOG_PRECONDITION_PARAM,
"self=%p",
self))
412 if (REDA_Sequence_copy((struct REDA_Sequence *)self,
413 (const struct REDA_Sequence *)src,
422 if (self->_contiguous_buffer != seq_copy._contiguous_buffer)
424 for (i = 0; i < seq_copy._maximum; i++)
426 self->_contiguous_buffer[i] = seq_copy._contiguous_buffer[i];
429 result = TSeq_map_w_length(
self,T_initialize,seq_copy._maximum,self->_maximum-1,max_str_len);
437 for (i = 0; i < src->_length; i++)
439 if (!T_copy(&self->_contiguous_buffer[i],
440 (
const T*) &src->_contiguous_buffer[i],
450 if ((seq_copy._contiguous_buffer != NULL) &&
451 (seq_copy._contiguous_buffer != self->_contiguous_buffer))
464 #ifndef TSeq_is_equal
465 #define _is_equal(TSeq) concatenate(TSeq, _is_equal)
466 #define TSeq_is_equal _is_equal(TSeq)
468 TSeq_is_equal(
const struct TSeq *left,
const struct TSeq *right)
474 result = REDA_Sequence_is_equal((
const struct REDA_Sequence*)left,
475 (
const struct REDA_Sequence*)right,RTI_FALSE);
481 for (i = 0; i < left->_length; i++)
483 if (T_compare((
const T*)&left->_contiguous_buffer[i],
484 (
const T*)&right->_contiguous_buffer[i]))
492 return REDA_Sequence_is_equal((
const struct REDA_Sequence *)left,
493 (
const struct REDA_Sequence *)right,RTI_TRUE);
500 #ifndef TSeq_loan_contiguous
501 #define _loan_contiguous(TSeq) concatenate(TSeq, _loan_contiguous)
502 #define TSeq_loan_contiguous _loan_contiguous(TSeq)
504 TSeq_loan_contiguous(
struct TSeq *
self,
void *buffer,
505 RTI_INT32 new_length, RTI_INT32 new_max)
507 return REDA_Sequence_loan_contiguous(
508 (
struct REDA_Sequence *)
self, buffer, new_length, new_max);
510 #undef _loan_contiguous
511 #undef TSeq_loan_contiguous
514 #ifndef TSeq_loan_discontiguous
515 #define _loan_discontiguous(TSeq) concatenate(TSeq, _loan_discontiguous)
516 #define TSeq_loan_discontiguous _loan_discontiguous(TSeq)
518 TSeq_loan_discontiguous(
struct TSeq *
self,
void *buffer,
519 RTI_INT32 new_length, RTI_INT32 new_max)
521 return REDA_Sequence_loan_discontiguous(
522 (
struct REDA_Sequence *)
self, buffer, new_length, new_max);
524 #undef _loan_discontiguous
525 #undef TSeq_loan_discontiguous
529 #ifndef TSeq_has_ownership
530 #define _has_ownership(TSeq) concatenate(TSeq, _has_ownership)
531 #define TSeq_has_ownership _has_ownership(TSeq)
533 TSeq_has_ownership(
const struct TSeq *
self)
535 return REDA_Sequence_has_ownership((
const struct REDA_Sequence *)
self);
538 #undef _has_ownership
539 #undef TSeq_has_ownership
543 #ifndef TSeq_has_discontiguous_buffer
544 #define _has_discontiguous_buffer(TSeq) concatenate(TSeq, _has_discontiguous_buffer)
545 #define TSeq_has_discontiguous_buffer _has_discontiguous_buffer(TSeq)
547 TSeq_has_discontiguous_buffer(
const struct TSeq *
self)
549 return REDA_Sequence_has_discontiguous_buffer(
550 (
const struct REDA_Sequence *)
self);
553 #undef _has_discontiguous_buffer
554 #undef TSeq_has_discontiguous_buffer
558 #ifndef TSeq_get_buffer
559 #define _get_buffer(TSeq) concatenate(TSeq, _get_buffer)
560 #define TSeq_get_buffer _get_buffer(TSeq)
562 TSeq_get_buffer(
const struct TSeq *
self)
564 return (T*)REDA_Sequence_get_buffer((
const struct REDA_Sequence *)
self);
568 #undef TSeq_get_buffer
572 #ifndef TSeq_set_buffer
573 #define _set_buffer(TSeq) concatenate(TSeq, _set_buffer)
574 #define TSeq_set_buffer _set_buffer(TSeq)
576 TSeq_set_buffer(
struct TSeq *
self, T *buffer)
578 return REDA_Sequence_set_buffer((
struct REDA_Sequence *)
self,
583 #undef TSeq_set_buffer
588 #define _unloan(TSeq) concatenate(TSeq, _unloan)
589 #define TSeq_unloan _unloan(TSeq)
591 TSeq_unloan(
struct TSeq *
self)
593 return REDA_Sequence_unloan((
struct REDA_Sequence *)
self);
599 #ifndef TSeq_set_token
600 #define _set_token(TSeq) concatenate(TSeq, _set_token)
601 #define TSeq_set_token _set_token(TSeq)
603 TSeq_set_token(
struct TSeq *
self,
void *token1,
void *token2)
605 REDA_Sequence_set_token((
struct REDA_Sequence *)
self,token1,token2);
608 #undef TSeq_set_token
611 #ifndef TSeq_get_token
612 #define _get_token(TSeq) concatenate(TSeq, _get_token)
613 #define TSeq_get_token _get_token(TSeq)
615 TSeq_get_token(
struct TSeq *
self,
void **token1,
void **token2)
617 REDA_Sequence_get_token((
struct REDA_Sequence *)
self,token1,token2);
620 #undef TSeq_get_token
627 #undef TSeq_map_w_length