Added a conversion support from msgpack::object to std::vector<bool>.
This commit is contained in:
Takatoshi Kondo
2015-01-25 21:59:39 +09:00
parent 414da4e8c6
commit 64ac09c492
7 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_VECTOR_BOOL_HPP
#define MSGPACK_TYPE_VECTOR_BOOL_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <vector>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
inline object const& operator>> (object const& o, std::vector<bool>& v)
{
if (o.type != type::ARRAY) { throw type_error(); }
if (o.via.array.size > 0) {
v.resize(o.via.array.size);
object* p = o.via.array.ptr;
for (std::vector<bool>::iterator it = v.begin(), end = v.end();
it != end;
++it) {
*it = p->as<bool>();
++p;
}
}
return o;
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_VECTOR_BOOL_HPP

View File

@@ -0,0 +1,34 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_VECTOR_BOOL_FWD_HPP
#define MSGPACK_TYPE_VECTOR_BOOL_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
object const& operator>> (object const& o, std::vector<bool>& v);
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_VECTOR_BOOL_FWD_HPP

View File

@@ -38,6 +38,7 @@
#include "msgpack/adaptor/set_fwd.hpp"
#include "msgpack/adaptor/string_fwd.hpp"
#include "msgpack/adaptor/vector_fwd.hpp"
#include "msgpack/adaptor/vector_bool_fwd.hpp"
#include "msgpack/adaptor/vector_char_fwd.hpp"
#if defined(MSGPACK_USE_CPP03)

View File

@@ -13,6 +13,7 @@
#include "adaptor/set.hpp"
#include "adaptor/string.hpp"
#include "adaptor/vector.hpp"
#include "adaptor/vector_bool.hpp"
#include "adaptor/vector_char.hpp"
#include "adaptor/msgpack_tuple.hpp"
#include "adaptor/define.hpp"