cpp: zone: adds msgpack_zone_swap and msgpack::zone::swap

This commit is contained in:
frsyuki 2010-09-26 11:37:37 +09:00
parent e8abcc1765
commit 7974060a40
2 changed files with 18 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/* /*
* MessagePack for C memory pool implementation * MessagePack for C memory pool implementation
* *
* Copyright (C) 2008-2009 FURUHASHI Sadayuki * Copyright (C) 2008-2010 FURUHASHI Sadayuki
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -73,6 +73,8 @@ static inline void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size
static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone, static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone,
void (*func)(void* data), void* data); void (*func)(void* data), void* data);
static inline void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b);
bool msgpack_zone_is_empty(msgpack_zone* zone); bool msgpack_zone_is_empty(msgpack_zone* zone);
void msgpack_zone_clear(msgpack_zone* zone); void msgpack_zone_clear(msgpack_zone* zone);
@ -129,6 +131,13 @@ bool msgpack_zone_push_finalizer(msgpack_zone* zone,
return true; return true;
} }
void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b)
{
msgpack_zone tmp = *a;
*a = *b;
*b = tmp;
}
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,7 +1,7 @@
// //
// MessagePack for C++ memory pool // MessagePack for C++ memory pool
// //
// Copyright (C) 2008-2009 FURUHASHI Sadayuki // Copyright (C) 2008-2010 FURUHASHI Sadayuki
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -43,6 +43,8 @@ public:
void clear(); void clear();
void swap(zone& o);
<%0.upto(GENERATION_LIMIT) {|i|%> <%0.upto(GENERATION_LIMIT) {|i|%>
template <typename T<%1.upto(i) {|j|%>, typename A<%=j%><%}%>> template <typename T<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
T* allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>); T* allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>);
@ -111,6 +113,11 @@ inline void zone::clear()
msgpack_zone_clear(this); msgpack_zone_clear(this);
} }
inline void zone::swap(zone& o)
{
msgpack_zone_swap(this, &o);
}
template <typename T> template <typename T>
void zone::object_destructor(void* obj) void zone::object_destructor(void* obj)
{ {