Apama  10.1.0.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
data_t.hpp
Go to the documentation of this file.
1 /*
2  * Title: bits/data_t.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: data_t.hpp 294926 2016-11-09 18:33:24Z matj $
7  */
8 
15 #ifndef _DATAT_BITS_INCLUDE_TAG
16 #error Must only be included from sag_connectivity_cpp.hpp, use that instead
17 #endif
18 
42 class data_t: protected sag_underlying_data_t
43 {
44  friend class map_t;
45  friend class list_t;
46  friend class Message;
47 public:
48 
51  {
52  memset(this, 0, sizeof(sag_underlying_data_t));
53  tag = SAG_DATA_EMPTY;
54  }
57  data_t(data_t &&other)
58  {
59  memset(this, 0, sizeof(sag_underlying_data_t));
60  tag = SAG_DATA_EMPTY;
61  swap(std::move(other));
62  }
63 
65  void swap(data_t &&other);
66 
70  {
71  data_t tmp(std::move(other));
72  swap(std::move(tmp));
73  return *this;
74  }
75 
77  ~data_t();
78 
80  bool empty() const { return tag == SAG_DATA_EMPTY; }
81 
83  data_t copy() const;
84 
86  bool operator==(const data_t &other) const;
88  bool operator!=(const data_t &other) const { return !operator==(other); }
89 
106  template<typename V>
107  typename V::result_type apply_visitor(const V &v) const;
124  template<typename V>
125  typename V::result_type apply_visitor(const V &v);
126 
131  const char *type_name() const
132  {
133  switch (tag) {
134  case SAG_DATA_EMPTY: return "empty";
135  case SAG_DATA_BOOLEAN: return "boolean";
136  case SAG_DATA_DOUBLE: return "double";
137  case SAG_DATA_INTEGER: return "integer";
138  case SAG_DATA_DECIMAL: return "decimal";
139  case SAG_DATA_STRING: return "string";
140  case SAG_DATA_LIST: return "list";
141  case SAG_DATA_MAP: return "map";
142  case SAG_DATA_BUFFER: return "buffer";
143  case SAG_DATA_CUSTOM: return "custom";
144  default:
145  assert(false); // shouldn't happen
146  return "Unknown";
147  }
148  }
149 
152  sag_data_tag type_tag() const { return tag; }
153 
154 private:
156  data_t(const data_t &other) { abort(); }
158  data_t &operator=(const data_t &other) { abort(); }
159 public:
160 
162  explicit data_t(int64_t d)
163  {
164  tag = SAG_DATA_INTEGER;
165  integer = d;
166  }
168  data_t &operator=(int64_t d)
169  {
170  data_t tmp(d);
171  swap(std::move(tmp));
172  return *this;
173  }
175  explicit data_t(bool b)
176  {
177  tag = SAG_DATA_BOOLEAN;
178  boolean = b;
179  }
181  data_t &operator=(bool b)
182  {
183  data_t tmp(b);
184  swap(std::move(tmp));
185  return *this;
186  }
188  explicit data_t(double d)
189  {
190  tag = SAG_DATA_DOUBLE;
191  fp = d;
192  }
194  data_t &operator=(double d)
195  {
196  data_t tmp(d);
197  swap(std::move(tmp));
198  return *this;
199  }
204  template<typename T>
205  explicit data_t(custom_t<T> &&d);
206 
211  template<typename T>
213  {
214  data_t tmp(std::move(d));
215  swap(std::move(tmp));
216  return *this;
217  }
219  explicit data_t(decimal_t d)
220  {
221  tag = SAG_DATA_DECIMAL;
222  decimal = d;
223  }
226  {
227  data_t tmp(d);
228  swap(std::move(tmp));
229  return *this;
230  }
234  explicit data_t(const char *s, size_t n);
237  explicit data_t(const char *s);
240  explicit data_t(const std::string &s);
244  data_t &operator=(const char *s)
245  {
246  data_t tmp(s);
247  swap(std::move(tmp));
248  return *this;
249  }
250 
254  data_t &operator=(const std::string &s)
255  {
256  data_t tmp(s);
257  swap(std::move(tmp));
258  return *this;
259  }
264  explicit data_t(list_t &&d);
270  {
271  data_t tmp(std::move(d));
272  swap(std::move(tmp));
273  return *this;
274  }
279  explicit data_t(map_t &&d);
285  {
286  data_t tmp(std::move(d));
287  swap(std::move(tmp));
288  return *this;
289  }
294  explicit data_t(buffer_t &&d);
300  {
301  data_t tmp(std::move(d));
302  swap(std::move(tmp));
303  return *this;
304  }
305 };
306 
307 
data_t & operator=(int64_t d)
Assign an int64_t to this, freeing the existing contents of this.
Definition: data_t.hpp:168
sag_data_tag
A descriminator for the content of the data_t union.
Definition: sag_connectivity_c.h:33
byte-array (8-bit signed int)
Definition: sag_connectivity_c.h:52
list of data
Definition: sag_connectivity_c.h:48
A list class which implements many of the functions on std::vector.
Definition: list_t.hpp:34
A container for an payload and associated metadata.
Definition: message.hpp:27
A map class which implements many of the functions on std::map.
Definition: map_t.hpp:36
data_t(bool b)
Create a data_t from a bool.
Definition: data_t.hpp:175
const char * type_name() const
Return the name of the contained type as a string (mainly useful for debugging)
Definition: data_t.hpp:131
data_t(data_t &&other)
Construct a data_t, move the contents from another data_t.
Definition: data_t.hpp:57
data_t & operator=(buffer_t &&d)
Assign this to a buffer_t, freeing the existing contents.
Definition: data_t.hpp:299
data_t(decimal_t d)
Create a data_t from a decimal.
Definition: data_t.hpp:219
sag_underlying_decimal_t decimal_t
Decimals are implemented with an underlying 64bit int conforming to IEEE 754 decimal 64...
Definition: sag_connectivity_cpp.hpp:49
bool operator==(const data_t &other) const
Returns true if two data_ts are deep-equals.
64-bit signed int
Definition: sag_connectivity_c.h:42
data_t & operator=(const std::string &s)
Assign this to a string, freeing the existing contents (copies the string).
Definition: data_t.hpp:254
64-bit IEEE-754 decimal
Definition: sag_connectivity_c.h:44
map of data:data
Definition: sag_connectivity_c.h:50
V::result_type apply_visitor(const V &v) const
Apply a visitor (using the boost::static_visitor pattern) to this data_t.
A wrapper type for holding arbitrary objects inside a data_t.
Definition: custom_t.hpp:42
data_t & operator=(decimal_t d)
Assign this to a decimal, freeing the existing contents.
Definition: data_t.hpp:225
data_t & operator=(map_t &&d)
Assign this to a map_t, freeing the existing contents.
Definition: data_t.hpp:284
data_t()
Construct an empty data_t.
Definition: data_t.hpp:50
A class that holds an untyped byte buffer.
Definition: buffer_t.hpp:27
bool empty() const
Returns true if this is the empty data_t.
Definition: data_t.hpp:80
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.
data_t(double d)
Create a data_t from a double.
Definition: data_t.hpp:188
data_t & operator=(const char *s)
Assign this to a string, freeing the existing contents (copies the string).
Definition: data_t.hpp:244
bool operator!=(const data_t &other) const
Returns true if two data_ts are non-equal (deep equality)
Definition: data_t.hpp:88
data_t & operator=(data_t &&other)
Move-assignment from another data_t.
Definition: data_t.hpp:69
data_t & operator=(list_t &&d)
Assign this to a list_t, freeing the existing contents.
Definition: data_t.hpp:269
a void* + deleter and copy function pointers
Definition: sag_connectivity_c.h:54
Bool.
Definition: sag_connectivity_c.h:38
utf8-encoded const char*
Definition: sag_connectivity_c.h:46
A variant type which can be one of the following:
Definition: data_t.hpp:42
data_t(int64_t d)
Create a data_t from an int64_t.
Definition: data_t.hpp:162
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: data_t.hpp:212
data_t & operator=(bool b)
Assign a bool to this, freeing the existing contents of this.
Definition: data_t.hpp:181
64-bit float
Definition: sag_connectivity_c.h:40
Empty.
Definition: sag_connectivity_c.h:36
data_t & operator=(double d)
Assign a double to this, freeing the existing contents of this.
Definition: data_t.hpp:194
~data_t()
For non-primitives free the underlying memory.
sag_data_tag type_tag() const
Return the descriminator for this union (as an enum of the possible values)
Definition: data_t.hpp:152