Skip to content

Replaced nil with nil_t. #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions include/msgpack/adaptor/boost/msgpack_variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace type {
template <typename STR, typename BIN, typename EXT>
struct basic_variant :
boost::variant<
nil, // NIL
nil_t, // NIL
bool, // BOOL
int64_t, // NEGATIVE_INTEGER
uint64_t, // POSITIVE_INTEGER
Expand All @@ -62,7 +62,7 @@ struct basic_variant :
>,
private boost::totally_ordered<basic_variant<STR, BIN, EXT> > {
typedef boost::variant<
nil, // NIL
nil_t, // NIL
bool, // BOOL
int64_t, // NEGATIVE_INTEGER
uint64_t, // POSITIVE_INTEGER
Expand Down Expand Up @@ -104,7 +104,7 @@ struct basic_variant :
basic_variant(unsigned long long v):base(uint64_t(v)) {}

bool is_nil() const {
return boost::get<nil>(this);
return boost::get<msgpack::type::nil_t>(this);
}
bool is_bool() const {
return boost::get<bool>(this);
Expand Down Expand Up @@ -268,7 +268,7 @@ struct as<msgpack::type::basic_variant<STR, BIN, EXT> > {
msgpack::type::basic_variant<STR, BIN, EXT> operator()(msgpack::object const& o) const {
switch(o.type) {
case type::NIL:
return o.as<msgpack::type::nil>();
return o.as<msgpack::type::nil_t>();
case type::BOOLEAN:
return o.as<bool>();
case type::POSITIVE_INTEGER:
Expand Down Expand Up @@ -304,7 +304,7 @@ struct convert<msgpack::type::basic_variant<STR, BIN, EXT> > {
msgpack::type::basic_variant<STR, BIN, EXT>& v) const {
switch(o.type) {
case type::NIL:
v = o.as<msgpack::type::nil>();
v = o.as<msgpack::type::nil_t>();
break;
case type::BOOLEAN:
v = o.as<bool>();
Expand Down Expand Up @@ -366,8 +366,8 @@ struct pack<msgpack::type::basic_variant<STR, BIN, EXT> > {
namespace detail {

struct object_imp : boost::static_visitor<void> {
void operator()(msgpack::type::nil const& v) const {
object<msgpack::type::nil>()(o_, v);
void operator()(msgpack::type::nil_t const& v) const {
object<msgpack::type::nil_t>()(o_, v);
}
void operator()(bool const& v) const {
object<bool>()(o_, v);
Expand Down
30 changes: 18 additions & 12 deletions include/msgpack/adaptor/nil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {

namespace type {

struct nil { };
struct nil_t { };

inline bool operator<(nil const& lhs, nil const& rhs) {
#if defined(MSGPACK_USE_LEGACY_NIL)

typedef nil_t nil;

#endif // defined(MSGPACK_USE_LEGACY_NIL)

inline bool operator<(nil_t const& lhs, nil_t const& rhs) {
return &lhs < &rhs;
}

inline bool operator==(nil const& lhs, nil const& rhs) {
inline bool operator==(nil_t const& lhs, nil_t const& rhs) {
return &lhs == &rhs;
}

Expand All @@ -36,32 +42,32 @@ inline bool operator==(nil const& lhs, nil const& rhs) {
namespace adaptor {

template <>
struct convert<type::nil> {
msgpack::object const& operator()(msgpack::object const& o, type::nil&) const {
struct convert<type::nil_t> {
msgpack::object const& operator()(msgpack::object const& o, type::nil_t&) const {
if(o.type != msgpack::type::NIL) { throw msgpack::type_error(); }
return o;
}
};

template <>
struct pack<type::nil> {
struct pack<type::nil_t> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::nil&) const {
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::nil_t&) const {
o.pack_nil();
return o;
}
};

template <>
struct object<type::nil> {
void operator()(msgpack::object& o, type::nil) const {
struct object<type::nil_t> {
void operator()(msgpack::object& o, type::nil_t) const {
o.type = msgpack::type::NIL;
}
};

template <>
struct object_with_zone<type::nil> {
void operator()(msgpack::object::with_zone& o, type::nil v) const {
struct object_with_zone<type::nil_t> {
void operator()(msgpack::object::with_zone& o, type::nil_t v) const {
static_cast<msgpack::object&>(o) << v;
}
};
Expand All @@ -71,7 +77,7 @@ struct object_with_zone<type::nil> {
template <>
inline void msgpack::object::as<void>() const
{
msgpack::type::nil v;
msgpack::type::nil_t v;
convert(v);
}

Expand Down
18 changes: 9 additions & 9 deletions test/boost_variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,36 @@ const double kEPS = 1e-10;
TEST(MSGPACK_BOOST, pack_convert_variant_nil)
{
std::stringstream ss;
msgpack::type::variant val1 = msgpack::type::nil();
msgpack::type::variant val1 = msgpack::type::nil_t();
EXPECT_TRUE(val1.is_nil());
msgpack::pack(ss, val1);

msgpack::unpacked ret;
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_TRUE(val2.is_nil());
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
}

TEST(MSGPACK_BOOST, object_variant_nil)
{
msgpack::type::variant val1 = msgpack::type::nil();
msgpack::type::variant val1 = msgpack::type::nil_t();
EXPECT_TRUE(val1.is_nil());
msgpack::object obj(val1);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_TRUE(val2.is_nil());
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
}

TEST(MSGPACK_BOOST, object_with_zone_variant_nil)
{
msgpack::zone z;
msgpack::type::variant val1 = msgpack::type::nil();
msgpack::type::variant val1 = msgpack::type::nil_t();
EXPECT_TRUE(val1.is_nil());
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_TRUE(val2.is_nil());
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
}

// nil (default constructor)
Expand All @@ -63,7 +63,7 @@ TEST(MSGPACK_BOOST, pack_convert_variant_nil_default)
msgpack::unpack(ret, ss.str().data(), ss.str().size());
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
EXPECT_TRUE(val2.is_nil());
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
}

TEST(MSGPACK_BOOST, object_variant_nil_default)
Expand All @@ -73,7 +73,7 @@ TEST(MSGPACK_BOOST, object_variant_nil_default)
msgpack::object obj(val1);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_TRUE(val2.is_nil());
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
}

TEST(MSGPACK_BOOST, object_with_zone_variant_nil_default)
Expand All @@ -84,7 +84,7 @@ TEST(MSGPACK_BOOST, object_with_zone_variant_nil_default)
msgpack::object obj(val1, z);
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
EXPECT_TRUE(val2.is_nil());
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
}

// bool
Expand Down