29 #include "reda/reda_sequence.h"
31 #define concatenate(A, B) A ## B
37 #ifdef REDA_SEQUENCE_USER_API
38 #ifndef REDA_SEQUENCE_API
39 #define REDA_SEQUENCE_API REDA_SEQUENCE_API_USER_DEFAULT
41 #if REDA_SEQUENCE_API < REDA_SEQUENCE_API_BASIC
42 #error "REDA_SEQUENCE_USER_API defined along with API level < REDA_SEQUENCE_API_BASIC"
47 #ifndef REDA_SEQUENCE_API
48 #define REDA_SEQUENCE_API REDA_SEQUENCE_API_DEFAULT
51 #if REDA_SEQUENCE_API < REDA_SEQUENCE_API_UNTYPED
52 #error "REDA_SEQUENCE_API_UNTYPED <= REDA_SEQUENCE_API <= REDA_SEQUENCE_API_FULL"
56 #if REDA_SEQUENCE_API > REDA_SEQUENCE_API_UNTYPED
57 #ifndef TSeq_initialize
58 #define TSeq_initialize
60 #ifndef TSeq_get_maximum
61 #define TSeq_get_maximum
63 #ifndef TSeq_set_maximum
64 #define TSeq_set_maximum
66 #ifndef TSeq_get_length
67 #define TSeq_get_length
69 #ifndef TSeq_set_length
70 #define TSeq_set_length
72 #ifndef TSeq_get_reference
73 #define TSeq_get_reference
80 #ifdef REDA_SEQUENCE_USER_API
88 #if REDA_SEQUENCE_API > REDA_SEQUENCE_API_BASIC
95 #ifndef TSeq_loan_contiguous
96 #define TSeq_loan_contiguous
98 #ifndef TSeq_loan_discontiguous
99 #define TSeq_loan_discontiguous
101 #ifndef TSeq_has_ownership
102 #define TSeq_has_ownership
104 #ifndef TSeq_has_discontiguous_buffer
105 #define TSeq_has_discontiguous_buffer
107 #ifndef TSeq_get_contiguous_buffer
108 #define TSeq_get_contiguous_buffer
110 #ifndef TSeq_get_discontiguous_buffer
111 #define TSeq_get_discontiguous_buffer
113 #ifndef TSeq_set_contiguous_buffer
114 #define TSeq_set_contiguous_buffer
119 #ifndef TSeq_set_token
120 #define TSeq_set_token
122 #ifndef TSeq_get_token
123 #define TSeq_get_token
125 #ifndef TSeq_ensure_length
126 #define TSeq_ensure_length
128 #ifndef TSeq_from_array
129 #define TSeq_from_array
131 #ifndef TSeq_to_array
132 #define TSeq_to_array
136 #if REDA_SEQUENCE_API > REDA_SEQUENCE_API_FULL
137 #error "REDA_SEQUENCE_API_UNTYPED <= REDA_SEQUENCE_API <= REDA_SEQUENCE_API_FULL"
140 #if defined(T_copy) && !defined(T_initialize)
141 #error "T_copy defined without T_initialize"
144 #if defined(T_compare) && !defined(T_initialize)
145 #error "T_compare defined without T_initialize"
149 #if defined(TSeq_isCDRStringType) && (!defined(T_initialize) || !defined(T_finalize) || !defined(T_copy))
150 #error "TSeq_isCDRStringType defined without T_initialize/T_finalize/T_copy"
153 #if defined(TSeq_isCDRStringType) && (!defined(T_initialize) || !defined(T_copy))
154 #error "TSeq_isCDRStringType defined without T_initialize/T_copy"
158 #if defined(T_initialize) || defined(T_finalize) || defined(T_copy)
160 #if !(defined(TSeq_isCDRStringType) && defined(RTI_CERT))
162 #define _map(TSeq) concatenate(TSeq, _map)
163 #define TSeq_map _map(TSeq)
165 TSeq_map(T *buffer,
RTI_BOOL(*map)(T*),RTI_INT32 begin, RTI_INT32 end)
169 for (i = begin; i <= end; i++)
171 if (!map(&buffer[i]))
182 #ifdef TSeq_isCDRStringType
183 #ifndef TSeq_map_w_length
184 #define _map_w_length(TSeq) concatenate(TSeq, _map_w_length)
185 #define TSeq_map_w_length _map_w_length(TSeq)
187 TSeq_map_w_length(T *buffer,
RTI_BOOL(*map)(T*, RTI_UINT32),RTI_INT32 begin, RTI_INT32 end, RTI_UINT32 max_str_len)
191 for (i = begin; i <= end; i++)
193 if (!map(&buffer[i], max_str_len))
206 #ifdef TSeq_initialize
207 #undef TSeq_initialize
208 #define _initialize(TSeq) concatenate(TSeq, _initialize)
209 #define TSeq_initialize _initialize(TSeq)
211 TSeq_initialize(
struct TSeq *
self)
213 return REDA_Sequence_initialize((
struct REDA_Sequence*)
self,
sizeof(T));
216 #undef TSeq_initialize
221 #define _finalize(TSeq) concatenate(TSeq, _finalize)
222 #define TSeq_finalize _finalize(TSeq)
224 TSeq_finalize(
struct TSeq *
self)
228 result = TSeq_map(self->_contiguous_buffer,T_finalize,0,self->_maximum-1);
233 return REDA_Sequence_finalize((
struct REDA_Sequence*)
self);
235 return REDA_Sequence_finalize((
struct REDA_Sequence*)
self);
243 #ifdef TSeq_get_maximum
244 #undef TSeq_get_maximum
245 #define _get_maximum(TSeq) concatenate(TSeq, _get_maximum)
246 #define TSeq_get_maximum _get_maximum(TSeq)
248 TSeq_get_maximum(
const struct TSeq *
self)
250 return REDA_Sequence_get_maximum((
const struct REDA_Sequence *)
self);
254 #ifdef TSeq_set_maximum
255 #undef TSeq_set_maximum
256 #define _set_maximum(TSeq) concatenate(TSeq, _set_maximum)
257 #define TSeq_set_maximum _set_maximum(TSeq)
258 #ifndef TSeq_isCDRStringType
260 TSeq_set_maximum(
struct TSeq *
self, RTI_INT32 new_max)
265 RTI_INT32 copy_length;
273 OSAPI_PRECONDITION(
self == NULL,
275 OSAPI_Log_entry_add_pointer(
"self",
self,RTI_TRUE);)
277 self->_element_size =
sizeof(T);
279 copy_buffer =
self->_contiguous_buffer;
280 copy_length =
self->_length;
281 copy_max =
self->_maximum;
284 result = REDA_Sequence_set_maximum((
struct REDA_Sequence*)
self,
291 result = TSeq_map(self->_contiguous_buffer,T_initialize,0,self->_maximum-1);
298 if (self->_length > 0)
302 for (i = 0; i < (new_max < copy_length ? new_max : copy_length); ++i)
304 if (!T_copy(&self->_contiguous_buffer[i],(
const T*)©_buffer[i]))
311 if (copy_buffer != NULL)
313 result = TSeq_map(copy_buffer,T_finalize,0,copy_max-1);
319 self->_element_size =
sizeof(T);
320 return REDA_Sequence_set_maximum((
struct REDA_Sequence*)
self, new_max,RTI_TRUE);
325 TSeq_set_maximum(
struct TSeq *
self, RTI_INT32 new_max, RTI_UINT32 max_str_len)
334 OSAPI_PRECONDITION(
self == NULL,
336 OSAPI_Log_entry_add_pointer(
"self",
self,RTI_TRUE);)
338 self->_element_size =
sizeof(T);
339 old_max = REDA_Sequence_get_maximum((
const struct REDA_Sequence *)
self);
342 if (old_max == new_max)
348 copy_buffer =
self->_contiguous_buffer;
353 result = REDA_Sequence_set_maximum((
struct REDA_Sequence*)
self,
362 for (i = 0; i < ((old_max < new_max) ? old_max : new_max); i++)
364 self->_contiguous_buffer[i] = copy_buffer[i];
371 result = TSeq_map_w_length(self->_contiguous_buffer,T_initialize,old_max,new_max-1,max_str_len);
380 if (copy_buffer != NULL)
382 result = TSeq_map(copy_buffer,T_finalize,new_max,old_max-1);
391 #ifdef TSeq_get_length
392 #undef TSeq_get_length
393 #define _get_length(TSeq) concatenate(TSeq, _get_length)
394 #define TSeq_get_length _get_length(TSeq)
396 TSeq_get_length(
const struct TSeq *
self)
398 return REDA_Sequence_get_length((
const struct REDA_Sequence *)
self);
401 #undef TSeq_get_length
405 #ifdef TSeq_set_length
406 #undef TSeq_set_length
407 #define _set_length(TSeq) concatenate(TSeq, _set_length)
408 #define TSeq_set_length _set_length(TSeq)
410 TSeq_set_length(
struct TSeq *
self, RTI_INT32 new_length)
412 return REDA_Sequence_set_length((
struct REDA_Sequence *)
self, new_length);
416 #ifdef TSeq_get_reference
417 #undef TSeq_get_reference
418 #define _get_reference(TSeq) concatenate(TSeq, _get_reference)
419 #define TSeq_get_reference _get_reference(TSeq)
421 TSeq_get_reference(
const struct TSeq *
self, RTI_INT32 i)
423 return (T*)REDA_Sequence_get_reference((
const struct REDA_Sequence*)
self,i);
425 #undef _get_reference
426 #undef TSeq_get_reference
432 #define _copy(TSeq) concatenate(TSeq, _copy)
433 #define TSeq_copy _copy(TSeq)
434 #ifndef TSeq_isCDRStringType
436 TSeq_copy(
struct TSeq *
self,
const struct TSeq *src)
446 OSAPI_PRECONDITION(
self == NULL,
448 OSAPI_Log_entry_add_pointer(
"self",
self,RTI_TRUE);)
450 copy_buffer = self->_contiguous_buffer;
451 if (src->_element_size > 0)
453 self->_element_size =
sizeof(T);
456 copy_max =
self->_maximum;
460 if (REDA_Sequence_copy((
struct REDA_Sequence *)
self,
461 (
const struct REDA_Sequence *)src,
468 if (self->_contiguous_buffer != copy_buffer)
470 result = TSeq_map(self->_contiguous_buffer,T_initialize,0,self->_maximum-1);
478 for (i = 0; i < src->_length; i++)
480 if (!T_copy(&self->_contiguous_buffer[i],
481 (
const T*) &src->_contiguous_buffer[i]))
491 if ((copy_buffer != NULL) &&
492 (copy_buffer != self->_contiguous_buffer))
494 result = TSeq_map(copy_buffer,T_finalize,0,copy_max-1);
505 if (src->_element_size > 0)
507 self->_element_size =
sizeof(T);
509 return (
struct TSeq*)REDA_Sequence_copy((
struct REDA_Sequence *)
self,
510 (
const struct REDA_Sequence *)src,
516 TSeq_copy(
struct TSeq *
self,
const struct TSeq *src, RTI_UINT32 max_str_len)
525 OSAPI_PRECONDITION(
self == NULL,
527 OSAPI_Log_entry_add_pointer(
"self",
self,RTI_TRUE);)
529 copy_buffer = self->_contiguous_buffer;
530 if (src->_element_size > 0)
532 self->_element_size =
sizeof(T);
535 copy_max =
self->_maximum;
539 if (REDA_Sequence_copy((
struct REDA_Sequence *)
self,
540 (
const struct REDA_Sequence *)src,
550 if (self->_contiguous_buffer != copy_buffer)
553 for (i = 0; i < copy_max; i++)
555 self->_contiguous_buffer[i] = copy_buffer[i];
560 result = TSeq_map_w_length(self->_contiguous_buffer,T_initialize,copy_max,self->_maximum-1,max_str_len);
566 result = TSeq_map_w_length(self->_contiguous_buffer,T_initialize,0,self->_maximum-1,max_str_len);
575 for (i = 0; i < src->_length; i++)
577 if (!T_copy(&self->_contiguous_buffer[i],
578 (
const T*) &src->_contiguous_buffer[i],
588 if ((copy_buffer != NULL) && (copy_buffer != self->_contiguous_buffer))
601 #define _is_equal(TSeq) concatenate(TSeq, _is_equal)
602 #define TSeq_is_equal _is_equal(TSeq)
604 TSeq_is_equal(
const struct TSeq *left,
const struct TSeq *right)
610 result = REDA_Sequence_is_equal((
const struct REDA_Sequence*)left,
611 (
const struct REDA_Sequence*)right,RTI_FALSE);
617 for (i = 0; i < left->_length; i++)
619 if (T_compare((
const T*)&left->_contiguous_buffer[i],
620 (
const T*)&right->_contiguous_buffer[i]))
628 return REDA_Sequence_is_equal((
const struct REDA_Sequence *)left,
629 (
const struct REDA_Sequence *)right,RTI_TRUE);
636 #ifdef TSeq_loan_contiguous
637 #undef TSeq_loan_contiguous
638 #define _loan_contiguous(TSeq) concatenate(TSeq, _loan_contiguous)
639 #define TSeq_loan_contiguous _loan_contiguous(TSeq)
641 TSeq_loan_contiguous(
struct TSeq *
self,
void *buffer,
642 RTI_INT32 new_length, RTI_INT32 new_max)
644 return REDA_Sequence_loan_contiguous(
645 (
struct REDA_Sequence *)
self, buffer, new_length, new_max);
649 #ifdef TSeq_loan_discontiguous
650 #undef TSeq_loan_discontiguous
651 #define _loan_discontiguous(TSeq) concatenate(TSeq, _loan_discontiguous)
652 #define TSeq_loan_discontiguous _loan_discontiguous(TSeq)
654 TSeq_loan_discontiguous(
struct TSeq *
self,
void *buffer,
655 RTI_INT32 new_length, RTI_INT32 new_max)
657 return REDA_Sequence_loan_discontiguous(
658 (
struct REDA_Sequence *)
self, buffer, new_length, new_max);
663 #ifdef TSeq_has_ownership
664 #undef TSeq_has_ownership
665 #define _has_ownership(TSeq) concatenate(TSeq, _has_ownership)
666 #define TSeq_has_ownership _has_ownership(TSeq)
668 TSeq_has_ownership(
const struct TSeq *
self)
670 return REDA_Sequence_has_ownership((
const struct REDA_Sequence *)
self);
675 #ifdef TSeq_has_discontiguous_buffer
676 #undef TSeq_has_discontiguous_buffer
677 #define _has_discontiguous_buffer(TSeq) concatenate(TSeq, _has_discontiguous_buffer)
678 #define TSeq_has_discontiguous_buffer _has_discontiguous_buffer(TSeq)
680 TSeq_has_discontiguous_buffer(
const struct TSeq *
self)
682 return REDA_Sequence_has_discontiguous_buffer(
683 (
const struct REDA_Sequence *)
self);
686 #undef _has_discontiguous_buffer
687 #undef TSeq_has_discontiguous_buffer
691 #ifdef TSeq_get_contiguous_buffer
692 #undef TSeq_get_contiguous_buffer
693 #define _get_contiguous_buffer(TSeq) concatenate(TSeq, _get_contiguous_buffer)
694 #define TSeq_get_contiguous_buffer _get_contiguous_buffer(TSeq)
696 TSeq_get_contiguous_buffer(
const struct TSeq *
self)
698 return (T*)REDA_Sequence_get_buffer((
const struct REDA_Sequence *)
self);
700 #undef _get_contiguous_buffer
701 #undef TSeq_get_contiguous_buffer
704 #ifdef TSeq_get_discontiguous_buffer
705 #undef TSeq_get_discontiguous_buffer
706 #define _get_discontiguous_buffer(TSeq) concatenate(TSeq, TSeq_get_discontiguous_buffer)
707 #define TSeq_get_discontiguous_buffer _get_discontiguous_buffer(TSeq)
709 TSeq_get_discontiguous_buffer(
const struct TSeq *
self)
711 return (T*)REDA_Sequence_get_buffer((
const struct REDA_Sequence *)
self);
713 #undef _get_discontiguous_buffer
714 #undef TSeq_get_discontiguous_buffer
717 #ifdef TSeq_set_contiguous_buffer
718 #undef TSeq_set_contiguous_buffer
719 #define _set_contiguous_buffer(TSeq) concatenate(TSeq, _set_contiguous_buffer)
720 #define TSeq_set_contiguous_buffer _set_contiguous_buffer(TSeq)
722 TSeq_set_contiguous_buffer(
struct TSeq *
self, T *buffer)
724 return REDA_Sequence_set_buffer((
struct REDA_Sequence *)
self,
727 #undef _set_contiguous_buffer
728 #undef TSeq_set_contiguous_buffer
734 #define _unloan(TSeq) concatenate(TSeq, _unloan)
735 #define TSeq_unloan _unloan(TSeq)
737 TSeq_unloan(
struct TSeq *
self)
739 return REDA_Sequence_unloan((
struct REDA_Sequence *)
self);
743 #ifdef TSeq_set_token
744 #undef TSeq_set_token
745 #define _set_token(TSeq) concatenate(TSeq, _set_token)
746 #define TSeq_set_token _set_token(TSeq)
748 TSeq_set_token(
struct TSeq *
self,
void *token1,
void *token2)
750 REDA_Sequence_set_token((
struct REDA_Sequence *)
self,token1,token2);
753 #undef TSeq_set_token
756 #ifdef TSeq_get_token
757 #undef TSeq_get_token
758 #define _get_token(TSeq) concatenate(TSeq, _get_token)
759 #define TSeq_get_token _get_token(TSeq)
761 TSeq_get_token(
struct TSeq *
self,
void **token1,
void **token2)
763 REDA_Sequence_get_token((
struct REDA_Sequence *)
self,token1,token2);
766 #undef TSeq_get_token
769 #ifdef TSeq_ensure_length
770 #undef TSeq_ensure_length
771 #define _ensure_length(TSeq) concatenate(TSeq, _ensure_length)
772 #define TSeq_ensure_length _ensure_length(TSeq)
774 #ifndef TSeq_isCDRStringType
775 TSeq_ensure_length(
struct TSeq *
self,RTI_INT32 length, RTI_INT32 max)
777 TSeq_ensure_length(
struct TSeq *
self,RTI_INT32 length, RTI_INT32 max,
778 RTI_INT32 max_str_len)
781 OSAPI_PRECONDITION((
self == NULL) || (length > max) ||
782 (length < 0) || (max < 0),
784 OSAPI_Log_entry_add_pointer(
"self",
self,RTI_FALSE);
785 OSAPI_Log_entry_add_int(
"length",length,RTI_FALSE);
786 OSAPI_Log_entry_add_int(
"max",max,RTI_TRUE);)
788 if (!TSeq_has_ownership(
self))
793 if (length > TSeq_get_maximum(
self))
795 #ifndef TSeq_isCDRStringType
796 if (!TSeq_set_maximum(
self, max))
798 if (!TSeq_set_maximum(
self, max,max_str_len))
805 return TSeq_set_length(
self, length);
807 #undef _ensure_length
808 #undef TSeq_ensure_length
811 #ifdef TSeq_from_array
812 #undef TSeq_from_array
813 #define _from_array(TSeq) concatenate(TSeq, _from_array)
814 #define TSeq_from_array _from_array(TSeq)
816 #ifndef TSeq_isCDRStringType
817 TSeq_from_array(
struct TSeq *
self,
const T elv[], RTI_INT32 length)
819 TSeq_from_array(
struct TSeq *
self,
const T elv[], RTI_INT32 length,RTI_INT32 max_str_length)
823 struct TSeq elms_seq;
825 struct TSeq elms_seq = REDA_DEFINE_EMPTY_SEQUENCE_INITIALIZER;
828 OSAPI_PRECONDITION((
self == NULL) || (length < 0),
830 OSAPI_Log_entry_add_pointer(
"self",
self,RTI_FALSE);
831 OSAPI_Log_entry_add_int(
"length",length,RTI_TRUE););
834 if (!TSeq_loan_contiguous(&elms_seq, (T*)elv, length, length))
840 #ifndef TSeq_isCDRStringType
841 if (TSeq_copy(
self, &elms_seq) == NULL)
843 if (TSeq_copy(
self, &elms_seq,max_str_length) == NULL)
850 TSeq_unloan(&elms_seq);
855 #undef TSeq_from_array
860 #define _to_array(TSeq) concatenate(TSeq, _to_array)
861 #define TSeq_to_array _to_array(TSeq)
863 #ifndef TSeq_isCDRStringType
864 TSeq_to_array(
struct TSeq *
self,T elv[], RTI_INT32 length)
866 TSeq_to_array(
struct TSeq *
self,T elv[], RTI_INT32 length,RTI_INT32 max_str_length)
870 struct TSeq elms_seq;
872 struct TSeq elms_seq = REDA_DEFINE_EMPTY_SEQUENCE_INITIALIZER;
875 OSAPI_PRECONDITION((
self == NULL) || (length < 0),
877 OSAPI_Log_entry_add_pointer(
"self",
self,RTI_FALSE);
878 OSAPI_Log_entry_add_int(
"length",length,RTI_TRUE););
881 if (!TSeq_loan_contiguous(&elms_seq, (T*)elv, length, length))
887 #ifndef TSeq_isCDRStringType
888 if (TSeq_copy(&elms_seq,
self) == NULL)
890 if (TSeq_copy(&elms_seq,
self,max_str_length) == NULL)
897 TSeq_unloan(&elms_seq);
908 #undef TSeq_map_w_length
910 #undef REDA_SEQUENCE_API
913 #undef TSeq_isCDRStringType
918 #undef REDA_SEQUENCE_USER_API
920 #undef TSeq_set_length
922 #undef TSeq_set_maximum
924 #undef TSeq_get_maximum
927 #undef _loan_discontiguous
928 #undef TSeq_loan_discontiguous
931 #undef _loan_contiguous
932 #undef TSeq_loan_contiguous
933 #undef _has_ownership
934 #undef TSeq_has_ownership