summaryrefslogtreecommitdiff
path: root/bindings/cpp/upb/upb.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/cpp/upb/upb.hpp')
-rw-r--r--bindings/cpp/upb/upb.hpp44
1 files changed, 39 insertions, 5 deletions
diff --git a/bindings/cpp/upb/upb.hpp b/bindings/cpp/upb/upb.hpp
index 226859c..48c2708 100644
--- a/bindings/cpp/upb/upb.hpp
+++ b/bindings/cpp/upb/upb.hpp
@@ -10,6 +10,16 @@
#include "upb/upb.h"
#include <iostream>
+#if defined(__GXX_EXPERIMENTAL_CXX0X__) && !defined(UPB_NO_CXX11)
+#define UPB_DISALLOW_CONSTRUCT_AND_DESTRUCT(class_name) \
+ class_name() = delete; \
+ ~class_name() = delete;
+#else
+#define UPB_DISALLOW_CONSTRUCT_AND_DESTRUCT(class_name) \
+ class_name(); \
+ ~class_name();
+#endif
+
namespace upb {
typedef upb_success_t Success;
@@ -31,11 +41,35 @@ class Status : public upb_status {
void Clear() { upb_status_clear(this); }
};
-class Value : public upb_value {
- public:
- Value(const upb_value& val) { *this = val; }
- Value() {}
-};
+typedef upb_value Value;
+
+template <typename T> T GetValue(Value v);
+template <typename T> Value MakeValue(T v);
+
+#define UPB_VALUE_ACCESSORS(type, ctype) \
+ template <> inline ctype GetValue<ctype>(Value v) { \
+ return upb_value_get ## type(v); \
+ } \
+ template <> inline Value MakeValue<ctype>(ctype v) { \
+ return upb_value_ ## type(v); \
+ }
+
+UPB_VALUE_ACCESSORS(double, double);
+UPB_VALUE_ACCESSORS(float, float);
+UPB_VALUE_ACCESSORS(int32, int32_t);
+UPB_VALUE_ACCESSORS(int64, int64_t);
+UPB_VALUE_ACCESSORS(uint32, uint32_t);
+UPB_VALUE_ACCESSORS(uint64, uint64_t);
+UPB_VALUE_ACCESSORS(bool, bool);
+
+#undef UPB_VALUE_ACCESSORS
+
+template <typename T> inline T* GetPtrValue(Value v) {
+ return static_cast<T*>(upb_value_getptr(v));
+}
+template <typename T> inline Value MakePtrValue(T* v) {
+ return upb_value_ptr(static_cast<void*>(v));
+}
INLINE std::ostream& operator<<(std::ostream& out, const Status& status) {
out << status.GetString();
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback