summaryrefslogtreecommitdiff
path: root/cpp/zone.hpp.erb
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/zone.hpp.erb')
-rw-r--r--cpp/zone.hpp.erb13
1 files changed, 13 insertions, 0 deletions
diff --git a/cpp/zone.hpp.erb b/cpp/zone.hpp.erb
index 8fd14a6..f1e4624 100644
--- a/cpp/zone.hpp.erb
+++ b/cpp/zone.hpp.erb
@@ -21,6 +21,7 @@
#include "msgpack/object.hpp"
#include "msgpack/zone.h"
#include <cstdlib>
+#include <memory>
#include <vector>
<% GENERATION_LIMIT = 15 %>
@@ -38,6 +39,9 @@ public:
void push_finalizer(void (*func)(void*), void* data);
+ template <typename T>
+ void push_finalizer(std::auto_ptr<T> obj);
+
void clear();
<%0.upto(GENERATION_LIMIT) {|i|%>
@@ -94,6 +98,15 @@ inline void zone::push_finalizer(void (*func)(void*), void* data)
}
}
+template <typename T>
+inline void zone::push_finalizer(std::auto_ptr<T> obj)
+{
+ if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, obj.get())) {
+ throw std::bad_alloc();
+ }
+ obj.release();
+}
+
inline void zone::clear()
{
msgpack_zone_clear(this);