RTI Connext DDS Micro  Version 2.4.6
 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-2015 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  * 19may2015,as MICRO-1193 Refactoring of Sequence API levels
14  * 26mar2016,tk MICRO-1133 Changed how Seq_copy and Seq_set_maximum copied the
15  * source sequence data locally to avoid C++
16  * constructor/destructor problems
17  * 12mar2015,eh MICRO-1053/PR#13585 Remove string seq map() from CERT
18  * 27jan2015,tk MICRO-1014/PR#13358 Removed redundant code for CERT in _copy
19  * (The preallocated memory version)
20  * 01dec2014,tk MICRO-951/PR#12315 Removed redundant code for CERT in _copy
21  * 01dec2014,tk MICRO-949/PR#11856 Removed redundant code for CERT in set_maximum
22  * 04aug2014,tk MICRO-841 Only copy new_max elements if sequence is reduced
23  * 03jun2013,kaj MICRO-502 support for string sequences req. max string length
24  * 20apr2008,tk Written
25  */
26 /*ce
27  * \file
28  */
29 #include "reda/reda_sequence.h"
30 
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 #undef _initialize
216 #undef TSeq_initialize
217 #endif /* TSeq_initialize */
218 
219 #ifdef TSeq_finalize
220 #undef TSeq_finalize
221 #define _finalize(TSeq) concatenate(TSeq, _finalize)
222 #define TSeq_finalize _finalize(TSeq)
223 RTI_BOOL
224 TSeq_finalize(struct TSeq *self)
225 {
226 #ifdef T_finalize
227  RTI_BOOL result;
228  result = TSeq_map(self->_contiguous_buffer,T_finalize,0,self->_maximum-1);
229  if (!result)
230  {
231  return result;
232  }
233  return REDA_Sequence_finalize((struct REDA_Sequence*)self);
234 #else /* T_finalize */
235  return REDA_Sequence_finalize((struct REDA_Sequence*)self);
236 #endif /* T_finalize */
237 
238 #undef _finalize
239 #undef TSeq_finalize
240 }
241 #endif /* TSeq_finalize */
242 
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)
247 RTI_INT32
248 TSeq_get_maximum(const struct TSeq *self)
249 {
250  return REDA_Sequence_get_maximum((const struct REDA_Sequence *)self);
251 }
252 #endif /* TSeq_get_maximum */
253 
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
259 RTI_BOOL
260 TSeq_set_maximum(struct TSeq *self, RTI_INT32 new_max)
261 {
262 #ifdef T_initialize
263 #ifndef RTI_CERT
264  T* copy_buffer;
265  RTI_INT32 copy_length;
266  RTI_INT32 copy_max;
267 #endif
268  RTI_BOOL result;
269 #ifndef RTI_CERT
270  RTI_INT32 i;
271 #endif /* !RTI_CERT */
272 
273  OSAPI_PRECONDITION(self == NULL,
274  return RTI_FALSE,
275  OSAPI_Log_entry_add_pointer("self",self,RTI_TRUE);)
276 
277  self->_element_size = sizeof(T);
278 #ifndef RTI_CERT
279  copy_buffer = self->_contiguous_buffer;
280  copy_length = self->_length;
281  copy_max = self->_maximum;
282 #endif
283 
284  result = REDA_Sequence_set_maximum((struct REDA_Sequence*)self,
285  new_max,RTI_FALSE);
286  if (!result)
287  {
288  return result;
289  }
290 
291  result = TSeq_map(self->_contiguous_buffer,T_initialize,0,self->_maximum-1);
292  if (!result)
293  {
294  return result;
295  }
296 
297 #ifndef RTI_CERT
298  if (self->_length > 0)
299  {
300  /* If the sequence is reduced in size, only copy the first new_max elements
301  */
302  for (i = 0; i < (new_max < copy_length ? new_max : copy_length); ++i)
303  {
304  if (!T_copy(&self->_contiguous_buffer[i],(const T*)&copy_buffer[i]))
305  {
306  return RTI_FALSE;
307  }
308  }
309  }
310 
311  if (copy_buffer != NULL)
312  {
313  result = TSeq_map(copy_buffer,T_finalize,0,copy_max-1);
314  OSAPI_Heap_free_buffer(copy_buffer);
315  }
316 #endif /* !RTI_CERT */
317  return result;
318 #else /* T_initialize */
319  self->_element_size = sizeof(T);
320  return REDA_Sequence_set_maximum((struct REDA_Sequence*)self, new_max,RTI_TRUE);
321 #endif /* T_initialize */
322 }
323 #else /* TSeq_isCDRStringType */
324 RTI_BOOL
325 TSeq_set_maximum(struct TSeq *self, RTI_INT32 new_max, RTI_UINT32 max_str_len)
326 {
327  RTI_BOOL result;
328  RTI_INT32 old_max;
329 #ifndef RTI_CERT
330  T *copy_buffer;
331  RTI_INT32 i;
332 #endif
333 
334  OSAPI_PRECONDITION(self == NULL,
335  return RTI_FALSE,
336  OSAPI_Log_entry_add_pointer("self",self,RTI_TRUE);)
337 
338  self->_element_size = sizeof(T);
339  old_max = REDA_Sequence_get_maximum((const struct REDA_Sequence *)self);
340 
341  /* if not resizing seqeunce then we are done */
342  if (old_max == new_max)
343  {
344  return RTI_TRUE;
345  }
346 
347 #ifndef RTI_CERT
348  copy_buffer = self->_contiguous_buffer;
349 #endif
350 
351  /* cannot use copy content because it will free the contiquous buffer
352  without finalizing any discarded elements */
353  result = REDA_Sequence_set_maximum((struct REDA_Sequence*)self,
354  new_max,RTI_FALSE);
355  if (!result)
356  {
357  return result;
358  }
359 
360 #ifndef RTI_CERT
361  /* copy elements (string memory) from old buffer to new buffer */
362  for (i = 0; i < ((old_max < new_max) ? old_max : new_max); i++)
363  {
364  self->_contiguous_buffer[i] = copy_buffer[i];
365  }
366 #endif
367 
368  /* initialize (allocate) any added elements (from old_max to new_max-1)
369  * If old_max > new_max-1 then the map function does not do anything
370  */
371  result = TSeq_map_w_length(self->_contiguous_buffer,T_initialize,old_max,new_max-1,max_str_len);
372  if (!result)
373  {
374  return result;
375  }
376 
377 #ifndef RTI_CERT
378  /* since the pointers were copied from old seq to new seq,
379  only finalize members between new_max and old_max-1 */
380  if (copy_buffer != NULL)
381  {
382  result = TSeq_map(copy_buffer,T_finalize,new_max,old_max-1);
383  OSAPI_Heap_free_buffer(copy_buffer);
384  }
385 #endif /* !RTI_CERT */
386  return result;
387 }
388 #endif /* TSeq_isCDRStringType defined */
389 #endif /* TSeq_set_maximum */
390 
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)
395 RTI_INT32
396 TSeq_get_length(const struct TSeq *self)
397 {
398  return REDA_Sequence_get_length((const struct REDA_Sequence *)self);
399 
400 #undef _get_length
401 #undef TSeq_get_length
402 }
403 #endif /* TSeq_get_length */
404 
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)
409 RTI_BOOL
410 TSeq_set_length(struct TSeq *self, RTI_INT32 new_length)
411 {
412  return REDA_Sequence_set_length((struct REDA_Sequence *)self, new_length);
413 }
414 #endif /* TSeq_set_length */
415 
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)
420 T*
421 TSeq_get_reference(const struct TSeq *self, RTI_INT32 i)
422 {
423  return (T*)REDA_Sequence_get_reference((const struct REDA_Sequence*)self,i);
424 
425 #undef _get_reference
426 #undef TSeq_get_reference
427 }
428 #endif /* TSeq_get_reference */
429 
430 #ifdef TSeq_copy
431 #undef TSeq_copy
432 #define _copy(TSeq) concatenate(TSeq, _copy)
433 #define TSeq_copy _copy(TSeq)
434 #ifndef TSeq_isCDRStringType
435 struct TSeq*
436 TSeq_copy(struct TSeq *self, const struct TSeq *src)
437 {
438 #ifdef T_copy
439  RTI_BOOL result;
440  RTI_INT32 i;
441  T *copy_buffer;
442 #ifndef RTI_CERT
443  RTI_INT32 copy_max;
444 #endif
445 
446  OSAPI_PRECONDITION(self == NULL,
447  return NULL,
448  OSAPI_Log_entry_add_pointer("self",self,RTI_TRUE);)
449 
450  copy_buffer = self->_contiguous_buffer;
451  if (src->_element_size > 0)
452  {
453  self->_element_size = sizeof(T);
454  }
455 #ifndef RTI_CERT
456  copy_max = self->_maximum;
457 #endif
458 
459  /* replaces contiguous buffer if self->max < src->size */
460  if (REDA_Sequence_copy((struct REDA_Sequence *)self,
461  (const struct REDA_Sequence *)src,
462  RTI_FALSE) == NULL)
463  {
464  return NULL;
465  }
466 
467  /* if replaced contiguous buffer then initialize new members */
468  if (self->_contiguous_buffer != copy_buffer)
469  {
470  result = TSeq_map(self->_contiguous_buffer,T_initialize,0,self->_maximum-1);
471  if (!result)
472  {
473  return NULL;
474  }
475  }
476 
477  /* copy content from source elements to destination elements */
478  for (i = 0; i < src->_length; i++)
479  {
480  if (!T_copy(&self->_contiguous_buffer[i],
481  (const T*) &src->_contiguous_buffer[i]))
482  {
483  return NULL;
484  }
485  }
486 
487 #ifndef RTI_CERT
488  /* If replaced contiguous buffer then finalize old new members
489  * and free old contiguous buffer
490  */
491  if ((copy_buffer != NULL) &&
492  (copy_buffer != self->_contiguous_buffer))
493  {
494  result = TSeq_map(copy_buffer,T_finalize,0,copy_max-1);
495  if (!result)
496  {
497  return NULL;
498  }
499  OSAPI_Heap_free_buffer(copy_buffer);
500  }
501 #endif /* !RTI_CERT */
502 
503  return self;
504 #else /* T_copy */
505  if (src->_element_size > 0)
506  {
507  self->_element_size = sizeof(T);
508  }
509  return (struct TSeq*)REDA_Sequence_copy((struct REDA_Sequence *)self,
510  (const struct REDA_Sequence *)src,
511  RTI_TRUE);
512 #endif /* T_copy */
513 }
514 #else /* TSeq_isCDRStringType defined, which requires T_copy defined */
515 struct TSeq*
516 TSeq_copy(struct TSeq *self, const struct TSeq *src, RTI_UINT32 max_str_len)
517 {
518  RTI_BOOL result;
519  RTI_INT32 i;
520  T *copy_buffer;
521 #ifndef RTI_CERT
522  RTI_INT32 copy_max;
523 #endif
524 
525  OSAPI_PRECONDITION(self == NULL,
526  return NULL,
527  OSAPI_Log_entry_add_pointer("self",self,RTI_TRUE);)
528 
529  copy_buffer = self->_contiguous_buffer;
530  if (src->_element_size > 0)
531  {
532  self->_element_size = sizeof(T);
533  }
534 #ifndef RTI_CERT
535  copy_max = self->_maximum;
536 #endif
537 
538  /* replaces contiguous buffer if self->max < src->size */
539  if (REDA_Sequence_copy((struct REDA_Sequence *)self,
540  (const struct REDA_Sequence *)src,
541  RTI_FALSE) == NULL)
542  {
543  return NULL;
544  }
545 
546  /* if replaced contiguous buffer then copy existing dest string buffers
547  * from old contiguous buffer to new dest contiguous buffer,
548  * and initialize (allocate string buffers) for new members added
549  */
550  if (self->_contiguous_buffer != copy_buffer)
551  {
552 #ifndef RTI_CERT
553  for (i = 0; i < copy_max; i++)
554  {
555  self->_contiguous_buffer[i] = copy_buffer[i];
556  }
557  /* initialize (allocate) any added elements (from old_max to new_max-1)
558  * If old_max > new_max-1 then the map function does not do anything
559  */
560  result = TSeq_map_w_length(self->_contiguous_buffer,T_initialize,copy_max,self->_maximum-1,max_str_len);
561 #else
562  /* For RTI_CERT (self->_contiguous_buffer != copy_buffer) is true only
563  * when copy_buffer was NULL, so there is no need for copying elements,
564  * but we need to initialize all the elements in the (new) buffer.
565  */
566  result = TSeq_map_w_length(self->_contiguous_buffer,T_initialize,0,self->_maximum-1,max_str_len);
567 #endif
568  if (!result)
569  {
570  return NULL;
571  }
572  }
573 
574  /* copy content from source to destination */
575  for (i = 0; i < src->_length; i++)
576  {
577  if (!T_copy(&self->_contiguous_buffer[i],
578  (const T*) &src->_contiguous_buffer[i],
579  max_str_len))
580  {
581  return NULL;
582  }
583  }
584 
585 #ifndef RTI_CERT
586  /* if replaced contiguous buffer then free old contiguous buffer (do not
587  finalize string buffers since were transfered to new contiguous buffer */
588  if ((copy_buffer != NULL) && (copy_buffer != self->_contiguous_buffer))
589  {
590  OSAPI_Heap_free_buffer(copy_buffer);
591  }
592 #endif /* !RTI_CERT */
593 
594  return self;
595 }
596 #endif /* TSeq_isCDRStringType*/
597 #endif /* TSeq_copy */
598 
599 #ifdef TSeq_is_equal
600 #undef TSeq_is_equal
601 #define _is_equal(TSeq) concatenate(TSeq, _is_equal)
602 #define TSeq_is_equal _is_equal(TSeq)
603 RTI_BOOL
604 TSeq_is_equal(const struct TSeq *left, const struct TSeq *right)
605 {
606 #ifdef T_compare
607  RTI_INT32 i;
608  RTI_BOOL result;
609 
610  result = REDA_Sequence_is_equal((const struct REDA_Sequence*)left,
611  (const struct REDA_Sequence*)right,RTI_FALSE);
612  if (!result)
613  {
614  return result;
615  }
616 
617  for (i = 0; i < left->_length; i++)
618  {
619  if (T_compare((const T*)&left->_contiguous_buffer[i],
620  (const T*)&right->_contiguous_buffer[i]))
621  {
622  return RTI_FALSE;
623  }
624  }
625 
626  return RTI_TRUE;
627 #else /* T_compare */
628  return REDA_Sequence_is_equal((const struct REDA_Sequence *)left,
629  (const struct REDA_Sequence *)right,RTI_TRUE);
630 #endif /* T_compare */
631 #undef _is_equal
632 #undef TSeq_is_equal
633 }
634 #endif /* TSeq_is_equal */
635 
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)
640 RTI_BOOL
641 TSeq_loan_contiguous(struct TSeq *self, void *buffer,
642  RTI_INT32 new_length, RTI_INT32 new_max)
643 {
644  return REDA_Sequence_loan_contiguous(
645  (struct REDA_Sequence *)self, buffer, new_length, new_max);
646 }
647 #endif /* TSeq_loan_contiguous */
648 
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)
653 RTI_BOOL
654 TSeq_loan_discontiguous(struct TSeq *self, void *buffer,
655  RTI_INT32 new_length, RTI_INT32 new_max)
656 {
657  return REDA_Sequence_loan_discontiguous(
658  (struct REDA_Sequence *)self, buffer, new_length, new_max);
659 }
660 #endif /* TSeq_loan_discontiguous */
661 
662 
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)
667 RTI_BOOL
668 TSeq_has_ownership(const struct TSeq *self)
669 {
670  return REDA_Sequence_has_ownership((const struct REDA_Sequence *)self);
671 }
672 #endif /* TSeq_has_ownership */
673 
674 
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)
679 RTI_BOOL
680 TSeq_has_discontiguous_buffer(const struct TSeq *self)
681 {
682  return REDA_Sequence_has_discontiguous_buffer(
683  (const struct REDA_Sequence *)self);
684 }
685 
686 #undef _has_discontiguous_buffer
687 #undef TSeq_has_discontiguous_buffer
688 #endif /* TSeq_has_discontiguous_buffer */
689 
690 
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)
695 T*
696 TSeq_get_contiguous_buffer(const struct TSeq *self)
697 {
698  return (T*)REDA_Sequence_get_buffer((const struct REDA_Sequence *)self);
699 }
700 #undef _get_contiguous_buffer
701 #undef TSeq_get_contiguous_buffer
702 #endif /* TSeq_get_buffer */
703 
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)
708 T*
709 TSeq_get_discontiguous_buffer(const struct TSeq *self)
710 {
711  return (T*)REDA_Sequence_get_buffer((const struct REDA_Sequence *)self);
712 }
713 #undef _get_discontiguous_buffer
714 #undef TSeq_get_discontiguous_buffer
715 #endif /* TSeq_get_discontiguous_buffer */
716 
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)
721 RTI_BOOL
722 TSeq_set_contiguous_buffer(struct TSeq *self, T *buffer)
723 {
724  return REDA_Sequence_set_buffer((struct REDA_Sequence *)self,
725  (void *)buffer);
726 }
727 #undef _set_contiguous_buffer
728 #undef TSeq_set_contiguous_buffer
729 #endif /* TSeq_set_buffer */
730 
731 
732 #ifdef TSeq_unloan
733 #undef TSeq_unloan
734 #define _unloan(TSeq) concatenate(TSeq, _unloan)
735 #define TSeq_unloan _unloan(TSeq)
736 RTI_BOOL
737 TSeq_unloan(struct TSeq *self)
738 {
739  return REDA_Sequence_unloan((struct REDA_Sequence *)self);
740 }
741 #endif /* TSeq_unloan */
742 
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)
747 void
748 TSeq_set_token(struct TSeq *self,void *token1,void *token2)
749 {
750  REDA_Sequence_set_token((struct REDA_Sequence *)self,token1,token2);
751 }
752 #undef _set_token
753 #undef TSeq_set_token
754 #endif /* TSeq_set_token */
755 
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)
760 void
761 TSeq_get_token(struct TSeq *self,void **token1,void **token2)
762 {
763  REDA_Sequence_get_token((struct REDA_Sequence *)self,token1,token2);
764 }
765 #undef _get_token
766 #undef TSeq_get_token
767 #endif /* TSeq_get_token */
768 
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)
773 RTI_BOOL
774 #ifndef TSeq_isCDRStringType
775 TSeq_ensure_length(struct TSeq *self,RTI_INT32 length, RTI_INT32 max)
776 #else
777 TSeq_ensure_length(struct TSeq *self,RTI_INT32 length, RTI_INT32 max,
778  RTI_INT32 max_str_len)
779 #endif
780 {
781  OSAPI_PRECONDITION((self == NULL) || (length > max) ||
782  (length < 0) || (max < 0),
783  return RTI_FALSE,
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);)
787 
788  if (!TSeq_has_ownership(self))
789  {
790  return RTI_FALSE;
791  }
792 
793  if (length > TSeq_get_maximum(self))
794  {
795 #ifndef TSeq_isCDRStringType
796  if (!TSeq_set_maximum(self, max))
797 #else
798  if (!TSeq_set_maximum(self, max,max_str_len))
799 #endif
800  {
801  return RTI_FALSE;
802  }
803  }
804 
805  return TSeq_set_length(self, length);
806 }
807 #undef _ensure_length
808 #undef TSeq_ensure_length
809 #endif /* TSeq_ensure_length */
810 
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)
815 REDADllExport RTI_BOOL
816 #ifndef TSeq_isCDRStringType
817 TSeq_from_array(struct TSeq *self, const T elv[], RTI_INT32 length)
818 #else
819 TSeq_from_array(struct TSeq *self, const T elv[], RTI_INT32 length,RTI_INT32 max_str_length)
820 #endif
821 {
822 #ifdef RTI_CPP
823  struct TSeq elms_seq;
824 #else
825  struct TSeq elms_seq = REDA_DEFINE_EMPTY_SEQUENCE_INITIALIZER;
826 #endif
827 
828  OSAPI_PRECONDITION((self == NULL) || (length < 0),
829  return RTI_FALSE,
830  OSAPI_Log_entry_add_pointer("self",self,RTI_FALSE);
831  OSAPI_Log_entry_add_int("length",length,RTI_TRUE););
832 
833  /* Loan the array to a local sequence on the stack */
834  if (!TSeq_loan_contiguous(&elms_seq, (T*)elv, length, length))
835  {
836  return RTI_FALSE;
837  }
838 
839  /* Copy into this sequence, resizing if necessary */
840 #ifndef TSeq_isCDRStringType
841  if (TSeq_copy(self, &elms_seq) == NULL)
842 #else
843  if (TSeq_copy(self, &elms_seq,max_str_length) == NULL)
844 #endif
845  {
846  return RTI_FALSE;
847  }
848 
849  /* Unloan the array from the local sequence on the stack */
850  TSeq_unloan(&elms_seq);
851 
852  return RTI_TRUE;
853 }
854 #undef _from_array
855 #undef TSeq_from_array
856 #endif /* TSeq_from_array */
857 
858 #ifdef TSeq_to_array
859 #undef TSeq_to_array
860 #define _to_array(TSeq) concatenate(TSeq, _to_array)
861 #define TSeq_to_array _to_array(TSeq)
862 REDADllExport RTI_BOOL
863 #ifndef TSeq_isCDRStringType
864 TSeq_to_array(struct TSeq *self,T elv[], RTI_INT32 length)
865 #else
866 TSeq_to_array(struct TSeq *self,T elv[], RTI_INT32 length,RTI_INT32 max_str_length)
867 #endif
868 {
869 #ifdef RTI_CPP
870  struct TSeq elms_seq;
871 #else
872  struct TSeq elms_seq = REDA_DEFINE_EMPTY_SEQUENCE_INITIALIZER;
873 #endif
874 
875  OSAPI_PRECONDITION((self == NULL) || (length < 0),
876  return RTI_FALSE,
877  OSAPI_Log_entry_add_pointer("self",self,RTI_FALSE);
878  OSAPI_Log_entry_add_int("length",length,RTI_TRUE););
879 
880  /* Loan the array to a local sequence on the stack */
881  if (!TSeq_loan_contiguous(&elms_seq, (T*)elv, length, length))
882  {
883  return RTI_FALSE;
884  }
885 
886  /* Copy into this sequence, resizing if necessary */
887 #ifndef TSeq_isCDRStringType
888  if (TSeq_copy(&elms_seq,self) == NULL)
889 #else
890  if (TSeq_copy(&elms_seq,self,max_str_length) == NULL)
891 #endif
892  {
893  return RTI_FALSE;
894  }
895 
896  /* Unloan the array from the local sequence on the stack */
897  TSeq_unloan(&elms_seq);
898 
899  return RTI_TRUE;
900 }
901 #undef _to_array
902 #undef TSeq_to_array
903 #endif /* TSeq_from_array */
904 
905 #undef _map
906 #undef TSeq_map
907 #undef _map_w_length
908 #undef TSeq_map_w_length
909 #undef concatenate
910 #undef REDA_SEQUENCE_API
911 #undef T
912 #undef TSeq
913 #undef TSeq_isCDRStringType
914 #undef T_initialize
915 #undef T_finalize
916 #undef T_copy
917 #undef T_compare
918 #undef REDA_SEQUENCE_USER_API
919 #undef _set_length
920 #undef TSeq_set_length
921 #undef _set_maximum
922 #undef TSeq_set_maximum
923 #undef _get_maximum
924 #undef TSeq_get_maximum
925 #undef _copy
926 #undef TSeq_copy
927 #undef _loan_discontiguous
928 #undef TSeq_loan_discontiguous
929 #undef _unloan
930 #undef TSeq_unloan
931 #undef _loan_contiguous
932 #undef TSeq_loan_contiguous
933 #undef _has_ownership
934 #undef TSeq_has_ownership
935 

RTI Connext DDS Micro Version 2.4.6 Copyright © Sun Jan 24 2016 Real-Time Innovations, Inc