Apama  9.12.0.5
 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 287769 2016-07-28 14:08:05Z matj $
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  }
259  explicit data_t(const char *s, size_t n);
262  explicit data_t(const char *s);
265  explicit data_t(const std::string &s);
269  data_t &operator=(const char *s)
270  {
271  data_t tmp(s);
272  swap(std::move(tmp));
273  return *this;
274  }
275 
279  data_t &operator=(const std::string &s)
280  {
281  data_t tmp(s);
282  swap(std::move(tmp));
283  return *this;
284  }
289  explicit data_t(list_t &&d);
295  {
296  data_t tmp(std::move(d));
297  swap(std::move(tmp));
298  return *this;
299  }
304  explicit data_t(map_t &&d);
310  {
311  data_t tmp(std::move(d));
312  swap(std::move(tmp));
313  return *this;
314  }
319  explicit data_t(buffer_t &&d);
325  {
326  data_t tmp(std::move(d));
327  swap(std::move(tmp));
328  return *this;
329  }
330 };
331 
348 template<typename V>
349 inline typename V::result_type apply_visitor(const V&v, data_t& t) { return t.apply_visitor(v); }
366 template<typename V>
367 inline typename V::result_type apply_visitor(const V&v, const data_t& t) { return t.apply_visitor(v); }
368 
390 template<typename T>
391 class custom_t: public sag_underlying_custom_t
392 {
393  typedef custom_t this_t;
394 public:
396  custom_t();
398  custom_t(T *payload);
400  ~custom_t();
402  T *get() { return this->data ? reinterpret_cast<T*>(this->data->custom) : 0; }
404  const T *get() const { return this->data ? reinterpret_cast<T*>(this->data->custom) : 0; }
406  custom_t(custom_t &&other);
408  custom_t &operator=(custom_t &&other);
410  void swap(custom_t &&other);
412  custom_t copy() const;
414  T &operator*() { return *get(); }
416  const T &operator*() const { return *get(); }
418  T *operator->() { return get(); }
420  const T *operator->() const { return get(); }
421 private:
423  static void deleter(void *d)
424  {
425  if (d) {
426  try {
427  delete reinterpret_cast<T*>(d);
428  } catch (...) {
429  // enforce nothrow behaviour
430  abort();
431  }
432  }
433  }
435  static void *copier(void *d)
436  {
437  try {
438  return d ? new T(*reinterpret_cast<T*>(d)) : 0;
439  } catch (...) {
440  // enforce nothrow behaviour
441  abort();
442  }
443  }
445  custom_t(const custom_t &other) { abort(); }
447  custom_t &operator=(const custom_t &other) { abort(); return *this; }
448 };
449 
450 
451 #include <sag_internal/convert_to.hpp>
452 
463 template<typename T>
464 inline typename get_details::GetVisitor<const T>::result_type get(const data_t &t) { return apply_visitor(get_details::GetVisitor<const T>(), t); }
475 template<typename T>
476 inline typename get_details::GetVisitor<T>::result_type get(data_t &t) { return apply_visitor(get_details::GetVisitor<T>(), t); }
484 template<typename T>
485 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); }
493 template<typename T>
494 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); }
495 
496 
512 class list_t: protected sag_underlying_vector_t
513 {
514  friend class data_t;
515  friend class map_t;
516  friend class Message;
518  static size_t MIN_CAPACITY() { return 10; }
519 public:
526  template<typename DATA, typename UNDERLYING>
527  struct _iterator: public std::iterator<std::random_access_iterator_tag, DATA>
528  {
530  _iterator() : ptr(0), direction(1) {}
531  explicit _iterator(UNDERLYING ptr, bool forward=true)
532  : ptr(ptr), direction(forward?1:-1)
533  {}
534  iterator &operator+=(size_t n) { ptr += direction*n; return *this; }
535  iterator &operator-=(size_t n) { ptr -= direction*n; return *this; }
536  iterator operator+(size_t n) const { return iterator(ptr+(direction*n), direction>0); }
537  iterator operator-(size_t n) const { return iterator(ptr+(direction*-n), direction > 0); }
538  ptrdiff_t operator-(const iterator &other) const { return direction*(ptr-other.ptr); }
539  DATA &operator[](size_t n) const { return static_cast<DATA&>(ptr[n*direction]); }
540  bool operator<(const iterator &other) const { return direction>0 ? ptr < other.ptr : ptr > other.ptr; }
541  bool operator>(const iterator &other) const { return direction>0 ? ptr > other.ptr : ptr < other.ptr; }
542  bool operator>=(const iterator &other) const { return direction>0 ? ptr >= other.ptr : ptr <= other.ptr; }
543  bool operator<=(const iterator &other) const { return direction>0 ? ptr <= other.ptr : ptr >= other.ptr; }
544  bool operator==(const iterator &other) const { return ptr == other.ptr; }
545  bool operator!=(const iterator &other) const { return !operator==(other); }
546  iterator &operator++() { return operator+=(1); }
547  iterator operator++(int)
548  {
549  iterator tmp(*this);
550  operator++();
551  return tmp;
552  }
553  iterator &operator--() { return operator-=(1); }
554  iterator operator--(int)
555  {
556  iterator tmp(*this);
557  operator--();
558  return tmp;
559  }
560  DATA &operator*() const { return static_cast<DATA&>(*ptr); }
561  DATA *operator->() const { return static_cast<DATA*>(ptr); }
562  UNDERLYING ptr;
563  int64_t direction;
564  };
569 
572  {
573  table = 0;
574  }
576  explicit list_t(size_t n);
577 
580  {
581  clear();
582  }
583 
587  {
588  list_t tmp;
589  // put us in tmp
590  swap(std::move(tmp));
591  // put other in us (and by extension the null tmp in other)
592  swap(std::move(other));
593  return *this;
594  }
596  list_t(list_t &&other)
597  {
598  table = 0;
599  swap(std::move(other));
600  }
602  void swap(list_t &&other)
603  {
604  std::swap(table, other.table);
605  }
607  list_t copy() const
608  {
609  list_t newlist(size());
610  for (const_iterator it = begin(); it != end(); ++it) {
611  newlist.push_back(it->copy());
612  }
613  return newlist;
614  }
615 
616 private:
618  list_t &operator=(const list_t &other) { abort(); }
620  list_t(const list_t &other) { abort(); }
621 public:
622 
624  bool operator==(const list_t &other) const;
625 
627  bool operator!=(const list_t &other) const { return !operator==(other); }
628 
629  /* Iteration:
630  * begin() and end() methods, both const and non-const, forward and backward.
631  */
633  iterator begin() { return iterator(table?table->data:0); }
635  iterator end() { return iterator(table?table->data+table->count:0); }
637  const_iterator begin() const { return const_iterator(table?table->data:0); }
639  const_iterator end() const { return const_iterator(table?table->data+table->count:0); }
641  const_iterator cbegin() const { return const_iterator(table?table->data:0); }
643  const_iterator cend() const { return const_iterator(table?table->data+table->count:0); }
645  iterator rbegin() { return iterator(table?table->data+table->count-1:0, false); }
647  iterator rend() { return iterator(table?table->data-1:0, false); }
649  const_iterator rbegin() const { return const_iterator(table?table->data+table->count-1:0, false); }
651  const_iterator rend() const { return const_iterator(table?table->data-1:0, false); }
652 
654  size_t size() const { return table?table->count:0; }
656  bool empty() const { return 0 == size(); }
657 
660  const data_t &operator[](size_t n) const;
663  data_t &operator[](size_t n);
666  const data_t &front() const { return operator[](0); }
669  const data_t &back() const { return operator[](table?table->count-1:0); }
672  data_t &front() { return operator[](0); }
675  data_t &back() { return operator[](table?table->count-1:0); }
676 
678  void reserve(size_t n)
679  {
680  if (!table) resize(n);
681  if (n > table->capacity) resize(n);
682  }
685  void clear();
686 
691  void push_back(data_t &&d);
692 
694  void pop_back();
695 
696 private:
703  void resize(size_t newsize);
704 };
705 
723 class map_t: protected sag_underlying_map_t
724 {
725  friend class data_t;
726  friend class Message;
728  static size_t MIN_CAPACITY() { return 8; }
729 protected:
730  typedef sag_underlying_map_table_entry_t item_t;
731  typedef int64_t hash_t;
732 public:
733 
734  template<typename DATA>
735  struct pair
736  {
737  hash_t hash;
738  DATA first;
739  DATA second;
740  };
741 
748  template<typename DATA, typename UNDERLYING, typename PAIR>
749  struct _iterator: public std::iterator<std::bidirectional_iterator_tag, DATA>
750  {
751  friend class map_t;
753  typedef PAIR element_t;
754 
755  _iterator(): tabledata(0), capacity(0), offs(0) {}
756  _iterator(const UNDERLYING &tabledata, size_t capacity, int64_t offs, bool stepToItem=false)
757  : tabledata(tabledata), capacity(capacity), offs(offs)
758  {
759  if (!valid() && stepToItem) {
760  operator++();
761  }
762  }
763 
764  iterator &operator--()
765  {
766  if (offs > -1) {
767  do {
768  --offs;
769  } while (!valid());
770  }
771  return *this;
772  }
773  iterator operator--(int)
774  {
775  iterator tmp(*this);
776  operator--();
777  return tmp;
778  }
779  iterator &operator++()
780  {
781  if (offs < capacity) {
782  do {
783  ++offs;
784  } while (!valid());
785  }
786  return *this;
787  }
788  iterator operator++(int)
789  {
790  iterator tmp(*this);
791  operator++();
792  return tmp;
793  }
794 
795  DATA &key() const { return static_cast<DATA&>(tabledata[offs].key); }
796  DATA &value() const { return static_cast<DATA&>(tabledata[offs].value); }
797 
798  bool operator==(const iterator &other) const
799  {
800  bool b = offs == other.offs;
801  return b;
802  }
803  bool operator!=(const iterator &other) const
804  {
805  bool b = !operator==(other);
806  return b;
807  }
808  element_t &operator*() const
809  {
810  return reinterpret_cast<element_t &>(tabledata[offs]);
811  }
812  element_t *operator->() const
813  {
814  return reinterpret_cast<element_t *>(tabledata + offs);
815  }
816  protected:
818  bool valid() const
819  {
820  return offs >= capacity || offs < 0 || tabledata[offs].hash > 1 || SAG_DATA_EMPTY != tabledata[offs].key.tag;
821  }
822  UNDERLYING tabledata;
823  int64_t capacity;
824  int64_t offs;
825  };
831  typedef pair<data_t> element;
833  typedef pair<const data_t> const_element;
834 
837  {
838  table = 0;
839  }
841  explicit map_t(size_t n);
842 
845  {
846  clear();
847  }
848 
852  {
853  map_t tmp;
854  // put us in tmp
855  swap(std::move(tmp));
856  // put other in us (and by extension the null tmp in other)
857  swap(std::move(other));
858  return *this;
859  }
861  map_t(map_t &&other)
862  {
863  table = 0;
864  swap(std::move(other));
865  }
866 
868  void swap(map_t &&other)
869  {
870  std::swap(table, other.table);
871  }
872 
874  map_t copy() const
875  {
876  map_t newmap(size());
877  for (const_iterator it = begin(); it != end(); ++it) {
878  newmap.insert(std::make_pair(it->first.copy(), it->second.copy()));
879  }
880  return newmap;
881  }
882 
883 private:
885  map_t &operator=(const map_t &other) { abort(); }
887  map_t(const map_t &other) { abort(); }
888 public:
889 
891  bool operator==(const map_t &other) const
892  {
893  if (size() != other.size()) return false;
894  for (const_iterator it = begin(); it != end(); ++it) {
895  const_iterator jt = other.find(it.key());
896  if (jt == other.end()) return false;
897  if (it.value() != jt.value()) return false;
898  }
899  return true;
900  }
901 
903  bool operator!=(const map_t &other) const { return !operator==(other); }
904 
905  /* Iteration:
906  * begin() and end() methods, both const and non-const.
907  * Unordered, so forward iteration only
908  */
910  iterator begin() { return iterator(table?table->table:0, table?table->capacity:0, 0, true); }
912  iterator end() { return iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
914  const_iterator begin() const { return const_iterator(table?table->table:0, table?table->capacity:0, 0, true); }
916  const_iterator end() const { return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
918  const_iterator cbegin() const { return const_iterator(table?table->table:0, table?table->capacity:0, 0, true); }
920  const_iterator cend() const { return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
921 
923  size_t size() const { return table?table->count:0; }
924 
926  bool empty() const { return 0 == size(); }
927 
931  {
932  return maybe_insert(std::pair<data_t&&,data_t&&>(std::move(k), data_t())).first->second;
933  }
934 
938  {
939  return maybe_insert(std::pair<const data_t&,const data_t&>(k, data_t())).first->second;
940  }
943  const data_t &operator[](const data_t &k) const
944  {
945  const_iterator it = find(k);
946  if (it == end()) {
947  throw std::runtime_error("Element not in map");
948  } else {
949  return it.value();
950  }
951  }
954  iterator find(const data_t &k);
955 
958  const_iterator find(const data_t &k) const;
959 
971  std::pair<iterator, bool> insert(const std::pair<data_t&&, data_t&&> &v);
972 
984  std::pair<iterator, bool> insert(data_t&& k, data_t&& v) {
985  return insert(std::make_pair(std::move(k), std::move(v)));
986  }
987 
990  std::pair<iterator, bool> insert(const std::pair<data_t&&, data_t&&> &v, hash_t hash);
991 
996  size_t erase(const data_t &k);
1001  void erase(iterator it);
1005  void clear();
1006 
1007 protected:
1014  void resize(size_t newsize);
1015 
1017  void really_insert(item_t &item, const std::pair<data_t&&, data_t&&> &v, hash_t hash);
1019  std::pair<iterator, bool> maybe_insert(const std::pair<const data_t&, const data_t&> &v);
1021  std::pair<iterator, bool> maybe_insert(const std::pair<data_t&&, data_t&&> &v);
1023  std::pair<map_t::const_iterator, map_t::const_iterator> find_for_insert(const data_t &k, hash_t hash) const;
1024 
1026  bool empty(const item_t &item) const { return 0 == item.hash && SAG_DATA_EMPTY == item.key.tag; }
1028  bool empty(const const_iterator::element_t &item) const { return 0 == item.hash && SAG_DATA_EMPTY == item.first.tag; }
1030  bool hole(const item_t &item) const { return 1 == item.hash && SAG_DATA_EMPTY == item.key.tag; }
1032  bool hole(const const_iterator::element_t &item) const { return 1 == item.hash && SAG_DATA_EMPTY == item.first.tag; }
1034  bool live(const item_t &item) const { return SAG_DATA_EMPTY != item.key.tag || item.hash > 1; }
1036  bool live(const const_iterator::element_t &item) const { return SAG_DATA_EMPTY != item.first.tag || item.hash > 1; }
1037 
1039  size_t index(hash_t hash) const
1040  {
1041  if (!table) return 0;
1042  return table->capacity ? hash % table->capacity : 0;
1043  }
1044 
1045 #ifdef _SAG_INTERNAL_UNSUPPORTED_DEBUG
1046 public:
1047  SAG_CONNECTIVITY_API static size_t clashes;
1048  SAG_CONNECTIVITY_API static size_t inserts;
1049  SAG_CONNECTIVITY_API static double resizeUsage;
1050  SAG_CONNECTIVITY_API static size_t resizes;
1051  SAG_CONNECTIVITY_API static size_t max_lookup_clash;
1052  SAG_CONNECTIVITY_API static size_t lookups;
1053  SAG_CONNECTIVITY_API static size_t lookup_clashes;
1054  static double getInsertClashRatio() { return (double)clashes/(double)inserts; }
1055  static double getAverageResizeRatio() { return resizeUsage/(double)resizes; }
1056  static void resetCounters() { clashes = inserts = resizeUsage = resizes = 0; }
1057  static double getAverageLookupProbes() { return 1.0+(double)lookup_clashes/(double)lookups; }
1058  static size_t getMaxLookupProbes() { return 1+max_lookup_clash; }
1059 #endif
1060 };
1061 
1070 class buffer_t: protected sag_underlying_buffer_t
1071 {
1072  friend class data_t;
1073 public:
1076  {
1077  table = 0;
1078  }
1080  explicit buffer_t(size_t n);
1081 
1084  {
1085  clear();
1086  }
1087 
1091  {
1092  buffer_t tmp;
1093  // put us in tmp
1094  swap(std::move(tmp));
1095  // put other in us (and by extension the null tmp in other)
1096  swap(std::move(other));
1097  return *this;
1098  }
1101  {
1102  table = 0;
1103  swap(std::move(other));
1104  }
1106  void swap(buffer_t &&other)
1107  {
1108  std::swap(table, other.table);
1109  }
1110 
1112  buffer_t copy() const;
1113 
1114 private:
1116  buffer_t &operator=(const buffer_t &other) { abort(); }
1118  buffer_t(const buffer_t &other) { abort(); }
1119 public:
1120 
1121  typedef uint8_t *iterator;
1122  typedef const uint8_t *const_iterator;
1123 
1125  bool operator==(const buffer_t &other) const
1126  {
1127  return (this->size() == other.size() &&
1128  std::equal(this->cbegin(), this->cend(), other.begin())
1129  );
1130  }
1132  bool operator!=(const buffer_t &other) const
1133  {
1134  return !(this->operator==(other));
1135  }
1136 
1137  /* Iteration:
1138  * begin() and end() methods, both const and non-const, forward and backward.
1139  */
1141  iterator begin() { return table?table->data:0; }
1143  iterator end() { return table?table->data+table->length:0; }
1145  const_iterator begin() const { return table?table->data:0; }
1147  const_iterator end() const { return table?table->data+table->length:0; }
1149  const_iterator cbegin() const { return table?table->data:0; }
1151  const_iterator cend() const { return table?table->data+table->length:0; }
1152 
1154  size_t size() const { return table ? table->length : 0; }
1156  bool empty() const { return 0 == size(); }
1157 
1160  uint8_t &operator[](size_t n)
1161  {
1162  if (n >= size()) throw std::runtime_error("Out of bounds");
1163  return table->data[n];
1164  }
1167  const uint8_t &operator[](size_t n) const
1168  {
1169  if (n >= size()) throw std::runtime_error("Out of bounds");
1170  return table->data[n];
1171  }
1175  void clear();
1176 };
1177 
1189 template<typename T>
1190 inline T convert_to(const data_t &d)
1191 {
1192  return apply_visitor(convert_to_details::_get_or_convert<T>(d.type_name()), d);
1193 }
1194 
1201 {
1202 public:
1203  // String
1205  static std::string getString(const map_t &map, const char *key) { return getAs<std::string>(map, key); }
1207  static std::string getString(const map_t &map, const char *key, const char *defaultValue) { return getAs<std::string>(map, key, defaultValue); }
1209  static std::string getString(const map_t &map, const std::string &key) { return getAs<std::string>(map, key.c_str()); }
1211  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); }
1212  // Integer
1214  static int64_t getInteger(const map_t &map, const char *key) { return getAs<int64_t>(map, key); }
1216  static int64_t getInteger(const map_t &map, const char *key, int64_t defaultValue) { return getAs<int64_t>(map, key, defaultValue); }
1218  static int64_t getInteger(const map_t &map, const std::string &key) { return getAs<int64_t>(map, key.c_str()); }
1220  static int64_t getInteger(const map_t &map, const std::string &key, int64_t defaultValue) { return getAs<int64_t>(map, key.c_str(), defaultValue); }
1221  // Double
1223  static double getDouble(const map_t &map, const char *key) { return getAs<double>(map, key); }
1225  static double getDouble(const map_t &map, const char *key, double defaultValue) { return getAs<double>(map, key, defaultValue); }
1227  static double getDouble(const map_t &map, const std::string &key) { return getAs<double>(map, key.c_str()); }
1229  static double getDouble(const map_t &map, const std::string &key, double defaultValue) { return getAs<double>(map, key.c_str(), defaultValue); }
1230  // Boolean
1232  static bool getBoolean(const map_t &map, const char *key) { return getAs<bool>(map, key); }
1234  static bool getBoolean(const map_t &map, const char *key, bool defaultValue) { return getAs<bool>(map, key, defaultValue); }
1236  static bool getBoolean(const map_t &map, const std::string &key) { return getAs<bool>(map, key.c_str()); }
1238  static bool getBoolean(const map_t &map, const std::string &key, bool defaultValue) { return getAs<bool>(map, key.c_str(), defaultValue); }
1239  // Map
1241  static const map_t &getMap(const map_t &map, const char *key) { return getAs<const map_t&>(map, key); }
1243  static const map_t &getMap(const map_t &map, const char *key, const map_t &defaultValue) { return getAs<const map_t&>(map, key, defaultValue); }
1245  static const map_t &getMap(const map_t &map, const std::string &key) { return getAs<const map_t&>(map, key.c_str()); }
1247  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); }
1248  // List
1250  static const list_t &getList(const map_t &map, const char *key) { return getAs<const list_t&>(map, key); }
1252  static const list_t &getList(const map_t &map, const char *key, const list_t &defaultValue) { return getAs<const list_t&>(map, key, defaultValue); }
1254  static const list_t &getList(const map_t &map, const std::string &key) { return getAs<const list_t&>(map, key.c_str()); }
1256  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); }
1257 
1258 private:
1260  template<typename T>
1261  static T getAs(const map_t &map, const char *key);
1263  template<typename T>
1264  static T getAs(const map_t &map, const char *key, const T &def);
1265 };
1266 
1267 
1268 
1288 class metadata_t: protected map_t
1289 {
1290  friend class data_t;
1291  friend class Message;
1292 public:
1299  template<typename DATA, typename UNDERLYING, typename PAIR>
1300  struct _iterator: public map_t::_iterator<DATA, UNDERLYING, PAIR>
1301  {
1302  typedef _iterator<DATA, UNDERLYING, PAIR> iterator;
1304 
1305  _iterator(): map_iterator() {}
1306  _iterator(const UNDERLYING &tabledata, size_t capacity, int64_t offs, bool stepToItem=false)
1307  : map_iterator(tabledata, capacity, offs, stepToItem)
1308  {}
1309  _iterator(const map_iterator &other): map_iterator(other) {}
1310  iterator &operator=(const map_iterator &other)
1311  {
1312  map_iterator::tabledata = other.tabledata;
1313  map_iterator::offs = other.offs;
1314  map_iterator::step = other.step;
1315  map_iterator::capacity = other.capacity;
1316  return *this;
1317  }
1318 
1319  const char* key() const
1320  {
1321  assert(map_iterator::tabledata[map_iterator::offs].key.tag == SAG_DATA_STRING);
1322  if (map_iterator::tabledata[map_iterator::offs].key.tag != SAG_DATA_STRING) throw std::runtime_error("Metadata key not a string");
1323  return map_iterator::tabledata[map_iterator::offs].key.string;
1324  }
1325  const char* value() const
1326  {
1327  assert(map_iterator::tabledata[map_iterator::offs].value.tag == SAG_DATA_STRING);
1328  if (map_iterator::tabledata[map_iterator::offs].value.tag != SAG_DATA_STRING) throw std::runtime_error("Metadata value not a string");
1329  return map_iterator::tabledata[map_iterator::offs].value.string;
1330  }
1331  private: // can't expose these as string/string so make them inaccessible
1332  typename map_iterator::element_t &operator*() const
1333  {
1334  return reinterpret_cast<typename map_iterator::element_t &>(map_iterator::tabledata[map_iterator::offs]);
1335  }
1336  typename map_iterator::element_t *operator->() const
1337  {
1338  return reinterpret_cast<typename map_iterator::element_t *>(map_iterator::tabledata + map_iterator::offs);
1339  }
1340  };
1343 
1347  explicit metadata_t(size_t n): map_t(n) {}
1349  metadata_t(metadata_t &&other) : map_t(std::move(other)) {}
1353  {
1354  metadata_t tmp;
1355  swap(std::move(tmp));
1356  swap(std::move(other));
1357  return *this;
1358  }
1360  metadata_t copy() const;
1361 
1362  using map_t::empty;
1363  using map_t::size;
1364  using map_t::clear;
1365 
1367  bool operator==(const metadata_t &other) const
1368  {
1369  return static_cast<const map_t&>(*this) == static_cast<const map_t&>(other);
1370  }
1372  bool operator!=(const metadata_t &other) const { return !operator==(other); }
1373 
1375  void swap(metadata_t &&other)
1376  {
1377  return static_cast<map_t&>(*this).swap(static_cast<map_t&&>(other));
1378  }
1379 
1383  const char *operator[](const char *k)
1384  {
1385  iterator it = find(k);
1386  if (it == end()) {
1387  throw std::runtime_error("Element not in map");
1388  } else {
1389  return it.value();
1390  }
1391  }
1394  const char *const operator[](const char *k) const
1395  {
1396  const_iterator it = find(k);
1397  if (it == end()) {
1398  throw std::runtime_error("Element not in map");
1399  } else {
1400  return it.value();
1401  }
1402  }
1406  const char *operator[](const std::string &k)
1407  {
1408  iterator it = find(k);
1409  if (it == end()) {
1410  throw std::runtime_error("Element not in map");
1411  } else {
1412  return it.value();
1413  }
1414  }
1417  const char *const operator[](const std::string &k) const
1418  {
1419  const_iterator it = find(k);
1420  if (it == end()) {
1421  throw std::runtime_error("Element not in map");
1422  } else {
1423  return it.value();
1424  }
1425  }
1428  iterator find(const char *k)
1429  {
1430  return map_t::find(data_t(k));
1431  }
1434  const_iterator find(const char *k) const
1435  {
1436  return map_t::find(data_t(k));
1437  }
1440  iterator find(const std::string &k)
1441  {
1442  return map_t::find(data_t(k));
1443  }
1446  const_iterator find(const std::string &k) const
1447  {
1448  return map_t::find(data_t(k));
1449  }
1450 
1453  iterator find(const data_t &k)
1454  {
1455  return map_t::find(k);
1456  }
1459  const_iterator find(const data_t &k) const
1460  {
1461  return map_t::find(k);
1462  }
1471  std::pair<iterator, bool> insert(const std::pair<std::string, std::string> &v)
1472  {
1473  return map_t::insert(std::make_pair(data_t(v.first), data_t(v.second)));
1474  }
1475 
1484  std::pair<iterator, bool> insert(const std::pair<const char*, const char*> &v)
1485  {
1486  return map_t::insert(std::make_pair(data_t(v.first), data_t(v.second)));
1487  }
1488 
1493  size_t erase(const std::string &k)
1494  {
1495  return map_t::erase(data_t(k));
1496  }
1501  size_t erase(const char *k)
1502  {
1503  return map_t::erase(data_t(k));
1504  }
1509  void erase(iterator it)
1510  {
1511  map_t::erase(it);
1512  }
1513 
1514  /* Iteration:
1515  * begin() and end() methods, both const and non-const. Unordered so no reverse iterator
1516  */
1518  iterator begin() { return iterator(table?table->table:0, table?table->capacity:0, 0, true); }
1520  iterator end() { return iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
1522  const_iterator begin() const { return const_iterator(table?table->table:0, table?table->capacity:0, 0, true); }
1524  const_iterator end() const { return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
1526  const_iterator cbegin() const { return const_iterator(table?table->table:0, table?table->capacity:0, 0, true); }
1528  const_iterator cend() const { return const_iterator(table?table->table:0, table?table->capacity:0, table?table->capacity:0, false); }
1529 
1530 private:
1532  metadata_t &operator=(const metadata_t &other) { abort(); }
1534  metadata_t(const metadata_t &other) { abort(); }
1535 };
1536 
1545 class Message: protected sag_underlying_message_t
1546 {
1547 public:
1553  Message();
1554 
1558  explicit Message(payload_t &&_payload);
1559 
1563  Message(payload_t &&_payload, metadata_t &&_metadata);
1564 
1566  ~Message();
1567 
1571  Message(Message &&other);
1572 
1577  {
1578  Message tmp;
1579  swap(std::move(tmp));
1580  swap(std::move(other));
1581  return *this;
1582  }
1584  const payload_t &getPayload() const;
1586  const metadata_t &getMetadata() const;
1587 
1589  payload_t &getPayload() { return static_cast<payload_t&>(payload); }
1591  metadata_t &getMetadata() { return static_cast<metadata_t&>(metadata); }
1592 
1596  void setPayload(payload_t &&_payload);
1600  void setMetadata(metadata_t &&_metadata);
1601 
1603  void swap(Message &&other);
1604 
1606  Message copy() const
1607  {
1608  return Message(getPayload().copy(), getMetadata().copy());
1609  }
1610 
1612  static const char *HOST_MESSAGE_TYPE() {
1613  return "sag.type";
1614  }
1615 
1617  static const char *CHANNEL() {
1618  return "sag.channel";
1619  }
1620 
1624  Message &putMetadataValue(const char *key, const char *value);
1625 
1630  Message &putMetadataValue(data_t &&key, data_t &&value);
1631 
1635  Message &putMetadataValue(const std::string &key, const std::string &value) { return putMetadataValue(key.c_str(), value.c_str()); }
1636 private:
1638  Message(const Message &other) { abort(); }
1640  Message &operator=(const Message &other) { abort(); }
1641 };
1642 
1643 
1667 template<typename DERIVED, typename RV>
1668 class visitor
1669 {
1670 public:
1672  typedef RV result_type;
1674  typedef DERIVED derived_t;
1675 
1677  result_type operator()() const { return derived().visitEmpty(); }
1679  result_type visitEmpty() const { return derived().error("empty"); }
1680 
1682  result_type operator()(int64_t &i) const { return derived().visitInteger(i); }
1684  result_type visitInteger(int64_t &i) const { return derived().error("integer"); }
1685 
1687  result_type operator()(double &i) const { return derived().visitDouble(i); }
1689  result_type visitDouble(double &i) const { return derived().error("double"); }
1690 
1692  result_type operator()(bool &i) const { return derived().visitBoolean(i); }
1694  result_type visitBoolean(bool &i) const { return derived().error("boolean"); }
1695 
1697  result_type operator()(const char *&i) const { return derived().visitString(i); }
1699  result_type visitString(const char *&i) const { return derived().error("string"); }
1700 
1702  result_type operator()(decimal_t &i) const { return derived().visitDecimal(i); }
1704  result_type visitDecimal(decimal_t &i) const { return derived().error("decimal"); }
1705 
1707  result_type operator()(buffer_t &i) const { return derived().visitBuffer(i); }
1709  result_type visitBuffer(buffer_t &i) const { return derived().error("buffer"); }
1710 
1712  result_type operator()(list_t &i) const { return derived().visitList(i); }
1714  result_type visitList(list_t &i) const { return derived().error("list"); }
1715 
1717  result_type operator()(map_t &i) const { return derived().visitMap(i); }
1719  result_type visitMap(map_t &i) const { return derived().error("map"); }
1720 
1722  result_type operator()(sag_underlying_custom_t &i) const { return derived().visitCustom(i); }
1724  result_type visitCustom(sag_underlying_custom_t &i) const { return derived().error("custom"); }
1725 
1726 protected:
1729  result_type error(const std::string &reason) const { throw std::runtime_error("Visit type error: "+reason); }
1730 private:
1732  const derived_t &derived() const { return static_cast<const derived_t&>(*this); }
1733 };
1734 
1759 template<typename DERIVED, typename RV>
1761 {
1762 public:
1764  typedef RV result_type;
1766  typedef DERIVED derived_t;
1767 
1769  result_type operator()() const { return derived().visitEmpty(); }
1771  result_type visitEmpty() const { return derived().error("empty"); }
1772 
1774  result_type operator()(int64_t i) const { return derived().visitInteger(i); }
1776  result_type visitInteger(int64_t i) const { return derived().error("integer"); }
1777 
1779  result_type operator()(double i) const { return derived().visitDouble(i); }
1781  result_type visitDouble(double i) const { return derived().error("double"); }
1782 
1784  result_type operator()(bool i) const { return derived().visitBoolean(i); }
1786  result_type visitBoolean(bool i) const { return derived().error("boolean"); }
1787 
1789  result_type operator()(const char *i) const { return derived().visitString(i); }
1791  result_type visitString(const char *i) const { return derived().error("string"); }
1792 
1794  result_type operator()(const decimal_t &i) const { return derived().visitDecimal(i); }
1796  result_type visitDecimal(const decimal_t &i) const { return derived().error("decimal"); }
1797 
1799  result_type operator()(const buffer_t &i) const { return derived().visitBuffer(i); }
1801  result_type visitBuffer(const buffer_t &i) const { return derived().error("buffer"); }
1802 
1804  result_type operator()(const list_t &i) const { return derived().visitList(i); }
1806  result_type visitList(const list_t &i) const { return derived().error("list"); }
1807 
1809  result_type operator()(const map_t &i) const { return derived().visitMap(i); }
1811  result_type visitMap(const map_t &i) const { return derived().error("map"); }
1812 
1814  result_type operator()(const sag_underlying_custom_t &i) const { return derived().visitCustom(i); }
1816  result_type visitCustom(const sag_underlying_custom_t &i) const { return derived().error("custom"); }
1817 
1818 protected:
1821  result_type error(const std::string &reason) const { throw std::runtime_error("Visit type error: "+reason); }
1822 private:
1824  const derived_t &derived() const { return static_cast<const derived_t&>(*this); }
1825 };
1826 
1827 
1828 }}} // com.softwareag.connectivity
1829 
1830 // internal implementation details in here
1831 #include <sag_internal/data.hpp>
1832 
1833 #endif // _CPPMESSAGEDATA_H_
data_t & operator=(list_t &&d)
Assign this to a list_t, freeing the existing contents.
Definition: sag_connectivity_cpp.hpp:294
result_type visitString(const char *&i) const
Visit a string.
Definition: sag_connectivity_cpp.hpp:1699
result_type visitList(list_t &i) const
Visit a list.
Definition: sag_connectivity_cpp.hpp:1714
bool empty() const
Returns true if the map is empty (size() == 0)
Definition: sag_connectivity_cpp.hpp:926
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...
Definition: sag_connectivity_cpp.hpp:1453
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:1227
~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:1709
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:1591
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:1147
result_type operator()(bool &i) const
Visit a boolean (don't override this, instead override visitBoolean)
Definition: sag_connectivity_cpp.hpp:1692
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:1428
result_type operator()(const buffer_t &i) const
Visit a byte buffer (don't override this, instead override visitBuffer)
Definition: sag_connectivity_cpp.hpp:1799
result_type visitMap(const map_t &i) const
Visit a map.
Definition: sag_connectivity_cpp.hpp:1811
const_iterator rend() const
Reverse const_iterator end.
Definition: sag_connectivity_cpp.hpp:651
T convert_to(const data_t &d)
Get a T from a data_t, parsing it from a string if necessary/possible.
Definition: sag_connectivity_cpp.hpp:1190
void clear()
Empty the map and free the underlying data.
iterator begin()
Forward iterator begin.
Definition: sag_connectivity_cpp.hpp:910
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:1372
com::softwareag::connectivity::metadata_t metadata_t
The type of a message metadata.
Definition: sag_connectivity_cpp.hpp:1549
Message copy() const
Return a deep copy of this message, payload and metadata.
Definition: sag_connectivity_cpp.hpp:1606
byte-array (8-bit signed int)
Definition: sag_connectivity_c.h:52
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:1200
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:666
result_type operator()(const list_t &i) const
Visit a list (don't override this, instead override visitList)
Definition: sag_connectivity_cpp.hpp:1804
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:1220
list of data
Definition: sag_connectivity_c.h:48
const T & operator*() const
Return the wrapped pointer as the correct type.
Definition: sag_connectivity_cpp.hpp:416
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:1760
const_iterator begin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:1145
iterator end()
Forward iterator end.
Definition: sag_connectivity_cpp.hpp:1520
iterator begin()
Forward iterator begin.
Definition: sag_connectivity_cpp.hpp:1518
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:672
void clear()
Free the underlying buffer;.
iterator begin()
Forward iterator begin.
Definition: sag_connectivity_cpp.hpp:633
result_type error(const std::string &reason) const
Handles visiting unhandled types.
Definition: sag_connectivity_cpp.hpp:1821
const_iterator begin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:1522
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:1218
A map class which implements many of the functions on std::map.
Definition: sag_connectivity_cpp.hpp:1288
iterator rend()
Reverse iterator end.
Definition: sag_connectivity_cpp.hpp:647
~Message()
Free the underlying payload and metadata.
map_t()
Construct an empty map.
Definition: sag_connectivity_cpp.hpp:836
result_type visitBoolean(bool i) const
Visit a boolean.
Definition: sag_connectivity_cpp.hpp:1786
iterator end()
Forward iterator end.
Definition: sag_connectivity_cpp.hpp:635
result_type operator()(double i) const
Visit a double (don't override this, instead override visitDouble)
Definition: sag_connectivity_cpp.hpp:1779
result_type visitDouble(double &i) const
Visit a double.
Definition: sag_connectivity_cpp.hpp:1689
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:1223
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:1229
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:1247
result_type visitMap(map_t &i) const
Visit a map.
Definition: sag_connectivity_cpp.hpp:1719
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:1209
RV result_type
The return type from applying this visitor.
Definition: sag_connectivity_cpp.hpp:1672
const_iterator rbegin() const
Reverse const_iterator begin.
Definition: sag_connectivity_cpp.hpp:649
STL namespace.
Definition: sag_connectivity_threading.h:178
data_t & operator[](const data_t &k)
Return a reference to the item with the given key.
Definition: sag_connectivity_cpp.hpp:937
const_iterator cend() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:1151
result_type operator()(list_t &i) const
Visit a list (don't override this, instead override visitList)
Definition: sag_connectivity_cpp.hpp:1712
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:349
size_t erase(const char *k)
Remove the item with the specified key.
Definition: sag_connectivity_cpp.hpp:1501
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:1254
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:1252
metadata_t(metadata_t &&other)
Move constructor.
Definition: sag_connectivity_cpp.hpp:1349
const_iterator cbegin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:1149
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:1243
bool operator==(const map_t &other) const
Returns true if this map deep-equals other.
Definition: sag_connectivity_cpp.hpp:891
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:1238
result_type operator()(int64_t &i) const
Visit an integer (don't override this, instead override visitInteger)
Definition: sag_connectivity_cpp.hpp:1682
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 assignment.
Definition: sag_connectivity_cpp.hpp:851
64-bit signed int
Definition: sag_connectivity_c.h:42
~custom_t()
deletes the underlying pointer.
const_iterator end() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:1524
const_iterator cend() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:643
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:607
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:984
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:1806
result_type operator()(buffer_t &i) const
Visit a byte buffer (don't override this, instead override visitBuffer)
Definition: sag_connectivity_cpp.hpp:1707
A list class which implements many of the functions on std::vector.
Definition: sag_connectivity_cpp.hpp:512
result_type operator()() const
Visit an empty variant (don't override this, instead override visitEmpty)
Definition: sag_connectivity_cpp.hpp:1677
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:579
result_type operator()(map_t &i) const
Visit a map (don't override this, instead override visitMap)
Definition: sag_connectivity_cpp.hpp:1717
result_type visitString(const char *i) const
Visit a string.
Definition: sag_connectivity_cpp.hpp:1791
metadata_t(size_t n)
Construct a map with (at least) capacity for n items.
Definition: sag_connectivity_cpp.hpp:1347
void swap(buffer_t &&other)
Swap the contents of this buffer and other.
Definition: sag_connectivity_cpp.hpp:1106
const_iterator cbegin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:918
const_iterator cbegin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:641
data_t()
Construct an empty data_t.
Definition: sag_connectivity_cpp.hpp:77
64-bit IEEE-754 decimal
Definition: sag_connectivity_c.h:44
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:1576
const_iterator cend() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:920
const uint8_t & operator[](size_t n) const
Return a reference the byte at the given offset.
Definition: sag_connectivity_cpp.hpp:1167
result_type visitDecimal(decimal_t &i) const
Visit a decimal.
Definition: sag_connectivity_cpp.hpp:1704
const_iterator begin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:914
result_type error(const std::string &reason) const
Handles visiting unhandled types.
Definition: sag_connectivity_cpp.hpp:1729
map of data:data
Definition: sag_connectivity_c.h:50
const char * operator[](const std::string &k)
Returns the item with the given key.
Definition: sag_connectivity_cpp.hpp:1406
list_t(list_t &&other)
Move construction.
Definition: sag_connectivity_cpp.hpp:596
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:1234
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:1434
const_iterator end() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:916
void swap(map_t &&other)
Swap the contents of this map and other.
Definition: sag_connectivity_cpp.hpp:868
const char *const operator[](const char *k) const
Returns the item with the given key.
Definition: sag_connectivity_cpp.hpp:1394
void erase(iterator it)
Erase the item pointed to by this iterator.
Definition: sag_connectivity_cpp.hpp:1509
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:1232
pair< const data_t > const_element
The type of an element in a const map.
Definition: sag_connectivity_cpp.hpp:833
const char *const operator[](const std::string &k) const
Returns the item with the given key.
Definition: sag_connectivity_cpp.hpp:1417
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:669
result_type visitCustom(sag_underlying_custom_t &i) const
Visit a custom object.
Definition: sag_connectivity_cpp.hpp:1724
result_type visitCustom(const sag_underlying_custom_t &i) const
Visit a custom object.
Definition: sag_connectivity_cpp.hpp:1816
const T * operator->() const
Return the wrapped pointer as the correct type.
Definition: sag_connectivity_cpp.hpp:420
~buffer_t()
Free the underlying buffer contents.
Definition: sag_connectivity_cpp.hpp:1083
const data_t & operator[](const data_t &k) const
Return a reference to the item with the given key.
Definition: sag_connectivity_cpp.hpp:943
bool operator!=(const list_t &other) const
Returns false if this list is deep equals to other list.
Definition: sag_connectivity_cpp.hpp:627
void reserve(size_t n)
Ensure the capacity is (at least) n.
Definition: sag_connectivity_cpp.hpp:678
list_t()
Construct an empty list.
Definition: sag_connectivity_cpp.hpp:571
_iterator< const data_t, const sag_underlying_data_t * > const_iterator
The type of iterators over a const list.
Definition: sag_connectivity_cpp.hpp:568
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:1484
RV result_type
The return type from applying this visitor.
Definition: sag_connectivity_cpp.hpp:1764
map_t(map_t &&other)
Move constructor.
Definition: sag_connectivity_cpp.hpp:861
data_t & operator=(const std::string &s)
Assign this to a string, freeing the existing contents (copies the string).
Definition: sag_connectivity_cpp.hpp:279
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:1256
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:1214
Message & putMetadataValue(const std::string &key, const std::string &value)
Sets a value in the metadata.
Definition: sag_connectivity_cpp.hpp:1635
T * operator->()
Return the wrapped pointer as the correct type.
Definition: sag_connectivity_cpp.hpp:418
iterator end()
Forward iterator end.
Definition: sag_connectivity_cpp.hpp:1143
result_type operator()(const char *i) const
Visit a string (don't override this, instead override visitString)
Definition: sag_connectivity_cpp.hpp:1789
uint8_t & operator[](size_t n)
Return a reference to the byte at the given offset.
Definition: sag_connectivity_cpp.hpp:1160
result_type operator()(const decimal_t &i) const
Visit a decimal (don't override this, instead override visitDecimal)
Definition: sag_connectivity_cpp.hpp:1794
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:1440
bool empty() const
Returns true if the buffer is unallocated (size() == 0)
Definition: sag_connectivity_cpp.hpp:1156
size_t size() const
Return the number of items in this list.
Definition: sag_connectivity_cpp.hpp:654
const_iterator end() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:639
payload_t & getPayload()
Return a reference to the payload.
Definition: sag_connectivity_cpp.hpp:1589
result_type visitDecimal(const decimal_t &i) const
Visit a decimal.
Definition: sag_connectivity_cpp.hpp:1796
A map class which implements many of the functions on std::map.
Definition: sag_connectivity_cpp.hpp:723
get_details::GetVisitor< custom_t< T > >::result_type get_custom(data_t &t)
Get the contents of the data_t as a typed custom_t.
Definition: sag_connectivity_cpp.hpp:485
size_t size() const
Returns the number of key/value pairs in the map.
Definition: sag_connectivity_cpp.hpp:923
result_type visitBuffer(const buffer_t &i) const
Visit a byte buffer.
Definition: sag_connectivity_cpp.hpp:1801
data_t & operator[](data_t &&k)
Return a reference to the item with the given key.
Definition: sag_connectivity_cpp.hpp:930
A container for an payload and associated metadata.
Definition: sag_connectivity_cpp.hpp:1545
const_iterator cend() const
Forward const_iterator end.
Definition: sag_connectivity_cpp.hpp:1528
data_t & operator=(const char *s)
Assign this to a string, freeing the existing contents (copies the string).
Definition: sag_connectivity_cpp.hpp:269
result_type operator()() const
Visit an empty variant (don't override this, instead override visitEmpty)
Definition: sag_connectivity_cpp.hpp:1769
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:1225
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:1471
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:1070
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:1809
~map_t()
Free the underlying map contents.
Definition: sag_connectivity_cpp.hpp:844
result_type visitEmpty() const
Visit an empty variant.
Definition: sag_connectivity_cpp.hpp:1771
result_type visitEmpty() const
Visit an empty variant.
Definition: sag_connectivity_cpp.hpp:1679
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:1205
_iterator< data_t, sag_underlying_data_t * > iterator
The type of iterators over a mutable list.
Definition: sag_connectivity_cpp.hpp:566
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:1216
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:1211
data_t & operator=(buffer_t &&d)
Assign this to a buffer_t, freeing the existing contents.
Definition: sag_connectivity_cpp.hpp:324
_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:829
data_t & operator=(map_t &&d)
Assign this to a map_t, freeing the existing contents.
Definition: sag_connectivity_cpp.hpp:309
bool operator!=(const buffer_t &other) const
Returns true if both buffers are different sizes or have different contents.
Definition: sag_connectivity_cpp.hpp:1132
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:1617
Decimals are implemented with an underlying 64bit int conforming to IEEE 754 decimal 64...
Definition: sag_connectivity_c.h:95
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:1375
const_iterator cbegin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:1526
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:1352
list_t & operator=(list_t &&other)
Move assignment operator.
Definition: sag_connectivity_cpp.hpp:586
const_iterator find(const data_t &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:1459
_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:827
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:675
map_t copy() const
Return a deep copy of this map.
Definition: sag_connectivity_cpp.hpp:874
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:1241
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:1814
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:1687
result_type operator()(const char *&i) const
Visit a string (don't override this, instead override visitString)
Definition: sag_connectivity_cpp.hpp:1697
Helper class for writing visitors to apply to data_t.
Definition: sag_connectivity_cpp.hpp:1668
result_type visitBoolean(bool &i) const
Visit a boolean.
Definition: sag_connectivity_cpp.hpp:1694
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:1766
a void* + deleter and copy function pointers
Definition: sag_connectivity_c.h:54
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:38
buffer_t(buffer_t &&other)
Move constructor.
Definition: sag_connectivity_cpp.hpp:1100
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:1612
utf8-encoded const char*
Definition: sag_connectivity_c.h:46
const_iterator begin() const
Forward const_iterator begin.
Definition: sag_connectivity_cpp.hpp:637
result_type visitInteger(int64_t &i) const
Visit an integer.
Definition: sag_connectivity_cpp.hpp:1684
bool operator!=(const map_t &other) const
Returns false if this map deep-equals other.
Definition: sag_connectivity_cpp.hpp:903
bool operator==(const metadata_t &other) const
Returns true if this map deep-equals other.
Definition: sag_connectivity_cpp.hpp:1367
iterator end()
Forward iterator end.
Definition: sag_connectivity_cpp.hpp:912
bool empty() const
Returns true if there are no items in this list.
Definition: sag_connectivity_cpp.hpp:656
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:1446
data_t payload_t
The type of a message payload.
Definition: sag_connectivity_cpp.hpp:1551
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:602
Forward/reverse and const/non-const iterators are implemented using this class.
Definition: sag_connectivity_cpp.hpp:527
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:1774
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:1722
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:831
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:1236
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:1250
result_type operator()(bool i) const
Visit a boolean (don't override this, instead override visitBoolean)
Definition: sag_connectivity_cpp.hpp:1784
custom_t()
Create an empty custom_t.
bool operator==(const buffer_t &other) const
Returns true if both buffers are the same size and have the same contents.
Definition: sag_connectivity_cpp.hpp:1125
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:1383
result_type visitInteger(int64_t i) const
Visit an integer.
Definition: sag_connectivity_cpp.hpp:1776
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:1245
DERIVED derived_t
The type of the derived class.
Definition: sag_connectivity_cpp.hpp:1674
64-bit float
Definition: sag_connectivity_c.h:40
buffer_t & operator=(buffer_t &&other)
Move assignment.
Definition: sag_connectivity_cpp.hpp:1090
Empty.
Definition: sag_connectivity_c.h:36
size_t erase(const std::string &k)
Remove the item with the specified key.
Definition: sag_connectivity_cpp.hpp:1493
T & operator*()
Return the wrapped pointer as the correct type.
Definition: sag_connectivity_cpp.hpp:414
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:1207
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:1300
Contains the C ABI for connectivity plugins.
metadata_t()
Construct an empty map.
Definition: sag_connectivity_cpp.hpp:1345
result_type visitDouble(double i) const
Visit a double.
Definition: sag_connectivity_cpp.hpp:1781
size_t size() const
Returns the size of the buffer.
Definition: sag_connectivity_cpp.hpp:1154
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:645
Forward/reverse and const/non-const iterators are implemented using this class.
Definition: sag_connectivity_cpp.hpp:749
buffer_t()
Construct an empty buffer.
Definition: sag_connectivity_cpp.hpp:1075
result_type operator()(decimal_t &i) const
Visit a decimal (don't override this, instead override visitDecimal)
Definition: sag_connectivity_cpp.hpp:1702
iterator begin()
Forward iterator begin.
Definition: sag_connectivity_cpp.hpp:1141