Skip to content

Commit 8bf2f33

Browse files
committed
Added unpack, pack, object, and object_handle documentation.
1 parent 356fbcf commit 8bf2f33

File tree

4 files changed

+925
-54
lines changed

4 files changed

+925
-54
lines changed

include/msgpack/object.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,42 @@ namespace msgpack {
2929
MSGPACK_API_VERSION_NAMESPACE(v1) {
3030
/// @endcond
3131

32+
/// The class holds object and zone
3233
class object_handle {
3334
public:
35+
/// Constructor that creates nil object and null zone.
3436
object_handle() {}
3537

38+
/// Constructor that creates an object_handle holding object `obj` and zone `z`.
39+
/**
40+
* @param obj object
41+
* @param z zone
42+
*/
3643
object_handle(msgpack::object const& obj, msgpack::unique_ptr<msgpack::zone> z) :
3744
m_obj(obj), m_zone(msgpack::move(z)) { }
3845

3946
// obsolete
4047
void set(msgpack::object const& obj)
4148
{ m_obj = obj; }
4249

50+
/// Get object reference
51+
/**
52+
* @return object
53+
*/
4354
const msgpack::object& get() const
4455
{ return m_obj; }
4556

57+
/// Get unique_ptr reference of zone.
58+
/**
59+
* @return unique_ptr reference of zone
60+
*/
4661
msgpack::unique_ptr<msgpack::zone>& zone()
4762
{ return m_zone; }
4863

64+
/// Get unique_ptr const reference of zone.
65+
/**
66+
* @return unique_ptr const reference of zone
67+
*/
4968
const msgpack::unique_ptr<msgpack::zone>& zone() const
5069
{ return m_zone; }
5170

@@ -133,6 +152,14 @@ inline std::size_t aligned_zone_size(msgpack::object const& obj) {
133152
return s;
134153
}
135154

155+
/// clone object
156+
/**
157+
* Clone (deep copy) object.
158+
* The copied object is located on newly allocated zone.
159+
* @param obj copy source object
160+
*
161+
* @return object_handle that holds deep copied object and zone.
162+
*/
136163
inline object_handle clone(msgpack::object const& obj) {
137164
std::size_t size = msgpack::aligned_zone_size(obj);
138165
msgpack::unique_ptr<msgpack::zone> z(size == 0 ? nullptr : new msgpack::zone(size));

include/msgpack/object_fwd.hpp

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ struct has_as {
9999

100100
#endif // !defined(MSGPACK_USE_CPP03)
101101

102-
102+
/// Object class that corresponding to MessagePack format object
103+
/**
104+
* See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_object
105+
*/
103106
struct object {
104107
union union_type {
105108
bool boolean;
@@ -119,42 +122,114 @@ struct object {
119122
msgpack::type::object_type type;
120123
union_type via;
121124

125+
/// Cheking nil
126+
/**
127+
* @return If the object is nil, then return true, else return false.
128+
*/
122129
bool is_nil() const { return type == msgpack::type::NIL; }
123130

124131
#if defined(MSGPACK_USE_CPP03)
125132

133+
/// Get value as T
134+
/**
135+
* If the object can't be converted to T, msgpack::type_error would be thrown.
136+
* @tparam T The type you want to get.
137+
* @return The converted object.
138+
*/
126139
template <typename T>
127140
T as() const;
128141

129142
#else // defined(MSGPACK_USE_CPP03)
130143

144+
/// Get value as T
145+
/**
146+
* If the object can't be converted to T, msgpack::type_error would be thrown.
147+
* @tparam T The type you want to get.
148+
* @return The converted object.
149+
*/
131150
template <typename T>
132151
typename std::enable_if<msgpack::has_as<T>::value, T>::type as() const;
133152

153+
/// Get value as T
154+
/**
155+
* If the object can't be converted to T, msgpack::type_error would be thrown.
156+
* @tparam T The type you want to get.
157+
* @return The converted object.
158+
*/
134159
template <typename T>
135160
typename std::enable_if<!msgpack::has_as<T>::value, T>::type as() const;
136161

137162
#endif // defined(MSGPACK_USE_CPP03)
138163

164+
/// Convert the object
165+
/**
166+
* If the object can't be converted to T, msgpack::type_error would be thrown.
167+
* @tparam T The type of v.
168+
* @param v The value you want to get. `v` is output parameter. `v` is overwritten by converted value from the object.
169+
* @return The reference of `v`.
170+
*/
139171
template <typename T>
140172
T& convert(T& v) const;
173+
174+
/// Convert the object (obsolete)
175+
/**
176+
* If the object can't be converted to T, msgpack::type_error would be thrown.
177+
* @tparam T The type of v.
178+
* @param v The pointer of the value you want to get. `v` is output parameter. `*v` is overwritten by converted value from the object.
179+
* @return The pointer of `v`.
180+
*/
141181
template <typename T>
142182
T* convert(T* v) const;
143183

184+
/// Convert the object if not nil
185+
/**
186+
* If the object is not nil and can't be converted to T, msgpack::type_error would be thrown.
187+
* @tparam T The type of v.
188+
* @param v The value you want to get. `v` is output parameter. `v` is overwritten by converted value from the object if the object is not nil.
189+
* @return If the object is nil, then return false, else return true.
190+
*/
144191
template <typename T>
145192
bool convert_if_not_nil(T& v) const;
146193

194+
/// Default constructor. The object is set to nil.
147195
object();
148196

197+
/// Copy constructor. Object is shallow copied.
149198
object(const msgpack_object& o);
150199

200+
/// Construct object from T
201+
/**
202+
* If `v` is the type that is corresponding to MessegePack format str, bin, ext, array, or map,
203+
* you need to call `object(const T& v, msgpack::zone& z)` instead of this constructor.
204+
*
205+
* @tparam T The type of `v`.
206+
* @param v The value you want to convert.
207+
*/
151208
template <typename T>
152209
explicit object(const T& v);
153210

211+
/// Construct object from T
212+
/**
213+
* The object is constructed on the zone `z`.
214+
* See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_object
215+
*
216+
* @tparam T The type of `v`.
217+
* @param v The value you want to convert.
218+
* @param z The zone that is used by the object.
219+
*/
154220
template <typename T>
155221
object(const T& v, msgpack::zone& z);
156222

157-
// obsolete
223+
/// Construct object from T (obsolete)
224+
/**
225+
* The object is constructed on the zone `z`.
226+
* Use `object(const T& v, msgpack::zone& z)` instead of this constructor.
227+
* See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_object
228+
*
229+
* @tparam T The type of `v`.
230+
* @param v The value you want to convert.
231+
* @param z The pointer to the zone that is used by the object.
232+
*/
158233
template <typename T>
159234
object(const T& v, msgpack::zone* z);
160235

0 commit comments

Comments
 (0)