31 namespace RobotRaconteur
36 class ROBOTRACONTEUR_CORE_API StructureStub
39 virtual RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackStructure(
const RR_INTRUSIVE_PTR<RRValue>& s) = 0;
41 virtual RR_INTRUSIVE_PTR<RRStructure> UnpackStructure(
42 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& m) = 0;
44 StructureStub(
const RR_SHARED_PTR<RobotRaconteurNode>& node);
46 RR_SHARED_PTR<RobotRaconteurNode> GetNode();
47 RR_SHARED_PTR<RobotRaconteurNode> RRGetNode() {
return GetNode(); }
48 RR_WEAK_PTR<RobotRaconteurNode> RRGetNodeWeak() {
return node; }
50 virtual ~StructureStub() {}
53 RR_WEAK_PTR<RobotRaconteurNode> node;
61 BOOST_STATIC_ASSERT(
sizeof(T) == -1);
82 template <
typename T,
size_t N,
bool varlength>
91 typename boost::array<T, N>::iterator end() {
return boost::array<T, N>::elems + len; }
92 typename boost::array<T, N>::const_iterator end()
const {
return boost::array<T, N>::elems + len; }
93 typename boost::array<T, N>::const_iterator cend()
const {
return boost::array<T, N>::elems + len; }
98 throw std::out_of_range(
"requested size exceeds array max size");
102 void clear() { resize(0); }
103 size_t size()
const {
return len; }
104 size_t max_size()
const {
return N; }
105 typename boost::array<T, N>::reference at(
size_t i) {
return rangecheck(i), boost::array<T, N>::elems[i]; }
106 typename boost::array<T, N>::const_reference at(
size_t i)
const
108 return rangecheck(i), boost::array<T, N>::elems[i];
110 typename boost::array<T, N>::reference back() {
return at(size() - 1); }
111 typename boost::array<T, N>::const_reference back()
const {
return at(size() - 1); }
112 template <
typename T2>
115 std::copy(rhs.begin(), rhs.end(), boost::array<T, N>::begin());
116 this->len = rhs->len;
119 bool rangecheck(
size_t i)
const
121 return i > size() ? boost::throw_exception(std::out_of_range(
"array<>: index out of range")), true :
true;
125 template <
typename T,
size_t N>
129 void resize(
size_t n)
132 throw std::out_of_range(
"requested size does not match fixed array size");
134 size_t max_size() {
return N; }
137 template <
typename T,
size_t N,
bool varlength>
138 RR_INTRUSIVE_PTR<RRArray<T> > pod_field_array_ToRRArray(
const pod_field_array<T, N, varlength>& i)
140 return AttachRRArrayCopy<T>(&i[0], i.size());
143 template <
typename T,
size_t N,
bool varlength>
144 void RRArrayTo_pod_field_array(pod_field_array<T, N, varlength>& v,
const RR_INTRUSIVE_PTR<RRArray<T> >& i)
147 throw NullValueException(
"Pod array must not be null");
149 memcpy(&v[0], i->data(),
sizeof(T) * i->size());
153 #define RRPodStubNumberType(type) \
155 class PodStub<type> \
158 template <typename U> \
159 static void PackField(const type& v, MessageStringRef name, U& out) \
161 out.push_back(CreateMessageElement(name, ScalarToRRArray<type>(v))); \
164 template <typename U> \
165 static void UnpackField(type& v, MessageStringRef name, U& in) \
167 v = RRArrayToScalar<type>(MessageElement::FindElement(in, name)->template CastData<RRArray<type> >()); \
171 template <size_t N, bool varlength> \
172 class PodStub<pod_field_array<type, N, varlength> > \
175 template <typename U> \
176 static void PackField(const pod_field_array<type, N, varlength>& v, MessageStringRef name, U& out) \
178 out.push_back(CreateMessageElement(name, pod_field_array_ToRRArray(v))); \
181 template <typename U> \
182 static void UnpackField(pod_field_array<type, N, varlength>& v, MessageStringRef name, U& in) \
184 RR_INTRUSIVE_PTR<RRArray<type> > a = \
185 MessageElement::FindElement(in, name)->template CastData<RRArray<type> >(); \
186 RRArrayTo_pod_field_array(v, a); \
191 RRPodStubNumberType(
double);
192 RRPodStubNumberType(
float);
193 RRPodStubNumberType(int8_t);
194 RRPodStubNumberType(uint8_t);
195 RRPodStubNumberType(int16_t);
196 RRPodStubNumberType(uint16_t);
197 RRPodStubNumberType(int32_t);
198 RRPodStubNumberType(uint32_t);
199 RRPodStubNumberType(int64_t);
200 RRPodStubNumberType(uint64_t);
202 template <
typename T,
size_t N,
bool varlength>
203 RR_INTRUSIVE_PTR<RRNamedArray<T> > pod_field_array_ToRRNamedArray(
const pod_field_array<T, N, varlength>& i)
205 typedef typename RRPrimUtil<T>::ElementArrayType element_type;
206 typename RR_INTRUSIVE_PTR<RRArray<element_type> > a = AttachRRArrayCopy<element_type>(
207 reinterpret_cast<const element_type*
>(&i[0]), i.size() * RRPrimUtil<T>::GetElementArrayCount());
208 return new RRNamedArray<T>(a);
211 template <
typename T,
size_t N,
bool varlength>
212 void RRNamedArrayTo_pod_field_array(pod_field_array<T, N, varlength>& v,
const RR_INTRUSIVE_PTR<RRNamedArray<T> >& i)
215 throw NullValueException(
"Pod array must not be null");
217 memcpy(&v[0], i->GetNumericArray()->data(),
sizeof(T) * i->size());
221 #define RRPodStubNamedArrayType(type) \
223 class PodStub<type> \
226 template <typename U> \
227 static void PackField(const type& v, MessageStringRef name, U& out) \
229 std::vector<RR_INTRUSIVE_PTR<MessageElement> > v1; \
230 v1.push_back(CreateMessageElement("array", ScalarToRRNamedArray<type>(v)->GetNumericArray())); \
231 out.push_back(CreateMessageElement( \
232 name, CreateMessageElementNestedElementList(DataTypes_namedarray_array_t, \
233 RRPrimUtil<type>::GetElementTypeString(), RR_MOVE(v1)))); \
236 template <typename U> \
237 static void UnpackField(type& v, MessageStringRef name, U& in) \
239 typedef typename RRPrimUtil<type>::ElementArrayType element_type; \
240 RR_INTRUSIVE_PTR<MessageElementNestedElementList> m = \
241 MessageElement::FindElement(in, name)->CastDataToNestedList(DataTypes_namedarray_array_t); \
242 if (m->TypeName != RRPrimUtil<type>::GetElementTypeString()) \
243 throw DataTypeException("Invalid namedarray"); \
244 RR_INTRUSIVE_PTR<RRArray<element_type> > a = \
245 MessageElement::FindElement(m->Elements, "array")->CastData<RRArray<element_type> >(); \
246 if (a->size() != RRPrimUtil<type>::GetElementArrayCount()) \
247 throw DataTypeException("Invalid namedarray"); \
248 memcpy(&v, a->void_ptr(), sizeof(v)); \
252 template <size_t N, bool varlength> \
253 class PodStub<pod_field_array<type, N, varlength> > \
256 template <typename U> \
257 static void PackField(const pod_field_array<type, N, varlength>& v, MessageStringRef name, U& out) \
259 RR_INTRUSIVE_PTR<RRNamedArray<type> > a = pod_field_array_ToRRNamedArray(v); \
260 std::vector<RR_INTRUSIVE_PTR<MessageElement> > a1; \
261 a1.push_back(CreateMessageElement("array", a->GetNumericArray())); \
262 out.push_back(CreateMessageElement( \
263 name, CreateMessageElementNestedElementList(DataTypes_namedarray_array_t, \
264 RRPrimUtil<type>::GetElementTypeString(), RR_MOVE(a1)))); \
267 template <typename U> \
268 static void UnpackField(pod_field_array<type, N, varlength>& v, MessageStringRef name, U& in) \
270 typedef RRPrimUtil<type>::ElementArrayType element_type; \
271 RR_INTRUSIVE_PTR<MessageElementNestedElementList> a = \
272 MessageElement::FindElement(in, name)->CastDataToNestedList(DataTypes_namedarray_array_t); \
273 RR_INTRUSIVE_PTR<RRArray<element_type> > a1 = \
274 MessageElement::FindElement(a->Elements, "array")->template CastData<RRArray<element_type> >(); \
275 v.resize(a1->size() / RRPrimUtil<type>::GetElementArrayCount()); \
276 memcpy(&v, a1->data(), a1->size() * sizeof(element_type)); \
280 template <
typename T,
size_t N,
bool varlength>
281 class PodStub<pod_field_array<T, N, varlength> >
284 template <
typename U>
285 static void PackField(
const pod_field_array<T, N, varlength>& v, MessageStringRef name, U& out)
287 std::vector<RR_INTRUSIVE_PTR<MessageElement> > o;
289 for (
size_t j = 0; j < v.size(); j++)
291 RR_INTRUSIVE_PTR<MessageElement> m =
292 CreateMessageElement(boost::numeric_cast<int32_t>(j), PodStub<T>::PackToMessageElementPod(v[j]));
296 CreateMessageElement(name, CreateMessageElementNestedElementList(
297 DataTypes_pod_array_t, RRPrimUtil<T>::GetElementTypeString(), RR_MOVE(o))));
300 template <
typename U>
301 static void UnpackField(pod_field_array<T, N, varlength>& v, MessageStringRef name, U& in)
303 RR_INTRUSIVE_PTR<MessageElementNestedElementList> a =
304 MessageElement::FindElement(in, name)->CastDataToNestedList(DataTypes_pod_array_t);
306 throw NullValueException(
"Unexpected null array");
307 if (a->TypeName != RRPrimUtil<T>::GetElementTypeString())
308 throw DataTypeException(
"Pod data type mismatch");
310 v.resize(a->Elements.size());
311 for (int32_t i = 0; i < boost::numeric_cast<int32_t>(a->Elements.size()); i++)
313 RR_INTRUSIVE_PTR<MessageElement> m = a->Elements.at(i);
315 if (!MessageElement_GetElementNumber(m, key))
317 throw DataTypeException(
"Invalid pod array format");
321 throw DataTypeException(
"Invalid pod array format");
323 PodStub<T>::UnpackFromMessageElementPod(v[i], m->CastDataToNestedList());
328 template <
typename T,
typename U>
329 void PodStub_PackField(
const T& v, MessageStringRef name, U& out)
331 PodStub<T>::PackField(v, name, out);
334 template <
typename T,
typename U>
335 void PodStub_UnpackField(T& v, MessageStringRef name, U& out)
337 PodStub<T>::UnpackField(v, name, out);
340 template <
typename T>
341 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PodStub_PackPodToArray(
const T& v)
343 std::vector<RR_INTRUSIVE_PTR<MessageElement> > o;
345 RR_INTRUSIVE_PTR<MessageElement> m = CreateMessageElement(0, PodStub<T>::PackToMessageElementPod(v));
348 return CreateMessageElementNestedElementList(DataTypes_pod_array_t, RRPrimUtil<T>::GetElementTypeString(),
352 template <
typename T>
353 void PodStub_UnpackPodFromArray(T& v,
const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& a)
356 throw DataTypeException(
"Pod scalar array must not be null");
357 if (a->GetTypeID() != DataTypes_pod_array_t)
358 throw DataTypeMismatchException(
"Expected a pod array");
359 if (a->TypeName != RRPrimUtil<T>::GetElementTypeString())
360 throw DataTypeException(
"Pod data type mismatch");
361 if (a->Elements.size() != 1)
362 throw DataTypeException(
"Invalid pod scalar array format");
364 RR_INTRUSIVE_PTR<MessageElement> m = a->Elements.at(0);
366 if (!MessageElement_GetElementNumber(m, key))
368 throw DataTypeException(
"Invalid pod scalar array format");
372 throw DataTypeException(
"Invalid pod scalar array format");
374 PodStub<T>::UnpackFromMessageElementPod(v, m->CastDataToNestedList());
377 template <
typename T>
378 T PodStub_UnpackPodFromArray(
const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& a)
381 PodStub_UnpackPodFromArray<T>(v, a);
385 template <
typename T>
386 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PodStub_PackPodArray(
const RR_INTRUSIVE_PTR<RRPodArray<T> >& a)
389 return RR_INTRUSIVE_PTR<MessageElementNestedElementList>();
390 std::vector<RR_INTRUSIVE_PTR<MessageElement> > o;
391 o.reserve(a->size());
392 for (
size_t i = 0; i < a->size(); i++)
394 RR_INTRUSIVE_PTR<MessageElement> m =
395 CreateMessageElement(boost::numeric_cast<int32_t>(i), PodStub<T>::PackToMessageElementPod(a->at(i)));
398 return CreateMessageElementNestedElementList(DataTypes_pod_array_t, RRPrimUtil<T>::GetElementTypeString(),
402 template <
typename T>
403 RR_INTRUSIVE_PTR<RRPodArray<T> > PodStub_UnpackPodArray(
const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& a)
406 return RR_INTRUSIVE_PTR<RRPodArray<T> >();
408 throw DataTypeMismatchException(
"Expected pod array");
410 RR_INTRUSIVE_PTR<RRPodArray<T> > o = AllocateEmptyRRPodArray<T>(a->Elements.size());
411 for (
size_t i = 0; i < a->Elements.size(); i++)
413 RR_INTRUSIVE_PTR<MessageElement> m = a->Elements.at(i);
415 if (!MessageElement_GetElementNumber(m, key))
417 throw DataTypeException(
"Invalid pod array format");
421 throw DataTypeException(
"Invalid pod array format");
422 PodStub<T>::UnpackFromMessageElementPod(o->at(i), m->CastDataToNestedList());
428 template <
typename T>
429 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PodStub_PackPodMultiDimArray(
430 const RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> >& a)
433 return RR_INTRUSIVE_PTR<MessageElementNestedElementList>();
435 std::vector<RR_INTRUSIVE_PTR<MessageElement> > m;
437 m.push_back(CreateMessageElement(
"dims", a->Dims));
439 throw NullValueException(
"Multidimarray array must not be null");
440 m.push_back(CreateMessageElement(
"array", PodStub_PackPodArray(a->PodArray)));
441 return CreateMessageElementNestedElementList(DataTypes_pod_multidimarray_t, RRPrimUtil<T>::GetElementTypeString(),
445 template <
typename T>
446 RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> > PodStub_UnpackPodMultiDimArray(
447 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& m)
450 return RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> >();
452 throw DataTypeMismatchException(
"Expected pod multidimarray message");
454 RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> > o = AllocateEmptyRRPodMultiDimArray<T>();
455 o->Dims = (MessageElement::FindElement(m->Elements,
"dims")->CastData<RRArray<uint32_t> >());
456 o->PodArray = PodStub_UnpackPodArray<T>(
457 MessageElement::FindElement(m->Elements,
"array")->CastDataToNestedList(DataTypes_pod_array_t));
459 throw NullValueException(
"Multidimarray array must not be null");
464 template <
typename T>
465 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackPodToArrayElement(MessageStringRef elementname,
const T& s)
467 return CreateMessageElement(elementname, PodStub_PackPodToArray(s));
470 template <
typename T>
471 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackPodArrayElement(MessageStringRef elementname,
472 const RR_INTRUSIVE_PTR<RRPodArray<T> >& s)
475 throw NullValueException(
"Arrays must not be null");
476 return CreateMessageElement(elementname, PodStub_PackPodArray(s));
479 template <
typename T>
480 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackPodMultiDimArrayElement(
481 MessageStringRef elementname,
const RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> >& s)
484 throw NullValueException(
"Arrays must not be null");
485 return CreateMessageElement(elementname, PodStub_PackPodMultiDimArray(s));
489 template <
typename T>
490 T MessageElement_UnpackPodFromArray(
const RR_INTRUSIVE_PTR<MessageElement>& m)
492 return RobotRaconteur::PodStub_UnpackPodFromArray<T>(m->CastDataToNestedList(DataTypes_pod_array_t));
495 template <
typename T>
496 RR_INTRUSIVE_PTR<RRPodArray<T> > MessageElement_UnpackPodArray(
const RR_INTRUSIVE_PTR<MessageElement>& m)
498 RR_INTRUSIVE_PTR<RRPodArray<T> > a =
499 RobotRaconteur::PodStub_UnpackPodArray<T>(m->CastDataToNestedList(DataTypes_pod_array_t));
501 throw NullValueException(
"Arrays must not be null");
505 template <
typename T>
506 RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> > MessageElement_UnpackPodMultiDimArray(
507 const RR_INTRUSIVE_PTR<MessageElement>& m)
509 RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> > a =
510 RobotRaconteur::PodStub_UnpackPodMultiDimArray<T>(m->CastDataToNestedList(DataTypes_pod_multidimarray_t));
512 throw NullValueException(
"Arrays must not be null");
516 template <
typename T>
517 static RR_INTRUSIVE_PTR<RRPodArray<T> > VerifyRRArrayLength(
const RR_INTRUSIVE_PTR<RRPodArray<T> >& a,
size_t len,
521 throw NullValueException(
"Arrays must not be null");
524 if (varlength && (a->size() > len))
526 throw DataTypeException(
"Array dimension mismatch");
528 if (!varlength && (a->size() != len))
530 throw DataTypeException(
"Array dimension mismatch");
536 template <
size_t Ndims,
typename T>
537 static RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> > VerifyRRMultiDimArrayLength(
538 const RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> >& a,
size_t n_elems, boost::array<uint32_t, Ndims> dims)
541 throw NullValueException(
"Arrays must not be null");
543 if (a->Dims->size() != Ndims)
545 throw DataTypeException(
"Array dimension mismatch");
548 if (a->PodArray->size() != n_elems)
550 throw DataTypeException(
"Array dimension mismatch");
553 for (
size_t i = 0; i < Ndims; i++)
555 if ((*a->Dims)[i] != dims[i])
557 throw DataTypeException(
"Array dimension mismatch");
566 template <
typename T>
567 RR_INTRUSIVE_PTR<MessageElementNestedElementList> NamedArrayStub_PackNamedArrayToArray(
const T& v)
569 typedef typename RRPrimUtil<T>::ElementArrayType element_type;
570 RR_INTRUSIVE_PTR<RRArray<element_type> > a = AllocateRRArray<element_type>(RRPrimUtil<T>::GetElementArrayCount());
571 memcpy(a->void_ptr(), &v,
sizeof(T));
572 std::vector<RR_INTRUSIVE_PTR<MessageElement> > a1;
573 a1.push_back(CreateMessageElement(
"array", a));
574 return CreateMessageElementNestedElementList(DataTypes_namedarray_array_t, RRPrimUtil<T>::GetElementTypeString(),
578 template <
typename T>
579 void NamedArrayStub_UnpackNamedArrayFromArray(T& v,
const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& a)
581 typedef typename RRPrimUtil<T>::ElementArrayType element_type;
583 throw DataTypeException(
"NamedArray scalar array must not be null");
584 if (a->GetTypeID() != DataTypes_namedarray_array_t)
585 throw DataTypeMismatchException(
"Expected namedarray array message");
586 if (a->TypeName != RRPrimUtil<T>::GetElementTypeString())
587 throw DataTypeException(
"NamedArray data type mismatch");
588 if (a->Elements.size() != 1)
589 throw DataTypeException(
"Invalid namedarray array format");
590 typename RR_INTRUSIVE_PTR<RRArray<element_type> > a1 =
591 MessageElement::FindElement(a->Elements,
"array")->template CastData<RRArray<element_type> >();
592 if (a1->size() !=
sizeof(T) /
sizeof(element_type))
593 throw DataTypeException(
"Invalid scalar namedarray array format");
595 v = *(
static_cast<T*
>(a1->void_ptr()));
598 template <
typename T>
599 T NamedArrayStub_UnpackNamedArrayFromArray(
const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& a)
602 NamedArrayStub_UnpackNamedArrayFromArray(o, a);
606 template <
typename T>
607 RR_INTRUSIVE_PTR<MessageElementNestedElementList> NamedArrayStub_PackNamedArray(
608 const RR_INTRUSIVE_PTR<RRNamedArray<T> >& a)
611 return RR_INTRUSIVE_PTR<MessageElementNestedElementList>();
612 std::vector<RR_INTRUSIVE_PTR<MessageElement> > a1;
613 a1.push_back(CreateMessageElement(
"array", a->GetNumericArray()));
614 return CreateMessageElementNestedElementList(DataTypes_namedarray_array_t, RRPrimUtil<T>::GetElementTypeString(),
618 template <
typename T>
619 RR_INTRUSIVE_PTR<RRNamedArray<T> > NamedArrayStub_UnpackNamedArray(
620 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& a)
622 typedef typename RRPrimUtil<T>::ElementArrayType element_type;
624 return RR_INTRUSIVE_PTR<RRNamedArray<T> >();
626 throw DataTypeMismatchException(
"Expected namedarray array message");
627 if (a->TypeName != RRPrimUtil<T>::GetElementTypeString())
628 throw DataTypeException(
"Invalid namedarray type");
629 typename RR_INTRUSIVE_PTR<RRArray<element_type> > a2 =
630 MessageElement::FindElement(a->Elements,
"array")->CastData<RRArray<element_type> >();
631 return new RRNamedArray<T>(a2);
634 template <
typename T>
635 RR_INTRUSIVE_PTR<MessageElementNestedElementList> NamedArrayStub_PackNamedMultiDimArray(
636 const RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> >& a)
639 return RR_INTRUSIVE_PTR<MessageElementNestedElementList>();
641 std::vector<RR_INTRUSIVE_PTR<MessageElement> > m;
643 m.push_back(CreateMessageElement(
"dims", a->Dims));
645 throw NullValueException(
"Multidimarray array must not be null");
646 m.push_back(CreateMessageElement(
"array", NamedArrayStub_PackNamedArray(a->NamedArray)));
647 return CreateMessageElementNestedElementList(DataTypes_namedarray_multidimarray_t,
648 RRPrimUtil<T>::GetElementTypeString(), RR_MOVE(m));
651 template <
typename T>
652 RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> > NamedArrayStub_UnpackNamedMultiDimArray(
653 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& m)
656 return RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> >();
658 throw DataTypeMismatchException(
"Expected namedarray multidimarray message");
660 typename RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> > o = AllocateEmptyRRNamedMultiDimArray<T>();
661 o->Dims = (MessageElement::FindElement(m->Elements,
"dims")->CastData<RRArray<uint32_t> >());
662 o->NamedArray = NamedArrayStub_UnpackNamedArray<T>(
663 MessageElement::FindElement(m->Elements,
"array")->CastDataToNestedList(DataTypes_namedarray_array_t));
665 throw NullValueException(
"Multidimarray array must not be null");
670 template <
typename T>
671 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackNamedArrayToArrayElement(MessageStringRef elementname,
const T& s)
673 return CreateMessageElement(elementname, NamedArrayStub_PackNamedArrayToArray(s));
676 template <
typename T>
677 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackNamedArrayElement(MessageStringRef elementname,
678 const RR_INTRUSIVE_PTR<RRNamedArray<T> >& s)
681 throw NullValueException(
"Arrays must not be null");
682 return CreateMessageElement(elementname, NamedArrayStub_PackNamedArray(s));
685 template <
typename T>
686 RR_INTRUSIVE_PTR<MessageElement> MessageElement_PackNamedMultiDimArrayElement(
687 MessageStringRef elementname,
const RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> >& s)
690 throw NullValueException(
"Arrays must not be null");
691 return CreateMessageElement(elementname, NamedArrayStub_PackNamedMultiDimArray(s));
695 template <
typename T>
696 T MessageElement_UnpackNamedArrayFromArray(
const RR_INTRUSIVE_PTR<MessageElement>& m)
698 return RobotRaconteur::NamedArrayStub_UnpackNamedArrayFromArray<T>(
699 m->CastDataToNestedList(DataTypes_namedarray_array_t));
702 template <
typename T>
703 RR_INTRUSIVE_PTR<RRNamedArray<T> > MessageElement_UnpackNamedArray(
const RR_INTRUSIVE_PTR<MessageElement>& m)
705 RR_INTRUSIVE_PTR<RRNamedArray<T> > a =
706 RobotRaconteur::NamedArrayStub_UnpackNamedArray<T>(m->CastDataToNestedList(DataTypes_namedarray_array_t));
708 throw NullValueException(
"Arrays must not be null");
712 template <
typename T>
713 RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> > MessageElement_UnpackNamedMultiDimArray(
714 const RR_INTRUSIVE_PTR<MessageElement>& m)
716 RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> > a = RobotRaconteur::NamedArrayStub_UnpackNamedMultiDimArray<T>(
717 m->CastDataToNestedList(DataTypes_namedarray_multidimarray_t));
719 throw NullValueException(
"Arrays must not be null");
723 template <
typename T>
724 static RR_INTRUSIVE_PTR<RRNamedArray<T> > VerifyRRArrayLength(
const RR_INTRUSIVE_PTR<RRNamedArray<T> >& a,
size_t len,
728 throw NullValueException(
"Arrays must not be null");
731 if (varlength && (a->size() > len))
733 throw DataTypeException(
"Array dimension mismatch");
735 if (!varlength && (a->size() != len))
737 throw DataTypeException(
"Array dimension mismatch");
743 template <
size_t Ndims,
typename T>
744 static RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> > VerifyRRMultiDimArrayLength(
745 const RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> >& a,
size_t n_elems, boost::array<uint32_t, Ndims> dims)
748 throw NullValueException(
"Arrays must not be null");
750 if (a->Dims->size() != Ndims)
752 throw DataTypeException(
"Array dimension mismatch");
755 if (a->NamedArray->size() != n_elems)
757 throw DataTypeException(
"Array dimension mismatch");
760 for (
size_t i = 0; i < Ndims; i++)
762 if ((*a->Dims)[i] != dims[i])
764 throw DataTypeException(
"Array dimension mismatch");
@ DataTypes_pod_array_t
pod array type (nested message type)
Definition: RobotRaconteurConstants.h:90
@ DataTypes_namedarray_multidimarray_t
namedarray multidimarray type (nested message type)
Definition: RobotRaconteurConstants.h:102
@ DataTypes_namedarray_array_t
namedarray array type (nested message type)
Definition: RobotRaconteurConstants.h:100
@ DataTypes_pod_multidimarray_t
pod multidimarray type (nested message type)
Definition: RobotRaconteurConstants.h:92
Storage for pod array fields.
Definition: ServiceStructure.h:84