Robot Raconteur Core C++ Library
Loading...
Searching...
No Matches
DataTypes.h
Go to the documentation of this file.
1
23
24#include <string>
25#include <vector>
26
27#include <stdint.h>
28#include <limits>
29#include <map>
30#include <deque>
31#include <list>
32
33#include <boost/array.hpp>
34#include <boost/tuple/tuple.hpp>
35
38
39#include <stdexcept>
40
42
43#ifdef ROBOTRACONTEUR_USE_SMALL_VECTOR
44#include <boost/container/small_vector.hpp>
45#endif
46
47#include <boost/asio/buffer.hpp>
48
49#include <boost/utility/value_init.hpp>
50#include <boost/container/static_vector.hpp>
51#include <boost/foreach.hpp>
52#include <boost/range/adaptor/map.hpp>
53#include <boost/range/numeric.hpp>
54
55#include <boost/smart_ptr/intrusive_ref_counter.hpp>
56
57#include <boost/numeric/conversion/cast.hpp>
58
59#include <boost/lexical_cast.hpp>
60
61#include <boost/utility/string_ref.hpp>
62
63#include <boost/variant.hpp>
64
65#include <boost/date_time/posix_time/ptime.hpp>
66#include "boost/date_time/posix_time/posix_time_types.hpp"
67
68#pragma once
69
70namespace RobotRaconteur
71{
77struct ROBOTRACONTEUR_CORE_API cdouble
78{
80 double real;
82 double imag;
84 cdouble() : real(0.0), imag(0.0) {}
91 cdouble(double r, double i) : real(r), imag(i) {}
92};
93
99struct ROBOTRACONTEUR_CORE_API cfloat
100{
102 float real;
104 float imag;
106 cfloat() : real(0.0), imag(0.0) {}
113 cfloat(float r, float i) : real(r), imag(i) {}
114};
115
122struct ROBOTRACONTEUR_CORE_API rr_bool
123{
129 uint8_t value;
130
132 rr_bool() : value(0) {}
138 rr_bool(uint8_t b) : value(b) {}
139};
140
141ROBOTRACONTEUR_CORE_API bool operator==(const cdouble& c1, const cdouble& c2);
142ROBOTRACONTEUR_CORE_API bool operator!=(const cdouble& c1, const cdouble& c2);
143ROBOTRACONTEUR_CORE_API bool operator==(const cfloat& c1, const cfloat& c2);
144ROBOTRACONTEUR_CORE_API bool operator!=(const cfloat& c1, const cfloat& c2);
145ROBOTRACONTEUR_CORE_API bool operator==(const rr_bool& c1, const rr_bool& c2);
146ROBOTRACONTEUR_CORE_API bool operator!=(const rr_bool& c1, const rr_bool& c2);
147
148template <typename T, typename U>
149class rr_cast_support
150{
151 public:
152 static RR_SHARED_PTR<T> rr_cast(const RR_SHARED_PTR<U>& objin)
153 {
154 if (!objin)
155 return RR_SHARED_PTR<T>();
156
157 RR_SHARED_PTR<T> c = RR_DYNAMIC_POINTER_CAST<T>(objin);
158 if (!c)
159 {
160 throw DataTypeMismatchException("Data type cast error");
161 }
162
163 return c;
164 }
165
166 static RR_INTRUSIVE_PTR<T> rr_cast(const RR_INTRUSIVE_PTR<U>& objin)
167 {
168 if (!objin)
169 return RR_INTRUSIVE_PTR<T>();
170
171 RR_INTRUSIVE_PTR<T> c = RR_DYNAMIC_POINTER_CAST<T>(objin);
172 if (!c)
173 {
174 throw DataTypeMismatchException("Data type cast error");
175 }
176
177 return c;
178 }
179};
180
181template <typename T>
182class rr_cast_support<T, T>
183{
184 public:
185 static const RR_SHARED_PTR<T>& rr_cast(const RR_SHARED_PTR<T>& objin) { return objin; }
186
187 static const RR_INTRUSIVE_PTR<T>& rr_cast(const RR_INTRUSIVE_PTR<T>& objin) { return objin; }
188};
189
199template <typename T, typename U>
200static RR_SHARED_PTR<T> rr_cast(const RR_SHARED_PTR<U>& objin)
201{
202 return rr_cast_support<T, U>::rr_cast(objin);
203}
204
215template <typename T, typename U>
216static RR_INTRUSIVE_PTR<T> rr_cast(const RR_INTRUSIVE_PTR<U>& objin)
217{
218 return rr_cast_support<T, U>::rr_cast(objin);
219}
220
228class ROBOTRACONTEUR_CORE_API RRObject : boost::noncopyable
229{
230 public:
231 RRObject();
232
233 virtual ~RRObject() {}
234
241 virtual std::string RRType() = 0;
242};
243
252class ROBOTRACONTEUR_CORE_API RRValue : public boost::intrusive_ref_counter<RRValue>, boost::noncopyable
253{
254 public:
255 RRValue();
256
257 virtual ~RRValue() {}
258
259 virtual std::string RRType() = 0;
260};
261
262namespace detail
263{
264class ROBOTRACONTEUR_CORE_API MessageStringData
265{
266 public:
267 std::string str;
268};
269
270class ROBOTRACONTEUR_CORE_API MessageStringData_string_ref
271{
272 public:
273 boost::string_ref ref;
274 MessageStringData_string_ref(const boost::string_ref& r) : ref(r) {}
275};
276class ROBOTRACONTEUR_CORE_API MessageStringData_static_string
277{
278 public:
279 boost::string_ref ref;
280 MessageStringData_static_string(const boost::string_ref& r) : ref(r) {}
281};
282
283} // namespace detail
284
285class ROBOTRACONTEUR_CORE_API MessageStringRef;
286
287class ROBOTRACONTEUR_CORE_API MessageStringPtr
288{
289 private:
290 boost::variant<detail::MessageStringData, detail::MessageStringData_static_string> _str_ptr;
291
292 public:
293 friend class MessageStringRef;
294
295 MessageStringPtr();
296
297 MessageStringPtr(const std::string& str);
298 MessageStringPtr(boost::string_ref str, bool is_static = false);
299 MessageStringPtr(const MessageStringPtr& str_ptr);
300 MessageStringPtr(const MessageStringRef& str_ref);
301#ifndef ROBOTRACONTEUR_NO_CXX11
302 MessageStringPtr(std::string&& str);
303#endif
304 // WARNING: ONLY USE WITH STRING LITERALS OR STATIC STRINGS!
305 template <size_t N>
306 inline MessageStringPtr(const char (&str)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays)
307 {
308 init_literal(str, strlen(str));
309 }
310
311 boost::string_ref str() const;
312 void reset();
313
314 bool operator==(MessageStringRef b) const;
315 bool operator!=(MessageStringRef b) const;
316 bool operator<(MessageStringRef b) const;
317
318 private:
319 void init_literal(const char* str, size_t len);
320};
321
322class ROBOTRACONTEUR_CORE_API MessageStringRef
323{
324 private:
325 boost::variant<const detail::MessageStringData*, detail::MessageStringData_static_string,
326 detail::MessageStringData_string_ref>
327 _str;
328
329 public:
330 friend class MessageStringPtr;
331
332 MessageStringRef(const std::string& str);
333 MessageStringRef(boost::string_ref str, bool is_static = false);
334 MessageStringRef(const MessageStringPtr& str_ptr);
335 MessageStringRef(const MessageStringRef& str_ref);
336
337 // WARNING: ONLY USE WITH STRING LITERALS OR STATIC STRINGS!
338 template <size_t N>
339 inline MessageStringRef(const char (&str)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays)
340 {
341 init_literal(str, strlen(str));
342 }
343
344 bool operator==(MessageStringRef b) const;
345 bool operator!=(MessageStringRef b) const;
346
347 boost::string_ref str() const;
348
349 private:
350 void init_literal(const char* str, size_t len);
351};
352
353std::size_t hash_value(const RobotRaconteur::MessageStringPtr& k);
354
355ROBOTRACONTEUR_CORE_API std::ostream& operator<<(std::ostream& out, const MessageStringPtr& str);
356ROBOTRACONTEUR_CORE_API std::ostream& operator<<(std::ostream& out, const MessageStringRef& str);
357
358// boost::string_ref operations
359inline boost::iterator_range<boost::string_ref::const_iterator> to_range(const boost::string_ref& str)
360{
361 return boost::iterator_range<boost::string_ref::const_iterator>(str.cbegin(), str.cend());
362}
363
364inline std::string operator+(const char* lhs, boost::string_ref rhs) { return lhs + rhs.to_string(); }
365
366inline std::string operator+(const std::string& lhs, boost::string_ref rhs) { return lhs + rhs.to_string(); }
367
368inline std::string operator+(boost::string_ref lhs, const char* rhs) { return lhs.to_string() + rhs; }
369
374class ROBOTRACONTEUR_CORE_API MessageElementData : public RRValue
375{
376 public:
377 virtual MessageStringPtr GetTypeString() = 0;
378 virtual DataTypes GetTypeID() = 0;
379};
380
381template <typename T>
382class RRArray;
383
391template <typename T>
392static RR_INTRUSIVE_PTR<RRArray<T> > ScalarToRRArray(T value);
393
401template <typename T>
402static T RRArrayToScalar(const RR_INTRUSIVE_PTR<RRArray<T> >& value);
403
412ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<RRArray<char> > stringToRRArray(boost::string_ref str);
413
422ROBOTRACONTEUR_CORE_API std::string RRArrayToString(const RR_INTRUSIVE_PTR<RRArray<char> >& arr);
423
424template <typename T>
425class RRPrimUtil
426{
427 public:
428 static DataTypes GetTypeID() { return DataTypes_void_t; }
429
430 static RR_INTRUSIVE_PTR<T> PrePack(const T& val) { return val; }
431
432 template <typename U>
433 static T PreUnpack(U& val)
434 {
435 return rr_cast<T>(val);
436 }
437
438 virtual ~RRPrimUtil(){};
439
440 typedef RR_INTRUSIVE_PTR<RRValue> BoxedType;
441};
442
443template <typename T>
444class RRPrimUtil<RR_INTRUSIVE_PTR<T> >
445{
446 public:
447 static DataTypes GetTypeID() { return DataTypes_void_t; }
448 static MessageStringPtr GetElementTypeString() { return MessageStringPtr(""); }
449
450 static boost::string_ref GetRRElementTypeString() { return ""; }
451
452 static RR_INTRUSIVE_PTR<RRValue> PrePack(const RR_INTRUSIVE_PTR<T>& val) { return rr_cast<RRValue>(val); }
453
454 template <typename U>
455 static RR_INTRUSIVE_PTR<T> PreUnpack(const U& val)
456 {
457 return rr_cast<T>(val);
458 }
459
460 virtual ~RRPrimUtil(){};
461
462 typedef RR_INTRUSIVE_PTR<T> BoxedType;
463};
464
465template <>
466class RRPrimUtil<std::string>
467{
468 public:
469 static DataTypes GetTypeID() { return DataTypes_string_t; }
470 static MessageStringPtr GetElementTypeString() { return MessageStringPtr(""); }
471 static boost::string_ref GetRRElementTypeString() { return ""; }
472 static RR_INTRUSIVE_PTR<RRValue> PrePack(boost::string_ref val);
473 static std::string PreUnpack(const RR_INTRUSIVE_PTR<RRValue>& val);
474
475 virtual ~RRPrimUtil(){};
476
477 typedef RR_INTRUSIVE_PTR<RRArray<char> > BoxedType;
478};
479
480#define RRPrimUtilNumeric(x, code) \
481 template <> \
482 class RRPrimUtil<x> \
483 { \
484 public: \
485 static DataTypes GetTypeID() { return code; } \
486 static MessageStringPtr GetElementTypeString() { return MessageStringPtr(""); } \
487 static boost::string_ref GetRRElementTypeString() { return ""; } \
488 static RR_INTRUSIVE_PTR<RRArray<x> > PrePack(const x& val); \
489 template <typename U> \
490 static x PreUnpack(const U& val) \
491 { \
492 return RRArrayToScalar(rr_cast<RRArray<x> >(val)); \
493 } \
494 typedef RR_INTRUSIVE_PTR<RRArray<x> > BoxedType; \
495 };
496
497RRPrimUtilNumeric(double, DataTypes_double_t);
498RRPrimUtilNumeric(float, DataTypes_single_t);
499
500RRPrimUtilNumeric(int8_t, DataTypes_int8_t);
501RRPrimUtilNumeric(uint8_t, DataTypes_uint8_t);
502RRPrimUtilNumeric(int16_t, DataTypes_int16_t);
503RRPrimUtilNumeric(uint16_t, DataTypes_uint16_t);
504RRPrimUtilNumeric(int32_t, DataTypes_int32_t);
505RRPrimUtilNumeric(uint32_t, DataTypes_uint32_t);
506RRPrimUtilNumeric(int64_t, DataTypes_int64_t);
507RRPrimUtilNumeric(uint64_t, DataTypes_uint64_t);
508RRPrimUtilNumeric(char, DataTypes_string_t);
509RRPrimUtilNumeric(cdouble, DataTypes_cdouble_t);
510RRPrimUtilNumeric(cfloat, DataTypes_csingle_t);
511RRPrimUtilNumeric(rr_bool, DataTypes_bool_t);
512
513ROBOTRACONTEUR_CORE_API std::string GetRRDataTypeString(DataTypes type);
514ROBOTRACONTEUR_CORE_API bool IsTypeRRArray(DataTypes type);
515ROBOTRACONTEUR_CORE_API bool IsTypeNumeric(DataTypes type);
516
525class ROBOTRACONTEUR_CORE_API RRBaseArray : public MessageElementData
526{
527 public:
528 RR_OVIRTUAL MessageStringPtr GetTypeString() RR_OVERRIDE
529 {
530 std::string type = GetRRDataTypeString(GetTypeID());
531 return type + "[]";
532 }
533
534 RR_OVIRTUAL ~RRBaseArray() RR_OVERRIDE {}
535
541 virtual size_t size() = 0;
542
543 RR_OVIRTUAL std::string RRType() RR_OVERRIDE;
544
550 virtual void* void_ptr() = 0;
551
557 virtual size_t ElementSize() = 0;
558};
559
577template <typename T>
578class RRArray : public RRBaseArray
579{
580 public:
581 RR_OVIRTUAL DataTypes GetTypeID() RR_OVERRIDE { return RRPrimUtil<T>::GetTypeID(); }
582
583 RRArray(T* data, size_t length, bool owned) : data_(data), element_count(length), owned(owned) {}
584
585 RR_OVIRTUAL ~RRArray() RR_OVERRIDE
586 {
587 if (owned)
588 delete[] data_;
589 }
590
591 RR_OVIRTUAL void* void_ptr() RR_OVERRIDE { return data(); }
592
593 T* operator->() const { return data_; }
594
595 RR_OVIRTUAL size_t size() RR_OVERRIDE { return element_count; }
596
597 RR_OVIRTUAL size_t ElementSize() RR_OVERRIDE { return sizeof(T); }
598
599 // C++ container support functions based on boost::array
600
601 // type definitions
603 typedef T value_type;
605 typedef T* iterator;
607 typedef const T* const_iterator;
609 typedef T& reference;
611 typedef const T& const_reference;
613 typedef std::size_t size_type;
615 typedef std::ptrdiff_t difference_type;
616
617 // iterator support
618
620 iterator begin() { return data_; }
622 const_iterator begin() const { return data_; }
624 const_iterator cbegin() const { return data_; }
625
627 iterator end() { return data_ + element_count; }
629 const_iterator end() const { return data_ + element_count; }
631 const_iterator cend() const { return data_ + element_count; }
632
634 typedef boost::reverse_iterator<iterator> reverse_iterator;
636 typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
637
644
651
654 {
655 BOOST_ASSERT_MSG(i < element_count, "out of range");
656 return data_[i];
657 }
658
661 {
662 BOOST_ASSERT_MSG(i < element_count, "out of range");
663 return data_[i];
664 }
665
668 {
669 rangecheck(i);
670 return data_[i];
671 }
672
674 {
675 rangecheck(i);
676 return data_[i];
677 }
678
680 reference front() { return data_[0]; }
681
683 const_reference front() const { return data_[0]; }
684
686 reference back() { return data_[element_count - 1]; }
687
689 const_reference back() const { return data_[element_count - 1]; }
690
692 bool empty() { return element_count == 0; }
694 size_type max_size() { return element_count; }
695
697 const T* data() const { return data_; }
699 T* data() { return data_; }
700
701 T* c_array() { return data_; }
702
710 template <typename T2>
711 RRArray<T>& operator=(const RRArray<T2>& rhs)
712 {
713 // Copying a longer array would write past the end of this one
714 if (static_cast<size_t>(rhs.end() - rhs.begin()) > size())
715 throw OutOfRangeException("Array is incorrect size");
716 std::copy(rhs.begin(), rhs.end(), begin());
717 return *this;
718 }
719
727 void assign(const T& value) { fill(value); }
733 void fill(const T& value) { std::fill_n(begin(), size(), value); }
734
735 void rangecheck(size_type i)
736 {
737 if (i >= size())
738 {
739 std::out_of_range e("array<>: index out of range");
740 boost::throw_exception(e);
741 }
742 }
743
744 private:
745 T* data_;
746 size_t element_count;
747 bool owned;
748};
749
750// RRPrimUtil members that create or destroy RR_INTRUSIVE_PTR<RRArray<T> > are defined here, after RRArray is
751// complete, so intrusive_ptr_release can be found by ADL when ~intrusive_ptr is instantiated (C++20 constexpr)
752inline RR_INTRUSIVE_PTR<RRValue> RRPrimUtil<std::string>::PrePack(boost::string_ref val)
753{
754 return rr_cast<RRValue>(stringToRRArray(val));
755}
756
757inline std::string RRPrimUtil<std::string>::PreUnpack(const RR_INTRUSIVE_PTR<RRValue>& val)
758{
759 return RRArrayToString(rr_cast<RRArray<char> >(val));
760}
761
762#define RRPrimUtilNumericPrePack(x) \
763 inline RR_INTRUSIVE_PTR<RRArray<x> > RRPrimUtil<x>::PrePack(const x& val) { return ScalarToRRArray(val); }
764
765RRPrimUtilNumericPrePack(double);
766RRPrimUtilNumericPrePack(float);
767RRPrimUtilNumericPrePack(int8_t);
768RRPrimUtilNumericPrePack(uint8_t);
769RRPrimUtilNumericPrePack(int16_t);
770RRPrimUtilNumericPrePack(uint16_t);
771RRPrimUtilNumericPrePack(int32_t);
772RRPrimUtilNumericPrePack(uint32_t);
773RRPrimUtilNumericPrePack(int64_t);
774RRPrimUtilNumericPrePack(uint64_t);
775RRPrimUtilNumericPrePack(char);
776RRPrimUtilNumericPrePack(cdouble);
777RRPrimUtilNumericPrePack(cfloat);
778RRPrimUtilNumericPrePack(rr_bool);
779
780#undef RRPrimUtilNumericPrePack
781
782template <typename T>
783class RRMap_keytype
784{
785 public:
786 static boost::string_ref get()
787 {
788 BOOST_STATIC_ASSERT_MSG(sizeof(T) == 0, "Invalid key type for Robot Raconteur map");
789 throw DataTypeException("Unknown data type");
790 }
791
792 static std::string get_map_rrtype()
793 {
794 BOOST_STATIC_ASSERT_MSG(sizeof(T) == 0, "Invalid key type for Robot Raconteur map");
795 throw DataTypeException("Unknown data type");
796 }
797};
798
799template <>
800class RRMap_keytype<int32_t>
801{
802 public:
803 static boost::string_ref get() { return "int32_t"; }
804
805 static std::string get_map_rrtype() { return "RobotRaconteur.RRMap<int32_t>"; }
806};
807
808template <>
809class RRMap_keytype<std::string>
810{
811 public:
812 static boost::string_ref get() { return "string"; }
813
814 static std::string get_map_rrtype() { return "RobotRaconteur.RRMap<string>"; }
815};
816
827template <typename K, typename T>
828class RRMap : public RRValue
829{
830 protected:
831 std::map<K, RR_INTRUSIVE_PTR<T> > map;
832
833 public:
834 RRMap() {}
835
836 RRMap(const std::map<K, RR_INTRUSIVE_PTR<T> >& mapin) : map(mapin) {}
837
838 RR_OVIRTUAL ~RRMap() RR_OVERRIDE {}
839
840 RR_OVIRTUAL std::string RRType() RR_OVERRIDE { return RRMap_keytype<K>::get_map_rrtype(); }
841
842 // C++ container support based on boost::container::map
843
845 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::key_type key_type;
847 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::mapped_type mapped_type;
849 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::value_type value_type;
851 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::pointer pointer;
853 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::const_pointer const_pointer;
855 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::reference reference;
857 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::const_reference const_reference;
859 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::size_type size_type;
861 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::iterator iterator;
863 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::const_iterator const_iterator;
865 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::reverse_iterator reverse_iterator;
867 typedef typename std::map<K, RR_INTRUSIVE_PTR<T> >::const_reverse_iterator const_reverse_iterator;
868
870 iterator begin() { return map.begin(); }
872 const_iterator cbegin() const { return map.cbegin(); }
874 const_iterator begin() const { return map.begin(); }
876 iterator end() { return map.end(); }
878 const_iterator cend() const { return map.end(); }
880 const_iterator end() const { return map.end(); }
882 reverse_iterator rbegin() { return map.rbegin(); };
884 const_reverse_iterator crbegin() const { return map.crbegin(); };
886 const_reverse_iterator rbegin() const { return map.rbegin(); };
888 reverse_iterator rend() { return map.rend(); }
890 const_reverse_iterator crend() const { return map.rend(); }
892 const_reverse_iterator rend() const { return map.rend(); }
894 bool empty() const { return map.empty(); }
896 size_type size() const { return map.size(); }
898 size_type max_size() const { return map.max_size(); };
900 mapped_type& operator[](const key_type& k) { return map[k]; }
902 mapped_type& at(const key_type& k) { return map.at(k); }
904 const mapped_type& at(const key_type& k) const { return map.at(k); }
906 std::pair<iterator, bool> insert(const value_type& x) { return map.insert(x); }
909 {
910 RR_UNUSED(p);
911 return map.insert(x);
912 }
913
914 template <class InputIterator>
915 void insert(InputIterator first, InputIterator last)
916 {
917 map.insert(first, last);
918 }
919
920 void erase(iterator p) { map.erase(p); }
922 size_type erase(const key_type& x) { return map.erase(x); }
924 void erase(iterator first, iterator last) { map.erase(first, last); }
926 void clear() { map.clear(); }
928 iterator find(const key_type& x) { return map.find(x); }
930 const_iterator find(const key_type& x) const { return map.find(x); }
932 size_type count(const key_type& x) const { return map.count(x); }
933
941 typename std::map<K, RR_INTRUSIVE_PTR<T> >& GetStorageContainer() { return map; }
942};
943
953template <typename T>
954class RRList : public RRValue
955{
956 protected:
957 std::list<RR_INTRUSIVE_PTR<T> > list;
958
959 public:
960 RRList() {}
961
962 RRList(std::list<RR_INTRUSIVE_PTR<T> > listin) { list = listin; }
963
964 RR_OVIRTUAL ~RRList() RR_OVERRIDE {}
965
966 RR_OVIRTUAL std::string RRType() RR_OVERRIDE { return "RobotRaconteur.RRList"; }
967
968 // C++ container support based on boost::container::list
969
971 typedef RR_INTRUSIVE_PTR<T> value_type;
973 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::pointer pointer;
975 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::const_pointer const_pointer;
977 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::reference reference;
979 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::const_reference const_reference;
981 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::size_type size_type;
983 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::difference_type difference_type;
985 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::iterator iterator;
987 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::const_iterator const_iterator;
989 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::reverse_iterator reverse_iterator;
991 typedef typename std::list<RR_INTRUSIVE_PTR<T> >::const_reverse_iterator const_reverse_iterator;
992
994 iterator begin() { return list.begin(); }
996 const_iterator begin() const { return list.begin(); }
998 iterator end() { return list.end(); }
1000 const_iterator end() const { return list.end(); }
1002 reverse_iterator rbegin() { return list.rbegin(); }
1004 const_reverse_iterator rbegin() const { return list.rbegin(); }
1006 reverse_iterator rend() { return list.rend(); }
1008 const_reverse_iterator crend() const { return list.crend(); }
1010 const_reverse_iterator rend() const { return list.rend(); }
1012 const_iterator cbegin() const { return list.cbegin(); }
1014 const_iterator cend() const { return list.cend(); }
1016 const_reverse_iterator const crbegin() { return list.crbegin(); }
1018 const_reverse_iterator const crend() { return list.crend(); }
1020 bool empty() const { return list.empty(); }
1022 virtual size_type size() const { return list.size(); }
1024 size_type max_size() const { return list.max_size(); }
1026 reference front() { return list.front(); }
1028 const_reference front() const { return list.front(); }
1030 reference back() { return list.back(); }
1032 const_reference back() const { return list.back(); }
1034 void push_front(const RR_INTRUSIVE_PTR<T>& x) { list.push_front(x); }
1036 void push_back(const RR_INTRUSIVE_PTR<T>& x) { list.push_back(x); }
1038 void pop_front() { list.pop_front(); }
1040 void pop_back() { list.pop_back(); }
1042 iterator insert(const_iterator p, const RR_INTRUSIVE_PTR<T>& x) { list.insert(p, x); }
1044 iterator erase(const_iterator p) { list.erase(p); }
1046 iterator erase(const_iterator first, const_iterator last) { list.erase(first, last); }
1048 void clear() { list.clear(); }
1050 void remove(const RR_INTRUSIVE_PTR<T>& value) { list.remove(value); }
1051
1059 typename std::list<RR_INTRUSIVE_PTR<T> >& GetStorageContainer() { return list; }
1060};
1061
1070class ROBOTRACONTEUR_CORE_API RRStructure : public RRValue
1071{
1072 public:
1073 RR_OVIRTUAL ~RRStructure() RR_OVERRIDE {}
1074};
1075
1091template <typename T>
1092static RR_INTRUSIVE_PTR<RRArray<T> > AllocateRRArray(size_t length)
1093{
1094 return RR_INTRUSIVE_PTR<RRArray<T> >(new RRArray<T>(new T[length], length, true));
1095}
1096
1115template <typename T>
1116static RR_INTRUSIVE_PTR<RRArray<T> > AttachRRArray(T* data, size_t length, bool owned)
1117{
1118 return RR_INTRUSIVE_PTR<RRArray<T> >(new RRArray<T>(data, length, owned));
1119}
1120
1133template <typename T>
1134static RR_INTRUSIVE_PTR<RRArray<T> > AttachRRArrayCopy(const T* data, const size_t length)
1135{
1136 RR_INTRUSIVE_PTR<RRArray<T> > ret(new RRArray<T>(new T[length], length, true));
1137 memcpy(ret->void_ptr(), data, length * sizeof(T));
1138 return ret;
1139}
1140
1158ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<RRBaseArray> AllocateRRArrayByType(DataTypes type, size_t length);
1159
1174template <typename T>
1175static RR_INTRUSIVE_PTR<RRArray<T> > AllocateEmptyRRArray(size_t length)
1176{
1177 RR_INTRUSIVE_PTR<RRArray<T> > o = AllocateRRArray<T>(length);
1178 if (length > 0)
1179 {
1180 memset(static_cast<void*>(o->data()), 0, length * sizeof(T));
1181 }
1182 return o;
1183}
1184
1198ROBOTRACONTEUR_CORE_API size_t RRArrayElementSize(DataTypes type);
1199
1207template <typename T>
1208static RR_INTRUSIVE_PTR<RRArray<T> > ScalarToRRArray(T value)
1209{
1210 return AttachRRArrayCopy(&value, 1);
1211}
1212
1220template <typename T>
1221static T RRArrayToScalar(const RR_INTRUSIVE_PTR<RRArray<T> >& value)
1222{
1223 if (!value)
1224 {
1225 throw NullValueException("Null pointer");
1226 }
1227
1228 if (value->size() == 0)
1229 throw OutOfRangeException("Index out of range");
1230
1231 return (*value)[0];
1232}
1233
1247template <typename Y, typename U>
1248static std::vector<Y> RRArrayToVector(const RR_INTRUSIVE_PTR<RRArray<U> >& in)
1249{
1250 if (!in)
1251 throw NullValueException("Unexpected null array");
1252 std::vector<Y> out(in->size());
1253 for (size_t i = 0; i < in->size(); i++)
1254 out[i] = boost::numeric_cast<Y>((*in)[i]);
1255 return out;
1256}
1257
1269template <typename Y, typename U>
1270static RR_INTRUSIVE_PTR<RRArray<Y> > VectorToRRArray(const std::vector<U>& in)
1271{
1272 RR_INTRUSIVE_PTR<RRArray<Y> > out = AllocateRRArray<Y>(in.size());
1273 for (size_t i = 0; i < in.size(); i++)
1274 (*out)[i] = boost::numeric_cast<Y>(in[i]);
1275 return out;
1276}
1277
1290template <typename Y, std::size_t N, typename U>
1291static boost::array<Y, N> RRArrayToArray(const RR_INTRUSIVE_PTR<RRArray<U> >& in)
1292{
1293 if (!in)
1294 throw NullValueException("Unexpected null array");
1295 if (in->size() != N)
1296 throw OutOfRangeException("Array is incorrect size");
1297 boost::array<Y, N> out = {};
1298 for (size_t i = 0; i < N; i++)
1299 out[i] = boost::numeric_cast<Y>((*in)[i]);
1300 return out;
1301}
1302
1314template <typename Y, std::size_t N, typename U>
1315static void RRArrayToArray(boost::array<Y, N>& out, const RR_INTRUSIVE_PTR<RRArray<U> >& in)
1316{
1317 if (!in)
1318 throw NullValueException("Unexpected null array");
1319 if (in->size() != N)
1320 throw OutOfRangeException("Array is incorrect size");
1321 for (size_t i = 0; i < N; i++)
1322 out[i] = boost::numeric_cast<Y>((*in)[i]);
1323}
1324
1337template <typename Y, typename U, std::size_t N>
1338static RR_INTRUSIVE_PTR<RRArray<Y> > ArrayToRRArray(boost::array<U, N> in)
1339{
1340 RR_INTRUSIVE_PTR<RRArray<Y> > out = AllocateRRArray<Y>(N);
1341 for (size_t i = 0; i < N; i++)
1342 (*out)[i] = boost::numeric_cast<Y>(in[i]);
1343 return out;
1344}
1345
1360template <typename Y, std::size_t N, typename U>
1361static boost::container::static_vector<Y, N> RRArrayToStaticVector(const RR_INTRUSIVE_PTR<RRArray<U> >& in)
1362{
1363 if (!in)
1364 throw NullValueException("Unexpected null array");
1365 if (in->size() > N)
1366 throw OutOfRangeException("Array is too large for static vector size");
1367 boost::container::static_vector<Y, N> out(in->size());
1368 for (size_t i = 0; i < in->size(); i++)
1369 out[i] = boost::numeric_cast<Y>((*in)[i]);
1370 return out;
1371}
1372
1387template <typename Y, std::size_t N, typename U>
1388static void RRArrayToStaticVector(boost::container::static_vector<Y, N>& out, const RR_INTRUSIVE_PTR<RRArray<U> >& in)
1389{
1390 if (!in)
1391 throw NullValueException("Unexpected null array");
1392 if (in->size() > N)
1393 throw OutOfRangeException("Array is too large for static vector size");
1394 out.resize(in->size());
1395 for (size_t i = 0; i < in->size(); i++)
1396 out[i] = boost::numeric_cast<Y>((*in)[i]);
1397}
1398
1413template <typename Y, typename U, std::size_t N>
1414static RR_INTRUSIVE_PTR<RRArray<Y> > StaticVectorToRRArray(boost::container::static_vector<U, N> in)
1415{
1416 RR_INTRUSIVE_PTR<RRArray<Y> > out = AllocateRRArray<Y>(in.size());
1417 for (size_t i = 0; i < in.size(); i++)
1418 (*out)[i] = boost::numeric_cast<Y>(in[i]);
1419 return out;
1420}
1421
1430ROBOTRACONTEUR_CORE_API RR_INTRUSIVE_PTR<RRList<RRArray<char> > > stringVectorToRRList(
1431 const std::vector<std::string>& string_vector);
1432
1441ROBOTRACONTEUR_CORE_API std::vector<std::string> RRListToStringVector(
1442 const RR_INTRUSIVE_PTR<RRList<RRArray<char> > >& list);
1443
1455template <typename T>
1456RR_INTRUSIVE_PTR<T>& rr_null_check(RR_INTRUSIVE_PTR<T>& ptr)
1457{
1458 if (!ptr)
1459 {
1460 throw NullValueException("Unexpected null value");
1461 }
1462 return ptr;
1463}
1464
1478template <typename T>
1479RR_INTRUSIVE_PTR<T>& rr_null_check(RR_INTRUSIVE_PTR<T>& ptr, const char* msg)
1480{
1481 if (!ptr)
1482 {
1483 throw NullValueException(msg);
1484 }
1485 return ptr;
1486}
1487
1499template <typename T>
1500const RR_INTRUSIVE_PTR<T>& rr_null_check(const RR_INTRUSIVE_PTR<T>& ptr)
1501{
1502 if (!ptr)
1503 {
1504 throw NullValueException("Unexpected null value");
1505 }
1506 return ptr;
1507}
1508
1522template <typename T>
1523const RR_INTRUSIVE_PTR<T>& rr_null_check(const RR_INTRUSIVE_PTR<T>& ptr, const char* msg)
1524{
1525 if (!ptr)
1526 {
1527 throw NullValueException(msg);
1528 }
1529 return ptr;
1530}
1531
1532#define RR_NULL_CHECK rr_null_check
1533
1534template <typename T>
1535static RR_INTRUSIVE_PTR<RRArray<T> > VerifyRRArrayLength(const RR_INTRUSIVE_PTR<RRArray<T> >& a, size_t len,
1536 bool varlength)
1537{
1538 if (!a)
1539 throw NullValueException("Arrays must not be null");
1540 if (len != 0)
1541 {
1542 if (varlength && (a->size() > len))
1543 {
1544 throw DataTypeException("Array dimension mismatch");
1545 }
1546 if (!varlength && (a->size() != len))
1547 {
1548 throw DataTypeException("Array dimension mismatch");
1549 }
1550 }
1551 return a;
1552}
1553
1554template <typename T>
1555static RR_INTRUSIVE_PTR<RRList<T> > VerifyRRArrayLength(const RR_INTRUSIVE_PTR<RRList<T> >& a, size_t len,
1556 bool varlength)
1557{
1558 if (!a)
1559 return a;
1560 BOOST_FOREACH (RR_INTRUSIVE_PTR<T>& aa, (*a))
1561 {
1562 VerifyRRArrayLength(aa, len, varlength);
1563 }
1564 return a;
1565}
1566
1567template <typename K, typename T>
1568static RR_INTRUSIVE_PTR<RRMap<K, T> > VerifyRRArrayLength(const RR_INTRUSIVE_PTR<RRMap<K, T> >& a, size_t len,
1569 bool varlength)
1570{
1571 if (!a)
1572 return a;
1573 BOOST_FOREACH (const RR_INTRUSIVE_PTR<T>& aa, *a | boost::adaptors::map_values)
1574 {
1575 VerifyRRArrayLength(aa, len, varlength);
1576 }
1577 return a;
1578}
1579
1587class ROBOTRACONTEUR_CORE_API RRMultiDimBaseArray : public RRValue
1588{
1589 public:
1590 RR_OVIRTUAL ~RRMultiDimBaseArray() RR_OVERRIDE {}
1591
1592 virtual DataTypes GetElementTypeID() = 0;
1593};
1594
1595namespace detail
1596{
1597ROBOTRACONTEUR_CORE_API class MultiDimArray_CalculateCopyIndicesIter
1598{
1599 public:
1600 virtual bool Next(uint32_t& indexa, uint32_t& indexb, uint32_t& len) = 0;
1601
1602 virtual ~MultiDimArray_CalculateCopyIndicesIter();
1603};
1604
1605// cSpell: ignore mema, memb
1606ROBOTRACONTEUR_CORE_API RR_SHARED_PTR<MultiDimArray_CalculateCopyIndicesIter>
1607MultiDimArray_CalculateCopyIndicesBeginIter(const std::vector<uint32_t>& mema_dims,
1608 const std::vector<uint32_t>& mema_pos,
1609 const std::vector<uint32_t>& memb_dims,
1610 const std::vector<uint32_t>& memb_pos, const std::vector<uint32_t>& count);
1611
1612// Throws InvalidArgumentException if the element count of dims is larger than array_size
1613ROBOTRACONTEUR_CORE_API void MultiDimArray_CheckArraySize(const std::vector<uint32_t>& dims, size_t array_size);
1614} // namespace detail
1615
1636template <typename T>
1637class RRMultiDimArray : public RRMultiDimBaseArray
1638{
1639 public:
1640 RR_INTRUSIVE_PTR<RRArray<uint32_t> > Dims;
1641
1642 RR_INTRUSIVE_PTR<RRArray<T> > Array;
1643
1644 RRMultiDimArray(){};
1645
1646 RRMultiDimArray(const RR_INTRUSIVE_PTR<RRArray<uint32_t> >& Dims, const RR_INTRUSIVE_PTR<RRArray<T> >& Array)
1647 {
1648 this->Dims = Dims;
1649 this->Array = Array;
1650 }
1651
1652 RR_OVIRTUAL ~RRMultiDimArray() RR_OVERRIDE {}
1653
1654 RR_OVIRTUAL std::string RRType() RR_OVERRIDE { return "RobotRaconteur.RRMultiDimArray"; }
1655
1656 RR_OVIRTUAL DataTypes GetElementTypeID() RR_OVERRIDE { return RRPrimUtil<T>::GetTypeID(); }
1657
1666 virtual void RetrieveSubArray(const std::vector<uint32_t>& memorypos,
1667 const RR_INTRUSIVE_PTR<RRMultiDimArray<T> >& buffer,
1668 const std::vector<uint32_t>& bufferpos, const std::vector<uint32_t>& count)
1669 {
1670
1671 std::vector<uint32_t> mema_dims = RRArrayToVector<uint32_t>(Dims);
1672 std::vector<uint32_t> memb_dims = RRArrayToVector<uint32_t>(buffer->Dims);
1673 detail::MultiDimArray_CheckArraySize(mema_dims, Array->size());
1674 detail::MultiDimArray_CheckArraySize(memb_dims, buffer->Array->size());
1675 RR_SHARED_PTR<detail::MultiDimArray_CalculateCopyIndicesIter> iter =
1676 detail::MultiDimArray_CalculateCopyIndicesBeginIter(mema_dims, memorypos, memb_dims, bufferpos, count);
1677
1678 uint32_t len = 0;
1679 uint32_t indexa = 0;
1680 uint32_t indexb = 0;
1681
1682 while (iter->Next(indexa, indexb, len))
1683 {
1684 memcpy((buffer->Array->data() + indexb), (Array->data()) + indexa, len * sizeof(T));
1685 }
1686 }
1687
1696 virtual void AssignSubArray(const std::vector<uint32_t>& memorypos,
1697 const RR_INTRUSIVE_PTR<RRMultiDimArray<T> >& buffer,
1698 const std::vector<uint32_t>& bufferpos, const std::vector<uint32_t>& count)
1699 {
1700
1701 std::vector<uint32_t> mema_dims = RRArrayToVector<uint32_t>(Dims);
1702 std::vector<uint32_t> memb_dims = RRArrayToVector<uint32_t>(buffer->Dims);
1703 detail::MultiDimArray_CheckArraySize(mema_dims, Array->size());
1704 detail::MultiDimArray_CheckArraySize(memb_dims, buffer->Array->size());
1705 RR_SHARED_PTR<detail::MultiDimArray_CalculateCopyIndicesIter> iter =
1706 detail::MultiDimArray_CalculateCopyIndicesBeginIter(mema_dims, memorypos, memb_dims, bufferpos, count);
1707
1708 uint32_t len = 0;
1709 uint32_t indexa = 0;
1710 uint32_t indexb = 0;
1711
1712 while (iter->Next(indexa, indexb, len))
1713 {
1714 memcpy((Array->data() + indexa), (buffer->Array->data() + indexb), len * sizeof(T));
1715 }
1716 }
1717};
1718
1719template <size_t Ndims, typename T>
1720static RR_INTRUSIVE_PTR<RRMultiDimArray<T> > VerifyRRMultiDimArrayLength(const RR_INTRUSIVE_PTR<RRMultiDimArray<T> >& a,
1721 size_t n_elems,
1722 const boost::array<uint32_t, Ndims>& dims)
1723{
1724 if (!a)
1725 throw NullValueException("Arrays must not be null");
1726
1727 if (a->Dims->size() != Ndims)
1728 {
1729 throw DataTypeException("Array dimension mismatch");
1730 }
1731
1732 if (a->Array->size() != n_elems)
1733 {
1734 throw DataTypeException("Array dimension mismatch");
1735 }
1736
1737 for (size_t i = 0; i < Ndims; i++)
1738 {
1739 if ((*a->Dims)[i] != dims[i])
1740 {
1741 throw DataTypeException("Array dimension mismatch");
1742 }
1743 }
1744
1745 return a;
1746}
1747
1748template <size_t Ndims, typename T>
1749static RR_INTRUSIVE_PTR<RRList<T> > VerifyRRMultiDimArrayLength(const RR_INTRUSIVE_PTR<RRList<T> >& a, size_t n_elems,
1750 const boost::array<uint32_t, Ndims>& dims)
1751{
1752 if (!a)
1753 {
1754 // Containers can be null
1755 return a;
1756 }
1757 else
1758 {
1759 BOOST_FOREACH (const RR_INTRUSIVE_PTR<T>& aa, (*a))
1760 {
1761 VerifyRRMultiDimArrayLength<Ndims>(aa, n_elems, dims);
1762 }
1763 }
1764 return a;
1765}
1766
1767template <size_t Ndims, typename K, typename T>
1768static RR_INTRUSIVE_PTR<RRMap<K, T> > VerifyRRMultiDimArrayLength(const RR_INTRUSIVE_PTR<RRMap<K, T> >& a,
1769 size_t n_elems,
1770 const boost::array<uint32_t, Ndims>& dims)
1771{
1772 if (!a)
1773 {
1774 // Containers can be null
1775 return a;
1776 }
1777 else
1778 {
1779 BOOST_FOREACH (const RR_INTRUSIVE_PTR<T>& aa, *a | boost::adaptors::map_values)
1780 {
1781 VerifyRRMultiDimArrayLength<Ndims>(aa, n_elems, dims);
1782 }
1783 return a;
1784 }
1785}
1786
1797template <typename T>
1798static RR_INTRUSIVE_PTR<RRMultiDimArray<T> > AllocateEmptyRRMultiDimArray(const std::vector<uint32_t>& dims)
1799{
1800 uint32_t n_elems = boost::accumulate(dims, 1, std::multiplies<uint32_t>());
1802}
1803
1810template <typename T>
1811static RR_INTRUSIVE_PTR<RRMultiDimArray<T> > AllocateEmptyRRMultiDimArray()
1812{
1813 std::vector<uint32_t> length;
1814 length.push_back(0);
1816}
1817
1828template <typename T>
1829static RR_INTRUSIVE_PTR<RRMultiDimArray<T> > AllocateRRMultiDimArray(const RR_INTRUSIVE_PTR<RRArray<uint32_t> >& dims,
1830 const RR_INTRUSIVE_PTR<RRArray<T> >& array_)
1831{
1832 return new RRMultiDimArray<T>(dims, array_); // NOLINT(cppcoreguidelines-owning-memory)
1833}
1834
1841template <typename T>
1842RR_INTRUSIVE_PTR<RRList<T> > AllocateEmptyRRList()
1843{
1844 return new RRList<T>(); // NOLINT(cppcoreguidelines-owning-memory)
1845}
1846
1855template <typename T, typename U>
1856RR_INTRUSIVE_PTR<RRList<T> > AllocateRRList(const U& c)
1857{
1858 return new RRList<T>(c); // NOLINT(cppcoreguidelines-owning-memory)
1859}
1860
1868template <typename K, typename T>
1869RR_INTRUSIVE_PTR<RRMap<K, T> > AllocateEmptyRRMap()
1870{
1871 return new RRMap<K, T>(); // NOLINT(cppcoreguidelines-owning-memory)
1872}
1873
1883template <typename K, typename T, typename U>
1884RR_INTRUSIVE_PTR<RRMap<K, T> > AllocateRRMap(const U& c)
1885{
1886 return new RRMap<K, T>(c); // NOLINT(cppcoreguidelines-owning-memory)
1887}
1888
1896class ROBOTRACONTEUR_CORE_API RRPod
1897{
1898 public:
1899};
1900
1907class RRPodBaseArray : public RRValue
1908{
1909 public:
1910 virtual boost::string_ref RRElementTypeString() = 0;
1911};
1912
1927template <typename T>
1928class RRPodArray : public RRPodBaseArray
1929{
1930 protected:
1931 typename std::vector<T> pod_array;
1932
1933 public:
1934 RRPodArray(size_t n) { pod_array.resize(n); }
1935
1936 RRPodArray(typename std::vector<T>& array_in) : pod_array(array_in) {}
1937
1938 RRPodArray(const T& value_in) { pod_array.push_back(value_in); }
1939
1940 RR_OVIRTUAL ~RRPodArray() RR_OVERRIDE {}
1941
1942 RR_OVIRTUAL std::string RRType() RR_OVERRIDE { return "RobotRaconteur.RRPodArray"; }
1943
1944 RR_OVIRTUAL boost::string_ref RRElementTypeString() RR_OVERRIDE { return RRPrimUtil<T>::GetRRElementTypeString(); }
1945
1946 // C++ container support based on boost::container::vector
1947
1949 typedef T value_type;
1951 typedef typename std::vector<T>::pointer pointer;
1953 typedef typename std::vector<T>::const_pointer const_pointer;
1955 typedef typename std::vector<T>::reference reference;
1957 typedef typename std::vector<T>::const_reference const_reference;
1959 typedef typename std::vector<T>::size_type size_type;
1961 typedef typename std::vector<T>::iterator iterator;
1963 typedef typename std::vector<T>::const_iterator const_iterator;
1965 typedef typename std::vector<T>::reverse_iterator reverse_iterator;
1967 typedef typename std::vector<T>::const_reverse_iterator const_reverse_iterator;
1968
1970 iterator begin() { return pod_array.begin(); }
1972 const_iterator begin() const { return pod_array.begin(); }
1974 iterator end() { return pod_array.end(); }
1976 const_iterator end() const { return pod_array.end(); }
1978 reverse_iterator rbegin() { return pod_array.rbegin(); }
1980 const_reverse_iterator rbegin() const { return pod_array.rbegin(); }
1982 reverse_iterator rend() { return pod_array.rend(); }
1984 const_reverse_iterator rend() const { return pod_array.rend(); }
1986 const_iterator cbegin() const { return pod_array.cbegin(); }
1988 const_iterator cend() const { return pod_array.cend(); }
1990 const_reverse_iterator const crbegin() { return pod_array.crbegin(); }
1992 const_reverse_iterator const crend() { return pod_array.crend(); }
1994 bool empty() const { return pod_array.empty(); }
1996 virtual size_type size() const { return pod_array.size(); }
1998 size_type max_size() const { return size(); }
2000 reference front() { return pod_array.front(); }
2002 const_reference front() const { return pod_array.front(); }
2004 reference back() { return pod_array.back(); }
2006 const_reference back() const { return pod_array.back(); }
2008 reference operator[](size_type i) { return pod_array[i]; }
2010 const_reference operator[](size_type i) const { return pod_array[i]; }
2012 reference at(size_type i) { return pod_array.at(i); }
2014 const_reference at(size_type i) const { return pod_array.at(i); }
2016 T* data() { return pod_array.data(); }
2018 const T* data() const { return pod_array.data(); }
2019
2027 typename std::vector<T>& GetStorageContainer() { return pod_array; }
2028};
2029
2030#define RRPrimUtilPod(x, type_string) \
2031 template <> \
2032 class RRPrimUtil<x> \
2033 { \
2034 public: \
2035 static DataTypes GetTypeID() { return DataTypes_pod_t; } \
2036 static MessageStringPtr GetElementTypeString() { return MessageStringPtr(type_string); } \
2037 static boost::string_ref GetRRElementTypeString() { return type_string; } \
2038 static RR_INTRUSIVE_PTR<RRPodArray<x> > PrePack(const x& val) { return ScalarToRRPodArray(val); } \
2039 template <typename U> \
2040 static x PreUnpack(const U& val) \
2041 { \
2042 return RRPodArrayToScalar(rr_cast<RRPodArray<x> >(val)); \
2043 } \
2044 typedef RR_INTRUSIVE_PTR<RRPodArray<x> > BoxedType; \
2045 };
2046
2054class RRPodBaseMultiDimArray : public RRValue
2055{
2056 public:
2057 RR_INTRUSIVE_PTR<RRArray<uint32_t> > Dims;
2058 virtual boost::string_ref RRElementTypeString() = 0;
2059};
2060
2080template <typename T>
2081class RRPodMultiDimArray : public RRPodBaseMultiDimArray
2082{
2083 public:
2084 typename RR_INTRUSIVE_PTR<RRPodArray<T> > PodArray;
2085
2086 RRPodMultiDimArray() {}
2087
2088 RRPodMultiDimArray(const RR_INTRUSIVE_PTR<RRArray<uint32_t> >& dims, const RR_INTRUSIVE_PTR<RRPodArray<T> >& a)
2089 {
2090 this->Dims = dims;
2091 this->PodArray = a;
2092 }
2093
2094 RR_OVIRTUAL ~RRPodMultiDimArray() RR_OVERRIDE {}
2095
2096 RR_OVIRTUAL std::string RRType() RR_OVERRIDE { return "RobotRaconteur.RRPodMultiDimArray"; }
2097
2098 RR_OVIRTUAL boost::string_ref RRElementTypeString() RR_OVERRIDE { return RRPrimUtil<T>::GetRRElementTypeString(); }
2099
2108 virtual void RetrieveSubArray(const std::vector<uint32_t>& memorypos,
2109 const RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> >& buffer,
2110 const std::vector<uint32_t>& bufferpos, const std::vector<uint32_t>& count)
2111 {
2112
2113 std::vector<uint32_t> mema_dims = RRArrayToVector<uint32_t>(Dims);
2114 std::vector<uint32_t> memb_dims = RRArrayToVector<uint32_t>(buffer->Dims);
2115 detail::MultiDimArray_CheckArraySize(mema_dims, PodArray->size());
2116 detail::MultiDimArray_CheckArraySize(memb_dims, buffer->PodArray->size());
2117 RR_SHARED_PTR<detail::MultiDimArray_CalculateCopyIndicesIter> iter =
2118 detail::MultiDimArray_CalculateCopyIndicesBeginIter(mema_dims, memorypos, memb_dims, bufferpos, count);
2119
2120 uint32_t len = 0;
2121 uint32_t indexa = 0;
2122 uint32_t indexb = 0;
2123
2124 while (iter->Next(indexa, indexb, len))
2125 {
2126 for (size_t i = 0; i < len; i++)
2127 {
2128 buffer->PodArray->at(indexb + i) = PodArray->at(indexa + i);
2129 }
2130 }
2131 }
2132
2141 virtual void AssignSubArray(const std::vector<uint32_t>& memorypos,
2142 const RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> >& buffer,
2143 const std::vector<uint32_t>& bufferpos, const std::vector<uint32_t>& count)
2144 {
2145
2146 std::vector<uint32_t> mema_dims = RRArrayToVector<uint32_t>(Dims);
2147 std::vector<uint32_t> memb_dims = RRArrayToVector<uint32_t>(buffer->Dims);
2148 detail::MultiDimArray_CheckArraySize(mema_dims, PodArray->size());
2149 detail::MultiDimArray_CheckArraySize(memb_dims, buffer->PodArray->size());
2150 RR_SHARED_PTR<detail::MultiDimArray_CalculateCopyIndicesIter> iter =
2151 detail::MultiDimArray_CalculateCopyIndicesBeginIter(mema_dims, memorypos, memb_dims, bufferpos, count);
2152
2153 uint32_t len = 0;
2154 uint32_t indexa = 0;
2155 uint32_t indexb = 0;
2156
2157 while (iter->Next(indexa, indexb, len))
2158 {
2159 for (size_t i = 0; i < len; i++)
2160 {
2161 PodArray->at(indexa + i) = buffer->PodArray->at(indexb + i);
2162 }
2163 }
2164 }
2165};
2166
2174template <typename T>
2175static RR_INTRUSIVE_PTR<RRPodArray<T> > ScalarToRRPodArray(const T& value)
2176{
2177 return new RRPodArray<T>(value); // NOLINT(cppcoreguidelines-owning-memory)
2178}
2179
2187template <typename T>
2188static T RRPodArrayToScalar(const RR_INTRUSIVE_PTR<RRPodArray<T> >& value)
2189{
2190 if (!value)
2191 {
2192 throw NullValueException("Null pointer");
2193 }
2194
2195 if (value->size() == 0)
2196 throw OutOfRangeException("Index out of range");
2197
2198 return value->at(0);
2199}
2200
2214template <typename T>
2215static RR_INTRUSIVE_PTR<RRPodArray<T> > AllocateEmptyRRPodArray(size_t length)
2216{
2217 return new RRPodArray<T>(length); // NOLINT(cppcoreguidelines-owning-memory)
2218}
2219
2233template <typename T>
2234static RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> > AllocateEmptyRRPodMultiDimArray(const std::vector<uint32_t>& dims)
2235{
2236 uint32_t n_elems = boost::accumulate(dims, 1, std::multiplies<uint32_t>());
2238}
2239
2250template <typename T>
2251static RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> > AllocateEmptyRRPodMultiDimArray()
2252{
2253 std::vector<uint32_t> length;
2254 length.push_back(0);
2256}
2257
2258#define RRPrimUtilNamedArray(x, type_string, array_type) \
2259 template <> \
2260 class RRPrimUtil<x> \
2261 { \
2262 public: \
2263 static DataTypes GetTypeID() { return DataTypes_pod_t; } \
2264 static MessageStringPtr GetElementTypeString() { return MessageStringPtr(type_string); } \
2265 static boost::string_ref GetRRElementTypeString() { return type_string; } \
2266 static RR_INTRUSIVE_PTR<RRNamedArray<x> > PrePack(const x& val) { return ScalarToRRNamedArray(val); } \
2267 template <typename U> \
2268 static x PreUnpack(const U& val) \
2269 { \
2270 return RRNamedArrayToScalar(rr_cast<RRNamedArray<x> >(val)); \
2271 } \
2272 typedef RR_INTRUSIVE_PTR<RRNamedArray<x> > BoxedType; \
2273 typedef array_type ElementArrayType; \
2274 static const size_t ElementArrayCount = sizeof(x) / sizeof(array_type); \
2275 static size_t GetElementArrayCount() { return ElementArrayCount; } \
2276 static DataTypes GetElementArrayTypeID() { return RRPrimUtil<array_type>::GetTypeID(); } \
2277 };
2278
2285class ROBOTRACONTEUR_CORE_API RRNamedBaseArray : public RRValue
2286{
2287 public:
2288 virtual DataTypes ElementArrayType() = 0;
2289
2290 virtual size_t ElementSize() = 0;
2291
2292 virtual size_t ElementArrayCount() = 0;
2293
2294 virtual RR_INTRUSIVE_PTR<RRBaseArray> GetNumericBaseArray() = 0;
2295
2296 virtual boost::string_ref RRElementTypeString() = 0;
2297};
2298
2313template <typename T>
2315{
2316 protected:
2317 RR_INTRUSIVE_PTR<RRArray<typename RRPrimUtil<T>::ElementArrayType> > rr_array;
2318
2319 public:
2332 RRNamedArray(const RR_INTRUSIVE_PTR<RRArray<typename RRPrimUtil<T>::ElementArrayType> >& rr_array)
2333 {
2334 if (!rr_array)
2335 throw NullValueException("Numeric array for namedarray must not be null");
2336 this->rr_array = rr_array;
2337 }
2338
2339 virtual DataTypes GetTypeID() { return RRPrimUtil<T>::GetTypeID(); }
2341 virtual size_t size() const { return rr_array->size() / (RRPrimUtil<T>::ElementArrayCount); }
2343 virtual size_t size() { return rr_array->size() / (RRPrimUtil<T>::ElementArrayCount); }
2345 virtual void* void_ptr() { return rr_array->void_ptr(); }
2347 RR_OVIRTUAL size_t ElementSize() RR_OVERRIDE { return sizeof(T); }
2349 RR_OVIRTUAL DataTypes ElementArrayType() RR_OVERRIDE { return RRPrimUtil<T>::GetElementArrayTypeID(); }
2351 RR_OVIRTUAL size_t ElementArrayCount() RR_OVERRIDE { return RRPrimUtil<T>::ElementArrayCount; }
2353 virtual RR_INTRUSIVE_PTR<RRArray<typename RRPrimUtil<T>::ElementArrayType> > GetNumericArray() { return rr_array; }
2355 RR_OVIRTUAL RR_INTRUSIVE_PTR<RRBaseArray> GetNumericBaseArray() RR_OVERRIDE { return rr_array; }
2356
2357 RR_OVIRTUAL std::string RRType() RR_OVERRIDE { return "RobotRaconteur.RRNamedArray"; }
2358
2359 RR_OVIRTUAL boost::string_ref RRElementTypeString() RR_OVERRIDE { return RRPrimUtil<T>::GetRRElementTypeString(); }
2360
2361 // C++ container support functions based on boost::array
2362
2363 // type definitions
2365 typedef T value_type;
2367 typedef T* iterator;
2369 typedef const T* const_iterator;
2371 typedef T& reference;
2373 typedef const T& const_reference;
2375 typedef std::size_t size_type;
2377 typedef std::ptrdiff_t difference_type;
2378
2379 // iterator support
2380
2381 // The numeric array is viewed as `namedarray` elements through void_ptr(), as operator[] does (a static_cast from
2382 // the numeric element pointer does not compile)
2383
2385 iterator begin() { return static_cast<T*>(rr_array->void_ptr()); }
2387 const_iterator begin() const { return static_cast<const T*>(rr_array->void_ptr()); }
2389 const_iterator cbegin() const { return begin(); }
2390
2392 iterator end() { return begin() + size(); }
2394 const_iterator end() const { return begin() + size(); }
2396 const_iterator cend() const { return end(); }
2397
2399 typedef boost::reverse_iterator<iterator> reverse_iterator;
2401 typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
2402
2409
2416
2419 {
2420 BOOST_ASSERT_MSG(i < size(), "out of range");
2421 return (static_cast<T*>(rr_array->void_ptr())[i]);
2422 }
2423
2426 {
2427 BOOST_ASSERT_MSG(i < size(), "out of range");
2428 return (static_cast<T*>(rr_array->void_ptr())[i]);
2429 }
2430
2433 {
2434 rangecheck(i);
2435 return (static_cast<T*>(rr_array->void_ptr())[i]);
2436 }
2437
2439 {
2440 rangecheck(i);
2441 return (static_cast<T*>(rr_array->void_ptr())[i]);
2442 }
2443
2445 reference front() { return this->at(0); }
2447 const_reference front() const { return this->at(0); }
2448
2450 reference back() { return this->at(size() - 1); }
2452 const_reference back() const { return this->at(size() - 1); }
2453
2455 bool empty() { return rr_array->empty(); }
2457 size_type max_size() { return size(); }
2458
2459 void rangecheck(size_type i) const
2460 {
2461 if (i >= size())
2462 {
2463 std::out_of_range e("array<>: index out of range");
2464 boost::throw_exception(e);
2465 }
2466 }
2467};
2468
2476class RRNamedBaseMultiDimArray : public RRValue
2477{
2478 public:
2479 RR_INTRUSIVE_PTR<RRArray<uint32_t> > Dims;
2480 virtual boost::string_ref RRElementTypeString() = 0;
2481};
2482
2502template <typename T>
2503class RRNamedMultiDimArray : public RRNamedBaseMultiDimArray
2504{
2505 public:
2506 typename RR_INTRUSIVE_PTR<RRNamedArray<T> > NamedArray;
2507
2508 RRNamedMultiDimArray() {}
2509
2510 RRNamedMultiDimArray(const RR_INTRUSIVE_PTR<RRArray<uint32_t> >& dims, const RR_INTRUSIVE_PTR<RRNamedArray<T> >& a)
2511 {
2512 this->Dims = dims;
2513 this->NamedArray = a;
2514 }
2515
2516 RR_OVIRTUAL ~RRNamedMultiDimArray() RR_OVERRIDE {}
2517
2518 RR_OVIRTUAL std::string RRType() RR_OVERRIDE { return "RobotRaconteur.RRNamedMultiDimArray"; }
2519
2520 RR_OVIRTUAL boost::string_ref RRElementTypeString() RR_OVERRIDE { return RRPrimUtil<T>::GetRRElementTypeString(); }
2521
2530 virtual void RetrieveSubArray(const std::vector<uint32_t>& memorypos,
2531 const RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> >& buffer,
2532 const std::vector<uint32_t>& bufferpos, const std::vector<uint32_t>& count)
2533 {
2534
2535 std::vector<uint32_t> mema_dims = RRArrayToVector<uint32_t>(Dims);
2536 std::vector<uint32_t> memb_dims = RRArrayToVector<uint32_t>(buffer->Dims);
2537 detail::MultiDimArray_CheckArraySize(mema_dims, NamedArray->size());
2538 detail::MultiDimArray_CheckArraySize(memb_dims, buffer->NamedArray->size());
2539 RR_SHARED_PTR<detail::MultiDimArray_CalculateCopyIndicesIter> iter =
2540 detail::MultiDimArray_CalculateCopyIndicesBeginIter(mema_dims, memorypos, memb_dims, bufferpos, count);
2541
2542 uint32_t len = 0;
2543 uint32_t indexa = 0;
2544 uint32_t indexb = 0;
2545
2546 while (iter->Next(indexa, indexb, len))
2547 {
2548 for (size_t i = 0; i < len; i++)
2549 {
2550 (*buffer->NamedArray)[(indexb + i)] = (*NamedArray)[(indexa + i)];
2551 }
2552 }
2553 }
2554
2563 virtual void AssignSubArray(const std::vector<uint32_t>& memorypos,
2564 const RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> >& buffer,
2565 const std::vector<uint32_t>& bufferpos, const std::vector<uint32_t>& count)
2566 {
2567
2568 std::vector<uint32_t> mema_dims = RRArrayToVector<uint32_t>(Dims);
2569 std::vector<uint32_t> memb_dims = RRArrayToVector<uint32_t>(buffer->Dims);
2570 detail::MultiDimArray_CheckArraySize(mema_dims, NamedArray->size());
2571 detail::MultiDimArray_CheckArraySize(memb_dims, buffer->NamedArray->size());
2572 RR_SHARED_PTR<detail::MultiDimArray_CalculateCopyIndicesIter> iter =
2573 detail::MultiDimArray_CalculateCopyIndicesBeginIter(mema_dims, memorypos, memb_dims, bufferpos, count);
2574
2575 uint32_t len = 0;
2576 uint32_t indexa = 0;
2577 uint32_t indexb = 0;
2578
2579 while (iter->Next(indexa, indexb, len))
2580 {
2581 for (size_t i = 0; i < len; i++)
2582 {
2583 (*NamedArray)[(indexa + i)] = (*buffer->NamedArray)[(indexb + i)];
2584 }
2585 }
2586 }
2587};
2588
2602template <typename T>
2603static RR_INTRUSIVE_PTR<RRNamedArray<T> > AllocateEmptyRRNamedArray(size_t length)
2604{
2605 typedef typename RRPrimUtil<T>::ElementArrayType a_type;
2606 RR_INTRUSIVE_PTR<RRArray<a_type> > a = AllocateEmptyRRArray<a_type>(length * RRPrimUtil<T>::GetElementArrayCount());
2607 return new RRNamedArray<T>(a); // NOLINT(cppcoreguidelines-owning-memory)
2608}
2609
2623template <typename T>
2624static RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> > AllocateEmptyRRNamedMultiDimArray(const std::vector<uint32_t>& dims)
2625{
2626 uint32_t n_elems = boost::accumulate(dims, 1, std::multiplies<uint32_t>());
2628}
2629
2640template <typename T>
2641static RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> > AllocateEmptyRRNamedMultiDimArray()
2642{
2643 std::vector<uint32_t> length;
2644 length.push_back(0);
2646}
2647
2658template <typename T>
2659static RR_INTRUSIVE_PTR<RRNamedArray<T> > ScalarToRRNamedArray(const T& value)
2660{
2661 RR_INTRUSIVE_PTR<RRNamedArray<T> > a = AllocateEmptyRRNamedArray<T>(1);
2662 (*a)[0] = value;
2663 return a;
2664}
2665
2676template <typename T>
2677static T RRNamedArrayToScalar(const RR_INTRUSIVE_PTR<RRNamedArray<T> >& value)
2678{
2679 if (!value)
2680 {
2681 throw NullValueException("Null pointer");
2682 }
2683
2684 if (value->size() == 0)
2685 throw OutOfRangeException("Index out of range");
2686
2687 return (*value)[0];
2688}
2689
2690#define RRPrimUtilEnum(x) \
2691 template <> \
2692 class RRPrimUtil<x> \
2693 { \
2694 public: \
2695 static DataTypes GetTypeID() { return DataTypes_enum_t; } \
2696 static MessageStringPtr GetElementTypeString() { return MessageStringPtr(""); } \
2697 static boost::string_ref GetRRElementTypeString() { return ""; } \
2698 static RR_INTRUSIVE_PTR<RRArray<int32_t> > PrePack(const x& val) { return ScalarToRRArray((int32_t)val); } \
2699 template <typename U> \
2700 static x PreUnpack(const U& val) \
2701 { \
2702 return (x)RRArrayToScalar(rr_cast<RRArray<int32_t> >(val)); \
2703 } \
2704 typedef RR_INTRUSIVE_PTR<RRArray<int32_t> > BoxedType; \
2705 };
2706
2707class ROBOTRACONTEUR_CORE_API RobotRaconteurNode;
2708
2718class ROBOTRACONTEUR_CORE_API TimeSpec
2719{
2720 public:
2722 int64_t seconds;
2725
2728
2735 TimeSpec(int64_t seconds, int32_t nanoseconds);
2736
2738 bool operator==(const TimeSpec& t2) const;
2740 bool operator!=(const TimeSpec& t2) const;
2742 TimeSpec operator-(const TimeSpec& t2) const;
2744 TimeSpec operator+(const TimeSpec& t2) const;
2746 bool operator>(const TimeSpec& t2) const;
2748 bool operator>=(const TimeSpec& t2) const;
2750 bool operator<(const TimeSpec& t2) const;
2752 bool operator<=(const TimeSpec& t2) const;
2753
2756};
2757
2764
2765boost::posix_time::ptime ROBOTRACONTEUR_CORE_API TimeSpecToPTime(const TimeSpec& ts);
2772TimeSpec ROBOTRACONTEUR_CORE_API ptimeToTimeSpec(const boost::posix_time::ptime& t);
2773
2774#ifdef ROBOTRACONTEUR_USE_SMALL_VECTOR
2775typedef boost::container::small_vector<boost::asio::const_buffer, 4> const_buffers;
2776typedef boost::container::small_vector<boost::asio::mutable_buffer, 4> mutable_buffers;
2777#else
2778typedef std::vector<boost::asio::const_buffer> const_buffers;
2779typedef std::vector<boost::asio::mutable_buffer> mutable_buffers;
2780#endif
2781
2782template <typename BufferSequence>
2783void buffers_consume(BufferSequence& b, size_t count)
2784{
2785 typename BufferSequence::iterator e = b.begin();
2786 ;
2787 typename BufferSequence::iterator end = b.end();
2788 for (; e != end;)
2789 {
2790 if (count > 0)
2791 {
2792 if (count > boost::asio::buffer_size(*e))
2793 {
2794 count -= boost::asio::buffer_size(*e);
2795 e = b.erase(e);
2796 }
2797 else
2798 {
2799 *e = *e + count;
2800 count = 0;
2801 ++e;
2802 }
2803 }
2804 else
2805 {
2806 break;
2807 }
2808 }
2809}
2810
2811template <typename BufferSequence>
2812BufferSequence buffers_consume_copy(BufferSequence& b, size_t count)
2813{
2814 BufferSequence o;
2815 typename BufferSequence::iterator e = b.begin();
2816 ;
2817 typename BufferSequence::iterator end = b.end();
2818 for (; e != end; e++)
2819 {
2820 if (count > 0)
2821 {
2822 if (count > boost::asio::buffer_size(*e))
2823 {
2824 count -= boost::asio::buffer_size(*e);
2825 }
2826 else
2827 {
2828 o.push_back(*e + count);
2829 count = 0;
2830 }
2831 }
2832 else
2833 {
2834 o.push_back(*e);
2835 }
2836 }
2837
2838 return o;
2839}
2840
2841template <typename BufferSequence>
2842BufferSequence buffers_consume_copy(const BufferSequence& b, size_t count)
2843{
2844 BufferSequence o;
2845 typename BufferSequence::const_iterator e = b.begin();
2846 ;
2847 typename BufferSequence::const_iterator end = b.end();
2848 for (; e != end; e++)
2849 {
2850 if (count > 0)
2851 {
2852 if (count > boost::asio::buffer_size(*e))
2853 {
2854 count -= boost::asio::buffer_size(*e);
2855 }
2856 else
2857 {
2858 o.push_back(*e + count);
2859 count = 0;
2860 }
2861 }
2862 else
2863 {
2864 o.push_back(*e);
2865 }
2866 }
2867
2868 return o;
2869}
2870
2871template <typename BufferSequence>
2872BufferSequence buffers_truncate(BufferSequence& b, size_t count)
2873{
2874 BufferSequence o;
2875 typename BufferSequence::iterator e = b.begin();
2876 ;
2877 typename BufferSequence::iterator end = b.end();
2878 size_t p = 0;
2879 for (; e != end; e++)
2880 {
2881 if (p + boost::asio::buffer_size(*e) <= count)
2882 {
2883 o.push_back(*e);
2884 p += boost::asio::buffer_size(*e);
2885 }
2886 else
2887 {
2888 o.push_back(boost::asio::buffer(*e, count - p));
2889 break;
2890 }
2891 }
2892
2893 return o;
2894}
2895
2896template <typename BufferSequence>
2897BufferSequence buffers_truncate(const BufferSequence& b, size_t count)
2898{
2899 BufferSequence o;
2900 typename BufferSequence::const_iterator e = b.begin();
2901 ;
2902 typename BufferSequence::const_iterator end = b.end();
2903 size_t p = 0;
2904 for (; e != end; e++)
2905 {
2906 if (p + boost::asio::buffer_size(*e) <= count)
2907 {
2908 o.push_back(*e);
2909 p += boost::asio::buffer_size(*e);
2910 }
2911 else
2912 {
2913 o.push_back(boost::asio::buffer(*e, count - p));
2914 break;
2915 }
2916 }
2917
2918 return o;
2919}
2920
2921/***
2922 * @brief Service path segment containing a name and an optional index
2923 */
2924struct ROBOTRACONTEUR_CORE_API ServicePathSegment
2925{
2926
2927 ServicePathSegment();
2928
2929 ServicePathSegment(const std::string& name,
2930 const boost::optional<std::string>& index = boost::optional<std::string>());
2931
2933 std::string name;
2935 boost::optional<std::string> index;
2936};
2937
2938ROBOTRACONTEUR_CORE_API bool operator==(const ServicePathSegment& lhs, const ServicePathSegment& rhs);
2939
2940ROBOTRACONTEUR_CORE_API bool operator!=(const ServicePathSegment& lhs, const ServicePathSegment& rhs);
2941
2948ROBOTRACONTEUR_CORE_API std::string EncodeServicePathIndex(const std::string& index);
2949
2956ROBOTRACONTEUR_CORE_API std::string DecodeServicePathIndex(const std::string& index);
2957
2964ROBOTRACONTEUR_CORE_API std::vector<ServicePathSegment> ParseServicePath(const std::string& path);
2965
2972ROBOTRACONTEUR_CORE_API std::string BuildServicePath(const std::vector<ServicePathSegment>& segments);
2973
2980ROBOTRACONTEUR_CORE_API bool IsStringName(boost::string_ref str);
2987ROBOTRACONTEUR_CORE_API bool IsStringScopedName(boost::string_ref str);
2994ROBOTRACONTEUR_CORE_API bool IsStringUUID(boost::string_ref str);
3001ROBOTRACONTEUR_CORE_API bool IsStringIdentifier(boost::string_ref str);
3002
3003namespace detail
3004{
3005ROBOTRACONTEUR_CORE_API std::string encode_index(boost::string_ref index);
3006
3007ROBOTRACONTEUR_CORE_API std::string decode_index(boost::string_ref index);
3008
3009template <typename T, typename U>
3010bool try_convert_string_to_number(const U& arg, T& result)
3011{
3012 if (boost::conversion::try_lexical_convert(arg, result))
3013 {
3014 return true;
3015 }
3016
3017 if (!boost::is_integral<T>::value)
3018 {
3019 return false;
3020 }
3021
3022 boost::regex hex_regex("^[+\\-]?0x[\\da-fA-F]+$");
3023 if (!boost::regex_match(arg.begin(), arg.end(), hex_regex))
3024 {
3025 return false;
3026 }
3027
3028 std::stringstream ss;
3029 ss << std::hex << arg;
3030 T v;
3031 ss >> v;
3032 if (ss.fail() || !ss.eof())
3033 {
3034 return false;
3035 }
3036
3037 result = v;
3038
3039 return true;
3040}
3041
3042// boost::lexical_cast and operator>> treat 8-bit integers as characters, so convert
3043// through int32_t and check the range
3044template <typename U>
3045bool try_convert_string_to_number(const U& arg, int8_t& result)
3046{
3047 int32_t v = 0;
3048 if (!try_convert_string_to_number(arg, v))
3049 {
3050 return false;
3051 }
3052 if (v < std::numeric_limits<int8_t>::min() || v > std::numeric_limits<int8_t>::max())
3053 {
3054 return false;
3055 }
3056 result = static_cast<int8_t>(v);
3057 return true;
3058}
3059
3060template <typename U>
3061bool try_convert_string_to_number(const U& arg, uint8_t& result)
3062{
3063 int32_t v = 0;
3064 if (!try_convert_string_to_number(arg, v))
3065 {
3066 return false;
3067 }
3068 if (v < 0 || v > std::numeric_limits<uint8_t>::max())
3069 {
3070 return false;
3071 }
3072 result = static_cast<uint8_t>(v);
3073 return true;
3074}
3075
3076} // namespace detail
3077
3078#ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
3080using RRObjectPtr = RR_SHARED_PTR<RRObject>;
3082using RRObjectConstPtr = RR_SHARED_PTR<const RRObject>;
3084using RRValuePtr = RR_INTRUSIVE_PTR<RRValue>;
3086using RRValueConstPtr = RR_INTRUSIVE_PTR<const RRValue>;
3088using MessageElementDataPtr = RR_INTRUSIVE_PTR<MessageElementData>;
3090using MessageElementDataConstPtr = RR_INTRUSIVE_PTR<const MessageElementData>;
3092using RRBaseArrayPtr = RR_INTRUSIVE_PTR<RRBaseArray>;
3094using RRBaseArrayConstPtr = RR_INTRUSIVE_PTR<const RRBaseArray>;
3096template <typename T>
3097using RRArrayPtr = RR_INTRUSIVE_PTR<RRArray<T> >;
3099template <typename T>
3100using RRArrayConstPtr = RR_INTRUSIVE_PTR<const RRArray<T> >;
3102template <typename K, typename T>
3103using RRMapPtr = RR_INTRUSIVE_PTR<RRMap<K, T> >;
3105template <typename K, typename T>
3106using RRMapConstPtr = RR_INTRUSIVE_PTR<const RRMap<K, T> >;
3108template <typename T>
3109using RRListPtr = RR_INTRUSIVE_PTR<RRList<T> >;
3111template <typename T>
3112using RRListConstPtr = RR_INTRUSIVE_PTR<const RRList<T> >;
3114using RRStructurePtr = RR_INTRUSIVE_PTR<RRStructure>;
3116using RRStructureConstPtr = RR_INTRUSIVE_PTR<const RRStructure>;
3118using RRMultiDimBaseArrayPtr = RR_INTRUSIVE_PTR<RRMultiDimBaseArray>;
3120using RRMultiDimBaseArrayConstPtr = RR_INTRUSIVE_PTR<const RRMultiDimBaseArray>;
3122template <typename T>
3123using RRMultiDimArrayPtr = RR_INTRUSIVE_PTR<RRMultiDimArray<T> >;
3125template <typename T>
3126using RRMultiDimArrayConstPtr = RR_INTRUSIVE_PTR<const RRMultiDimArray<T> >;
3128using RRPodBaseArrayPtr = RR_INTRUSIVE_PTR<RRPodBaseArray>;
3130using RRPodBaseArrayConstPtr = RR_INTRUSIVE_PTR<const RRPodBaseArray>;
3132template <typename T>
3133using RRPodArrayPtr = RR_INTRUSIVE_PTR<RRPodArray<T> >;
3135template <typename T>
3136using RRPodArrayConstPtr = RR_INTRUSIVE_PTR<const RRPodArray<T> >;
3138using RRPodBaseMultiDimArrayPtr = RR_INTRUSIVE_PTR<RRPodBaseMultiDimArray>;
3140using RRPodBaseMultiDimBaseArrayConstPtr = RR_INTRUSIVE_PTR<const RRPodBaseMultiDimArray>;
3142template <typename T>
3143using RRPodMultiDimArrayPtr = RR_INTRUSIVE_PTR<RRPodMultiDimArray<T> >;
3145template <typename T>
3146using RRPodMultiDimArrayConstPtr = RR_INTRUSIVE_PTR<const RRPodMultiDimArray<T> >;
3148using RRNamedBaseArrayPtr = RR_INTRUSIVE_PTR<RRNamedBaseArray>;
3150using RRNamedBaseArrayConstPtr = RR_INTRUSIVE_PTR<const RRNamedBaseArray>;
3152template <typename T>
3153using RRNamedArrayPtr = RR_INTRUSIVE_PTR<RRNamedArray<T> >;
3155template <typename T>
3156using RRNamedArrayConstPtr = RR_INTRUSIVE_PTR<const RRNamedArray<T> >;
3158using RRNamedBaseMultiDimArrayPtr = RR_INTRUSIVE_PTR<RRNamedBaseMultiDimArray>;
3160using RRNamedBaseMultiDimBaseArrayConstPtr = RR_INTRUSIVE_PTR<const RRNamedBaseMultiDimArray>;
3162template <typename T>
3163using RRNamedMultiDimArrayPtr = RR_INTRUSIVE_PTR<RRNamedMultiDimArray<T> >;
3165template <typename T>
3166using RRNamedMultiDimArrayConstPtr = RR_INTRUSIVE_PTR<const RRNamedMultiDimArray<T> >;
3167#endif
3168} // namespace RobotRaconteur
boost::intrusive_ptr< RRMap< K, T > > AllocateEmptyRRMap()
Allocate an empty RRMap.
Definition DataTypes.h:1869
static T RRNamedArrayToScalar(const boost::intrusive_ptr< RRNamedArray< T > > &value)
Convert a namedarray array with one element into a namedarray.
Definition DataTypes.h:2677
boost::intrusive_ptr< RRArray< char > > stringToRRArray(boost::string_ref str)
Convert a string to an array of characters.
static boost::intrusive_ptr< RRPodArray< T > > AllocateEmptyRRPodArray(size_t length)
Allocate a pod array with the specified type and length and initialize to zero.
Definition DataTypes.h:2215
static boost::intrusive_ptr< RRArray< Y > > VectorToRRArray(const std::vector< U > &in)
Convert a std::vector to an RRArray<Y>.
Definition DataTypes.h:1270
boost::shared_ptr< const RRObject > RRObjectConstPtr
Convenience alias for RRObject const shared_ptr.
Definition DataTypes.h:3082
boost::intrusive_ptr< RRList< T > > RRListPtr
Convenience alias for RRList intrusive_ptr.
Definition DataTypes.h:3109
boost::intrusive_ptr< RRPodBaseMultiDimArray > RRPodBaseMultiDimArrayPtr
Convenience alias for RRPodBaseMultiDimArray intrusive_ptr.
Definition DataTypes.h:3138
boost::intrusive_ptr< T > & rr_null_check(boost::intrusive_ptr< T > &ptr)
Checks if a value RR_INTRUSIVE_PTR is null.
Definition DataTypes.h:1456
static boost::intrusive_ptr< RRArray< Y > > ArrayToRRArray(boost::array< U, N > in)
Convert a boost::array to an RRArray.
Definition DataTypes.h:1338
static T RRArrayToScalar(const boost::intrusive_ptr< RRArray< T > > &value)
Convert an array with one element into a scalar.
Definition DataTypes.h:1221
boost::intrusive_ptr< RRMap< K, T > > RRMapPtr
Convenience alias for RRMap intrusive_ptr.
Definition DataTypes.h:3103
static boost::intrusive_ptr< RRArray< T > > AttachRRArrayCopy(const T *data, const size_t length)
Allocates an array object and copies existing numeric.
Definition DataTypes.h:1134
boost::intrusive_ptr< const RRList< T > > RRListConstPtr
Convenience alias for RRList const intrusive_ptr.
Definition DataTypes.h:3112
boost::intrusive_ptr< RRPodBaseArray > RRPodBaseArrayPtr
Convenience alias for RRPodBaseArray intrusive_ptr.
Definition DataTypes.h:3128
static boost::shared_ptr< T > rr_cast(const boost::shared_ptr< U > &objin)
Dynamic cast a RR_SHARED_PTR type. Throws DataTypeMismatchException if cast is invalid instead of ret...
Definition DataTypes.h:200
boost::intrusive_ptr< RRPodArray< T > > RRPodArrayPtr
Convenience alias for RRPodArray intrusive_ptr.
Definition DataTypes.h:3133
size_t RRArrayElementSize(DataTypes type)
Get the number of bytes to store a numeric primitive scalar.
static boost::intrusive_ptr< RRPodMultiDimArray< T > > AllocateEmptyRRPodMultiDimArray(const std::vector< uint32_t > &dims)
Allocate an empty multidimensional pod array with the specified dimensions.
Definition DataTypes.h:2234
static boost::intrusive_ptr< RRArray< T > > ScalarToRRArray(T value)
Convert a scalar number into an array with one element.
Definition DataTypes.h:1208
boost::intrusive_ptr< const MessageElementData > MessageElementDataConstPtr
Convenience alias for MessageElementData const intrusive_ptr.
Definition DataTypes.h:3090
std::vector< ServicePathSegment > ParseServicePath(const std::string &path)
Parse a Robot Raconteur service path into segments.
boost::intrusive_ptr< const RRNamedBaseMultiDimArray > RRNamedBaseMultiDimBaseArrayConstPtr
Convenience alias for RRNamedBaseMultiDimArray const intrusive_ptr.
Definition DataTypes.h:3160
boost::intrusive_ptr< MessageElementData > MessageElementDataPtr
Convenience alias for MessageElementData intrusive_ptr.
Definition DataTypes.h:3088
bool IsStringIdentifier(boost::string_ref str)
Test if a string is a Robot Raconteur identifier.
boost::intrusive_ptr< RRValue > RRValuePtr
Convenience alias for RRValue intrusive_ptr.
Definition DataTypes.h:3084
boost::posix_time::ptime TimeSpecToPTime(const TimeSpec &ts)
Convert a TimeSpec into a boost::posix_time::ptime.
boost::intrusive_ptr< const RRPodMultiDimArray< T > > RRPodMultiDimArrayConstPtr
Convenience alias for RRPodMultiDimArray const intrusive_ptr.
Definition DataTypes.h:3146
static boost::intrusive_ptr< RRPodArray< T > > ScalarToRRPodArray(const T &value)
Convert a scalar pod into a pod array with one element.
Definition DataTypes.h:2175
boost::intrusive_ptr< RRList< T > > AllocateRRList(const U &c)
Allocate RRList with a value.
Definition DataTypes.h:1856
std::string RRArrayToString(const boost::intrusive_ptr< RRArray< char > > &arr)
Convert an array of characters into std::string.
TimeSpec ptimeToTimeSpec(const boost::posix_time::ptime &t)
Convert a boost::posix_time::ptime into a TimeSpec.
static T RRPodArrayToScalar(const boost::intrusive_ptr< RRPodArray< T > > &value)
Convert a pod array with one element into a scalar pod.
Definition DataTypes.h:2188
boost::intrusive_ptr< RRList< RRArray< char > > > stringVectorToRRList(const std::vector< std::string > &string_vector)
Convert a string vector to a RRList.
boost::intrusive_ptr< RRPodMultiDimArray< T > > RRPodMultiDimArrayPtr
Convenience alias for RRPodMultiDimArray intrusive_ptr.
Definition DataTypes.h:3143
boost::intrusive_ptr< const RRPodArray< T > > RRPodArrayConstPtr
Convenience alias for RRPodArray const intrusive_ptr.
Definition DataTypes.h:3136
boost::intrusive_ptr< const RRPodBaseMultiDimArray > RRPodBaseMultiDimBaseArrayConstPtr
Convenience alias for RRPodBaseMultiDimArray const intrusive_ptr.
Definition DataTypes.h:3140
boost::intrusive_ptr< const RRNamedBaseArray > RRNamedBaseArrayConstPtr
Convenience alias for RRNamedBaseArray const intrusive_ptr.
Definition DataTypes.h:3150
static boost::intrusive_ptr< RRArray< T > > AllocateEmptyRRArray(size_t length)
Allocate a numeric primitive or character array with the specified type and length and initialize to ...
Definition DataTypes.h:1175
boost::shared_ptr< RRObject > RRObjectPtr
Convenience alias for RRObject shared_ptr.
Definition DataTypes.h:3080
boost::intrusive_ptr< RRNamedArray< T > > RRNamedArrayPtr
Convenience alias for RRNamedArray intrusive_ptr.
Definition DataTypes.h:3153
boost::intrusive_ptr< const RRMultiDimArray< T > > RRMultiDimArrayConstPtr
Convenience alias for RRMultiDimArray const intrusive_ptr.
Definition DataTypes.h:3126
static boost::intrusive_ptr< RRNamedArray< T > > AllocateEmptyRRNamedArray(size_t length)
Allocate a namedarray array with the specified type and length and initialize to zero.
Definition DataTypes.h:2603
std::vector< std::string > RRListToStringVector(const boost::intrusive_ptr< RRList< RRArray< char > > > &list)
Convert a RRList containing strings to a string vector.
boost::intrusive_ptr< RRMultiDimBaseArray > RRMultiDimBaseArrayPtr
Convenience alias for RRMultiDimBaseArray intrusive_ptr.
Definition DataTypes.h:3118
static boost::intrusive_ptr< RRArray< T > > AllocateRRArray(size_t length)
Allocate a numeric primitive or character array with the specified type and length.
Definition DataTypes.h:1092
boost::intrusive_ptr< RRNamedBaseMultiDimArray > RRNamedBaseMultiDimArrayPtr
Convenience alias for RRNamedBaseMultiDimArray intrusive_ptr.
Definition DataTypes.h:3158
boost::intrusive_ptr< const RRArray< T > > RRArrayConstPtr
Convenience alias for RRArray const intrusive_ptr.
Definition DataTypes.h:3100
boost::intrusive_ptr< RRNamedMultiDimArray< T > > RRNamedMultiDimArrayPtr
Convenience alias for RRNamedMultiDimArray intrusive_ptr.
Definition DataTypes.h:3163
boost::intrusive_ptr< RRBaseArray > AllocateRRArrayByType(DataTypes type, size_t length)
Allocate an RRBaseArray by type code.
boost::intrusive_ptr< const RRMultiDimBaseArray > RRMultiDimBaseArrayConstPtr
Convenience alias for RRMultiDimBaseArray const intrusive_ptr.
Definition DataTypes.h:3120
boost::intrusive_ptr< RRArray< T > > RRArrayPtr
Convenience alias for RRArray intrusive_ptr.
Definition DataTypes.h:3097
boost::intrusive_ptr< RRStructure > RRStructurePtr
Convenience alias for RRStructure intrusive_ptr.
Definition DataTypes.h:3114
bool IsStringUUID(boost::string_ref str)
Test if a string is a UUID.
static boost::intrusive_ptr< RRMultiDimArray< T > > AllocateRRMultiDimArray(const boost::intrusive_ptr< RRArray< uint32_t > > &dims, const boost::intrusive_ptr< RRArray< T > > &array_)
Allocate a multidimensional using existing dimensions and data array.
Definition DataTypes.h:1829
static boost::intrusive_ptr< RRNamedArray< T > > ScalarToRRNamedArray(const T &value)
Convert a scalar namedarray into a namedarray array with one element.
Definition DataTypes.h:2659
bool IsStringName(boost::string_ref str)
Test if a string is a valid Robot Raconteur name.
boost::intrusive_ptr< const RRBaseArray > RRBaseArrayConstPtr
Convenience alias for RRBaseArray const intrusive_ptr.
Definition DataTypes.h:3094
boost::intrusive_ptr< RRBaseArray > RRBaseArrayPtr
Convenience alias for RRBaseArray intrusive_ptr.
Definition DataTypes.h:3092
static boost::intrusive_ptr< RRArray< T > > AttachRRArray(T *data, size_t length, bool owned)
Allocates an array object and attaches to existing numeric primitive or character array pointer.
Definition DataTypes.h:1116
boost::intrusive_ptr< RRMap< K, T > > AllocateRRMap(const U &c)
Allocate RRMap with value.
Definition DataTypes.h:1884
boost::intrusive_ptr< RRMultiDimArray< T > > RRMultiDimArrayPtr
Convenience alias for RRMultiDimArray intrusive_ptr.
Definition DataTypes.h:3123
boost::intrusive_ptr< const RRPodBaseArray > RRPodBaseArrayConstPtr
Convenience alias for RRPodBaseArray const intrusive_ptr.
Definition DataTypes.h:3130
boost::intrusive_ptr< const RRStructure > RRStructureConstPtr
Convenience alias for RRStructure const intrusive_ptr.
Definition DataTypes.h:3116
boost::intrusive_ptr< const RRValue > RRValueConstPtr
Convenience alias for RRValue const intrusive_ptr.
Definition DataTypes.h:3086
boost::intrusive_ptr< const RRMap< K, T > > RRMapConstPtr
Convenience alias for RRMap const intrusive_ptr.
Definition DataTypes.h:3106
boost::intrusive_ptr< const RRNamedMultiDimArray< T > > RRNamedMultiDimArrayConstPtr
Convenience alias for RRNamedMultiDimArray const intrusive_ptr.
Definition DataTypes.h:3166
std::string BuildServicePath(const std::vector< ServicePathSegment > &segments)
Build a Robot Raconteur service path from segments.
bool IsStringScopedName(boost::string_ref str)
Test if a string is a valid Robot Raconteur scoped name.
boost::intrusive_ptr< const RRNamedArray< T > > RRNamedArrayConstPtr
Convenience alias for RRNamedArray const intrusive_ptr.
Definition DataTypes.h:3156
boost::intrusive_ptr< RRList< T > > AllocateEmptyRRList()
Allocate an empty RRList.
Definition DataTypes.h:1842
static boost::container::static_vector< Y, N > RRArrayToStaticVector(const boost::intrusive_ptr< RRArray< U > > &in)
Convert an RRArray to a boost::static_vector.
Definition DataTypes.h:1361
static boost::intrusive_ptr< RRNamedMultiDimArray< T > > AllocateEmptyRRNamedMultiDimArray(const std::vector< uint32_t > &dims)
Allocate an empty multidimensional namedarray array with the specified dimensions.
Definition DataTypes.h:2624
std::string EncodeServicePathIndex(const std::string &index)
Encode a service path index for use in a Robot Raconteur service path.
static std::vector< Y > RRArrayToVector(const boost::intrusive_ptr< RRArray< U > > &in)
Convert an RRArray<U> to a std::vector<Y>.
Definition DataTypes.h:1248
static boost::array< Y, N > RRArrayToArray(const boost::intrusive_ptr< RRArray< U > > &in)
Convert an RRArray to a boost::array.
Definition DataTypes.h:1291
boost::intrusive_ptr< RRNamedBaseArray > RRNamedBaseArrayPtr
Convenience alias for RRNamedBaseArray intrusive_ptr.
Definition DataTypes.h:3148
static boost::intrusive_ptr< RRArray< Y > > StaticVectorToRRArray(boost::container::static_vector< U, N > in)
Convert a boost::container::static_vector to an RRArray.
Definition DataTypes.h:1414
std::string DecodeServicePathIndex(const std::string &index)
Decode a service path index from a Robot Raconteur service path.
static boost::intrusive_ptr< RRMultiDimArray< T > > AllocateEmptyRRMultiDimArray(const std::vector< uint32_t > &dims)
Allocate an empty multidimensional array with the specified dimensions.
Definition DataTypes.h:1798
DataTypes
Type codes for types supported by Robot Raconteur.
Definition RobotRaconteurConstants.h:41
@ DataTypes_single_t
IEEE-754 32-bit floating point number.
Definition RobotRaconteurConstants.h:47
@ DataTypes_uint8_t
8-bit unsigned integer
Definition RobotRaconteurConstants.h:51
@ DataTypes_int16_t
16-bit signed integer
Definition RobotRaconteurConstants.h:53
@ DataTypes_uint32_t
32-bit unsigned integer
Definition RobotRaconteurConstants.h:59
@ DataTypes_uint16_t
16-bit unsigned integer
Definition RobotRaconteurConstants.h:55
@ DataTypes_int8_t
8-bit signed integer
Definition RobotRaconteurConstants.h:49
@ DataTypes_uint64_t
64-bit unsigned integer
Definition RobotRaconteurConstants.h:63
@ DataTypes_double_t
IEEE-754 64-bit floating point number.
Definition RobotRaconteurConstants.h:45
@ DataTypes_int64_t
64-bit signed integer
Definition RobotRaconteurConstants.h:61
@ DataTypes_string_t
UTF-8 string.
Definition RobotRaconteurConstants.h:65
@ DataTypes_int32_t
32-bit signed integer
Definition RobotRaconteurConstants.h:57
@ DataTypes_void_t
void or null type
Definition RobotRaconteurConstants.h:43
@ DataTypes_bool_t
8-bit boolean
Definition RobotRaconteurConstants.h:71
@ DataTypes_cdouble_t
128-bit complex double (real,imag)
Definition RobotRaconteurConstants.h:67
@ DataTypes_csingle_t
64-bit complex float (real,imag)
Definition RobotRaconteurConstants.h:69
DataTypeMismatchException(const std::string &message, std::string sub_name="", const boost::intrusive_ptr< RRValue > &param_=boost::intrusive_ptr< RRValue >())
Construct a DataTypeMismatchException.
Base class for types that can be stored in MessageElement.
Definition DataTypes.h:375
Exception thrown for an unexpected null value.
Definition Error.h:669
Exception thrown when an attempt to access an array or container index is out of range.
Definition Error.h:875
Numeric primitive or character array value type.
Definition DataTypes.h:579
std::ptrdiff_t difference_type
Definition DataTypes.h:615
RRArray< T > & operator=(const RRArray< T2 > &rhs)
assignment with type conversion
Definition DataTypes.h:711
T value_type
Definition DataTypes.h:603
reference operator[](size_type i)
access specified element
Definition DataTypes.h:653
reference back()
access the last element
Definition DataTypes.h:686
RR_OVIRTUAL size_t size() RR_OVERRIDE
Get the number of elements in the array.
Definition DataTypes.h:595
const_reverse_iterator rend() const
returns a reverse iterator to the end
Definition DataTypes.h:648
const_iterator cend() const
returns a const iterator to the end
Definition DataTypes.h:631
bool empty()
checks whether the container is empty
Definition DataTypes.h:692
const T & const_reference
Definition DataTypes.h:611
std::size_t size_type
Definition DataTypes.h:613
void fill(const T &value)
Fill array with value.
Definition DataTypes.h:733
const_reference at(size_type i) const
access specified element with bounds checking
Definition DataTypes.h:673
iterator begin()
returns an iterator to the beginning
Definition DataTypes.h:620
const_reverse_iterator crend() const
returns a reverse iterator to the end
Definition DataTypes.h:650
reverse_iterator rend()
returns a reverse iterator to the end
Definition DataTypes.h:646
iterator end()
returns an iterator to the end
Definition DataTypes.h:627
const_reference operator[](size_type i) const
access specified element
Definition DataTypes.h:660
size_type max_size()
returns the maximum possible number of elements
Definition DataTypes.h:694
reverse_iterator rbegin()
returns a reverse iterator to the beginning
Definition DataTypes.h:639
boost::reverse_iterator< const_iterator > const_reverse_iterator
Definition DataTypes.h:636
boost::reverse_iterator< iterator > reverse_iterator
Definition DataTypes.h:634
const_iterator end() const
returns an iterator to the end
Definition DataTypes.h:629
const_reverse_iterator rbegin() const
returns a reverse iterator to the beginning
Definition DataTypes.h:641
T * data()
direct access to the underlying array
Definition DataTypes.h:699
const_reference back() const
access the last element
Definition DataTypes.h:689
reference front()
access the first element
Definition DataTypes.h:680
const T * const_iterator
Definition DataTypes.h:607
RR_OVIRTUAL void * void_ptr() RR_OVERRIDE
Get a void pointer to the contained array.
Definition DataTypes.h:591
T * iterator
Definition DataTypes.h:605
T & reference
Definition DataTypes.h:609
const_iterator cbegin() const
returns a const iterator to the beginning
Definition DataTypes.h:624
const_reverse_iterator crbegin() const
returns a reverse iterator to the beginning
Definition DataTypes.h:643
const_reference front() const
access the first element
Definition DataTypes.h:683
const_iterator begin() const
returns an iterator to the beginning
Definition DataTypes.h:622
void assign(const T &value)
Assign one value to all elements.
Definition DataTypes.h:727
reference at(size_type i)
access specified element with bounds checking
Definition DataTypes.h:667
const T * data() const
direct access to the underlying array
Definition DataTypes.h:697
RR_OVIRTUAL size_t ElementSize() RR_OVERRIDE
Get the number of bytes per element of the array.
Definition DataTypes.h:597
Base class for numeric and character array value types.
Definition DataTypes.h:526
virtual size_t size()=0
Get the number of elements in the array.
virtual size_t ElementSize()=0
Get the number of bytes per element of the array.
virtual void * void_ptr()=0
Get a void pointer to the contained array.
List container value type.
Definition DataTypes.h:955
const_iterator begin() const
returns an iterator to the beginning
Definition DataTypes.h:996
std::list< boost::intrusive_ptr< T > >::const_iterator const_iterator
Definition DataTypes.h:987
std::list< boost::intrusive_ptr< T > > & GetStorageContainer()
Get the underlying storage container.
Definition DataTypes.h:1059
void pop_back()
removes the last element
Definition DataTypes.h:1040
std::list< boost::intrusive_ptr< T > >::reference reference
Definition DataTypes.h:977
std::list< boost::intrusive_ptr< T > >::iterator iterator
Definition DataTypes.h:985
std::list< boost::intrusive_ptr< T > >::reverse_iterator reverse_iterator
Definition DataTypes.h:989
std::list< boost::intrusive_ptr< T > >::const_pointer const_pointer
Definition DataTypes.h:975
iterator erase(const_iterator first, const_iterator last)
erases element
Definition DataTypes.h:1046
std::list< boost::intrusive_ptr< T > >::const_reverse_iterator const_reverse_iterator
Definition DataTypes.h:991
const_reverse_iterator const crend()
returns a reverse iterator to the end
Definition DataTypes.h:1018
reference front()
access the first element
Definition DataTypes.h:1026
std::list< boost::intrusive_ptr< T > >::size_type size_type
Definition DataTypes.h:981
void clear()
clears the contents
Definition DataTypes.h:1048
size_type max_size() const
returns the maximum possible number of elements
Definition DataTypes.h:1024
const_reverse_iterator crend() const
returns a reverse iterator to the end
Definition DataTypes.h:1008
iterator insert(const_iterator p, const boost::intrusive_ptr< T > &x)
inserts element
Definition DataTypes.h:1042
std::list< boost::intrusive_ptr< T > >::pointer pointer
Definition DataTypes.h:973
const_reference back() const
access the last element
Definition DataTypes.h:1032
std::list< boost::intrusive_ptr< T > >::difference_type difference_type
Definition DataTypes.h:983
const_reference front() const
access the first element
Definition DataTypes.h:1028
void push_front(const boost::intrusive_ptr< T > &x)
inserts an element at the beginning
Definition DataTypes.h:1034
reference back()
access the last element
Definition DataTypes.h:1030
void remove(const boost::intrusive_ptr< T > &value)
removes elements equal to value
Definition DataTypes.h:1050
reverse_iterator rbegin()
returns a reverse iterator to the beginning
Definition DataTypes.h:1002
void push_back(const boost::intrusive_ptr< T > &x)
adds an element to the end
Definition DataTypes.h:1036
const_iterator cend() const
returns an iterator to the end
Definition DataTypes.h:1014
const_reverse_iterator const crbegin()
returns a reverse iterator to the beginning
Definition DataTypes.h:1016
iterator begin()
returns an iterator to the beginning
Definition DataTypes.h:994
const_reverse_iterator rend() const
returns a reverse iterator to the end
Definition DataTypes.h:1010
bool empty() const
checks whether the container is empty
Definition DataTypes.h:1020
boost::intrusive_ptr< T > value_type
Definition DataTypes.h:971
void pop_front()
removes the first element
Definition DataTypes.h:1038
virtual size_type size() const
returns the number of elements
Definition DataTypes.h:1022
const_iterator end() const
returns an iterator to the end
Definition DataTypes.h:1000
const_reverse_iterator rbegin() const
returns a reverse iterator to the beginning
Definition DataTypes.h:1004
std::list< boost::intrusive_ptr< T > >::const_reference const_reference
Definition DataTypes.h:979
const_iterator cbegin() const
returns an iterator to the beginning
Definition DataTypes.h:1012
reverse_iterator rend()
returns a reverse iterator to the end
Definition DataTypes.h:1006
iterator erase(const_iterator p)
erases element
Definition DataTypes.h:1044
iterator end()
returns an iterator to the end
Definition DataTypes.h:998
Map container value type.
Definition DataTypes.h:829
void erase(iterator p)
erases element
Definition DataTypes.h:920
std::pair< iterator, bool > insert(const value_type &x)
inserts elements
Definition DataTypes.h:906
iterator end()
returns an iterator to the end
Definition DataTypes.h:876
std::map< K, boost::intrusive_ptr< T > >::value_type value_type
Definition DataTypes.h:849
std::map< K, boost::intrusive_ptr< T > >::key_type key_type
Definition DataTypes.h:845
const_reverse_iterator rbegin() const
returns a reverse iterator to the beginning
Definition DataTypes.h:886
const_iterator begin() const
returns an iterator to the beginning
Definition DataTypes.h:874
const_reverse_iterator crbegin() const
returns a reverse iterator to the beginning
Definition DataTypes.h:884
mapped_type & operator[](const key_type &k)
access or insert the specified element
Definition DataTypes.h:900
std::map< K, boost::intrusive_ptr< T > > & GetStorageContainer()
Get the underlying storage container.
Definition DataTypes.h:941
std::map< K, boost::intrusive_ptr< T > >::const_iterator const_iterator
Definition DataTypes.h:863
const_reverse_iterator crend() const
returns a reverse iterator to the end
Definition DataTypes.h:890
size_type size() const
returns the number of elements
Definition DataTypes.h:896
const_iterator find(const key_type &x) const
finds element with the specified key
Definition DataTypes.h:930
bool empty() const
checks whether the container is empty
Definition DataTypes.h:894
iterator find(const key_type &x)
finds element with the specified key
Definition DataTypes.h:928
void erase(iterator first, iterator last)
erases element
Definition DataTypes.h:924
std::map< K, boost::intrusive_ptr< T > >::const_reverse_iterator const_reverse_iterator
Definition DataTypes.h:867
const mapped_type & at(const key_type &k) const
access specified element with bounds checking
Definition DataTypes.h:904
std::map< K, boost::intrusive_ptr< T > >::pointer pointer
Definition DataTypes.h:851
size_type count(const key_type &x) const
returns the number of elements matching the specified key
Definition DataTypes.h:932
reverse_iterator rend()
returns a reverse iterator to the end
Definition DataTypes.h:888
std::map< K, boost::intrusive_ptr< T > >::iterator iterator
Definition DataTypes.h:861
mapped_type & at(const key_type &k)
access specified element with bounds checking
Definition DataTypes.h:902
const_iterator end() const
returns an iterator to the end
Definition DataTypes.h:880
void clear()
clears the contents
Definition DataTypes.h:926
std::map< K, boost::intrusive_ptr< T > >::reverse_iterator reverse_iterator
Definition DataTypes.h:865
std::map< K, boost::intrusive_ptr< T > >::mapped_type mapped_type
Definition DataTypes.h:847
std::map< K, boost::intrusive_ptr< T > >::reference reference
Definition DataTypes.h:855
const_iterator cend() const
returns an iterator to the end
Definition DataTypes.h:878
size_type max_size() const
returns the maximum possible number of elements
Definition DataTypes.h:898
std::map< K, boost::intrusive_ptr< T > >::const_reference const_reference
Definition DataTypes.h:857
iterator begin()
returns an iterator to the beginning
Definition DataTypes.h:870
iterator insert(const_iterator p, const value_type &x)
inserts elements
Definition DataTypes.h:908
const_reverse_iterator rend() const
returns a reverse iterator to the end
Definition DataTypes.h:892
const_iterator cbegin() const
returns an iterator to the beginning
Definition DataTypes.h:872
std::map< K, boost::intrusive_ptr< T > >::const_pointer const_pointer
Definition DataTypes.h:853
std::map< K, boost::intrusive_ptr< T > >::size_type size_type
Definition DataTypes.h:859
size_type erase(const key_type &x)
erases element
Definition DataTypes.h:922
void insert(InputIterator first, InputIterator last)
inserts elements
Definition DataTypes.h:915
reverse_iterator rbegin()
returns a reverse iterator to the beginning
Definition DataTypes.h:882
Numeric primitive multidimensional array value type.
Definition DataTypes.h:1638
virtual void AssignSubArray(const std::vector< uint32_t > &memorypos, const boost::intrusive_ptr< RRMultiDimArray< T > > &buffer, const std::vector< uint32_t > &bufferpos, const std::vector< uint32_t > &count)
Assign a subset of an array.
Definition DataTypes.h:1696
virtual void RetrieveSubArray(const std::vector< uint32_t > &memorypos, const boost::intrusive_ptr< RRMultiDimArray< T > > &buffer, const std::vector< uint32_t > &bufferpos, const std::vector< uint32_t > &count)
Retrieve a subset of an array.
Definition DataTypes.h:1666
Base class for numeric multidimensional arrays.
Definition DataTypes.h:1588
namedarray array value type
Definition DataTypes.h:2315
iterator end()
returns an iterator to the end
Definition DataTypes.h:2392
T & reference
Definition DataTypes.h:2371
const_iterator end() const
returns an iterator to the end
Definition DataTypes.h:2394
const_reverse_iterator crend() const
returns a reverse iterator to the end
Definition DataTypes.h:2415
reverse_iterator rbegin()
returns a reverse iterator to the beginning
Definition DataTypes.h:2404
virtual size_t size() const
returns the number of elements (namedarray elements)
Definition DataTypes.h:2341
RR_OVIRTUAL boost::intrusive_ptr< RRBaseArray > GetNumericBaseArray() RR_OVERRIDE
get the underlying numeric array as an RRBaseArray
Definition DataTypes.h:2355
const_reference front() const
access the first element
Definition DataTypes.h:2447
bool empty()
checks whether the container is empty
Definition DataTypes.h:2455
virtual size_t size()
returns the number of elements (namedarray elements)
Definition DataTypes.h:2343
const_reference at(size_type i) const
access specified namedarray element with bounds checking
Definition DataTypes.h:2438
const_iterator cbegin() const
returns an iterator to the beginning
Definition DataTypes.h:2389
reference back()
access the last element
Definition DataTypes.h:2450
std::size_t size_type
Definition DataTypes.h:2375
const T & const_reference
Definition DataTypes.h:2373
RR_OVIRTUAL DataTypes ElementArrayType() RR_OVERRIDE
get the type of the underlying numeric array
Definition DataTypes.h:2349
const_reference operator[](size_type i) const
access specified namedarray element
Definition DataTypes.h:2425
iterator begin()
returns an iterator to the beginning
Definition DataTypes.h:2385
std::ptrdiff_t difference_type
Definition DataTypes.h:2377
reference front()
access the first element
Definition DataTypes.h:2445
RR_OVIRTUAL size_t ElementSize() RR_OVERRIDE
get the number of bytes per namedarray element of the array
Definition DataTypes.h:2347
const_reverse_iterator rbegin() const
returns a reverse iterator to the beginning
Definition DataTypes.h:2406
const_iterator begin() const
returns an iterator to the beginning
Definition DataTypes.h:2387
RR_OVIRTUAL size_t ElementArrayCount() RR_OVERRIDE
get the total number of elements in the underlying numeric array
Definition DataTypes.h:2351
RRNamedArray(const boost::intrusive_ptr< RRArray< typename RRPrimUtil< T >::ElementArrayType > > &rr_array)
Construct a RRNamedArray object.
Definition DataTypes.h:2332
const_reverse_iterator crbegin() const
returns a reverse iterator to the beginning
Definition DataTypes.h:2408
const_reference back() const
access the last element
Definition DataTypes.h:2452
virtual boost::intrusive_ptr< RRArray< typename RRPrimUtil< T >::ElementArrayType > > GetNumericArray()
get the underlying numeric RRArray
Definition DataTypes.h:2353
reverse_iterator rend()
returns a reverse iterator to the end
Definition DataTypes.h:2411
size_type max_size()
returns the maximum possible number of elements
Definition DataTypes.h:2457
reference operator[](size_type i)
access specified namedarray element
Definition DataTypes.h:2418
const_reverse_iterator rend() const
returns a reverse iterator to the end
Definition DataTypes.h:2413
T * iterator
Definition DataTypes.h:2367
T value_type
Definition DataTypes.h:2365
boost::reverse_iterator< const_iterator > const_reverse_iterator
Definition DataTypes.h:2401
const_iterator cend() const
returns an iterator to the end
Definition DataTypes.h:2396
const T * const_iterator
Definition DataTypes.h:2369
reference at(size_type i)
access specified namedarray element with bounds checking
Definition DataTypes.h:2432
boost::reverse_iterator< iterator > reverse_iterator
Definition DataTypes.h:2399
virtual void * void_ptr()
get a void pointer to the underlying numeric array
Definition DataTypes.h:2345
Base class for namedarray array value types.
Definition DataTypes.h:2286
Base class for namedarray multidimensional arrays.
Definition DataTypes.h:2477
namedarray multidimensional array value type
Definition DataTypes.h:2504
virtual void AssignSubArray(const std::vector< uint32_t > &memorypos, const boost::intrusive_ptr< RRNamedMultiDimArray< T > > &buffer, const std::vector< uint32_t > &bufferpos, const std::vector< uint32_t > &count)
Assign a subset of an array.
Definition DataTypes.h:2563
virtual void RetrieveSubArray(const std::vector< uint32_t > &memorypos, const boost::intrusive_ptr< RRNamedMultiDimArray< T > > &buffer, const std::vector< uint32_t > &bufferpos, const std::vector< uint32_t > &count)
Retrieve a subset of an array.
Definition DataTypes.h:2530
virtual std::string RRType()=0
Gets the type of the object as a string. This string is in C++ format, using two colons to separate n...
pod array value type
Definition DataTypes.h:1929
std::vector< T >::iterator iterator
Definition DataTypes.h:1961
size_type max_size() const
returns the maximum possible number of elements
Definition DataTypes.h:1998
reference front()
access the first element
Definition DataTypes.h:2000
const_reverse_iterator rbegin() const
returns a reverse iterator to the beginning
Definition DataTypes.h:1980
T * data()
direct access to the underlying array
Definition DataTypes.h:2016
const_reference at(size_type i) const
access the specified element with bounds checking
Definition DataTypes.h:2014
std::vector< T >::const_reverse_iterator const_reverse_iterator
Definition DataTypes.h:1967
std::vector< T >::const_reference const_reference
Definition DataTypes.h:1957
reference operator[](size_type i)
access the specified element
Definition DataTypes.h:2008
const_iterator cend() const
returns an iterator to the end
Definition DataTypes.h:1988
const_reference operator[](size_type i) const
access the specified element
Definition DataTypes.h:2010
const_reverse_iterator const crend()
returns a reverse iterator to the end
Definition DataTypes.h:1992
const_reverse_iterator const crbegin()
returns a reverse iterator to the beginning
Definition DataTypes.h:1990
T value_type
Definition DataTypes.h:1949
iterator begin()
returns an iterator to the beginning
Definition DataTypes.h:1970
const_reference back() const
access the last element
Definition DataTypes.h:2006
std::vector< T > & GetStorageContainer()
Get the underlying storage container.
Definition DataTypes.h:2027
reverse_iterator rend()
returns a reverse iterator to the end
Definition DataTypes.h:1982
const_iterator cbegin() const
returns an iterator to the beginning
Definition DataTypes.h:1986
const_iterator end() const
returns an iterator to the end
Definition DataTypes.h:1976
std::vector< T >::reference reference
Definition DataTypes.h:1955
reference back()
access the last element
Definition DataTypes.h:2004
std::vector< T >::const_iterator const_iterator
Definition DataTypes.h:1963
const T * data() const
direct access to the underlying array
Definition DataTypes.h:2018
const_reference front() const
access the first element
Definition DataTypes.h:2002
std::vector< T >::size_type size_type
Definition DataTypes.h:1959
virtual size_type size() const
returns the number of elements
Definition DataTypes.h:1996
iterator end()
returns an iterator to the end
Definition DataTypes.h:1974
reference at(size_type i)
access the specified element with bounds checking
Definition DataTypes.h:2012
const_iterator begin() const
returns an iterator to the beginning
Definition DataTypes.h:1972
reverse_iterator rbegin()
returns a reverse iterator to the beginning
Definition DataTypes.h:1978
bool empty() const
checks whether the container is empty
Definition DataTypes.h:1994
std::vector< T >::pointer pointer
Definition DataTypes.h:1951
std::vector< T >::reverse_iterator reverse_iterator
Definition DataTypes.h:1965
const_reverse_iterator rend() const
returns a reverse iterator to the end
Definition DataTypes.h:1984
std::vector< T >::const_pointer const_pointer
Definition DataTypes.h:1953
Base class for pod array value types.
Definition DataTypes.h:1908
Base class for pod multidimensional arrays.
Definition DataTypes.h:2055
Base class for user defined pod value types.
Definition DataTypes.h:1897
pod multidimensional array value type
Definition DataTypes.h:2082
virtual void AssignSubArray(const std::vector< uint32_t > &memorypos, const boost::intrusive_ptr< RRPodMultiDimArray< T > > &buffer, const std::vector< uint32_t > &bufferpos, const std::vector< uint32_t > &count)
Assign a subset of an array.
Definition DataTypes.h:2141
virtual void RetrieveSubArray(const std::vector< uint32_t > &memorypos, const boost::intrusive_ptr< RRPodMultiDimArray< T > > &buffer, const std::vector< uint32_t > &bufferpos, const std::vector< uint32_t > &count)
Retrieve a subset of an array.
Definition DataTypes.h:2108
Base class for user defined structure value types.
Definition DataTypes.h:1071
Represents. a point in time. Used by wire members to timestamp packets.
Definition DataTypes.h:2719
bool operator==(const TimeSpec &t2) const
equality comparison
int64_t seconds
Seconds since epoch.
Definition DataTypes.h:2722
bool operator<=(const TimeSpec &t2) const
less-than-or-equal comparison
TimeSpec operator-(const TimeSpec &t2) const
subtraction operator
void cleanup_nanosecs()
normalize nanoseconds to be within 0 and 1e9-1
bool operator>=(const TimeSpec &t2) const
greater-than-or-equal comparison
TimeSpec(int64_t seconds, int32_t nanoseconds)
Construct timespec with specified time.
bool operator!=(const TimeSpec &t2) const
inequality comparison
bool operator<(const TimeSpec &t2) const
less-then comparison
TimeSpec operator+(const TimeSpec &t2) const
addition operator
bool operator>(const TimeSpec &t2) const
greater-than comparison
int32_t nanoseconds
Nanoseconds from epoch. Normalized to be between 0 and 1e9-1.
Definition DataTypes.h:2724
TimeSpec()
Construct empty timespec.
Complex double precision floating point number.
Definition DataTypes.h:78
double real
real component
Definition DataTypes.h:80
cdouble(double r, double i)
Construct a new cdouble.
Definition DataTypes.h:91
cdouble()
Construct a new cdouble with 0.0 real and imag.
Definition DataTypes.h:84
double imag
imaginary component
Definition DataTypes.h:82
Complex single precision floating point number.
Definition DataTypes.h:100
cfloat()
Construct a new csingle with 0.0 real and imag.
Definition DataTypes.h:106
float real
real component
Definition DataTypes.h:102
float imag
imaginary component
Definition DataTypes.h:104
cfloat(float r, float i)
Construct a new cfloat.
Definition DataTypes.h:113
Logical boolean represented using 8 bits.
Definition DataTypes.h:123
rr_bool()
Construct a new false rr_bool.
Definition DataTypes.h:132
uint8_t value
The value of the boolean.
Definition DataTypes.h:129
rr_bool(uint8_t b)
Construct a new rr_bool object.
Definition DataTypes.h:138