summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/bench.cpp6
-rw-r--r--cpp/object.cpp19
-rw-r--r--cpp/object.hpp61
-rw-r--r--cpp/pack.hpp4
-rw-r--r--cpp/test.cpp6
-rw-r--r--cpp/unpack.cpp6
-rw-r--r--cpp/unpack.hpp4
-rw-r--r--cpp/unpack_inline.cpp4
-rw-r--r--cpp/zone.hpp.erb28
9 files changed, 77 insertions, 61 deletions
diff --git a/cpp/bench.cpp b/cpp/bench.cpp
index 649c0cc..4133a2e 100644
--- a/cpp/bench.cpp
+++ b/cpp/bench.cpp
@@ -10,7 +10,7 @@ static const unsigned int TASK_INT_NUM = 1<<24;
static const unsigned int TASK_STR_LEN = 1<<15;
//static const unsigned int TASK_INT_NUM = 1<<23;
//static const unsigned int TASK_STR_LEN = 1<<14;
-static const void* TASK_STR_PTR;
+static const char* TASK_STR_PTR;
class simple_timer {
@@ -49,7 +49,7 @@ public:
}
public:
- inline void write(const void* buf, size_t len)
+ inline void write(const char* buf, size_t len)
{
if(m_allocated - m_used < len) {
expand_buffer(len);
@@ -168,7 +168,7 @@ void bench_msgpack_str()
int main(void)
{
- void* str = malloc(TASK_STR_LEN);
+ char* str = (char*)malloc(TASK_STR_LEN);
memset(str, 'a', TASK_STR_LEN);
TASK_STR_PTR = str;
diff --git a/cpp/object.cpp b/cpp/object.cpp
index d6815ac..4068007 100644
--- a/cpp/object.cpp
+++ b/cpp/object.cpp
@@ -320,29 +320,30 @@ FLOAT_OBJECT(double)
EXTRA \
bool object_##NAME::operator== (const object_class* x) const \
try { \
- const_raw xr(x->xraw()); \
+ raw xr(x->xraw()); \
return len == xr.len && (ptr == xr.ptr || memcmp(ptr, xr.ptr, len) == 0); \
} catch (type_error&) { return false; } \
bool object_##NAME::operator< (const object_class* x) const { \
- const_raw xr(x->xraw()); \
+ raw xr(x->xraw()); \
if(len == xr.len) { return ptr != xr.ptr && memcmp(ptr, xr.ptr, len) < 0; } \
else { return len < xr.len; } } \
bool object_##NAME::operator> (const object_class* x) const { \
- const_raw xr(x->xraw()); \
+ raw xr(x->xraw()); \
if(len == xr.len) { return ptr != xr.ptr && memcmp(ptr, xr.ptr, len) > 0; } \
else { return len > xr.len; } } \
void object_##NAME::pack(dynamic_packer& p) const \
{ p.pack_raw(ptr, len); } \
const object_class* object_##NAME::inspect(std::ostream& s) const \
- { (s << '"').write((const char*)ptr, len) << '"'; return this; } // FIXME escape
+ { (s << '"').write(ptr, len) << '"'; return this; } // FIXME escape
-RAW_OBJECT(raw_ref,
- raw object_raw_ref::xraw() { return raw(ptr, len); }
- const_raw object_raw_ref::xraw() const { return const_raw(ptr, len); } )
+// FIXME
+RAW_OBJECT(mutable_raw_ref,
+ /*mutable_raw object_mutable_raw_ref::xraw() { return mutable_raw(ptr, len); }*/
+ raw object_mutable_raw_ref::xraw() const { return raw(ptr, len); } )
-RAW_OBJECT(const_raw_ref,
- const_raw object_const_raw_ref::xraw() const { return const_raw(ptr, len); } )
+RAW_OBJECT(raw_ref,
+ raw object_raw_ref::xraw() const { return raw(ptr, len); } )
#undef RAW_OBJECT(NAME, EXTRA)
diff --git a/cpp/object.hpp b/cpp/object.hpp
index 959d84e..9f91677 100644
--- a/cpp/object.hpp
+++ b/cpp/object.hpp
@@ -37,25 +37,25 @@ class positive_overflow_error : public overflow_error { };
class negative_overflow_error : public overflow_error { };
-struct raw {
- explicit raw() : ptr(NULL), len(0) {}
- explicit raw(void* p, size_t l) : ptr(p), len(l) {}
+struct mutable_raw {
+ explicit mutable_raw() : ptr(NULL), len(0) {}
+ explicit mutable_raw(char* p, size_t l) : ptr(p), len(l) {}
public:
- void* ptr;
+ char* ptr;
size_t len;
public:
- std::string str() { return std::string((const char*)ptr, len); }
+ std::string str() { return std::string(ptr, len); }
};
-struct const_raw {
- explicit const_raw() : ptr(NULL), len(0) {}
- explicit const_raw(const void* p, size_t l) : ptr(p), len(l) {}
- const_raw(const raw& m) : ptr(m.ptr), len(m.len) {}
+struct raw {
+ explicit raw() : ptr(NULL), len(0) {}
+ explicit raw(const char* p, size_t l) : ptr(p), len(l) {}
+ raw(const mutable_raw& m) : ptr(m.ptr), len(m.len) {}
public:
- const void* ptr;
+ const char* ptr;
size_t len;
public:
- std::string str() { return std::string((const char*)ptr, len); }
+ std::string str() { return std::string(ptr, len); }
};
@@ -81,10 +81,10 @@ struct object_class {
virtual int64_t xi64 () const { throw cast_error(); }
virtual float xfloat () const { throw cast_error(); }
virtual double xdouble() const { throw cast_error(); }
- virtual raw xraw () { throw cast_error(); }
- virtual array& xarray () { throw cast_error(); }
- virtual map& xmap () { throw cast_error(); }
- virtual const_raw xraw () const { throw cast_error(); }
+ //virtual mutable_raw xraw () { throw cast_error(); } // FIXME
+ virtual array& xarray() { throw cast_error(); }
+ virtual map& xmap () { throw cast_error(); }
+ virtual raw xraw () const { throw cast_error(); }
virtual const array& xarray() const { throw cast_error(); }
virtual const map& xmap () const { throw cast_error(); }
virtual bool operator== (const object_class* x) const { return false; }
@@ -103,10 +103,10 @@ struct object_class {
operator int64_t() const { return xi64(); }
operator float() const { return xfloat(); }
operator double() const { return xdouble(); }
- operator raw() { return xraw(); }
- operator array&() { return xarray(); }
- operator map&() { return xmap(); }
- operator const_raw() const { return xraw(); }
+ //operator mutable_raw() { return xraw(); } // FIXME
+ operator array&() { return xarray(); }
+ operator map&() { return xmap(); }
+ operator raw() const { return xraw(); }
operator const array&() const { return xarray(); }
operator const map&() const { return xmap(); }
virtual const object_class* inspect(std::ostream& s) const
@@ -138,10 +138,10 @@ struct object {
int64_t xi64 () const { return val->xi64(); }
float xfloat () const { return val->xfloat(); }
double xdouble() const { return val->xdouble(); }
- raw xraw () { return val->xraw(); }
- array& xarray () { return val->xarray(); }
- map& xmap () { return val->xmap(); }
- const_raw xraw () const { return const_cast<const object_class*>(val)->xraw(); }
+ //mutable_raw xraw () { return val->xraw(); } // FIXME
+ array& xarray() { return val->xarray(); }
+ map& xmap () { return val->xmap(); }
+ raw xraw () const { return const_cast<const object_class*>(val)->xraw(); }
const array& xarray() const { return const_cast<const object_class*>(val)->xarray(); }
const map& xmap () const { return const_cast<const object_class*>(val)->xmap(); }
bool operator== (object x) const { return val->operator== (x.val); }
@@ -149,6 +149,8 @@ struct object {
bool operator< (object x) const { return val->operator< (x.val); }
bool operator> (object x) const { return val->operator> (x.val); }
void pack(dynamic_packer& p) const { val->pack(p); }
+ template <typename Stream>
+ void pack(Stream& s) const { dynamic_packer p(s); pack(p); }
operator bool() const { return val->operator bool(); }
operator uint8_t() const { return val->operator uint8_t(); }
operator uint16_t() const { return val->operator uint16_t(); }
@@ -160,10 +162,10 @@ struct object {
operator int64_t() const { return val->operator int64_t(); }
operator float() const { return val->operator float(); }
operator double() const { return val->operator double(); }
- operator raw() { return val->operator raw(); }
- operator array&() { return val->operator array&(); }
- operator map&() { return val->operator map&(); }
- operator const_raw() const { return val->operator const_raw(); }
+ //operator mutable_raw() { return val->operator mutable_raw(); } // FIXME
+ operator array&() { return val->operator array&(); }
+ operator map&() { return val->operator map&(); }
+ operator raw() const { return val->operator raw(); }
operator const array&() const { return val->operator const array&(); }
operator const map&() const { return val->operator const map&(); }
const object& inspect(std::ostream& s) const
@@ -275,8 +277,9 @@ private: \
uint32_t len; \
};
-RAW_CLASS(raw_ref, void*, raw xraw(); const_raw xraw() const; )
-RAW_CLASS(const_raw_ref, const void*, const_raw xraw() const; )
+// FIXME
+RAW_CLASS(mutable_raw_ref, char*, /*mutable_raw xraw();*/ raw xraw() const; )
+RAW_CLASS(raw_ref, const char*, raw xraw() const; )
#undef RAW_CLASS(NAME, TYPE, EXTRA)
diff --git a/cpp/pack.hpp b/cpp/pack.hpp
index 94b5b9a..9580679 100644
--- a/cpp/pack.hpp
+++ b/cpp/pack.hpp
@@ -50,7 +50,7 @@ public:
void pack_array(unsigned int n) { pack_array_impl(m_stream, n); }
void pack_map(unsigned int n) { pack_map_impl(m_stream, n); }
void pack_string(const char* b) { pack_string_impl(m_stream, b); }
- void pack_raw(const void* b, size_t l) { pack_raw_impl(m_stream, b, l); }
+ void pack_raw(const char* b, size_t l) { pack_raw_impl(m_stream, (const void*)b, l); }
private:
static void pack_int_impl(Stream& x, int d);
@@ -134,7 +134,7 @@ public:
void pack_array(unsigned int n) { pack_array_impl(m_stream, n); }
void pack_map(unsigned int n) { pack_map_impl(m_stream, n); }
void pack_string(const char* b) { pack_string_impl(m_stream, b); }
- void pack_raw(const void* b, size_t l) { pack_raw_impl(m_stream, b, l); }
+ void pack_raw(const char* b, size_t l) { pack_raw_impl(m_stream, (const void*)b, l); }
private:
static void pack_int_impl(dynamic_stream& x, int d);
diff --git a/cpp/test.cpp b/cpp/test.cpp
index b63f9a1..68050a3 100644
--- a/cpp/test.cpp
+++ b/cpp/test.cpp
@@ -4,7 +4,7 @@
//#include <msgpack/pack.hpp>
#include <msgpack.hpp>
#include <sstream>
-#include <boost/scoped_ptr.hpp>
+#include <memory>
class checker {
public:
@@ -176,7 +176,7 @@ int main(void)
// 2. read data to buffer() up to buffer_capacity() bytes
size_t sz = stream.readsome(
- (char*)upk.buffer(),
+ upk.buffer(),
upk.buffer_capacity());
total_bytes -= sz;
@@ -195,7 +195,7 @@ int main(void)
msgpack::object o = upk.data();
// 5.2. the parsed object is valid until the zone is deleted
- boost::scoped_ptr<msgpack::zone> pz(upk.release_zone());
+ std::auto_ptr<msgpack::zone> pz(upk.release_zone());
std::cout << o << std::endl;
++num_msg;
diff --git a/cpp/unpack.cpp b/cpp/unpack.cpp
index de33051..fe7f4b5 100644
--- a/cpp/unpack.cpp
+++ b/cpp/unpack.cpp
@@ -31,9 +31,9 @@ struct unpacker::context {
~context() { }
- int execute(const void* data, size_t len, size_t* off)
+ int execute(const char* data, size_t len, size_t* off)
{
- return msgpack_unpacker_execute(&m_ctx, (const char*)data, len, off);
+ return msgpack_unpacker_execute(&m_ctx, data, len, off);
}
object_class* data()
@@ -171,7 +171,7 @@ void unpacker::reset()
}
-object unpacker::unpack(const void* data, size_t len, zone& z)
+object unpacker::unpack(const char* data, size_t len, zone& z)
{
context ctx(&z);
size_t off = 0;
diff --git a/cpp/unpack.hpp b/cpp/unpack.hpp
index f5896f3..473e8e9 100644
--- a/cpp/unpack.hpp
+++ b/cpp/unpack.hpp
@@ -100,7 +100,7 @@ private:
unpacker(const unpacker&);
public:
- static object unpack(const void* data, size_t len, zone& z);
+ static object unpack(const char* data, size_t len, zone& z);
};
@@ -136,7 +136,7 @@ inline void unpacker::remove_nonparsed_buffer()
{ m_used = m_off; }
-inline object unpack(const void* data, size_t len, zone& z)
+inline object unpack(const char* data, size_t len, zone& z)
{
return unpacker::unpack(data, len, z);
}
diff --git a/cpp/unpack_inline.cpp b/cpp/unpack_inline.cpp
index 37e0b66..40f2769 100644
--- a/cpp/unpack_inline.cpp
+++ b/cpp/unpack_inline.cpp
@@ -71,12 +71,12 @@ static inline void msgpack_unpack_array_item(zone** z, object_class* c, object_c
{ reinterpret_cast<object_array*>(c)->push_back(o); }
static inline object_class* msgpack_unpack_map_start(zone** z, unsigned int n)
-{ return (*z)->narray(); }
+{ return (*z)->nmap(); }
static inline void msgpack_unpack_map_item(zone** z, object_class* c, object_class* k, object_class* v)
{ reinterpret_cast<object_map*>(c)->store(k, v); }
-static inline object_class* msgpack_unpack_raw(zone** z, const void* b, const void* p, size_t l)
+static inline object_class* msgpack_unpack_raw(zone** z, const char* b, const char* p, unsigned int l)
{ return (*z)->nraw_ref(p, l); }
diff --git a/cpp/zone.hpp.erb b/cpp/zone.hpp.erb
index d63fae8..8af8da2 100644
--- a/cpp/zone.hpp.erb
+++ b/cpp/zone.hpp.erb
@@ -58,19 +58,20 @@ public:
object_float* nfloat (float v) { return new (alloc()) object_float(v); }
object_double* ndouble(double v) { return new (alloc()) object_double(v); }
- object_raw_ref* nraw_ref(void* ptr, uint32_t len)
- { return new (alloc()) object_raw_ref(ptr, len); }
- object_const_raw_ref* nraw_ref(const void* ptr, uint32_t len)
- { return new (alloc()) object_const_raw_ref(ptr, len); }
+ object_mutable_raw_ref* nraw_ref(char* ptr, uint32_t len)
+ { return new (alloc()) object_mutable_raw_ref(ptr, len); }
+
+ object_raw_ref* nraw_ref(const char* ptr, uint32_t len)
+ { return new (alloc()) object_raw_ref(ptr, len); }
- object_raw_ref* nraw_copy(const void* ptr, uint32_t len)
+ object_mutable_raw_ref* nraw_copy(const char* ptr, uint32_t len)
{
- void* copy = malloc(len);
+ char* copy = (char*)malloc(len);
if(!copy) { throw std::bad_alloc(); }
- object_raw_ref* o;
+ object_mutable_raw_ref* o;
try {
- o = new (alloc()) object_raw_ref(copy, len);
+ o = new (alloc()) object_mutable_raw_ref(copy, len);
push_finalizer<void>(&zone::finalize_free, NULL, copy);
} catch (...) {
free(copy);
@@ -80,6 +81,17 @@ public:
return o;
}
+
+ object_mutable_raw_ref* nraw_cstr_ref(char* str)
+ { return nraw_ref(str, strlen(str)); }
+
+ object_raw_ref* nraw_cstr_ref(const char* str)
+ { return nraw_ref(str, strlen(str)); }
+
+ object_mutable_raw_ref* nraw_cstr_copy(const char* str)
+ { return nraw_copy(str, strlen(str)); }
+
+
object_array* narray()
{ return new (alloc()) object_array(); }