mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-06-04 13:49:20 +02:00
type conversion operator msgpack_object <-> msgpack::object
This commit is contained in:
parent
11abec1093
commit
d078eb0ad5
@ -32,7 +32,7 @@ fi
|
|||||||
# FIXME
|
# FIXME
|
||||||
AC_PROG_CXX
|
AC_PROG_CXX
|
||||||
|
|
||||||
CXXFLAGS="-O4 -Wall $CXXFLAGS -I.."
|
CXXFLAGS="-O4 -Wall $CXXFLAGS -I.. -I../c"
|
||||||
|
|
||||||
|
|
||||||
AM_CONDITIONAL(ENABLE_CXX, test "$enable_cxx" != "no")
|
AM_CONDITIONAL(ENABLE_CXX, test "$enable_cxx" != "no")
|
||||||
|
@ -18,8 +18,10 @@
|
|||||||
#ifndef MSGPACK_OBJECT_HPP__
|
#ifndef MSGPACK_OBJECT_HPP__
|
||||||
#define MSGPACK_OBJECT_HPP__
|
#define MSGPACK_OBJECT_HPP__
|
||||||
|
|
||||||
|
#include "msgpack/object.h"
|
||||||
#include "msgpack/pack.hpp"
|
#include "msgpack/pack.hpp"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@ -72,6 +74,7 @@ struct object {
|
|||||||
object_array array;
|
object_array array;
|
||||||
object_map map;
|
object_map map;
|
||||||
object_raw raw;
|
object_raw raw;
|
||||||
|
object_raw ref; // obsolete
|
||||||
};
|
};
|
||||||
|
|
||||||
type::object_type type;
|
type::object_type type;
|
||||||
@ -85,6 +88,10 @@ struct object {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void convert(T* v);
|
void convert(T* v);
|
||||||
|
|
||||||
|
object();
|
||||||
|
object(msgpack_object obj);
|
||||||
|
operator msgpack_object();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct implicit_type;
|
struct implicit_type;
|
||||||
|
|
||||||
@ -192,6 +199,23 @@ inline bool operator!=(const object x, const object y)
|
|||||||
{ return !(x == y); }
|
{ return !(x == y); }
|
||||||
|
|
||||||
|
|
||||||
|
inline object::object() { }
|
||||||
|
|
||||||
|
inline object::object(msgpack_object obj)
|
||||||
|
{
|
||||||
|
// FIXME beter way?
|
||||||
|
::memcpy(this, &obj, sizeof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline object::operator msgpack_object()
|
||||||
|
{
|
||||||
|
// FIXME beter way?
|
||||||
|
msgpack_object obj;
|
||||||
|
::memcpy(&obj, this, sizeof(obj));
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline object::implicit_type object::convert()
|
inline object::implicit_type object::convert()
|
||||||
{
|
{
|
||||||
return implicit_type(*this);
|
return implicit_type(*this);
|
||||||
|
@ -191,8 +191,7 @@ inline bool unpacker::execute()
|
|||||||
|
|
||||||
inline object unpacker::data()
|
inline object unpacker::data()
|
||||||
{
|
{
|
||||||
msgpack_object obj = msgpack_unpacker_data(this);
|
return msgpack_unpacker_data(this);
|
||||||
return *reinterpret_cast<object*>(&obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline zone* unpacker::release_zone()
|
inline zone* unpacker::release_zone()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user