Apama  10.0.0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
custom_t.hpp
Go to the documentation of this file.
1 /*
2  * Title: bits/custom_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: custom_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 
19 
41 template<typename T>
42 class custom_t: public sag_underlying_custom_t
43 {
44  typedef custom_t this_t;
45 public:
47  custom_t();
49  custom_t(T *payload);
51  ~custom_t();
53  T *get() const { return this->data ? reinterpret_cast<T*>(this->data->custom) : 0; }
55  custom_t(custom_t &&other);
57  custom_t &operator=(custom_t &&other);
59  void swap(custom_t &&other);
61  custom_t copy() const;
63  T &operator*() const { return *get(); }
65  T *operator->() const { return get(); }
66 private:
68  static void deleter(void *d)
69  {
70  if (d) {
71  try {
72  delete reinterpret_cast<T*>(d);
73  } catch (...) {
74  // enforce nothrow behaviour
75  abort();
76  }
77  }
78  }
80  static void *copier(void *d)
81  {
82  try {
83  return d ? new T(*reinterpret_cast<T*>(d)) : 0;
84  } catch (...) {
85  // enforce nothrow behaviour
86  abort();
87  }
88  }
90  custom_t(const custom_t &other) { abort(); }
92  custom_t &operator=(const custom_t &other) { abort(); return *this; }
93 };
94 
T & operator*() const
Return the wrapped pointer as the correct type.
Definition: custom_t.hpp:63
void swap(custom_t &&other)
Swap with another custom_t of the same type.
A wrapper type for holding arbitrary objects inside a data_t.
Definition: custom_t.hpp:42
~custom_t()
deletes the underlying pointer.
custom_t copy() const
Return a copy of the underlying pointer.
custom_t()
Create an empty custom_t.
T * operator->() const
Return the wrapped pointer as the correct type.
Definition: custom_t.hpp:65
custom_t & operator=(custom_t &&other)
Move assignment, destroying the current contents.