1 #ifndef OPENDDS_DCPS_SAFETYPROFILESEQUENCE_H 2 #define OPENDDS_DCPS_SAFETYPROFILESEQUENCE_H 19 namespace SafetyProfile {
34 return std::strcmp(lhs, rhs);
41 template <seq_
size_type N>
43 static const seq_size_type Bounds = N;
47 static const seq_size_type Bounds = INT_MAX;
50 template <
typename T,
typename Sequence,
typename Bounds>
53 template <
typename T,
typename Sequence, seq_
size_type N>
56 seq_size_type
maximum()
const {
return N; }
58 void replace(seq_size_type length, T* data, seq_flag_type release =
false)
64 T*
allocate(seq_size_type = N)
const {
return allocbuf(); }
68 template <
typename T,
typename Sequence>
70 static T* allocbuf(seq_size_type n);
71 seq_size_type
maximum()
const {
return maximum_; }
73 void replace(seq_size_type maximum, seq_size_type length,
74 T* data, seq_flag_type release =
false)
82 return allocbuf(request ? request : maximum_);
97 static const seq_size_type extra = 0;
99 static void construct(T*, seq_size_type, seq_flag_type) {}
100 static void copy_n(
const T* input, seq_size_type n, T* output);
101 static void move_n(T* in, seq_size_type n, T* out) { copy_n(in, n, out); }
103 static T*
destroy(T* buffer, seq_size_type) {
return buffer; }
109 template <
typename T>
114 static const seq_size_type extra = 1;
116 static void construct(T* buffer, seq_size_type n, seq_flag_type cookie);
117 static void copy_n(
const T* input, seq_size_type n, T* output);
118 static void move_n(T* in, seq_size_type n, T* out);
119 static void reset_n(T* buffer, seq_size_type n);
120 static T* destroy(T* buffer, seq_size_type n);
125 template <
typename CharT>
131 Element(CharT*& element, seq_flag_type release)
132 : element_(element), release_(release) {}
135 : element_(elt.element_), release_(elt.release_) {}
140 return move_from(tmp);
146 return move_from(tmp);
152 return move_from(tmp);
158 return move_from(tmp);
161 operator const CharT*()
const {
return element_; }
162 const CharT*
in()
const {
return element_; }
163 CharT*&
inout() {
return element_; }
173 CharT*
const tmp = element_;
182 element_ = rhs.
_retn();
204 static const seq_size_type extra = 1;
205 static void construct(CharT** buf, seq_size_type n, seq_flag_type cookie);
206 static void copy_n(
const CharT*
const* in, seq_size_type n, CharT** out);
207 static void move_n(CharT** in, seq_size_type n, CharT** out);
208 static void reset_n(CharT**, seq_size_type);
209 static CharT** destroy(CharT** buffer, seq_size_type n);
217 template <
typename Forany,
typename T =
typename Forany::_array_type>
222 static const seq_size_type extra =
225 static void construct(T* buffer, seq_size_type n, seq_flag_type use_cookie);
226 static void copy_n(
const T* input, seq_size_type n, T* output);
227 static void move_n(T* in, seq_size_type n, T* out) { copy_n(in, n, out); }
228 static void reset_n(T* buffer, seq_size_type n);
229 static T* destroy(T* buffer, seq_size_type n);
245 template <
typename T,
typename Bounds,
typename Elts = DefaultEltPolicy<T> >
247 :
public AllocPolicy<T, Sequence<T, Bounds, Elts>, Bounds>
255 explicit Sequence(size_type maximum = 0, size_type length = 0,
256 T* data = 0, seq_flag_type release =
false);
264 void length(size_type len);
265 size_type
length()
const {
return length_; }
274 ConstElement operator[](size_type idx)
const;
275 Element operator[](size_type idx);
277 seq_flag_type
release()
const {
return release_; }
279 T* get_buffer(seq_flag_type orphan =
false);
280 const ConstRawElement* get_buffer()
const;
283 static void freebuf(T* data);
301 const T*
begin()
const {
return buffer_; }
304 const T*
end()
const {
return buffer_ + length_; }
305 T*
end() {
return buffer_ + length_; }
310 size_type
size()
const {
return length_; }
312 bool empty()
const {
return !length_; }
316 void replace_i(size_type maximum, size_type length,
317 T* data, seq_flag_type release);
321 void lazy_alloc()
const;
331 template <
typename T,
typename Sequence, seq_
size_type N>
336 T*
const mem =
static_cast<T*
>(raw);
337 Sequence::ElementPolicy::construct(mem, N,
false);
341 template <
typename T,
typename Sequence>
344 const size_t bytes = (n + Sequence::ElementPolicy::extra) *
sizeof(T);
346 T*
const mem =
static_cast<T*
>(raw);
347 Sequence::ElementPolicy::construct(mem, n,
true);
348 return mem + Sequence::ElementPolicy::extra;
354 template <
typename T>
357 std::memcpy(out, in, n *
sizeof(T));
363 template <
typename CharT>
365 seq_flag_type use_cookie)
367 for (seq_size_type i = use_cookie; i < n + use_cookie; ++i) {
371 *
reinterpret_cast<seq_size_type*
>(buffer) = n;
375 template <
typename CharT>
377 seq_size_type n, CharT** out)
379 for (seq_size_type i = 0; i < n; ++i) {
385 template <
typename CharT>
389 for (seq_size_type i = 0; i < n; ++i) {
394 template <
typename CharT>
397 for (seq_size_type i = 0; i < n; ++i) {
403 template <
typename CharT>
405 seq_size_type n_or_int_max)
407 seq_size_type n = n_or_int_max;
408 CharT** allocated = buffer;
410 if (n_or_int_max == INT_MAX) {
411 allocated = buffer - 1;
412 n = *
reinterpret_cast<seq_size_type*
>(allocated);
415 for (seq_size_type i = 0; i < n; ++i) {
425 template <
typename T>
427 seq_flag_type use_cookie)
429 std::uninitialized_fill_n(buffer + use_cookie, n, T());
431 *
reinterpret_cast<seq_size_type*
>(buffer) = n;
435 template <
typename T>
441 template <
typename T>
444 std::swap_ranges(in, in + n, out);
447 template <
typename T>
450 std::fill_n(buffer, n, T());
453 template <
typename T>
456 seq_size_type n = n_or_int_max;
457 T* allocated = buffer;
459 if (n_or_int_max == INT_MAX) {
460 allocated = buffer - 1;
461 n = *
reinterpret_cast<seq_size_type*
>(allocated);
464 for (seq_size_type i = 0; i < n; ++i) {
474 template <
typename Forany,
typename T>
477 seq_flag_type use_cookie)
479 const seq_size_type start = use_cookie ? extra : 0;
480 for (seq_size_type i = start; i < n + start; ++i) {
484 *
reinterpret_cast<seq_size_type*
>(buffer) = n;
488 template <
typename Forany,
typename T>
492 for (seq_size_type i = 0; i < n; ++i) {
497 template <
typename Forany,
typename T>
500 for (seq_size_type i = 0; i < n; ++i) {
505 template <
typename Forany,
typename T>
508 seq_size_type num = n;
512 alloc = buffer - extra;
513 num = *
reinterpret_cast<seq_size_type*
>(alloc);
516 for (seq_size_type i = 0; i < num; ++i) {
526 template <
typename T,
typename Bounds,
typename Elts>
529 T* data, seq_flag_type release)
537 template <
typename T,
typename Bounds,
typename Elts>
549 template <
typename T,
typename Bounds,
typename Elts>
557 template <
typename T,
typename Bounds,
typename Elts>
566 template <
typename T,
typename Bounds,
typename Elts>
575 template <
typename T,
typename Bounds,
typename Elts>
577 size_type
length, T* data,
580 Sequence tmp(maximum, length, data, release);
584 template <
typename T,
typename Bounds,
typename Elts>
593 template <
typename T,
typename Bounds,
typename Elts>
596 if (len <= maximum()) {
607 Sequence tmp(len, len, allocate(len),
true);
612 template <
typename T,
typename Bounds,
typename Elts>
619 template <
typename T,
typename Bounds,
typename Elts>
626 template <
typename T,
typename Bounds,
typename Elts>
645 template <
typename T,
typename Bounds,
typename Elts>
653 template <
typename T,
typename Bounds,
typename Elts>
657 T*
const allocated = Elts::destroy(data, Bounds::Bounds);
661 template <
typename T,
typename Bounds,
typename Elts>
664 const size_type sz =
size();
665 if (sz != rhs.
size()) {
668 for (size_type i = 0; i < sz; ++i) {
669 if (!((*
this)[i] == rhs[i])) {
676 template <
typename T,
typename Bounds,
typename Elts>
679 return !(*
this == rhs);
static T & make_element(T &elt, seq_flag_type)
void swap(MessageBlock &lhs, MessageBlock &rhs)
static void construct(T *, seq_size_type, seq_flag_type)
T * allocate(seq_size_type=N) const
void replace(seq_size_type length, T *data, seq_flag_type release=false)
static CORBA::Char * alloc(CORBA::ULong len)
static void freebuf(T *data)
static CORBA::Char * empty()
static CharT ** destroy(CharT **buffer, seq_size_type n)
Elts::ConstElement ConstElement
seq_size_type max_size() const
static const seq_size_type Bounds
static T * destroy(T *buffer, seq_size_type)
static T * destroy(T *buffer, seq_size_type n)
char * string_alloc(ULong len)
static void construct(T *buffer, seq_size_type n, seq_flag_type cookie)
const CharT * ConstRawElement
static void reset_n(T *buffer, seq_size_type n)
Element(CharT *&element, seq_flag_type release)
bool operator==(const Sequence &rhs) const
Element(const Element &elt)
static void copy_n(const T *input, seq_size_type n, T *output)
virtual void free(void *ptr)=0
static void reset_n(T *, seq_size_type)
seq_flag_type release() const
static Element make_element(CharT *&elt, seq_flag_type release)
static void copy_n(const CharT *const *in, seq_size_type n, CharT **out)
Element & operator=(CharT *rhs)
bool operator==(const DisjointSequence::OrderedRanges< T > &a, const DisjointSequence::OrderedRanges< T > &b)
static int cmp(const CORBA::Char *lhs, const CORBA::Char *rhs)
static void reset_n(T *buffer, seq_size_type n)
static void move_n(T *in, seq_size_type n, T *out)
const ConstRawElement * get_buffer() const
void replace_i(size_type maximum, size_type length, T *data, seq_flag_type release)
char * string_dup(const char *)
bool operator!=(const Sequence &rhs) const
static void free(CORBA::Char *s)
std::ptrdiff_t difference_type
Class to serialize and deserialize data for DDS.
seq_size_type max_size() const
static CORBA::Char * dup(const CORBA::Char *s)
static ACE_Allocator * instance(void)
static void reset_n(CharT **, seq_size_type)
T * allocate(seq_size_type request=0) const
AllocPolicy(seq_size_type=N)
CORBA::ULong seq_size_type
CORBA::Boolean seq_flag_type
static void copy_n(const T *input, seq_size_type n, T *output)
size_t read_string(ACE_CDR::Char *&dest, StrAllocate str_alloc=0, StrFree str_free=0)
void replace(seq_size_type maximum, seq_size_type length, T *data, seq_flag_type release=false)
const T & const_reference
Elts::ConstRawElement ConstRawElement
character_type * _retn(void)
bool operator!=(const GUID_t &lhs, const GUID_t &rhs)
Sequence & operator=(const Sequence &seq)
static void construct(T *buffer, seq_size_type n, seq_flag_type use_cookie)
ConstElement operator[](size_type idx) const
seq_size_type maximum() const
static void copy_n(const T *input, seq_size_type n, T *output)
Element & operator=(const ::TAO::String_var< CharT > &rhs)
static void move_n(T *in, seq_size_type n, T *out)
static T & make_element(T &elt, seq_flag_type)
DDS::ReturnCode_t copy(DDS::DynamicData_ptr dest, DDS::DynamicData_ptr src)
const CharT * ConstElement
AllocPolicy(seq_size_type n=0)
static void construct(CharT **buf, seq_size_type n, seq_flag_type cookie)
static void move_n(CharT **in, seq_size_type n, CharT **out)
ACE_HANDLE dup(ACE_HANDLE handle)
Element & operator=(const CharT *rhs)
void swap(AllocPolicy &rhs)
static void move_n(T *in, seq_size_type n, T *out)
ConstElement const_subscript_type
static T * destroy(T *buffer, seq_size_type n)
seq_size_type maximum() const
Element & move_from(::TAO::String_var< CharT > &rhs)
static T & make_element(T &elt, seq_flag_type)
The Internal API and Implementation of OpenDDS.
Sequence(size_type maximum=0, size_type length=0, T *data=0, seq_flag_type release=false)
::TAO::String_out< CharT > out() const
virtual void * malloc(size_type nbytes)=0
Element & operator=(const ::TAO::String_Manager_T< CharT > &rhs)
friend bool operator>>(DCPS::Serializer &ser, Element elt)