Skip to content

Commit

Permalink
Fixed msgpack#399
Browse files Browse the repository at this point in the history
Removed the pointer version of object::convert().
Updated tests and documents.

Migration note:

Replace
  int i;
  obj.convert(&i); // Removed pointer version
with
  int i;
  obj.convert(i);  // Reference version
  • Loading branch information
redboltz committed Jan 19, 2016
1 parent 6c035f7 commit 3b1dbda
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 38 deletions.
4 changes: 2 additions & 2 deletions QUICKSTART-CPP.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(void) {

// convert it into statically typed object.
std::vector<std::string> rvec;
obj.convert(&rvec);
obj.convert(rvec);
}
```
Expand Down Expand Up @@ -154,6 +154,6 @@ int main(void) {
// you can convert object to myclass directly
std::vector<myclass> rvec;
obj.convert(&rvec);
obj.convert(rvec);
}
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int main(void)
// convert msgpack::object instance into the original type.
// if the type is mismatched, it throws msgpack::type_error exception.
msgpack::type::tuple<int, bool, std::string> dst;
deserialized.convert(&dst);
deserialized.convert(dst);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions example/cpp03/custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(void)
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size());
msgpack::object obj = result.get();

obj.convert(&nc);
obj.convert(nc);

std::cout << obj << " value=" << nc.value << " flag=" << nc.flag << std::endl;
}
Expand All @@ -60,7 +60,7 @@ int main(void)
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size());
msgpack::object obj = result.get();

obj.convert(&oc);
obj.convert(oc);

std::cout << obj << " value=" << oc.value << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion example/cpp03/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(void)
// convert msgpack::object instance into the original type.
// if the type is mismatched, it throws msgpack::type_error exception.
msgpack::type::tuple<int, bool, std::string> dst;
deserialized.convert(&dst);
deserialized.convert(dst);

return 0;
}
2 changes: 1 addition & 1 deletion example/cpp03/speed_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void test_map_pack_unpack() {
std::cout << "Start converting..." << std::endl;
{
boost::timer::cpu_timer timer;
unpacked.get().convert(&m2);
unpacked.get().convert(m2);
std::string result = timer.format();
std::cout << result << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion example/cpp03/speed_test_nested_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void test_array_of_array() {
std::cout << "Start converting..." << std::endl;
{
boost::timer::cpu_timer timer;
unpacked.get().convert(&v2);
unpacked.get().convert(v2);
std::string result = timer.format();
std::cout << result << std::endl;
}
Expand Down
7 changes: 0 additions & 7 deletions include/msgpack/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,6 @@ inline T& object::convert(T& v) const
return v;
}

template <typename T>
inline T* object::convert(T* v) const
{
convert(*v);
return v;
}

template <typename T>
inline bool object::convert_if_not_nil(T& v) const
{
Expand Down
22 changes: 6 additions & 16 deletions test/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ TEST(convert, compatibility_less)
src[0] = "kumofs";

msgpack::zone z;
msgpack::object obj(src, &z);
msgpack::object obj(src, z);

compatibility c;
EXPECT_NO_THROW( obj.convert(&c) );
EXPECT_NO_THROW( obj.convert(c) );

EXPECT_EQ("kumofs", c.str1);
EXPECT_EQ("default", c.str2);
Expand All @@ -50,10 +50,10 @@ TEST(convert, compatibility_more)
src[2] = "cloudy";

msgpack::zone z;
msgpack::object obj(src, &z);
msgpack::object obj(src, z);

compatibility to;
EXPECT_NO_THROW( obj.convert(&to) );
EXPECT_NO_THROW( obj.convert(to) );

EXPECT_EQ("kumofs", to.str1);
EXPECT_EQ("mpio", to.str2);
Expand All @@ -65,24 +65,14 @@ TEST(convert, enum_member)
src.flag = enum_member::B;

msgpack::zone z;
msgpack::object obj(src, &z);
msgpack::object obj(src, z);

enum_member to;
EXPECT_NO_THROW( obj.convert(&to) );
EXPECT_NO_THROW( obj.convert(to) );

EXPECT_EQ(enum_member::B, to.flag);
}

TEST(convert, return_value_ptr)
{
msgpack::zone z;
msgpack::object obj(1, z);

int i;
EXPECT_EQ(obj.convert(&i), &i);
EXPECT_EQ(1, i);
}

TEST(convert, return_value_ref)
{
msgpack::zone z;
Expand Down
3 changes: 1 addition & 2 deletions test/fixint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void check_convert() {
msgpack::unpack(&msg, sbuf.data(), sbuf.size());

T v2;
msg.get().convert(&v2);
msg.get().convert(v2);

EXPECT_EQ(v1.get(), v2.get());

Expand All @@ -52,4 +52,3 @@ TEST(fixint, convert)
check_convert<msgpack::type::fix_uint32>();
check_convert<msgpack::type::fix_uint64>();
}

2 changes: 1 addition & 1 deletion test/msgpack_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const unsigned int kLoop = 1000;
if (it == vec.end()) goto out; \
msgpack::object obj = result.get(); \
vec_type::value_type val; \
obj.convert(&val); \
obj.convert(val); \
EXPECT_EQ(*it, val); \
++it; \
} \
Expand Down
2 changes: 1 addition & 1 deletion test/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ TEST(object, convert)
msgpack::unpack(ret, sbuf.data(), sbuf.size());

myclass m2;
ret.get().convert(&m2);
ret.get().convert(m2);

EXPECT_EQ(m1, m2);
}
Expand Down
6 changes: 3 additions & 3 deletions test/user_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ class TestUnionMemberClass
void msgpack_unpack(msgpack::object o)
{
msgpack::type::tuple<bool, msgpack::object> tuple;
o.convert(&tuple);
o.convert(tuple);

is_double = tuple.get<0>();
if (is_double)
tuple.get<1>().convert(&value.f);
tuple.get<1>().convert(value.f);
else
tuple.get<1>().convert(&value.i);
tuple.get<1>().convert(value.i);
}
};

Expand Down

0 comments on commit 3b1dbda

Please sign in to comment.