Skip to content

Commit 3c27189

Browse files
committed
Fixed #399
If MSGPACK_DISABLE_LEGACY_CONVERT is defined, msgpack::object::convert(T*) is removed. Added MSGPACK_DISABLE_LEGACY_CONVERT to build system and documents. Please define MSGPACK_DISABLE_LEGACY_CONVERT and update your code as follows: Replace int i; obj.convert(&i); // Removed pointer version with int i; obj.convert(i); // Reference version
1 parent 83ab53e commit 3c27189

File tree

15 files changed

+44
-35
lines changed

15 files changed

+44
-35
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OPTION (MSGPACK_32BIT "32bit compile" OFF)
2222
OPTION (MSGPACK_BOOST "Using boost libraries" OFF)
2323

2424
SET (CMAKE_CXX_FLAGS "-DMSGPACK_DISABLE_LEGACY_NIL ${CMAKE_CXX_FLAGS}")
25+
SET (CMAKE_CXX_FLAGS "-DMSGPACK_DISABLE_LEGACY_CONVERT ${CMAKE_CXX_FLAGS}")
2526

2627
IF (APPLE)
2728
SET(CMAKE_MACOSX_RPATH ON)

QUICKSTART-CPP.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ int main(void) {
4040

4141
// convert it into statically typed object.
4242
std::vector<std::string> rvec;
43-
obj.convert(&rvec);
43+
obj.convert(rvec);
4444
}
4545
```
4646
4747
Compile it as follows:
4848
4949
```
50-
$ g++ -Ipath_to_msgpack/include -DMSGPACK_DISABLE_LEGACY_NIL hello.cc -o hello
50+
$ g++ -Ipath_to_msgpack/include -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT hello.cc -o hello
5151
$ ./hello
5252
["Hello", "MessagePack"]
5353
```
5454
55-
See [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140).
55+
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).
5656
5757
## Streaming feature
5858
@@ -85,15 +85,15 @@ int main(void) {
8585
}
8686
8787
// results:
88-
// $ g++ -Ipath_to_msgpack/include -DMSGPACK_DISABLE_LEGACY_NIL stream.cc -o stream
88+
// $ g++ -Ipath_to_msgpack/include -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT stream.cc -o stream
8989
// $ ./stream
9090
// "Log message ... 1"
9191
// "Log message ... 2"
9292
// "Log message ... 3"
9393
}
9494
```
9595

96-
See [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140).
96+
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).
9797

9898
### Streaming into an array or map
9999

@@ -158,6 +158,6 @@ int main(void) {
158158
159159
// you can convert object to myclass directly
160160
std::vector<myclass> rvec;
161-
obj.convert(&rvec);
161+
obj.convert(rvec);
162162
}
163163
```

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int main(void)
9696
// convert msgpack::object instance into the original type.
9797
// if the type is mismatched, it throws msgpack::type_error exception.
9898
msgpack::type::tuple<int, bool, std::string> dst;
99-
deserialized.convert(&dst);
99+
deserialized.convert(dst);
100100
101101
return 0;
102102
}
@@ -112,9 +112,9 @@ Usage
112112
When you use msgpack on C++03 and C++11, you can just add
113113
msgpack-c/include to your include path:
114114

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

117-
See [MSGPACK_DISABLE_LEGACY_NIL](https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_configure#msgpack_disable_legacy_nil-since-140).
117+
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).
118118

119119
If you want to use C version of msgpack, you need to build it. You can
120120
also install the C and C++ versions of msgpack.

example/cpp03/custom.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int main(void)
4444
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size());
4545
msgpack::object obj = result.get();
4646

47-
obj.convert(&nc);
47+
obj.convert(nc);
4848

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

63-
obj.convert(&oc);
63+
obj.convert(oc);
6464

6565
std::cout << obj << " value=" << oc.value << std::endl;
6666
}

example/cpp03/simple.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main(void)
4040
// convert msgpack::object instance into the original type.
4141
// if the type is mismatched, it throws msgpack::type_error exception.
4242
msgpack::type::tuple<int, bool, std::string> dst;
43-
deserialized.convert(&dst);
43+
deserialized.convert(dst);
4444

4545
return 0;
4646
}

example/cpp03/speed_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void test_map_pack_unpack() {
5050
std::cout << "Start converting..." << std::endl;
5151
{
5252
boost::timer::cpu_timer timer;
53-
unpacked.get().convert(&m2);
53+
unpacked.get().convert(m2);
5454
std::string result = timer.format();
5555
std::cout << result << std::endl;
5656
}

example/cpp03/speed_test_nested_array.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void test_array_of_array() {
7373
std::cout << "Start converting..." << std::endl;
7474
{
7575
boost::timer::cpu_timer timer;
76-
unpacked.get().convert(&v2);
76+
unpacked.get().convert(v2);
7777
std::string result = timer.format();
7878
std::cout << result << std::endl;
7979
}

include/msgpack/object.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,14 @@ inline T& object::convert(T& v) const
523523
return v;
524524
}
525525

526+
#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
526527
template <typename T>
527528
inline T* object::convert(T* v) const
528529
{
529530
convert(*v);
530531
return v;
531532
}
533+
#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
532534

533535
template <typename T>
534536
inline bool object::convert_if_not_nil(T& v) const

include/msgpack/object_fwd.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ struct object {
171171
template <typename T>
172172
T& convert(T& v) const;
173173

174+
175+
#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
174176
/// Convert the object (obsolete)
175177
/**
176178
* If the object can't be converted to T, msgpack::type_error would be thrown.
@@ -180,6 +182,7 @@ struct object {
180182
*/
181183
template <typename T>
182184
T* convert(T* v) const;
185+
#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
183186

184187
/// Convert the object if not nil
185188
/**

test/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AM_CPPFLAGS = -I$(top_srcdir)/include -pthread -DMSGPACK_DISABLE_LEGACY_NIL
1+
AM_CPPFLAGS = -I$(top_srcdir)/include -pthread -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT
22
AM_C_CPPFLAGS = -I$(top_srcdir)/include -pthread
33
AM_LDFLAGS = $(top_builddir)/src/libmsgpackc.la -lgtest_main -lgtest -lpthread
44

0 commit comments

Comments
 (0)