RTI Connext DDS Micro  Version 2.4.11
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
reda_sequence_defn.h
Go to the documentation of this file.
1 /*
2  * FILE: reda_sequence_defn.h - Sequence template
3  *
4  * Copyright 2008-2016 Real-Time Innovations, Inc.
5  *
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  *
11  * Modification History
12  * --------------------
13  * 10feb2016,tk MICRO-1530 Unified REDA_StringSeq, CDR_StringSeq, and DDS_StringSeq
14  * 19may2015,as MICRO-1193 Refactoring of Sequence API levels
15  * 26mar2016,tk MICRO-1133 Changed how Seq_copy and Seq_set_maximum copied the
16  * source sequence data locally to avoid C++
17  * constructor/destructor problems
18  * 12mar2015,eh MICRO-1053/PR#13585 Remove string seq map() from CERT
19  * 27jan2015,tk MICRO-1014/PR#13358 Removed redundant code for CERT in _copy
20  * (The preallocated memory version)
21  * 01dec2014,tk MICRO-951/PR#12315 Removed redundant code for CERT in _copy
22  * 01dec2014,tk MICRO-949/PR#11856 Removed redundant code for CERT in set_maximum
23  * 04aug2014,tk MICRO-841 Only copy new_max elements if sequence is reduced
24  * 03jun2013,kaj MICRO-502 support for string sequences req. max string length
25  * 20apr2008,tk Written
26  */
27 /*ce
28  * \file
29  */
30 #include "reda/reda_sequence.h"
31 #define concatenate(A, B) A ## B
32 
33 #ifndef T
34 #define T RTI_UINT32
35 #endif
36 
37 #ifdef REDA_SEQUENCE_USER_API
38 #ifndef REDA_SEQUENCE_API
39 #define REDA_SEQUENCE_API REDA_SEQUENCE_API_USER_DEFAULT
40 #else
41 #if REDA_SEQUENCE_API < REDA_SEQUENCE_API_BASIC
42 #error "REDA_SEQUENCE_USER_API defined along with API level < REDA_SEQUENCE_API_BASIC"
43 #endif
44 #endif
45 #endif /* REDA_SEQUENCE_USER_API */
46 
47 #ifndef REDA_SEQUENCE_API
48 #define REDA_SEQUENCE_API REDA_SEQUENCE_API_DEFAULT
49 #endif /* REDA_SEQUENCE_API */
50 
51 #if REDA_SEQUENCE_API < REDA_SEQUENCE_API_UNTYPED
52 #error "REDA_SEQUENCE_API_UNTYPED <= REDA_SEQUENCE_API <= REDA_SEQUENCE_API_FULL"
53 #endif
54 
55 /* This corresponds to the BASIC API, the lowest level */
56 #if REDA_SEQUENCE_API > REDA_SEQUENCE_API_UNTYPED
57 #ifndef TSeq_initialize
58 #define TSeq_initialize
59 #endif
60 #ifndef TSeq_get_maximum
61 #define TSeq_get_maximum
62 #endif
63 #ifndef TSeq_set_maximum
64 #define TSeq_set_maximum
65 #endif
66 #ifndef TSeq_get_length
67 #define TSeq_get_length
68 #endif
69 #ifndef TSeq_set_length
70 #define TSeq_set_length
71 #endif
72 #ifndef TSeq_get_reference
73 #define TSeq_get_reference
74 #endif
75 #ifndef RTI_CERT
76 #ifndef TSeq_finalize
77 #define TSeq_finalize
78 #endif
79 #endif /* RTI_CERT */
80 #ifdef REDA_SEQUENCE_USER_API
81 #ifndef TSeq_copy
82 #define TSeq_copy
83 #endif
84 #endif /* REDA_SEQUENCE_USER_API */
85 #endif /* REDA_SEQUENCE_API > REDA_SEQUENCE_API_UNTYPED */
86 
87 /* The FULL API adds the following methods */
88 #if REDA_SEQUENCE_API > REDA_SEQUENCE_API_BASIC
89 #ifndef TSeq_copy
90 #define TSeq_copy
91 #endif
92 #ifndef TSeq_is_equal
93 #define TSeq_is_equal
94 #endif
95 #ifndef TSeq_loan_contiguous
96 #define TSeq_loan_contiguous
97 #endif
98 #ifndef TSeq_loan_discontiguous
99 #define TSeq_loan_discontiguous
100 #endif
101 #ifndef TSeq_has_ownership
102 #define TSeq_has_ownership
103 #endif
104 #ifndef TSeq_has_discontiguous_buffer
105 #define TSeq_has_discontiguous_buffer
106 #endif
107 #ifndef TSeq_get_contiguous_buffer
108 #define TSeq_get_contiguous_buffer
109 #endif
110 #ifndef TSeq_get_discontiguous_buffer
111 #define TSeq_get_discontiguous_buffer
112 #endif
113 #ifndef TSeq_set_contiguous_buffer
114 #define TSeq_set_contiguous_buffer
115 #endif
116 #ifndef TSeq_unloan
117 #define TSeq_unloan
118 #endif
119 #ifndef TSeq_set_token
120 #define TSeq_set_token
121 #endif
122 #ifndef TSeq_get_token
123 #define TSeq_get_token
124 #endif
125 #ifndef TSeq_ensure_length
126 #define TSeq_ensure_length
127 #endif
128 #ifndef TSeq_from_array
129 #define TSeq_from_array
130 #endif
131 #ifndef TSeq_to_array
132 #define TSeq_to_array
133 #endif
134 #endif /* REDA_SEQUENCE_API > REDA_SEQUENCE_API_BASIC */
135 
136 #if REDA_SEQUENCE_API > REDA_SEQUENCE_API_FULL
137 #error "REDA_SEQUENCE_API_UNTYPED <= REDA_SEQUENCE_API <= REDA_SEQUENCE_API_FULL"
138 #endif
139 
140 #if defined(T_copy) && !defined(T_initialize)
141 #error "T_copy defined without T_initialize"
142 #endif
143 
144 #if defined(T_compare) && !defined(T_initialize)
145 #error "T_compare defined without T_initialize"
146 #endif
147 
148 #ifndef RTI_CERT
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"
151 #endif
152 #else /* RTI_CERT */
153 #if defined(TSeq_isCDRStringType) && (!defined(T_initialize) || !defined(T_copy))
154 #error "TSeq_isCDRStringType defined without T_initialize/T_copy"
155 #endif
156 #endif /* !RTI_CERT */
157 
158 #if defined(T_initialize) || defined(T_finalize) || defined(T_copy)
159 
160 #if !(defined(TSeq_isCDRStringType) && defined(RTI_CERT))
161 #ifndef TSeq_map
162 #define _map(TSeq) concatenate(TSeq, _map)
163 #define TSeq_map _map(TSeq)
164 RTI_PRIVATE RTI_BOOL
165 TSeq_map(T *buffer,RTI_BOOL(*map)(T*),RTI_INT32 begin, RTI_INT32 end)
166 {
167  RTI_INT32 i;
168 
169  for (i = begin; i <= end; i++)
170  {
171  if (!map(&buffer[i]))
172  {
173  return RTI_FALSE;
174  }
175  }
176 
177  return RTI_TRUE;
178 }
179 #endif /* TSeq_map */
180 #endif /* !(TSeq_isCDRStringType && defined(RTI_CERT)) */
181 
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)
186 RTI_PRIVATE RTI_BOOL
187 TSeq_map_w_length(T *buffer,RTI_BOOL(*map)(T*, RTI_UINT32),RTI_INT32 begin, RTI_INT32 end, RTI_UINT32 max_str_len)
188 {
189  RTI_INT32 i;
190 
191  for (i = begin; i <= end; i++)
192  {
193  if (!map(&buffer[i], max_str_len))
194  {
195  return RTI_FALSE;
196  }
197  }
198 
199  return RTI_TRUE;
200 }
201 #endif /* TSeq_map_w_length */
202 #endif /* TSeq_isCDRStringType */
203 
204 #endif /* TSeq_isComplexType */
205 
206 #ifdef TSeq_initialize
207 #undef TSeq_initialize
208 #define _initialize(TSeq) concatenate(TSeq, _initialize)
209 #define TSeq_initialize _initialize(TSeq)
210 RTI_BOOL
211 TSeq_initialize(struct TSeq *self)
212 {
213  return REDA_Sequence_initialize((struct REDA_Sequence*)self, sizeof(T));
214 }
215 #endif /* TSeq_initialize */
216 
217 #ifdef TSeq_finalize
218 #undef TSeq_finalize
219 #define _finalize(TSeq) concatenate(TSeq, _finalize)
220 #define TSeq_finalize _finalize(TSeq)
221 RTI_BOOL
222 TSeq_finalize(struct TSeq *self)
223 {
224 #ifdef T_finalize
225  RTI_BOOL result;
226  result = TSeq_map(self->_contiguous_buffer,T_finalize,0,self->_maximum-1);
227  if (!result)
228  {
229  return result;
230  }
231  return REDA_Sequence_finalize((struct REDA_Sequence*)self);
232 #else /* T_finalize */
233  return REDA_Sequence_finalize((struct REDA_Sequence*)self);
234 #endif /* T_finalize */
235 
236 #undef _finalize
237 #undef TSeq_finalize
238 }
239 #endif /* TSeq_finalize */
240 
241 #ifdef TSeq_get_maximum
242 #undef TSeq_get_maximum
243 #define _get_maximum(TSeq) concatenate(TSeq, _get_maximum)
244 #define TSeq_get_maximum _get_maximum(TSeq)
245 RTI_INT32
246 TSeq_get_maximum(const struct TSeq *self)
247 {
248  return REDA_Sequence_get_maximum((const struct REDA_Sequence *)self);
249 }
250 #endif /* TSeq_get_maximum */
251 
252 #ifdef TSeq_set_maximum
253 #undef TSeq_set_maximum
254 #define _set_maximum(TSeq) concatenate(TSeq, _set_maximum)
255 #define TSeq_set_maximum _set_maximum(TSeq)
256 #ifndef TSeq_isCDRStringType
257 RTI_BOOL
258 TSeq_set_maximum(struct TSeq *self, RTI_INT32 new_max)
259 {
260 #ifdef T_initialize
261 #ifndef RTI_CERT
262  T* copy_buffer;
263  RTI_INT32 copy_length;
264  RTI_INT32 copy_max;
265 #endif
266  RTI_BOOL result;
267  RTI_INT32 old_max;
268 #ifndef RTI_CERT
269  RTI_INT32 i;
270 #endif /* !RTI_CERT */
271 
272  OSAPI_PRECONDITION(self == NULL,
273  return RTI_FALSE,
274  OSAPI_Log_entry_add_pointer("self",self,RTI_TRUE);)
275 
276  self->_element_size = sizeof(T);
277 #ifndef RTI_CERT
278  copy_buffer = self->_contiguous_buffer;
279  copy_length = self->_length;
280  copy_max = self->_maximum;
281 #endif
282 
283  old_max = REDA_Sequence_get_maximum((const struct REDA_Sequence *)self);
284 
285  /* if not resizing sequence then we are done */
286  if (old_max == new_max)
287  {
288  return RTI_TRUE;
289  }
290 
291  result = REDA_Sequence_set_maximum((struct REDA_Sequence*)self,
292  new_max,RTI_FALSE);
293  if (!result)
294  {
295  return result;
296  }
297 
298  result = TSeq_map(self->_contiguous_buffer,T_initialize,0,self->_maximum-1);
299  if (!result)
300  {
301  return result;
302  }
303 
304 #ifndef RTI_CERT
305  if (self->_length > 0)
306  {
307  /* If the sequence is reduced in size, only copy the first new_max elements
308  */
309  for (i = 0; i < (new_max < copy_length ? new_max : copy_length); ++i)
310  {
311  if (!T_copy(&self->_contiguous_buffer[i],(const T*)&copy_buffer[i]))
312  {
313  return RTI_FALSE;
314  }
315  }
316  }
317 
318  /* since the pointers were copied from old seq to new seq,
319  * only finalize members between new_max and old_max-1. Note that
320  * copy_buffer cannot be the same as _contiguous_buffer if the sequence
321  * was resized since a new allocation is made, that is no reallocation.
322  * If the sequence size is the same as the existing sequence no reallocation
323  * takes place.
324  */
325  if (copy_buffer != NULL)
326  {
327  result = TSeq_map(copy_buffer,T_finalize,0,copy_max-1);
328  OSAPI_Heap_free_buffer(copy_buffer);
329  }
330 #endif /* !RTI_CERT */
331  return result;
332 #else /* T_initialize */
333  self->_element_size = sizeof(T);
334  return REDA_Sequence_set_maximum((struct REDA_Sequence*)self, new_max,RTI_TRUE);
335 #endif /* T_initialize */
336 }
337 #else /* TSeq_isCDRStringType */
338 #ifdef TSeq_isCDRStringType_no_max
339 RTI_BOOL
340 TSeq_set_maximum(struct TSeq *self, RTI_INT32 new_max, RTI_UINT32 max_str_len)
341 #else
342 #undef TSeq_set_maximum_w_max
343 #define _set_maximum_w_max(TSeq) concatenate(TSeq, _set_maximum_w_max)
344 #define TSeq_set_maximum_w_max _set_maximum_w_max(TSeq)
345 RTI_BOOL
346 TSeq_set_maximum_w_max(struct TSeq *self, RTI_INT32 new_max, RTI_UINT32 max_str_len)
347 #endif
348 {
349  RTI_BOOL result;
350  RTI_INT32 old_max;
351 #ifndef RTI_CERT
352  T *copy_buffer;
353  RTI_INT32 i;
354 #endif
355 
356  OSAPI_PRECONDITION(self == NULL,
357  return RTI_FALSE,
358  OSAPI_Log_entry_add_int("max_str_len",(RTI_INT32)max_str_len,RTI_FALSE);
359  OSAPI_Log_entry_add_pointer("self",self,RTI_TRUE);)
360 
361  self->_element_size = sizeof(T);
362  if (max_str_len < REDA_SEQUENCE_ELEMENT_ALLOC)
363  {
364  self->_flags |= REDA_SEQUENCE_FLAG_PTR_ALLOCATION;
365  }
366 
367  old_max = REDA_Sequence_get_maximum((const struct REDA_Sequence *)self);
368 
369  /* if not resizing seqeunce then we are done */
370  if (old_max == new_max)
371  {
372  return RTI_TRUE;
373  }
374 
375 #ifndef RTI_CERT
376  copy_buffer = self->_contiguous_buffer;
377 #endif
378 
379  /* cannot use copy content because it will free the contiquous buffer
380  without finalizing any discarded elements */
381  result = REDA_Sequence_set_maximum((struct REDA_Sequence*)self,
382  new_max,RTI_FALSE);
383  if (!result)
384  {
385  return result;
386  }
387 
388 #ifndef RTI_CERT
389  /* copy elements (string memory) from old buffer to new buffer */
390  for (i = 0; i < ((old_max < new_max) ? old_max : new_max); i++)
391  {
392  self->_contiguous_buffer[i] = copy_buffer[i];
393  }
394 #endif
395 
396  /* initialize (allocate) any added elements (from old_max to new_max-1)
397  * If old_max > new_max-1 then the map function does not do anything
398  */
399  result = TSeq_map_w_length(self->_contiguous_buffer,T_initialize,old_max,new_max-1,max_str_len);
400  if (!result)
401  {
402  return result;
403  }
404 
405 #ifndef RTI_CERT
406  /* since the pointers were copied from old seq to new seq,
407  * only finalize members between new_max and old_max-1. Note that
408  * copy_buffer cannot be the same as _contiguous_buffer if the sequence
409  * was resized since a new allocation is made, that is no reallocation.
410  * If the sequence size is the same as the existing sequence no reallocation
411  * takes place.
412  */
413  if (copy_buffer != NULL)
414  {
415  result = TSeq_map(copy_buffer,T_finalize,new_max,old_max-1);
416  OSAPI_Heap_free_buffer(copy_buffer);
417  }
418 #endif /* !RTI_CERT */
419  return result;
420 }
421 
422 #ifndef TSeq_isCDRStringType_no_max
423 RTI_BOOL
424 TSeq_set_maximum(struct TSeq *self, RTI_INT32 new_max)
425 {
426  return TSeq_set_maximum_w_max(self,new_max,REDA_SEQUENCE_ELEMENT_ALLOC);
427 }
428 #endif
429 
430 #endif /* TSeq_isCDRStringType defined */
431 #endif /* TSeq_set_maximum */
432 
433 #ifdef TSeq_get_length
434 #undef TSeq_get_length
435 #define _get_length(TSeq) concatenate(TSeq, _get_length)
436 #define TSeq_get_length _get_length(TSeq)
437 RTI_INT32
438 TSeq_get_length(const struct TSeq *self)
439 {
440  return REDA_Sequence_get_length((const struct REDA_Sequence *)self);
441 
442 #undef _get_length
443 #undef TSeq_get_length
444 }
445 #endif /* TSeq_get_length */
446 
447 #ifdef TSeq_set_length
448 #undef TSeq_set_length
449 #define _set_length(TSeq) concatenate(TSeq, _set_length)
450 #define TSeq_set_length _set_length(TSeq)
451 RTI_BOOL
452 TSeq_set_length(struct TSeq *self, RTI_INT32 new_length)
453 {
454  return REDA_Sequence_set_length((struct REDA_Sequence *)self, new_length);
455 }
456 #endif /* TSeq_set_length */
457 
458 #ifdef TSeq_get_reference
459 #undef TSeq_get_reference
460 #define _get_reference(TSeq) concatenate(TSeq, _get_reference)
461 #define TSeq_get_reference _get_reference(TSeq)
462 T*
463 TSeq_get_reference(const struct TSeq *self, RTI_INT32 i)
464 {
465  return (T*)REDA_Sequence_get_reference((const struct REDA_Sequence*)self,i);
466 
467 #undef _get_reference
468 #undef TSeq_get_reference
469 }
470 #endif /* TSeq_get_reference */
471 
472 #ifdef TSeq_copy
473 #undef TSeq_copy
474 #define _copy(TSeq) concatenate(TSeq, _copy)
475 #define TSeq_copy _copy(TSeq)
476 #ifndef TSeq_isCDRStringType
477 struct TSeq*
478 TSeq_copy(struct TSeq *self, const struct TSeq *src)
479 {
480 #ifdef T_copy
481  RTI_BOOL result;
482  RTI_INT32 i;
483  T *copy_buffer;
484 #ifndef RTI_CERT
485  RTI_INT32 copy_max;
486 #endif
487 
488  OSAPI_PRECONDITION(self == NULL,
489  return NULL,
490  OSAPI_Log_entry_add_pointer("self",self,RTI_TRUE);)
491 
492  copy_buffer = self->_contiguous_buffer;
493  if (src->_element_size > 0)
494  {
495  self->_element_size = sizeof(T);
496  }
497 #ifndef RTI_CERT
498  copy_max = self->_maximum;
499 #endif
500 
501  /* replaces contiguous buffer if self->max < src->size */
502  if (REDA_Sequence_copy((struct REDA_Sequence *)self,
503  (const struct REDA_Sequence *)src,
504  RTI_FALSE) == NULL)
505  {
506  return NULL;
507  }
508 
509  /* if replaced contiguous buffer then initialize new members */
510  if (self->_contiguous_buffer != copy_buffer)
511  {
512  result = TSeq_map(self->_contiguous_buffer,T_initialize,0,self->_maximum-1);
513  if (!result)
514  {
515  return NULL;
516  }
517  }
518 
519  /* copy content from source elements to destination elements */
520  for (i = 0; i < src->_length; i++)
521  {
522  if (!T_copy(&self->_contiguous_buffer[i],
523  (const T*) &src->_contiguous_buffer[i]))
524  {
525  return NULL;
526  }
527  }
528 
529 #ifndef RTI_CERT
530  /* If replaced contiguous buffer then finalize old new members
531  * and free old contiguous buffer
532  */
533  if ((copy_buffer != NULL) &&
534  (copy_buffer != self->_contiguous_buffer))
535  {
536  result = TSeq_map(copy_buffer,T_finalize,0,copy_max-1);
537  if (!result)
538  {
539  return NULL;
540  }
541  OSAPI_Heap_free_buffer(copy_buffer);
542  }
543 #endif /* !RTI_CERT */
544 
545  return self;
546 #else /* T_copy */
547  if (src->_element_size > 0)
548  {
549  self->_element_size = sizeof(T);
550  }
551  return (struct TSeq*)REDA_Sequence_copy((struct REDA_Sequence *)self,
552  (const struct REDA_Sequence *)src,
553  RTI_TRUE);
554 #endif /* T_copy */
555 }
556 #else /* TSeq_isCDRStringType defined, which requires T_copy defined */
557 #ifdef TSeq_isCDRStringType_no_max
558 struct TSeq*
559 TSeq_copy(struct TSeq *self, const struct TSeq *src, RTI_UINT32 max_str_len)
560 #else
561 #undef TSeq_copy_w_max
562 #define _copy_w_max(TSeq) concatenate(TSeq, _copy_w_max)
563 #define TSeq_copy_w_max _copy_w_max(TSeq)
564 struct TSeq*
565 TSeq_copy_w_max(struct TSeq *self, const struct TSeq *src, RTI_UINT32 max_str_len)
566 #endif
567 {
568  RTI_BOOL result;
569  RTI_INT32 i;
570  T *copy_buffer;
571 #ifndef RTI_CERT
572  RTI_INT32 copy_max;
573 #endif
574 
575  OSAPI_PRECONDITION(self == NULL,
576  return NULL,
577  OSAPI_Log_entry_add_int("max_str_len",(RTI_INT32)max_str_len,RTI_FALSE);
578  OSAPI_Log_entry_add_pointer("self",self,RTI_TRUE);)
579 
580  if (max_str_len < REDA_SEQUENCE_ELEMENT_ALLOC)
581  {
582  self->_flags |= REDA_SEQUENCE_FLAG_PTR_ALLOCATION;
583  }
584 
585  copy_buffer = self->_contiguous_buffer;
586  if (src->_element_size > 0)
587  {
588  self->_element_size = sizeof(T);
589  }
590 #ifndef RTI_CERT
591  copy_max = self->_maximum;
592 #endif
593 
594  /* replaces contiguous buffer if self->max < src->size */
595  if (REDA_Sequence_copy((struct REDA_Sequence *)self,
596  (const struct REDA_Sequence *)src,
597  RTI_FALSE) == NULL)
598  {
599  return NULL;
600  }
601 
602  /* if replaced contiguous buffer then copy existing dest string buffers
603  * from old contiguous buffer to new dest contiguous buffer,
604  * and initialize (allocate string buffers) for new members added
605  */
606  if (self->_contiguous_buffer != copy_buffer)
607  {
608 #ifndef RTI_CERT
609  for (i = 0; i < copy_max; i++)
610  {
611  self->_contiguous_buffer[i] = copy_buffer[i];
612  }
613  /* initialize (allocate) any added elements (from old_max to new_max-1)
614  * If old_max > new_max-1 then the map function does not do anything
615  */
616  result = TSeq_map_w_length(self->_contiguous_buffer,T_initialize,copy_max,self->_maximum-1,max_str_len);
617 #else
618  /* For RTI_CERT (self->_contiguous_buffer != copy_buffer) is true only
619  * when copy_buffer was NULL, so there is no need for copying elements,
620  * but we need to initialize all the elements in the (new) buffer.
621  */
622  result = TSeq_map_w_length(self->_contiguous_buffer,T_initialize,0,self->_maximum-1,max_str_len);
623 #endif
624  if (!result)
625  {
626  return NULL;
627  }
628  }
629 
630  /* copy content from source to destination */
631  for (i = 0; i < src->_length; i++)
632  {
633  if (!T_copy(&self->_contiguous_buffer[i],
634  (const T*) &src->_contiguous_buffer[i],
635  max_str_len))
636  {
637  return NULL;
638  }
639  }
640 
641 #ifndef RTI_CERT
642  /* if replaced contiguous buffer then free old contiguous buffer (do not
643  finalize string buffers since were transfered to new contiguous buffer */
644  if ((copy_buffer != NULL) && (copy_buffer != self->_contiguous_buffer))
645  {
646  OSAPI_Heap_free_buffer(copy_buffer);
647  }
648 #endif /* !RTI_CERT */
649 
650  return self;
651 }
652 
653 #ifndef TSeq_isCDRStringType_no_max
654 struct TSeq*
655 TSeq_copy(struct TSeq *self, const struct TSeq *src)
656 {
657  if (self->_flags & REDA_SEQUENCE_FLAG_PTR_ALLOCATION)
658  {
659  return TSeq_copy_w_max(self,src,REDA_SEQUENCE_ELEMENT_REPLACE);
660  }
661  else
662  {
663  return TSeq_copy_w_max(self,src,REDA_SEQUENCE_ELEMENT_ALLOC);
664  }
665 }
666 #endif
667 
668 #endif /* TSeq_isCDRStringType*/
669 #endif /* TSeq_copy */
670 
671 #ifdef TSeq_is_equal
672 #undef TSeq_is_equal
673 #define _is_equal(TSeq) concatenate(TSeq, _is_equal)
674 #define TSeq_is_equal _is_equal(TSeq)
675 RTI_BOOL
676 TSeq_is_equal(const struct TSeq *left, const struct TSeq *right)
677 {
678 #ifdef T_compare
679  RTI_INT32 i;
680  RTI_BOOL result;
681 
682  result = REDA_Sequence_is_equal((const struct REDA_Sequence*)left,
683  (const struct REDA_Sequence*)right,RTI_FALSE);
684  if (!result)
685  {
686  return result;
687  }
688 
689  for (i = 0; i < left->_length; i++)
690  {
691  if (T_compare((const T*)&left->_contiguous_buffer[i],
692  (const T*)&right->_contiguous_buffer[i]))
693  {
694  return RTI_FALSE;
695  }
696  }
697 
698  return RTI_TRUE;
699 #else /* T_compare */
700  return REDA_Sequence_is_equal((const struct REDA_Sequence *)left,
701  (const struct REDA_Sequence *)right,RTI_TRUE);
702 #endif /* T_compare */
703 #undef _is_equal
704 #undef TSeq_is_equal
705 }
706 #endif /* TSeq_is_equal */
707 
708 #ifdef TSeq_loan_contiguous
709 #undef TSeq_loan_contiguous
710 #define _loan_contiguous(TSeq) concatenate(TSeq, _loan_contiguous)
711 #define TSeq_loan_contiguous _loan_contiguous(TSeq)
712 RTI_BOOL
713 TSeq_loan_contiguous(struct TSeq *self, void *buffer,
714  RTI_INT32 new_length, RTI_INT32 new_max)
715 {
716  return REDA_Sequence_loan_contiguous(
717  (struct REDA_Sequence *)self, buffer, new_length, new_max);
718 }
719 #endif /* TSeq_loan_contiguous */
720 
721 #ifdef TSeq_loan_discontiguous
722 #undef TSeq_loan_discontiguous
723 #define _loan_discontiguous(TSeq) concatenate(TSeq, _loan_discontiguous)
724 #define TSeq_loan_discontiguous _loan_discontiguous(TSeq)
725 RTI_BOOL
726 TSeq_loan_discontiguous(struct TSeq *self, void *buffer,
727  RTI_INT32 new_length, RTI_INT32 new_max)
728 {
729  return REDA_Sequence_loan_discontiguous(
730  (struct REDA_Sequence *)self, buffer, new_length, new_max);
731 }
732 #endif /* TSeq_loan_discontiguous */
733 
734 
735 #ifdef TSeq_has_ownership
736 #undef TSeq_has_ownership
737 #define _has_ownership(TSeq) concatenate(TSeq, _has_ownership)
738 #define TSeq_has_ownership _has_ownership(TSeq)
739 RTI_BOOL
740 TSeq_has_ownership(const struct TSeq *self)
741 {
742  return REDA_Sequence_has_ownership((const struct REDA_Sequence *)self);
743 }
744 #endif /* TSeq_has_ownership */
745 
746 
747 #ifdef TSeq_has_discontiguous_buffer
748 #undef TSeq_has_discontiguous_buffer
749 #define _has_discontiguous_buffer(TSeq) concatenate(TSeq, _has_discontiguous_buffer)
750 #define TSeq_has_discontiguous_buffer _has_discontiguous_buffer(TSeq)
751 RTI_BOOL
752 TSeq_has_discontiguous_buffer(const struct TSeq *self)
753 {
754  return REDA_Sequence_has_discontiguous_buffer(
755  (const struct REDA_Sequence *)self);
756 }
757 
758 #undef _has_discontiguous_buffer
759 #undef TSeq_has_discontiguous_buffer
760 #endif /* TSeq_has_discontiguous_buffer */
761 
762 
763 #ifdef TSeq_get_contiguous_buffer
764 #undef TSeq_get_contiguous_buffer
765 #define _get_contiguous_buffer(TSeq) concatenate(TSeq, _get_contiguous_buffer)
766 #define TSeq_get_contiguous_buffer _get_contiguous_buffer(TSeq)
767 T*
768 TSeq_get_contiguous_buffer(const struct TSeq *self)
769 {
770  return (T*)REDA_Sequence_get_buffer((const struct REDA_Sequence *)self);
771 }
772 #undef _get_contiguous_buffer
773 #undef TSeq_get_contiguous_buffer
774 #endif /* TSeq_get_buffer */
775 
776 #ifdef TSeq_get_discontiguous_buffer
777 #undef TSeq_get_discontiguous_buffer
778 #define _get_discontiguous_buffer(TSeq) concatenate(TSeq, TSeq_get_discontiguous_buffer)
779 #define TSeq_get_discontiguous_buffer _get_discontiguous_buffer(TSeq)
780 T*
781 TSeq_get_discontiguous_buffer(const struct TSeq *self)
782 {
783  return (T*)REDA_Sequence_get_buffer((const struct REDA_Sequence *)self);
784 }
785 #undef _get_discontiguous_buffer
786 #undef TSeq_get_discontiguous_buffer
787 #endif /* TSeq_get_discontiguous_buffer */
788 
789 #ifdef TSeq_set_contiguous_buffer
790 #undef TSeq_set_contiguous_buffer
791 #define _set_contiguous_buffer(TSeq) concatenate(TSeq, _set_contiguous_buffer)
792 #define TSeq_set_contiguous_buffer _set_contiguous_buffer(TSeq)
793 RTI_BOOL
794 TSeq_set_contiguous_buffer(struct TSeq *self, T *buffer)
795 {
796  return REDA_Sequence_set_buffer((struct REDA_Sequence *)self,
797  (void *)buffer);
798 }
799 #undef _set_contiguous_buffer
800 #undef TSeq_set_contiguous_buffer
801 #endif /* TSeq_set_buffer */
802 
803 
804 #ifdef TSeq_unloan
805 #undef TSeq_unloan
806 #define _unloan(TSeq) concatenate(TSeq, _unloan)
807 #define TSeq_unloan _unloan(TSeq)
808 RTI_BOOL
809 TSeq_unloan(struct TSeq *self)
810 {
811  return REDA_Sequence_unloan((struct REDA_Sequence *)self);
812 }
813 #endif /* TSeq_unloan */
814 
815 #ifdef TSeq_set_token
816 #undef TSeq_set_token
817 #define _set_token(TSeq) concatenate(TSeq, _set_token)
818 #define TSeq_set_token _set_token(TSeq)
819 void
820 TSeq_set_token(struct TSeq *self,void *token1,void *token2)
821 {
822  REDA_Sequence_set_token((struct REDA_Sequence *)self,token1,token2);
823 }
824 #undef _set_token
825 #undef TSeq_set_token
826 #endif /* TSeq_set_token */
827 
828 #ifdef TSeq_get_token
829 #undef TSeq_get_token
830 #define _get_token(TSeq) concatenate(TSeq, _get_token)
831 #define TSeq_get_token _get_token(TSeq)
832 void
833 TSeq_get_token(struct TSeq *self,void **token1,void **token2)
834 {
835  REDA_Sequence_get_token((struct REDA_Sequence *)self,token1,token2);
836 }
837 #undef _get_token
838 #undef TSeq_get_token
839 #endif /* TSeq_get_token */
840 
841 #ifdef TSeq_ensure_length
842 #undef TSeq_ensure_length
843 #define _ensure_length(TSeq) concatenate(TSeq, _ensure_length)
844 #define TSeq_ensure_length _ensure_length(TSeq)
845 RTI_BOOL
846 #ifndef TSeq_isCDRStringType
847 TSeq_ensure_length(struct TSeq *self,RTI_INT32 length, RTI_INT32 max)
848 #else
849 #ifdef TSeq_isCDRStringType_no_max
850 TSeq_ensure_length(struct TSeq *self,RTI_INT32 length, RTI_INT32 max,
851  RTI_INT32 max_str_len)
852 #else
853 #undef TSeq_ensure_length_w_max
854 #define _ensure_length_w_max(TSeq) concatenate(TSeq, _ensure_length_w_max)
855 #define TSeq_ensure_length_w_max _ensure_length_w_max(TSeq)
856 TSeq_ensure_length_w_max(struct TSeq *self,RTI_INT32 length, RTI_INT32 max,
857  RTI_INT32 max_str_len)
858 #endif
859 #endif
860 {
861  OSAPI_PRECONDITION((self == NULL) || (length > max) ||
862  (length < 0) || (max < 0),
863  return RTI_FALSE,
864  OSAPI_Log_entry_add_pointer("self",self,RTI_FALSE);
865  OSAPI_Log_entry_add_int("length",length,RTI_FALSE);
866  OSAPI_Log_entry_add_int("max",max,RTI_TRUE);)
867 
868  if (!TSeq_has_ownership(self))
869  {
870  return RTI_FALSE;
871  }
872 
873  if (length > TSeq_get_maximum(self))
874  {
875 #ifndef TSeq_isCDRStringType
876  if (!TSeq_set_maximum(self, max))
877 #elif defined(TSeq_isCDRStringType_no_max)
878  if (!TSeq_set_maximum(self, max,(RTI_UINT32)max_str_len))
879 #else
880  if (!TSeq_set_maximum_w_max(self, max,(RTI_UINT32)max_str_len))
881 #endif
882  {
883  return RTI_FALSE;
884  }
885  }
886 
887  return TSeq_set_length(self, length);
888 }
889 
890 #if defined(TSeq_isCDRStringType) && !defined(TSeq_isCDRStringType_no_max)
891 RTI_BOOL
892 TSeq_ensure_length(struct TSeq *self,RTI_INT32 length, RTI_INT32 max)
893 {
894  return TSeq_ensure_length_w_max(self,length,max,REDA_SEQUENCE_ELEMENT_ALLOC);
895 }
896 #endif
897 
898 #undef _ensure_length
899 #undef TSeq_ensure_length
900 #undef _ensure_length_w_max
901 #undef TSeq_ensure_length_w_max
902 #endif /* TSeq_ensure_length */
903 
904 #ifdef TSeq_from_array
905 #undef TSeq_from_array
906 #define _from_array(TSeq) concatenate(TSeq, _from_array)
907 #define TSeq_from_array _from_array(TSeq)
908 REDADllExport RTI_BOOL
909 #ifndef TSeq_isCDRStringType
910 TSeq_from_array(struct TSeq *self, const T elv[], RTI_INT32 length)
911 #else
912 #ifdef TSeq_isCDRStringType_no_max
913 TSeq_from_array(struct TSeq *self, const T elv[], RTI_INT32 length,RTI_INT32 max_str_length)
914 #else
915 #undef TSeq_from_array_w_max
916 #define _from_array_w_max(TSeq) concatenate(TSeq, _from_array_w_max)
917 #define TSeq_from_array_w_max _from_array_w_max(TSeq)
918 TSeq_from_array_w_max(struct TSeq *self, const T elv[], RTI_INT32 length,RTI_INT32 max_str_length)
919 #endif
920 #endif
921 {
922 #ifdef RTI_CPP
923  struct TSeq elms_seq;
924 #else
925  struct TSeq elms_seq = REDA_DEFINE_EMPTY_SEQUENCE_INITIALIZER;
926 
927  if (!TSeq_initialize(&elms_seq))
928  {
929  return RTI_FALSE;
930  }
931 #endif
932 
933  OSAPI_PRECONDITION((self == NULL) || (length < 0),
934  return RTI_FALSE,
935  OSAPI_Log_entry_add_pointer("self",self,RTI_FALSE);
936  OSAPI_Log_entry_add_int("length",length,RTI_TRUE););
937 
938  /* Loan the array to a local sequence on the stack */
939  if (!TSeq_loan_contiguous(&elms_seq, (T*)elv, length, length))
940  {
941  return RTI_FALSE;
942  }
943 
944  /* Copy into this sequence, resizing if necessary */
945 #ifndef TSeq_isCDRStringType
946  if (TSeq_copy(self, &elms_seq) == NULL)
947 #elif defined(TSeq_isCDRStringType_no_max)
948  if (TSeq_copy(self, &elms_seq,(RTI_UINT32)max_str_length) == NULL)
949 #else
950  if (TSeq_copy_w_max(self, &elms_seq,(RTI_UINT32)max_str_length) == NULL)
951 #endif
952  {
953  return RTI_FALSE;
954  }
955 
956  /* Unloan the array from the local sequence on the stack */
957  TSeq_unloan(&elms_seq);
958 
959  return RTI_TRUE;
960 }
961 
962 #if defined(TSeq_isCDRStringType) && !defined(TSeq_isCDRStringType_no_max)
963 REDADllExport RTI_BOOL
964 TSeq_from_array(struct TSeq *self, const T elv[], RTI_INT32 length)
965 {
966  return TSeq_from_array_w_max(self,elv,length,REDA_SEQUENCE_ELEMENT_ALLOC);
967 }
968 #endif
969 
970 #undef _from_array
971 #undef TSeq_from_array
972 #undef _from_array_w_max
973 #undef TSeq_from_array_w_max
974 
975 #endif /* TSeq_from_array */
976 
977 #ifdef TSeq_to_array
978 #undef TSeq_to_array
979 #define _to_array(TSeq) concatenate(TSeq, _to_array)
980 #define TSeq_to_array _to_array(TSeq)
981 REDADllExport RTI_BOOL
982 #ifndef TSeq_isCDRStringType
983 TSeq_to_array(struct TSeq *self,T elv[], RTI_INT32 length)
984 #else
985 #ifdef TSeq_isCDRStringType_no_max
986 TSeq_to_array(struct TSeq *self,T elv[], RTI_INT32 length,RTI_INT32 max_str_length)
987 #else
988 #undef TSeq_to_array_w_max
989 #define _to_array_w_max(TSeq) concatenate(TSeq, _to_array_w_max)
990 #define TSeq_to_array_w_max _to_array_w_max(TSeq)
991 TSeq_to_array_w_max(struct TSeq *self,T elv[], RTI_INT32 length,RTI_INT32 max_str_length)
992 #endif
993 #endif
994 {
995 #ifdef RTI_CPP
996  struct TSeq elms_seq;
997 #else
998  struct TSeq elms_seq = REDA_DEFINE_EMPTY_SEQUENCE_INITIALIZER;
999 
1000  if (!TSeq_initialize(&elms_seq))
1001  {
1002  return RTI_FALSE;
1003  }
1004 #endif
1005 
1006  OSAPI_PRECONDITION((self == NULL) || (length < 0),
1007  return RTI_FALSE,
1008  OSAPI_Log_entry_add_pointer("self",self,RTI_FALSE);
1009  OSAPI_Log_entry_add_int("length",length,RTI_TRUE););
1010 
1011  /* Loan the array to a local sequence on the stack */
1012  if (!TSeq_loan_contiguous(&elms_seq, (T*)elv, length, length))
1013  {
1014  return RTI_FALSE;
1015  }
1016 
1017  /* Copy into this sequence, resizing if necessary */
1018 #ifndef TSeq_isCDRStringType
1019  if (TSeq_copy(&elms_seq,self) == NULL)
1020 #elif defined(TSeq_isCDRStringType_no_max)
1021  if (TSeq_copy(&elms_seq,self,(RTI_UINT32)max_str_length) == NULL)
1022 #else
1023  if (TSeq_copy_w_max(&elms_seq,self,(RTI_UINT32)max_str_length) == NULL)
1024 #endif
1025  {
1026  return RTI_FALSE;
1027  }
1028 
1029  /* Unloan the array from the local sequence on the stack */
1030  TSeq_unloan(&elms_seq);
1031 
1032  return RTI_TRUE;
1033 }
1034 
1035 #if defined(TSeq_isCDRStringType) && !defined(TSeq_isCDRStringType_no_max)
1036 REDADllExport RTI_BOOL
1037 TSeq_to_array(struct TSeq *self,T elv[], RTI_INT32 length)
1038 {
1039  return TSeq_to_array_w_max(self,elv,length,REDA_SEQUENCE_ELEMENT_ALLOC);
1040 }
1041 #endif
1042 
1043 #undef _to_array
1044 #undef TSeq_to_array
1045 #undef _to_array_w_max
1046 #undef TSeq_to_array_w_max
1047 #endif /* TSeq_from_array */
1048 
1049 #undef _map
1050 #undef TSeq_map
1051 #undef _map_w_length
1052 #undef TSeq_map_w_length
1053 #undef concatenate
1054 #undef REDA_SEQUENCE_API
1055 #undef T
1056 #undef TSeq
1057 #undef TSeq_isCDRStringType
1058 #undef TSeq_isCDRStringType_no_max
1059 #undef T_initialize
1060 #undef T_finalize
1061 #undef T_copy
1062 #undef T_compare
1063 #undef REDA_SEQUENCE_USER_API
1064 #undef _set_length
1065 #undef TSeq_set_length
1066 #undef _set_maximum
1067 #undef _set_maximum_w_max
1068 #undef TSeq_set_maximum
1069 #undef TSeq_set_maximum_w_max
1070 #undef _get_maximum
1071 #undef TSeq_get_maximum
1072 #undef _copy
1073 #undef TSeq_copy
1074 #undef _copy_w_max
1075 #undef TSeq_copy_w_max
1076 #undef _loan_discontiguous
1077 #undef TSeq_loan_discontiguous
1078 #undef _unloan
1079 #undef TSeq_unloan
1080 #undef _loan_contiguous
1081 #undef TSeq_loan_contiguous
1082 #undef _has_ownership
1083 #undef TSeq_has_ownership
1084 #undef _initialize
1085 #undef TSeq_initialize
1086 #undef TSeq_isCDRCharStringType
1087 

RTI Connext DDS Micro Version 2.4.11 Copyright © Mon Jul 23 2018 Real-Time Innovations, Inc