Apama  9.10.0.4.289795
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sag_connectivity_cpp.hpp
Go to the documentation of this file.
1 /*
2  * Title: sag_connectivity_cpp.hpp
3  * Description: C++ header-only wrapper for C-ABI data_t type
4  * $Copyright (c) 2015-2016 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.$
5  * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG
6  * @Version: $Id: sag_connectivity_cpp.hpp 273763 2016-01-22 12:27:42Z shd $
7  */
8 
14 #ifndef _CPPMESSAGEDATA_H_
15 #define _CPPMESSAGEDATA_H_
16 
17 #include <sag_connectivity_c.h>
18 #include <algorithm>
19 #include <stdexcept>
20 #include <cstddef>
21 #include <stddef.h>
22 #include <assert.h>
23 #include <string>
24 #include <sstream>
25 #include <typeinfo>
26 #include <string.h>
27 
28 /*
29  * C++ API for manipulating data in Connectivity plugins.
30  *
31  * This uses a C ABI under the hood, but should be manipulated via the classes
32  * in this file.
33  */
34 
35 namespace com {
36 namespace softwareag {
38 namespace connectivity {
39 
40 class list_t;
41 class map_t;
42 class buffer_t;
43 template<typename T> class custom_t;
45 
69 class data_t: protected sag_underlying_data_t
70 {
71  friend class map_t;
72  friend class list_t;
73  friend class Message;
74 public:
75 
78  {
79  memset(this, 0, sizeof(sag_underlying_data_t));
80  tag = SAG_DATA_EMPTY;
81  }
84  data_t(data_t &&other)
85  {
86  memset(this, 0, sizeof(sag_underlying_data_t));
87  tag = SAG_DATA_EMPTY;
88  swap(std::move(other));
89  }
90 
92  void swap(data_t &&other);
93 
97  {
98  data_t tmp(std::move(other));
99  swap(std::move(tmp));
100  return *this;
101  }
102 
104  ~data_t();
105 
107  bool empty() const { return tag == SAG_DATA_EMPTY; }
108 
110  data_t copy() const;
111 
113  bool operator==(const data_t &other) const;
115  bool operator!=(const data_t &other) const { return !operator==(other); }
116 
133  template<typename V>
134  typename V::result_type apply_visitor(const V &v) const;
151  template<typename V>
152  typename V::result_type apply_visitor(const V &v);
153 
156  const char *type_name() const
157  {
158  switch (tag) {
159  case SAG_DATA_EMPTY: return "Empty";
160  case SAG_DATA_BOOLEAN: return "Boolean";
161  case SAG_DATA_DOUBLE: return "Double";
162  case SAG_DATA_INTEGER: return "Integer";
163  case SAG_DATA_DECIMAL: return "Decimal";
164  case SAG_DATA_STRING: return "String";
165  case SAG_DATA_LIST: return "List";
166  case SAG_DATA_MAP: return "Map";
167  case SAG_DATA_BUFFER: return "Buffer";
168  case SAG_DATA_CUSTOM: return "Custom";
169  default:
170  assert(false); // shouldn't happen
171  return "Unknown";
172  }
173  }
174 
177  sag_data_tag type_tag() const { return tag; }
178 
179 private:
181  data_t(const data_t &other) { abort(); }
183  data_t &operator=(const data_t &other) { abort(); }
184 public:
185 
187  explicit data_t(int64_t d)
188  {
189  tag = SAG_DATA_INTEGER;
190  integer = d;
191  }
193  data_t &operator=(int64_t d)
194  {
195  data_t tmp(d);
196  swap(std::move(tmp));
197  return *this;
198  }
200  explicit data_t(bool b)
201  {
202  tag = SAG_DATA_BOOLEAN;
203  boolean = b;
204  }
206  data_t &operator=(bool b)
207  {
208  data_t tmp(b);
209  swap(std::move(tmp));
210  return *this;
211  }
213  explicit data_t(double d)
214  {
215  tag = SAG_DATA_DOUBLE;
216  fp = d;
217  }
219  data_t &operator=(double d)
220  {
221  data_t tmp(d);
222  swap(std::move(tmp));
223  return *this;
224  }
229  template<typename T>
230  explicit data_t(custom_t<T> &&d);
231 
236  template<typename T>
238  {
239  data_t tmp(std::move(d));
240  swap(std::move(tmp));
241  return *this;
242  }
244  explicit data_t(decimal_t d)
245  {
246  tag = SAG_DATA_DECIMAL;
247  decimal = d;
248  }
250  data_t &operator=(decimal_t d)
251  {
252  data_t tmp(d);
253  swap(std::move(tmp));
254  return *this;
255  }
258  explicit data_t(const char *s);
261  explicit data_t(const std::string &s);
265  data_t &operator=(const char *s)
266  {
267  data_t tmp(s);
268  swap(std::move(tmp));
269  return *this;
270  }
271 
275  data_t &operator=(const std::string &s)
276  {
277  data_t tmp(s);
278  swap(std::move(tmp));
279  return *this;
280  }
285  explicit data_t(list_t &&d);
291  {
292  data_t tmp(std::move(d));
293  swap(std::move(tmp));
294  return *this;
295  }
300  explicit data_t(map_t &&d);
306  {
307  data_t tmp(std::move(d));
308  swap(std::move(tmp));
309  return *this;
310  }
315  explicit data_t(buffer_t &&d);
321  {
322  data_t tmp(std::move(d));
323  swap(std::move(tmp));
324  return *this;
325  }
326 };
327 
344 template<typename V>
345 inline typename V::result_type apply_visitor(const V&v, data_t& t) { return t.apply_visitor(v); }
362 template<typename V>
363 inline typename V::result_type apply_visitor(const V&v, const data_t& t) { return t.apply_visitor(v); }
364 
386 template<typename T>
387 class custom_t: public sag_underlying_custom_t
388 {
389  typedef custom_t this_t;
390 public:
392  custom_t();
394  custom_t(T *payload);
396  ~custom_t();
398  T *get() { return this->data ? reinterpret_cast<T*>(this->data->custom) : 0; }
400  const T *get() const { return this->data ? reinterpret_cast<T*>(this->data->custom) : 0; }
402  custom_t(custom_t &&other);
404  custom_t &operator=(custom_t &&other);
406  void swap(custom_t &&other);
408  custom_t copy() const;
410  T &operator*() { return *get(); }
412  const T &operator*() const { return *get(); }
414  T *operator->() { return get(); }
416  const T *operator->() const { return get(); }
417 private:
419  static void deleter(void *d)
420  {
421  if (d) {
422  try {
423  delete reinterpret_cast<T*>(d);
424  } catch (...) {
425  // enforce nothrow behaviour
426  abort();
427  }
428  }
429  }
431  static void *copier(void *d)
432  {
433  try {
434  return d ? new T(*reinterpret_cast<T*>(d)) : 0;
435  } catch (...) {
436  // enforce nothrow behaviour
437  abort();
438  }
439  }
441  custom_t(const custom_t &other) { abort(); }
443  custom_t &operator=(const custom_t &other) { abort(); return *this; }
444 };
445 
446 
447 #include <sag_internal/convert_to.hpp>
448 
459 template<typename T>
460 inline typename get_details::GetVisitor<const T>::result_type get(const data_t &t) { return apply_visitor(get_details::GetVisitor<const T>(), t); }
471 template<typename T>
472 inline typename get_details::GetVisitor<T>::result_type get(data_t &t) { return apply_visitor(get_details::GetVisitor<T>(), t); }
480 template<typename T>
481 inline typename get_details::GetVisitor<custom_t<T> >::result_type get_custom(data_t &t) { return apply_visitor(get_details::GetVisitor<custom_t<T> >(), t); }
489 template<typename T>
490 inline typename get_details::GetVisitor<const custom_t<T> >::result_type get_custom(const data_t &t) { return apply_visitor(get_details::GetVisitor<const custom_t<T> >(), t); }
491 
492 
508 class list_t: protected sag_underlying_vector_t
509 {
510  friend class data_t;
511  friend class map_t;
512  friend class Message;
514  static size_t MIN_CAPACITY() { return 10; }
515 public:
522  template<typename DATA, typename UNDERLYING>
523  struct _iterator: public std::iterator<std::random_access_iterator_tag, DATA>
524  {
526  _iterator() : ptr(0), direction(1) {}
527  explicit _iterator(UNDERLYING ptr, bool forward=true)
528  : ptr(ptr), direction(forward?1:-1)
529  {}
530  iterator &operator+=(size_t n) { ptr += direction*n; return *this; }
531  iterator &operator-=(size_t n) { ptr -= direction*n; return *this; }
532  iterator operator+(size_t n) const { return iterator(ptr+(direction*n), direction>0); }
533  iterator operator-(size_t n) const { return iterator(ptr+(direction*-n), direction > 0); }
534  ptrdiff_t operator-(const iterator &other) const { return direction*(ptr-other.ptr); }
535  DATA &operator[](size_t n) const { return static_cast<DATA&>(ptr[n*direction]); }
536  bool operator<(const iterator &other) const { return direction>0 ? ptr < other.ptr : ptr > other.ptr; }
537  bool operator>(const iterator &other) const { return direction>0 ? ptr > other.ptr : ptr < other.ptr; }
538  bool operator>=(const iterator &other) const { return direction>0 ? ptr >= other.ptr : ptr <= other.ptr; }
539  bool operator<=(const iterator &other) const { return direction>0 ? ptr <= other.ptr : ptr >= other.ptr; }
540  bool operator==(const iterator &other) const { return ptr == other.ptr; }
541  bool operator!=(const iterator &other) const { return !operator==(other); }
542  iterator &operator++() { return operator+=(1); }
543  iterator operator++(int)
544  {
545  iterator tmp(*this);
546  operator++();
547  return tmp;
548  }
549  iterator &operator--() { return operator-=(1); }
550  iterator operator--(int)
551  {
552  iterator tmp(*this);
553  operator--();
554  return tmp;
555  }
556  DATA &operator*() const { return static_cast<DATA&>(*ptr); }
557  DATA *operator->() const { return static_cast<DATA*>(ptr); }
558  UNDERLYING ptr;
559  int64_t direction;
560  };
565 
568  {
569  table = 0;
570  }
572  explicit list_t(size_t n);
573 
576  {
577  clear();
578  }
579 
583  {
584  list_t tmp;
585  // put us in tmp
586  swap(std::move(tmp));
587  // put other in us (and by extension the null tmp in other)
588  swap(std::move(other));
589  return *this;
590  }
592  list_t(list_t &&other)
593  {
594  table = 0;
595  swap(std::move(other));
596  }
598  void swap(list_t &&other)
599  {
600  std::swap(table, other.table);
601  }
603  list_t copy() const
604  {
605  list_t newlist(size());
606  for (const_iterator it = begin(); it != end(); ++it) {
607  newlist.push_back(it->copy());
608  }
609  return newlist;
610  }
611 
612 private:
614  list_t &operator=(const list_t &other) { abort(); }
616  list_t(const list_t &other) { abort(); }
617 public:
618 
620  bool operator==(const list_t &other) const;
621 
623  bool operator!=(const list_t &other) const { return !operator==(other); }
624 
625  /* Iteration:
626  * begin() and end() methods, both const and non-const, forward and backward.
627  */
629  iterator begin() { return iterator(table?table->data:0); }
631  iterator end() { return iterator(table?table->data+table->count:0); }
633  const_iterator begin() const { return const_iterator(table?table->data:0); }
635  const_iterator end() const { return const_iterator(table?table->data+table->count:0); }
637  const_iterator cbegin() const { return const_iterator(table?table->data:0); }
639  const_iterator cend() const { return const_iterator(table?table->data+table->count:0); }
641  iterator rbegin() { return iterator(table?table->data+table->count-1:0, false); }
643  iterator rend() { return iterator(table?table->data-1:0, false); }
645  const_iterator rbegin() const { return const_iterator(table?table->data+table->count-1:0, false); }
647  const_iterator rend() const { return const_iterator(table?table->data-1:0, false); }
648 
650  size_t size() const { return table?table->count:0; }
652  bool empty() const { return 0 == size(); }
653 
656  const data_t &operator[](size_t n) const;
659  data_t &operator[](size_t n);
662  const data_t &front() const { return operator[](0); }
665  const data_t &back() const { return operator[](table?table->count-1:0); }
668  data_t &front() { return operator[](0); }
671  data_t &back() { return operator[](table?table->count-1:0); }
672 
674  void reserve(size_t n)
675  {
676  if (!table) resize(n);
677  if (n > table->capacity) resize(n);
678  }
681  void clear();
682 
687  void push_back(data_t &&d);
688 
690  void pop_back();
691 
692 private:
699  void resize(size_t newsize);
700 };
701 
719 class map_t: protected sag_underlying_map_t
720 {
721  friend class data_t;
722  friend class Message;
724  static size_t MIN_CAPACITY() { return 8; }
725 protected:
726  typedef sag_underlying_map_table_entry_t item_t;
727  typedef int64_t hash_t;
728 public:
729 
730  template<typename DATA>
731  struct pair
732  {
733  hash_t hash;
734  DATA first;
735  DATA second;
736  };
737 
744  template<typename DATA, typename UNDERLYING, typename PAIR>
745  struct _iterator: public std::iterator<std::bidirectional_iterator_tag, DATA>
746  {
747  friend class map_t;
749  typedef PAIR element_t;
750 
751  _iterator(): tabledata(0), capacity(0), offs(0) {}
752  _iterator(const UNDERLYING &tabledata, size_t capacity, int64_t offs, bool stepToItem=false)
753  : tabledata(tabledata), capacity(capacity), offs(offs)
754  {
755  if (!valid() && stepToItem) {
756  operator++();
757  }
758  }
759 
760  iterator &operator--()
761  {
762  if (offs > -1) {
763  do {
764  --offs;
765  } while (!valid());
766  }
767  return *this;
768  }
769  iterator operator--(int)
770  {
771  iterator tmp(*this);
772  operator--();
773  return tmp;
774  }
775  iterator &operator++()
776  {
777  if (offs < capacity) {
778  do {
779  ++offs;
780  } while (!valid());
781  }
782  return *this;
783  }
784  iterator operator++(int)
785  {
786  iterator tmp(*this);
787  operator++();
788  return tmp;
789  }
790 
791  DATA &key() const { return static_cast<DATA&>(tabledata[offs].key); }
792  DATA &value() const { return static_cast<DATA&>(tabledata[offs].value); }
793 
794  bool operator==(const iterator &other) const
795  {
796  bool b = offs == other.offs;
797  return b;
798  }
799  bool operator!=(const iterator &other) const
800  {
801  bool b = !operator==(other);
802  return b;
803  }
804  element_t &operator*() const
805  {
806  return reinterpret_cast<element_t &>(tabledata[offs]);
807  }
808  element_t *operator->() const
809  {
810  return reinterpret_cast<element_t *>(tabledata + offs);
811  }
812  protected:
814  bool valid() const
815  {
816  return offs >= capacity || offs < 0 || tabledata[offs].key.tag != SAG_DATA_EMPTY;
817  }
818  UNDERLYING tabledata;
819  int64_t capacity;
820  int64_t offs;
821  };
827  typedef pair<data_t> element;
829  typedef pair<const data_t> const_element;
830 
833  {
834  table = 0;
835  }
837  explicit map_t(size_t n);
838 
841  {
842  clear();
843  }
844 
848  {
849  map_t tmp;
850  // put us in tmp
851  swap(std::move(tmp));
852  // put other in us (and by extension the null tmp in other)
853  swap(std::move(other));
854  return *this;
855  }
857  map_t(map_t &&other)
858  {
859  table = 0;
860  swap(std::move(other));
861  }
862 
864  void swap(map_t &&other)
865  {
866  std::swap(table, other.table);
867  }
868 
870  map_t copy() const
871  {
872  map_t newmap(size());
873  for (const_iterator it = begin(); it != end(); ++it) {
874  newmap.insert(std::make_pair(it->first.copy(), it->second.copy()));
875  }
876  return newmap;
877  }
878 
879 private:
881  map_t &operator=(const map_t &other) { abort(); }
883  map_t(const map_t &other) { abort(); }
884 public:
885 
887  bool operator==(const map_t &other) const
888  {
889  if (size() != other.size()) return false;
890  for (const_iterator it = begin(); it != end(); ++it) {
891  const_iterator jt = other.find(it.key());
892  if (jt == other.end()) return false;
893  if (it.value() != jt.value()) return false;
894  }
895  return true;
896  }
897 
899  bool operator!=(const map_t &other) const { return !operator==(other); }
900 
901  /* Iteration:
902  * begin() and end() methods, both const and non-const.
903  * Unordered, so forward iteration only
904  */
906  iterator begin() { return iterator(table?table->table:0, table?table->capacity:0, 0, true); }
908  iterator end() { return iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
910  const_iterator begin() const { return const_iterator(table?table->table:0, table?table->capacity:0, 0, true); }
912  const_iterator end() const { return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
914  const_iterator cbegin() const { return const_iterator(table?table->table:0, table?table->capacity:0, 0, true); }
916  const_iterator cend() const { return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
917 
919  size_t size() const { return table?table->count:0; }
921  bool empty() const { return 0 == size(); }
922 
926  {
927  return maybe_insert(std::pair<const data_t&,const data_t&>(k, data_t())).first->second;
928  }
931  const data_t &operator[](const data_t &k) const
932  {
933  const_iterator it = find(k);
934  if (it == end()) {
935  throw std::runtime_error("Element not in map");
936  } else {
937  return it.value();
938  }
939  }
942  iterator find(const data_t &k);
943 
946  const_iterator find(const data_t &k) const;
947 
959  std::pair<iterator, bool> insert(const std::pair<data_t&&, data_t&&> &v);
960 
972  std::pair<iterator, bool> insert(data_t&& k, data_t&& v) {
973  return insert(std::make_pair(std::move(k), std::move(v)));
974  }
975 
978  std::pair<iterator, bool> insert(const std::pair<data_t&&, data_t&&> &v, hash_t hash);
979 
984  size_t erase(const data_t &k);
989  void erase(iterator it);
993  void clear();
994 
995 protected:
1002  void resize(size_t newsize);
1003 
1005  void really_insert(item_t &item, const std::pair<data_t&&, data_t&&> &v, hash_t hash);
1007  std::pair<iterator, bool> maybe_insert(const std::pair<const data_t&, const data_t&> &v);
1009  std::pair<map_t::const_iterator, map_t::const_iterator> find_for_insert(const data_t &k, hash_t hash) const;
1010 
1012  bool empty(const item_t &item) const { return 0 == item.hash && SAG_DATA_EMPTY == item.key.tag; }
1014  bool empty(const const_iterator::element_t &item) const { return 0 == item.hash && SAG_DATA_EMPTY == item.first.tag; }
1016  bool hole(const item_t &item) const { return 0 != item.hash && SAG_DATA_EMPTY == item.key.tag; }
1018  bool hole(const const_iterator::element_t &item) const { return 0 != item.hash && SAG_DATA_EMPTY == item.first.tag; }
1020  bool live(const item_t &item) const { return SAG_DATA_EMPTY != item.key.tag; }
1022  bool live(const const_iterator::element_t &item) const { return SAG_DATA_EMPTY != item.first.tag; }
1023 
1025  size_t index(hash_t hash) const
1026  {
1027  if (!table) return 0;
1028  return table->capacity ? hash % table->capacity : 0;
1029  }
1030 
1031 #ifdef _SAG_INTERNAL_UNSUPPORTED_DEBUG
1032 public:
1033  SAG_CONNECTIVITY_API static size_t clashes;
1034  SAG_CONNECTIVITY_API static size_t inserts;
1035  SAG_CONNECTIVITY_API static double resizeUsage;
1036  SAG_CONNECTIVITY_API static size_t resizes;
1037  SAG_CONNECTIVITY_API static size_t max_lookup_clash;
1038  SAG_CONNECTIVITY_API static size_t lookups;
1039  SAG_CONNECTIVITY_API static size_t lookup_clashes;
1040  static double getInsertClashRatio() { return (double)clashes/(double)inserts; }
1041  static double getAverageResizeRatio() { return resizeUsage/(double)resizes; }
1042  static void resetCounters() { clashes = inserts = resizeUsage = resizes = 0; }
1043  static double getAverageLookupProbes() { return 1.0+(double)lookup_clashes/(double)lookups; }
1044  static size_t getMaxLookupProbes() { return 1+max_lookup_clash; }
1045 #endif
1046 };
1047 
1054 class buffer_t: protected sag_underlying_buffer_t
1055 {
1056  friend class data_t;
1057 public:
1060  {
1061  table = 0;
1062  }
1064  explicit buffer_t(size_t n);
1065 
1068  {
1069  clear();
1070  }
1071 
1075  {
1076  buffer_t tmp;
1077  // put us in tmp
1078  swap(std::move(tmp));
1079  // put other in us (and by extension the null tmp in other)
1080  swap(std::move(other));
1081  return *this;
1082  }
1085  {
1086  table = 0;
1087  swap(std::move(other));
1088  }
1090  void swap(buffer_t &&other)
1091  {
1092  std::swap(table, other.table);
1093  }
1094 
1096  buffer_t copy() const;
1097 
1098 private:
1100  buffer_t &operator=(const buffer_t &other) { abort(); }
1102  buffer_t(const buffer_t &other) { abort(); }
1103 public:
1104 
1106  bool operator==(const buffer_t &other) const
1107  {
1108  return true;
1109  }
1111  bool operator!=(const buffer_t &other) const
1112  {
1113  return false;
1114  }
1115 
1116  typedef uint8_t *iterator;
1117  typedef const uint8_t *const_iterator;
1118 
1119  /* Iteration:
1120  * begin() and end() methods, both const and non-const, forward and backward.
1121  */
1123  iterator begin() { return table?table->data:0; }
1125  iterator end() { return table?table->data+table->length:0; }
1127  const_iterator begin() const { return table?table->data:0; }
1129  const_iterator end() const { return table?table->data+table->length:0; }
1131  const_iterator cbegin() const { return table?table->data:0; }
1133  const_iterator cend() const { return table?table->data+table->length:0; }
1134 
1136  size_t size() const { return table ? table->length : 0; }
1138  bool empty() const { return 0 == size(); }
1139 
1142  uint8_t &operator[](size_t n)
1143  {
1144  if (n >= size()) throw std::runtime_error("Out of bounds");
1145  return table->data[n];
1146  }
1149  const uint8_t &operator[](size_t n) const
1150  {
1151  if (n >= size()) throw std::runtime_error("Out of bounds");
1152  return table->data[n];
1153  }
1157  void clear();
1158 };
1159 
1171 template<typename T>
1172 inline T convert_to(const data_t &d)
1173 {
1174  return apply_visitor(convert_to_details::_get_or_convert<T>(d.type_name()), d);
1175 }
1176 
1183 {
1184 public:
1185  // String
1187  static std::string getString(const map_t &map, const char *key) { return getAs<std::string>(map, key); }
1189  static std::string getString(const map_t &map, const char *key, const char *defaultValue) { return getAs<std::string>(map, key, defaultValue); }
1191  static std::string getString(const map_t &map, const std::string &key) { return getAs<std::string>(map, key.c_str()); }
1193  static std::string getString(const map_t &map, const std::string &key, const std::string &defaultValue) { return getAs<std::string>(map, key.c_str(), defaultValue); }
1194  // Integer
1196  static int64_t getInteger(const map_t &map, const char *key) { return getAs<int64_t>(map, key); }
1198  static int64_t getInteger(const map_t &map, const char *key, int64_t defaultValue) { return getAs<int64_t>(map, key, defaultValue); }
1200  static int64_t getInteger(const map_t &map, const std::string &key) { return getAs<int64_t>(map, key.c_str()); }
1202  static int64_t getInteger(const map_t &map, const std::string &key, int64_t defaultValue) { return getAs<int64_t>(map, key.c_str(), defaultValue); }
1203  // Double
1205  static double getDouble(const map_t &map, const char *key) { return getAs<double>(map, key); }
1207  static double getDouble(const map_t &map, const char *key, double defaultValue) { return getAs<double>(map, key, defaultValue); }
1209  static double getDouble(const map_t &map, const std::string &key) { return getAs<double>(map, key.c_str()); }
1211  static double getDouble(const map_t &map, const std::string &key, double defaultValue) { return getAs<double>(map, key.c_str(), defaultValue); }
1212  // Boolean
1214  static bool getBoolean(const map_t &map, const char *key) { return getAs<bool>(map, key); }
1216  static bool getBoolean(const map_t &map, const char *key, bool defaultValue) { return getAs<bool>(map, key, defaultValue); }
1218  static bool getBoolean(const map_t &map, const std::string &key) { return getAs<bool>(map, key.c_str()); }
1220  static bool getBoolean(const map_t &map, const std::string &key, bool defaultValue) { return getAs<bool>(map, key.c_str(), defaultValue); }
1221  // Map
1223  static const map_t &getMap(const map_t &map, const char *key) { return getAs<const map_t&>(map, key); }
1225  static const map_t &getMap(const map_t &map, const char *key, const map_t &defaultValue) { return getAs<const map_t&>(map, key, defaultValue); }
1227  static const map_t &getMap(const map_t &map, const std::string &key) { return getAs<const map_t&>(map, key.c_str()); }
1229  static const map_t &getMap(const map_t &map, const std::string &key, const map_t &defaultValue) { return getAs<const map_t&>(map, key.c_str(), defaultValue); }
1230  // List
1232  static const list_t &getList(const map_t &map, const char *key) { return getAs<const list_t&>(map, key); }
1234  static const list_t &getList(const map_t &map, const char *key, const list_t &defaultValue) { return getAs<const list_t&>(map, key, defaultValue); }
1236  static const list_t &getList(const map_t &map, const std::string &key) { return getAs<const list_t&>(map, key.c_str()); }
1238  static const list_t &getList(const map_t &map, const std::string &key, const list_t &defaultValue) { return getAs<const list_t&>(map, key.c_str(), defaultValue); }
1239 
1240 private:
1242  template<typename T>
1243  static T getAs(const map_t &map, const char *key);
1245  template<typename T>
1246  static T getAs(const map_t &map, const char *key, const T &def);
1247 };
1248 
1249 
1250 
1270 class metadata_t: protected map_t
1271 {
1272  friend class data_t;
1273  friend class Message;
1274 public:
1281  template<typename DATA, typename UNDERLYING, typename PAIR>
1282  struct _iterator: public map_t::_iterator<DATA, UNDERLYING, PAIR>
1283  {
1284  typedef _iterator<DATA, UNDERLYING, PAIR> iterator;
1286 
1287  _iterator(): map_iterator() {}
1288  _iterator(const UNDERLYING &tabledata, size_t capacity, int64_t offs, bool stepToItem=false)
1289  : map_iterator(tabledata, capacity, offs, stepToItem)
1290  {}
1291  _iterator(const map_iterator &other): map_iterator(other) {}
1292  iterator &operator=(const map_iterator &other)
1293  {
1294  map_iterator::tabledata = other.tabledata;
1295  map_iterator::offs = other.offs;
1296  map_iterator::step = other.step;
1297  map_iterator::capacity = other.capacity;
1298  return *this;
1299  }
1300 
1301  const char* key() const
1302  {
1303  assert(map_iterator::tabledata[map_iterator::offs].key.tag == SAG_DATA_STRING);
1304  if (map_iterator::tabledata[map_iterator::offs].key.tag != SAG_DATA_STRING) throw std::runtime_error("Metadata key not a string");
1305  return map_iterator::tabledata[map_iterator::offs].key.string;
1306  }
1307  const char* value() const
1308  {
1309  assert(map_iterator::tabledata[map_iterator::offs].value.tag == SAG_DATA_STRING);
1310  if (map_iterator::tabledata[map_iterator::offs].value.tag != SAG_DATA_STRING) throw std::runtime_error("Metadata value not a string");
1311  return map_iterator::tabledata[map_iterator::offs].value.string;
1312  }
1313  private: // can't expose these as string/string so make them inaccessible
1314  typename map_iterator::element_t &operator*() const
1315  {
1316  return reinterpret_cast<typename map_iterator::element_t &>(map_iterator::tabledata[map_iterator::offs]);
1317  }
1318  typename map_iterator::element_t *operator->() const
1319  {
1320  return reinterpret_cast<typename map_iterator::element_t *>(map_iterator::tabledata + map_iterator::offs);
1321  }
1322  };
1325 
1329  explicit metadata_t(size_t n): map_t(n) {}
1331  metadata_t(metadata_t &&other) : map_t(std::move(other)) {}
1335  {
1336  metadata_t tmp;
1337  swap(std::move(tmp));
1338  swap(std::move(other));
1339  return *this;
1340  }
1342  metadata_t copy() const;
1343 
1344  using map_t::empty;
1345  using map_t::size;
1346  using map_t::clear;
1347 
1349  bool operator==(const metadata_t &other) const
1350  {
1351  return static_cast<const map_t&>(*this) == static_cast<const map_t&>(other);
1352  }
1354  bool operator!=(const metadata_t &other) const { return !operator==(other); }
1355 
1357  void swap(metadata_t &&other)
1358  {
1359  return static_cast<map_t&>(*this).swap(static_cast<map_t&&>(other));
1360  }
1361 
1365  const char *operator[](const char *k)
1366  {
1367  iterator it = find(k);
1368  if (it == end()) {
1369  throw std::runtime_error("Element not in map");
1370  } else {
1371  return it.value();
1372  }
1373  }
1376  const char *const operator[](const char *k) const
1377  {
1378  const_iterator it = find(k);
1379  if (it == end()) {
1380  throw std::runtime_error("Element not in map");
1381  } else {
1382  return it.value();
1383  }
1384  }
1388  const char *operator[](const std::string &k)
1389  {
1390  iterator it = find(k);
1391  if (it == end()) {
1392  throw std::runtime_error("Element not in map");
1393  } else {
1394  return it.value();
1395  }
1396  }
1399  const char *const operator[](const std::string &k) const
1400  {
1401  const_iterator it = find(k);
1402  if (it == end()) {
1403  throw std::runtime_error("Element not in map");
1404  } else {
1405  return it.value();
1406  }
1407  }
1410  iterator find(const char *k)
1411  {
1412  return map_t::find(data_t(k));
1413  }
1416  const_iterator find(const char *k) const
1417  {
1418  return map_t::find(data_t(k));
1419  }
1422  iterator find(const std::string &k)
1423  {
1424  return map_t::find(data_t(k));
1425  }
1428  const_iterator find(const std::string &k) const
1429  {
1430  return map_t::find(data_t(k));
1431  }
1432 
1441  std::pair<iterator, bool> insert(const std::pair<std::string, std::string> &v)
1442  {
1443  return map_t::insert(std::make_pair(data_t(v.first), data_t(v.second)));
1444  }
1445 
1454  std::pair<iterator, bool> insert(const std::pair<const char*, const char*> &v)
1455  {
1456  return map_t::insert(std::make_pair(data_t(v.first), data_t(v.second)));
1457  }
1462  size_t erase(const std::string &k)
1463  {
1464  return map_t::erase(data_t(k));
1465  }
1470  size_t erase(const char *k)
1471  {
1472  return map_t::erase(data_t(k));
1473  }
1478  void erase(iterator it)
1479  {
1480  map_t::erase(it);
1481  }
1482 
1483  /* Iteration:
1484  * begin() and end() methods, both const and non-const. Unordered so no reverse iterator
1485  */
1487  iterator begin() { return iterator(table?table->table:0, table?table->capacity:0, 0, true); }
1489  iterator end() { return iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
1491  const_iterator begin() const { return const_iterator(table?table->table:0, table?table->capacity:0, 0, true); }
1493  const_iterator end() const { return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
1495  const_iterator cbegin() const { return const_iterator(table?table->table:0, table?table->capacity:0, 0, true); }
1497  const_iterator cend() const { return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
1498 
1499 private:
1501  metadata_t &operator=(const metadata_t &other) { abort(); }
1503  metadata_t(const metadata_t &other) { abort(); }
1504 };
1505 
1514 class Message: protected sag_underlying_message_t
1515 {
1516 public:
1522  Message();
1523 
1527  explicit Message(payload_t &&_payload);
1528 
1532  Message(payload_t &&_payload, metadata_t &&_metadata);
1533 
1535  ~Message();
1536 
1540  Message(Message &&other);
1541 
1546  {
1547  Message tmp;
1548  swap(std::move(tmp));
1549  swap(std::move(other));
1550  return *this;
1551  }
1553  const payload_t &getPayload() const;
1555  const metadata_t &getMetadata() const;
1556 
1558  payload_t &getPayload() { return static_cast<payload_t&>(payload); }
1560  metadata_t &getMetadata() { return static_cast<metadata_t&>(metadata); }
1561 
1565  void setPayload(payload_t &&_payload);
1569  void setMetadata(metadata_t &&_metadata);
1570 
1572  void swap(Message &&other);
1573 
1575  Message copy() const
1576  {
1577  return Message(getPayload().copy(), getMetadata().copy());
1578  }
1579 
1581  static const char *HOST_MESSAGE_TYPE() {
1582  return "sag.type";
1583  }
1584 
1586  static const char *CHANNEL() {
1587  return "sag.channel";
1588  }
1589 
1593  Message &putMetadataValue(const char *key, const char *value);
1594 
1598  Message &putMetadataValue(const std::string &key, const std::string &value) { return putMetadataValue(key.c_str(), value.c_str()); }
1599 private:
1601  Message(const Message &other) { abort(); }
1603  Message &operator=(const Message &other) { abort(); }
1604 };
1605 
1606 
1630 template<typename DERIVED, typename RV>
1631 class visitor
1632 {
1633 public:
1635  typedef RV result_type;
1637  typedef DERIVED derived_t;
1638 
1640  result_type operator()() const { return derived().visitEmpty(); }
1642  result_type visitEmpty() const { return derived().error("Empty"); }
1643 
1645  result_type operator()(int64_t &i) const { return derived().visitInteger(i); }
1647  result_type visitInteger(int64_t &i) const { return derived().error("Integer"); }
1648 
1650  result_type operator()(double &i) const { return derived().visitDouble(i); }
1652  result_type visitDouble(double &i) const { return derived().error("Double"); }
1653 
1655  result_type operator()(bool &i) const { return derived().visitBoolean(i); }
1657  result_type visitBoolean(bool &i) const { return derived().error("Boolean"); }
1658 
1660  result_type operator()(const char *&i) const { return derived().visitString(i); }
1662  result_type visitString(const char *&i) const { return derived().error("String"); }
1663 
1665  result_type operator()(decimal_t &i) const { return derived().visitDecimal(i); }
1667  result_type visitDecimal(decimal_t &i) const { return derived().error("Decimal"); }
1668 
1670  result_type operator()(buffer_t &i) const { return derived().visitBuffer(i); }
1672  result_type visitBuffer(buffer_t &i) const { return derived().error("Buffer"); }
1673 
1675  result_type operator()(list_t &i) const { return derived().visitList(i); }
1677  result_type visitList(list_t &i) const { return derived().error("List"); }
1678 
1680  result_type operator()(map_t &i) const { return derived().visitMap(i); }
1682  result_type visitMap(map_t &i) const { return derived().error("Map"); }
1683 
1685  result_type operator()(sag_underlying_custom_t &i) const { return derived().visitCustom(i); }
1687  result_type visitCustom(sag_underlying_custom_t &i) const { return derived().error("Custom"); }
1688 
1689 protected:
1692  result_type error(const std::string &reason) const { throw std::runtime_error("Visit type error: "+reason); }
1693 private:
1695  const derived_t &derived() const { return static_cast<const derived_t&>(*this); }
1696 };
1697 
1722 template<typename DERIVED, typename RV>
1724 {
1725 public:
1727  typedef RV result_type;
1729  typedef DERIVED derived_t;
1730 
1732  result_type operator()() const { return derived().visitEmpty(); }
1734  result_type visitEmpty() const { return derived().error("Empty"); }
1735 
1737  result_type operator()(int64_t i) const { return derived().visitInteger(i); }
1739  result_type visitInteger(int64_t i) const { return derived().error("Integer"); }
1740 
1742  result_type operator()(double i) const { return derived().visitDouble(i); }
1744  result_type visitDouble(double i) const { return derived().error("Double"); }
1745 
1747  result_type operator()(bool i) const { return derived().visitBoolean(i); }
1749  result_type visitBoolean(bool i) const { return derived().error("Boolean"); }
1750 
1752  result_type operator()(const char *i) const { return derived().visitString(i); }
1754  result_type visitString(const char *i) const { return derived().error("String"); }
1755 
1757  result_type operator()(const decimal_t &i) const { return derived().visitDecimal(i); }
1759  result_type visitDecimal(const decimal_t &i) const { return derived().error("Decimal"); }
1760 
1762  result_type operator()(const buffer_t &i) const { return derived().visitBuffer(i); }
1764  result_type visitBuffer(const buffer_t &i) const { return derived().error("Buffer"); }
1765 
1767  result_type operator()(const list_t &i) const { return derived().visitList(i); }
1769  result_type visitList(const list_t &i) const { return derived().error("List"); }
1770 
1772  result_type operator()(const map_t &i) const { return derived().visitMap(i); }
1774  result_type visitMap(const map_t &i) const { return derived().error("Map"); }
1775 
1777  result_type operator()(const sag_underlying_custom_t &i) const { return derived().visitCustom(i); }
1779  result_type visitCustom(const sag_underlying_custom_t &i) const { return derived().error("Custom"); }
1780 
1781 protected:
1784  result_type error(const std::string &reason) const { throw std::runtime_error("Visit type error: "+reason); }
1785 private:
1787  const derived_t &derived() const { return static_cast<const derived_t&>(*this); }
1788 };
1789 
1790 
1791 }}} // com.softwareag.connectivity
1792 
1793 // internal implementation details in here
1794 #include <sag_internal/data.hpp>
1795 
1796 #endif // _CPPMESSAGEDATA_H_
data_t & operator=(list_t &&d)
Assign this to a list_t, freeing the existing contents.
Definition: sag_connectivity_cpp.hpp:290
result_type visitString(const char *&i) const
Visit a string.
Definition: sag_connectivity_cpp.hpp:1662
result_type visitList(list_t &i) const
Visit a list.
Definition: sag_connectivity_cpp.hpp:1677
bool empty() const
Returns true if the map is empty (size() == 0)
Definition: sag_connectivity_cpp.hpp:921
static double getDouble(const map_t &map, const std::string &key)
Get a double value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1209
~data_t()
For non-primitives free the underlying memory.
void setMetadata(metadata_t &&_metadata)
Set the metadata.
metadata_t copy() const
Return a deep copy of this map.
result_type visitBuffer(buffer_t &i) const
Visit a byte buffer.
Definition: sag_connectivity_cpp.hpp:1672
const metadata_t & getMetadata() const
Return a reference to the metadata.
metadata_t & getMetadata()
Return a reference to the metadata.
Definition: sag_connectivity_cpp.hpp:1560
void clear()
Clear the list and free the underlying data structure (capacity is now 0)
const_iterator end() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:1129
result_type operator()(bool &i) const
Visit a boolean (don't override this, instead override visitBoolean)
Definition: sag_connectivity_cpp.hpp:1655
iterator find(const char *k)
Searches the map for an item with the given key and returns an iterator to that position in the map...
Definition: sag_connectivity_cpp.hpp:1410
result_type operator()(const buffer_t &i) const
Visit a byte buffer (don't override this, instead override visitBuffer)
Definition: sag_connectivity_cpp.hpp:1762
result_type visitMap(const map_t &i) const
Visit a map.
Definition: sag_connectivity_cpp.hpp:1774
const_iterator rend() const
Reverse const_iterator end.
Definition: sag_connectivity_cpp.hpp:647
T convert_to(const data_t &d)
Get a T from a data_t, parsing it from a string if neccessary/possible.
Definition: sag_connectivity_cpp.hpp:1172
void clear()
Empty the map and free the underlying data.
iterator begin()
Forward iterator begin.
Definition: sag_connectivity_cpp.hpp:906
sag_data_tag
A descriminator for the content of the data_t union.
Definition: sag_connectivity_c.h:33
bool operator!=(const metadata_t &other) const
Returns false if this map deep-equals other.
Definition: sag_connectivity_cpp.hpp:1354
com::softwareag::connectivity::metadata_t metadata_t
the type of a message metadata
Definition: sag_connectivity_cpp.hpp:1518
Message copy() const
Return a deep copy of this message, payload and metadata.
Definition: sag_connectivity_cpp.hpp:1575
byte-array (8-bit signed int)
Definition: sag_connectivity_c.h:43
Helper class for extracting values from a string->data_t map_t in a type-safe way with error checking...
Definition: sag_connectivity_cpp.hpp:1182
const data_t & front() const
Returns a reference to the data_t at position 0 Throws std::runtime_error if the list is empty...
Definition: sag_connectivity_cpp.hpp:662
result_type operator()(const list_t &i) const
Visit a list (don't override this, instead override visitList)
Definition: sag_connectivity_cpp.hpp:1767
static int64_t getInteger(const map_t &map, const std::string &key, int64_t defaultValue)
Get an integer value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1202
list of data
Definition: sag_connectivity_c.h:41
const T & operator*() const
Return the wrapped pointer as the correct type.
Definition: sag_connectivity_cpp.hpp:412
data_t(int64_t d)
Create a data_t from an int64_t.
Definition: sag_connectivity_cpp.hpp:187
bool operator==(const data_t &other) const
Returns true if two data_ts are deep-equals.
Helper class for writing visitors to apply to data_t.
Definition: sag_connectivity_cpp.hpp:1723
const_iterator begin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:1127
iterator end()
Forward iterator end.
Definition: sag_connectivity_cpp.hpp:1489
iterator begin()
Forward iterator begin.
Definition: sag_connectivity_cpp.hpp:1487
data_t & front()
Returns a reference to the data_t at position 0 Throws std::runtime_error if the list is empty...
Definition: sag_connectivity_cpp.hpp:668
void clear()
Free the underlying buffer;.
iterator begin()
Forward iterator begin.
Definition: sag_connectivity_cpp.hpp:629
result_type error(const std::string &reason) const
Handles visiting unhandled types.
Definition: sag_connectivity_cpp.hpp:1784
const_iterator begin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:1491
data_t copy() const
Return a deep copy of this data_t.
void swap(data_t &&other)
Swap the contents of this data_t with another.
static int64_t getInteger(const map_t &map, const std::string &key)
Get an integer value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1200
A map class which implements many of the functions on std::map.
Definition: sag_connectivity_cpp.hpp:1270
iterator rend()
Reverse iterator end.
Definition: sag_connectivity_cpp.hpp:643
~Message()
Free the underlying payload and metadata.
map_t()
Construct an empty map.
Definition: sag_connectivity_cpp.hpp:832
result_type visitBoolean(bool i) const
Visit a boolean.
Definition: sag_connectivity_cpp.hpp:1749
iterator end()
Forward iterator end.
Definition: sag_connectivity_cpp.hpp:631
result_type operator()(double i) const
Visit a double (don't override this, instead override visitDouble)
Definition: sag_connectivity_cpp.hpp:1742
result_type visitDouble(double &i) const
Visit a double.
Definition: sag_connectivity_cpp.hpp:1652
static double getDouble(const map_t &map, const char *key)
Get a double value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1205
static double getDouble(const map_t &map, const std::string &key, double defaultValue)
Get a double value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1211
static const map_t & getMap(const map_t &map, const std::string &key, const map_t &defaultValue)
Get a map value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1229
result_type visitMap(map_t &i) const
Visit a map.
Definition: sag_connectivity_cpp.hpp:1682
static std::string getString(const map_t &map, const std::string &key)
Get a string value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1191
RV result_type
The return type from applying this visitor.
Definition: sag_connectivity_cpp.hpp:1635
const_iterator rbegin() const
Reverse const_iterator begin.
Definition: sag_connectivity_cpp.hpp:645
STL namespace.
Definition: sag_connectivity_cpp.hpp:35
data_t & operator[](const data_t &k)
Return a reference to the item with the given key.
Definition: sag_connectivity_cpp.hpp:925
const_iterator cend() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:1133
result_type operator()(list_t &i) const
Visit a list (don't override this, instead override visitList)
Definition: sag_connectivity_cpp.hpp:1675
bool operator==(const list_t &other) const
Returns true if this list is deep equals to other list.
V::result_type apply_visitor(const V &v, data_t &t)
Apply a visitor (using the boost::static_visitor pattern) to the given data_t.
Definition: sag_connectivity_cpp.hpp:345
size_t erase(const char *k)
Remove the item with the specified key.
Definition: sag_connectivity_cpp.hpp:1470
static const list_t & getList(const map_t &map, const std::string &key)
Get a list value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1236
static const list_t & getList(const map_t &map, const char *key, const list_t &defaultValue)
Get a list value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1234
metadata_t(metadata_t &&other)
Move constructor. Other will be left as the empty map.
Definition: sag_connectivity_cpp.hpp:1331
const_iterator cbegin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:1131
static const map_t & getMap(const map_t &map, const char *key, const map_t &defaultValue)
Get a map value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1225
bool operator==(const map_t &other) const
Returns true if this map deep-equals other.
Definition: sag_connectivity_cpp.hpp:887
static bool getBoolean(const map_t &map, const std::string &key, bool defaultValue)
Get a boolean value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1220
result_type operator()(int64_t &i) const
Visit an integer (don't override this, instead override visitInteger)
Definition: sag_connectivity_cpp.hpp:1645
Message & putMetadataValue(const char *key, const char *value)
Sets a value in the metadata.
bool empty() const
Returns true if this is the empty data_t.
Definition: sag_connectivity_cpp.hpp:107
size_t erase(const data_t &k)
Remove the item with the specified key.
data_t & operator=(double d)
Assign a double to this, freeing the existing contents of this.
Definition: sag_connectivity_cpp.hpp:219
map_t & operator=(map_t &&other)
Move assignement.
Definition: sag_connectivity_cpp.hpp:847
64-bit signed int
Definition: sag_connectivity_c.h:38
~custom_t()
deletes the underlying pointer.
const_iterator end() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:1493
const_iterator cend() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:639
data_t & operator=(bool b)
Assign a bool to this, freeing the existing contents of this.
Definition: sag_connectivity_cpp.hpp:206
data_t & operator=(decimal_t d)
Assign this to a decimal, freeing the existing contents.
Definition: sag_connectivity_cpp.hpp:250
Message()
Construct an empty message.
list_t copy() const
Return a deep copy of this list.
Definition: sag_connectivity_cpp.hpp:603
std::pair< iterator, bool > insert(data_t &&k, data_t &&v)
Insert a new key/value pair into the map.
Definition: sag_connectivity_cpp.hpp:972
A wrapper type for holding arbitrary objects inside a data_t.
Definition: sag_connectivity_cpp.hpp:43
result_type visitList(const list_t &i) const
Visit a list.
Definition: sag_connectivity_cpp.hpp:1769
result_type operator()(buffer_t &i) const
Visit a byte buffer (don't override this, instead override visitBuffer)
Definition: sag_connectivity_cpp.hpp:1670
A list class which implements many of the functions on std::vector.
Definition: sag_connectivity_cpp.hpp:508
result_type operator()() const
Visit an empty variant (don't override this, instead override visitEmpty)
Definition: sag_connectivity_cpp.hpp:1640
data_t & operator=(custom_t< T > &&d)
Assign this to a custom value, freeing the existing contents This is a move constructor and will leav...
Definition: sag_connectivity_cpp.hpp:237
~list_t()
Free the underlying list.
Definition: sag_connectivity_cpp.hpp:575
result_type operator()(map_t &i) const
Visit a map (don't override this, instead override visitMap)
Definition: sag_connectivity_cpp.hpp:1680
result_type visitString(const char *i) const
Visit a string.
Definition: sag_connectivity_cpp.hpp:1754
metadata_t(size_t n)
Construct a map with (at least) capacity for n items.
Definition: sag_connectivity_cpp.hpp:1329
void swap(buffer_t &&other)
Swap the contents of this buffer and other.
Definition: sag_connectivity_cpp.hpp:1090
const_iterator cbegin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:914
const_iterator cbegin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:637
data_t()
Construct an empty data_t.
Definition: sag_connectivity_cpp.hpp:77
64-bit IEEE-754 decimal
Definition: sag_connectivity_c.h:39
void swap(Message &&other)
Swap the contents of this message with another.
Message & operator=(Message &&other)
Move assignment from another message.
Definition: sag_connectivity_cpp.hpp:1545
const_iterator cend() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:916
const uint8_t & operator[](size_t n) const
Return a reference the byte at the given offset.
Definition: sag_connectivity_cpp.hpp:1149
result_type visitDecimal(decimal_t &i) const
Visit a decimal.
Definition: sag_connectivity_cpp.hpp:1667
const_iterator begin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:910
result_type error(const std::string &reason) const
Handles visiting unhandled types.
Definition: sag_connectivity_cpp.hpp:1692
map of data:data
Definition: sag_connectivity_c.h:42
const char * operator[](const std::string &k)
Returns the item with the given key.
Definition: sag_connectivity_cpp.hpp:1388
list_t(list_t &&other)
Move construction. Other will be left as the empty list.
Definition: sag_connectivity_cpp.hpp:592
const payload_t & getPayload() const
Return a reference to the payload.
static bool getBoolean(const map_t &map, const char *key, bool defaultValue)
Get a boolean value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1216
const_iterator find(const char *k) const
Searches the map for an item with the given key and returns an iterator to that position in the map...
Definition: sag_connectivity_cpp.hpp:1416
const_iterator end() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:912
void swap(map_t &&other)
Swap the contents of this map and other.
Definition: sag_connectivity_cpp.hpp:864
const char *const operator[](const char *k) const
Returns the item with the given key.
Definition: sag_connectivity_cpp.hpp:1376
void erase(iterator it)
Erase the item pointed to by this iterator.
Definition: sag_connectivity_cpp.hpp:1478
data_t & operator=(data_t &&other)
Move-assignment from another data_t.
Definition: sag_connectivity_cpp.hpp:96
static bool getBoolean(const map_t &map, const char *key)
Get a boolean value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1214
pair< const data_t > const_element
The type of an element in a const map.
Definition: sag_connectivity_cpp.hpp:829
const char *const operator[](const std::string &k) const
Returns the item with the given key.
Definition: sag_connectivity_cpp.hpp:1399
const data_t & back() const
Returns a reference to the data_t at position size()-1 Throws std::runtime_error if the list is empty...
Definition: sag_connectivity_cpp.hpp:665
result_type visitCustom(sag_underlying_custom_t &i) const
Visit a custom object.
Definition: sag_connectivity_cpp.hpp:1687
result_type visitCustom(const sag_underlying_custom_t &i) const
Visit a custom object.
Definition: sag_connectivity_cpp.hpp:1779
const T * operator->() const
Return the wrapped pointer as the correct type.
Definition: sag_connectivity_cpp.hpp:416
~buffer_t()
Free the underlying buffer contents.
Definition: sag_connectivity_cpp.hpp:1067
const data_t & operator[](const data_t &k) const
Return a reference to the item with the given key.
Definition: sag_connectivity_cpp.hpp:931
bool operator!=(const list_t &other) const
Returns false if this list is deep equals to other list.
Definition: sag_connectivity_cpp.hpp:623
void reserve(size_t n)
Ensure the capacity is (at least) n.
Definition: sag_connectivity_cpp.hpp:674
list_t()
Construct an empty list.
Definition: sag_connectivity_cpp.hpp:567
_iterator< const data_t, const sag_underlying_data_t * > const_iterator
The type of iterators over a const list.
Definition: sag_connectivity_cpp.hpp:564
std::pair< iterator, bool > insert(const std::pair< data_t &&, data_t && > &v)
Insert a new key/value pair into the map.
std::pair< iterator, bool > insert(const std::pair< const char *, const char * > &v)
Insert a new key/value pair into the map.
Definition: sag_connectivity_cpp.hpp:1454
RV result_type
The return type from applying this visitor.
Definition: sag_connectivity_cpp.hpp:1727
map_t(map_t &&other)
Move constructor. Other will be left as the empty map.
Definition: sag_connectivity_cpp.hpp:857
data_t & operator=(const std::string &s)
Assign this to a string, freeing the existing contents (copies the string).
Definition: sag_connectivity_cpp.hpp:275
static const list_t & getList(const map_t &map, const std::string &key, const list_t &defaultValue)
Get a list value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1238
static int64_t getInteger(const map_t &map, const char *key)
Get an integer value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1196
Message & putMetadataValue(const std::string &key, const std::string &value)
Sets a value in the metadata.
Definition: sag_connectivity_cpp.hpp:1598
T * operator->()
Return the wrapped pointer as the correct type.
Definition: sag_connectivity_cpp.hpp:414
iterator end()
Forward iterator end.
Definition: sag_connectivity_cpp.hpp:1125
result_type operator()(const char *i) const
Visit a string (don't override this, instead override visitString)
Definition: sag_connectivity_cpp.hpp:1752
uint8_t & operator[](size_t n)
Return a reference the byte at the given offset.
Definition: sag_connectivity_cpp.hpp:1142
result_type operator()(const decimal_t &i) const
Visit a decimal (don't override this, instead override visitDecimal)
Definition: sag_connectivity_cpp.hpp:1757
iterator find(const std::string &k)
Searches the map for an item with the given key and returns an iterator to that position in the map...
Definition: sag_connectivity_cpp.hpp:1422
bool empty() const
Returns true if the buffer is unallocated (size() == 0)
Definition: sag_connectivity_cpp.hpp:1138
size_t size() const
Return the number of items in this list.
Definition: sag_connectivity_cpp.hpp:650
const_iterator end() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:635
payload_t & getPayload()
Return a reference to the payload.
Definition: sag_connectivity_cpp.hpp:1558
result_type visitDecimal(const decimal_t &i) const
Visit a decimal.
Definition: sag_connectivity_cpp.hpp:1759
A map class which implements many of the functions on std::map.
Definition: sag_connectivity_cpp.hpp:719
get_details::GetVisitor< custom_t< T > >::result_type get_custom(data_t &t)
Get the contents of the variant as a typed custom_t.
Definition: sag_connectivity_cpp.hpp:481
size_t size() const
Returns the number of key/value pairs in the map.
Definition: sag_connectivity_cpp.hpp:919
result_type visitBuffer(const buffer_t &i) const
Visit a byte buffer.
Definition: sag_connectivity_cpp.hpp:1764
A container for an payload and associated metadata.
Definition: sag_connectivity_cpp.hpp:1514
const_iterator cend() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:1497
data_t & operator=(const char *s)
Assign this to a string, freeing the existing contents (copies the string).
Definition: sag_connectivity_cpp.hpp:265
result_type operator()() const
Visit an empty variant (don't override this, instead override visitEmpty)
Definition: sag_connectivity_cpp.hpp:1732
static double getDouble(const map_t &map, const char *key, double defaultValue)
Get a double value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1207
std::pair< iterator, bool > insert(const std::pair< std::string, std::string > &v)
Insert a new key/value pair into the map.
Definition: sag_connectivity_cpp.hpp:1441
data_t(bool b)
Create a data_t from a bool.
Definition: sag_connectivity_cpp.hpp:200
A class that holds an untyped byte buffer.
Definition: sag_connectivity_cpp.hpp:1054
void swap(custom_t &&other)
Swap with another custom_t of the same type.
result_type operator()(const map_t &i) const
Visit a map (don't override this, instead override visitMap)
Definition: sag_connectivity_cpp.hpp:1772
~map_t()
Free the underlying map contents.
Definition: sag_connectivity_cpp.hpp:840
result_type visitEmpty() const
Visit an empty variant.
Definition: sag_connectivity_cpp.hpp:1734
result_type visitEmpty() const
Visit an empty variant.
Definition: sag_connectivity_cpp.hpp:1642
static std::string getString(const map_t &map, const char *key)
Get a string value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1187
_iterator< data_t, sag_underlying_data_t * > iterator
The type of iterators over a mutable list.
Definition: sag_connectivity_cpp.hpp:562
static int64_t getInteger(const map_t &map, const char *key, int64_t defaultValue)
Get an integer value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1198
static std::string getString(const map_t &map, const std::string &key, const std::string &defaultValue)
Get a string value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1193
data_t & operator=(buffer_t &&d)
Assign this to a buffer_t, freeing the existing contents.
Definition: sag_connectivity_cpp.hpp:320
_iterator< const data_t, sag_underlying_map_table_entry_t const *, const pair< const data_t > > const_iterator
The type of iterators on const maps.
Definition: sag_connectivity_cpp.hpp:825
data_t & operator=(map_t &&d)
Assign this to a map_t, freeing the existing contents.
Definition: sag_connectivity_cpp.hpp:305
bool operator!=(const buffer_t &other) const
Returns false.
Definition: sag_connectivity_cpp.hpp:1111
static const char * CHANNEL()
Returns the metadata key used by the host for identifying the channel of the message - "sag...
Definition: sag_connectivity_cpp.hpp:1586
Decimals are implemented with an underlying 64bit int conforming to IEEE 754 decimal 64...
Definition: sag_connectivity_c.h:74
data_t & operator=(int64_t d)
Assign an int64_t to this, freeing the existing contents of this.
Definition: sag_connectivity_cpp.hpp:193
void swap(metadata_t &&other)
Swap the contents of this map and other.
Definition: sag_connectivity_cpp.hpp:1357
const_iterator cbegin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:1495
bool operator!=(const data_t &other) const
Returns true if two data_ts are non-equal (deep equality)
Definition: sag_connectivity_cpp.hpp:115
data_t(double d)
Create a data_t from a double.
Definition: sag_connectivity_cpp.hpp:213
metadata_t & operator=(metadata_t &&other)
Move assignment.
Definition: sag_connectivity_cpp.hpp:1334
list_t & operator=(list_t &&other)
Move assignement operator.
Definition: sag_connectivity_cpp.hpp:582
_iterator< data_t, sag_underlying_map_table_entry_t *, pair< data_t > > iterator
The type of iterators on mutable maps.
Definition: sag_connectivity_cpp.hpp:823
data_t & back()
Returns a reference to the data_t at position size()-1 Throws std::runtime_error if the list is empty...
Definition: sag_connectivity_cpp.hpp:671
map_t copy() const
Return a deep copy of this map.
Definition: sag_connectivity_cpp.hpp:870
sag_data_tag type_tag() const
Return the descriminator for this union (as an enum of the possible values)
Definition: sag_connectivity_cpp.hpp:177
static const map_t & getMap(const map_t &map, const char *key)
Get a map value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1223
result_type operator()(const sag_underlying_custom_t &i) const
Visit a custom object (don't override this, instead override visitCustom)
Definition: sag_connectivity_cpp.hpp:1777
const data_t & operator[](size_t n) const
Returns a reference to the data_t at position n.
result_type operator()(double &i) const
Visit a double (don't override this, instead override visitDouble)
Definition: sag_connectivity_cpp.hpp:1650
result_type operator()(const char *&i) const
Visit a string (don't override this, instead override visitString)
Definition: sag_connectivity_cpp.hpp:1660
Helper class for writing visitors to apply to data_t.
Definition: sag_connectivity_cpp.hpp:1631
result_type visitBoolean(bool &i) const
Visit a boolean.
Definition: sag_connectivity_cpp.hpp:1657
const char * type_name() const
Return the name of the contained type as a string (mainly useful for debugging)
Definition: sag_connectivity_cpp.hpp:156
DERIVED derived_t
The type of the derived class.
Definition: sag_connectivity_cpp.hpp:1729
a void* + deleter and copy function pointers
Definition: sag_connectivity_c.h:44
void push_back(data_t &&d)
Add an item to the end of the list.
custom_t & operator=(custom_t &&other)
Move assignment, destroying the current contents.
Bool.
Definition: sag_connectivity_c.h:36
buffer_t(buffer_t &&other)
Move constructor. Other will be left as the empty buffer.
Definition: sag_connectivity_cpp.hpp:1084
static const char * HOST_MESSAGE_TYPE()
Returns the metadata key used by the host for identifying the type of the message - "sag...
Definition: sag_connectivity_cpp.hpp:1581
utf8-encoded const char*
Definition: sag_connectivity_c.h:40
const_iterator begin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:633
result_type visitInteger(int64_t &i) const
Visit an integer.
Definition: sag_connectivity_cpp.hpp:1647
bool operator!=(const map_t &other) const
Returns false if this map deep-equals other.
Definition: sag_connectivity_cpp.hpp:899
bool operator==(const metadata_t &other) const
Returns true if this map deep-equals other.
Definition: sag_connectivity_cpp.hpp:1349
iterator end()
Forward iterator end.
Definition: sag_connectivity_cpp.hpp:908
bool empty() const
Returns true if there are no items in this list.
Definition: sag_connectivity_cpp.hpp:652
V::result_type apply_visitor(const V &v) const
Apply a visitor (using the boost::static_visitor pattern) to this data_t.
const_iterator find(const std::string &k) const
Searches the map for an item with the given key and returns an iterator to that position in the map...
Definition: sag_connectivity_cpp.hpp:1428
data_t payload_t
the type of a message payload
Definition: sag_connectivity_cpp.hpp:1520
buffer_t copy() const
Return a deep copy of this buffer.
void swap(list_t &&other)
Swap the contents of this list with other.
Definition: sag_connectivity_cpp.hpp:598
Forward/reverse and const/non-const iterators are implemented using this class.
Definition: sag_connectivity_cpp.hpp:523
A variant type which can be one of the following:
Definition: sag_connectivity_cpp.hpp:69
void pop_back()
Remove the last item in the list.
result_type operator()(int64_t i) const
Visit an integer (don't override this, instead override visitInteger)
Definition: sag_connectivity_cpp.hpp:1737
data_t(data_t &&other)
Construct a data_t, move the contents from another data_t.
Definition: sag_connectivity_cpp.hpp:84
result_type operator()(sag_underlying_custom_t &i) const
Visit a custom object (don't override this, instead override visitCustom)
Definition: sag_connectivity_cpp.hpp:1685
iterator find(const data_t &k)
Searches the map for an item with the given key and returns an iterator to that position in the map...
pair< data_t > element
The type of an element in a mutable map.
Definition: sag_connectivity_cpp.hpp:827
static bool getBoolean(const map_t &map, const std::string &key)
Get a boolean value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1218
static const list_t & getList(const map_t &map, const char *key)
Get a list value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1232
result_type operator()(bool i) const
Visit a boolean (don't override this, instead override visitBoolean)
Definition: sag_connectivity_cpp.hpp:1747
custom_t()
Create an empty custom_t.
bool operator==(const buffer_t &other) const
Returns true.
Definition: sag_connectivity_cpp.hpp:1106
custom_t copy() const
Return a copy of the underlying pointer.
const char * operator[](const char *k)
Returns the item with the given key.
Definition: sag_connectivity_cpp.hpp:1365
result_type visitInteger(int64_t i) const
Visit an integer.
Definition: sag_connectivity_cpp.hpp:1739
static const map_t & getMap(const map_t &map, const std::string &key)
Get a map value from the map, throwing if the key is not present.
Definition: sag_connectivity_cpp.hpp:1227
DERIVED derived_t
The type of the derived class.
Definition: sag_connectivity_cpp.hpp:1637
64-bit float
Definition: sag_connectivity_c.h:37
buffer_t & operator=(buffer_t &&other)
Move assignement.
Definition: sag_connectivity_cpp.hpp:1074
Empty.
Definition: sag_connectivity_c.h:35
size_t erase(const std::string &k)
Remove the item with the specified key.
Definition: sag_connectivity_cpp.hpp:1462
T & operator*()
Return the wrapped pointer as the correct type.
Definition: sag_connectivity_cpp.hpp:410
static std::string getString(const map_t &map, const char *key, const char *defaultValue)
Get a string value from the map, returning the given default if the key is not present.
Definition: sag_connectivity_cpp.hpp:1189
void setPayload(payload_t &&_payload)
Set the payload.
Forward/reverse and const/non-const iterators are implemented using this class.
Definition: sag_connectivity_cpp.hpp:1282
Contains the C ABI for connectivity plugins.
metadata_t()
Construct an empty map.
Definition: sag_connectivity_cpp.hpp:1327
result_type visitDouble(double i) const
Visit a double.
Definition: sag_connectivity_cpp.hpp:1744
size_t size() const
Returns the size of the buffer.
Definition: sag_connectivity_cpp.hpp:1136
data_t(decimal_t d)
Create a data_t from a decimal.
Definition: sag_connectivity_cpp.hpp:244
iterator rbegin()
Reverse iterator begin.
Definition: sag_connectivity_cpp.hpp:641
Forward/reverse and const/non-const iterators are implemented using this class.
Definition: sag_connectivity_cpp.hpp:745
buffer_t()
Construct an empty buffer.
Definition: sag_connectivity_cpp.hpp:1059
result_type operator()(decimal_t &i) const
Visit a decimal (don't override this, instead override visitDecimal)
Definition: sag_connectivity_cpp.hpp:1665
iterator begin()
Forward iterator begin.
Definition: sag_connectivity_cpp.hpp:1123