Skip to content

Commit

Permalink
Merge pull request #410 from redboltz/fix_399
Browse files Browse the repository at this point in the history
Fixed #399
  • Loading branch information
redboltz committed Jan 21, 2016
2 parents 83ab53e + 3c27189 commit 7d1be40
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 35 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OPTION (MSGPACK_32BIT "32bit compile" OFF)
OPTION (MSGPACK_BOOST "Using boost libraries" OFF)

SET (CMAKE_CXX_FLAGS "-DMSGPACK_DISABLE_LEGACY_NIL ${CMAKE_CXX_FLAGS}")
SET (CMAKE_CXX_FLAGS "-DMSGPACK_DISABLE_LEGACY_CONVERT ${CMAKE_CXX_FLAGS}")

IF (APPLE)
SET(CMAKE_MACOSX_RPATH ON)
Expand Down
12 changes: 6 additions & 6 deletions QUICKSTART-CPP.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ int main(void) {

// convert it into statically typed object.
std::vector<std::string> rvec;
obj.convert(&rvec);
obj.convert(rvec);
}
```
Compile it as follows:
```
$ g++ -Ipath_to_msgpack/include -DMSGPACK_DISABLE_LEGACY_NIL hello.cc -o hello
$ g++ -Ipath_to_msgpack/include -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT hello.cc -o hello
$ ./hello
["Hello", "MessagePack"]
```
See [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140).
See [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140) and [MSGPACK_DISABLE_LEGACY_CONVERT](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_convert-since-140).
## Streaming feature
Expand Down Expand Up @@ -85,15 +85,15 @@ int main(void) {
}
// results:
// $ g++ -Ipath_to_msgpack/include -DMSGPACK_DISABLE_LEGACY_NIL stream.cc -o stream
// $ g++ -Ipath_to_msgpack/include -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT stream.cc -o stream
// $ ./stream
// "Log message ... 1"
// "Log message ... 2"
// "Log message ... 3"
}
```

See [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140).
See [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140) and [MSGPACK_DISABLE_LEGACY_CONVERT](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_convert-since-140).

### Streaming into an array or map

Expand Down Expand Up @@ -158,6 +158,6 @@ int main(void) {
// you can convert object to myclass directly
std::vector<myclass> rvec;
obj.convert(&rvec);
obj.convert(rvec);
}
```
6 changes: 3 additions & 3 deletions 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 All @@ -112,9 +112,9 @@ Usage
When you use msgpack on C++03 and C++11, you can just add
msgpack-c/include to your include path:

g++ -I msgpack-c/include -DMSGPACK_DISABLE_LEGACY_NIL your_source_file.cpp
g++ -I msgpack-c/include -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT your_source_file.cpp

See [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140).
See [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140) and [MSGPACK_DISABLE_LEGACY_CONVERT](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_convert-since-140).

If you want to use C version of msgpack, you need to build it. You can
also install the C and C++ versions of msgpack.
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
2 changes: 2 additions & 0 deletions include/msgpack/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,14 @@ inline T& object::convert(T& v) const
return v;
}

#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
template <typename T>
inline T* object::convert(T* v) const
{
convert(*v);
return v;
}
#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)

template <typename T>
inline bool object::convert_if_not_nil(T& v) const
Expand Down
3 changes: 3 additions & 0 deletions include/msgpack/object_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ struct object {
template <typename T>
T& convert(T& v) const;


#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
/// Convert the object (obsolete)
/**
* If the object can't be converted to T, msgpack::type_error would be thrown.
Expand All @@ -180,6 +182,7 @@ struct object {
*/
template <typename T>
T* convert(T* v) const;
#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)

/// Convert the object if not nil
/**
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AM_CPPFLAGS = -I$(top_srcdir)/include -pthread -DMSGPACK_DISABLE_LEGACY_NIL
AM_CPPFLAGS = -I$(top_srcdir)/include -pthread -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT
AM_C_CPPFLAGS = -I$(top_srcdir)/include -pthread
AM_LDFLAGS = $(top_builddir)/src/libmsgpackc.la -lgtest_main -lgtest -lpthread

Expand Down
30 changes: 17 additions & 13 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,35 +65,39 @@ 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)
TEST(convert, return_value_ref)
{
msgpack::zone z;
msgpack::object obj(1, z);

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

TEST(convert, return_value_ref)
#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)

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

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

#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)

TEST(convert, if_not_nil_nil)
{
msgpack::object obj;
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 7d1be40

Please sign in to comment.