From d452625ed1d54a2fcffc48f310b1be43b146302d Mon Sep 17 00:00:00 2001 From: sztomi Date: Mon, 9 Oct 2017 20:23:25 +0200 Subject: [PATCH] Added * and -> operators to object_handle --- include/msgpack/v1/object.hpp | 12 ++++++++++++ test/object.cpp | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/include/msgpack/v1/object.hpp b/include/msgpack/v1/object.hpp index 6ea84464..64da8c53 100644 --- a/include/msgpack/v1/object.hpp +++ b/include/msgpack/v1/object.hpp @@ -70,6 +70,18 @@ public: const msgpack::object& get() const { return m_obj; } + /** + * @return object (to mimic smart pointers). + */ + const msgpack::object& operator*() const + { return get(); } + + /** + * @return the address of the object (to mimic smart pointers). + */ + const msgpack::object* operator->() const + { return &get(); } + /// Get unique_ptr reference of zone. /** * @return unique_ptr reference of zone diff --git a/test/object.cpp b/test/object.cpp index 1fd19451..64895102 100644 --- a/test/object.cpp +++ b/test/object.cpp @@ -445,3 +445,12 @@ TEST(object, pack_double) EXPECT_EQ(static_cast(9), ss1.str().size()); EXPECT_EQ(ss1.str(), ss2.str()); } + +TEST(object, handle_operators) +{ + int i = 1; + msgpack::object obj(i); + msgpack::object_handle oh = msgpack::clone(obj); + EXPECT_EQ(oh.get(), *oh); + EXPECT_EQ(oh->as(), oh.get().as()); +}