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

RTI Connext DDS Micro Version 2.4.9 Copyright © Thu Dec 15 2016 Real-Time Innovations, Inc