mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-11-10 08:08:32 +01:00
Added std::forward_list support.
Fixed cmake filename typo.
This commit is contained in:
@@ -81,6 +81,7 @@ IF (MSGPACK_ENABLE_CXX)
|
||||
include/msgpack/adaptor/bool.hpp
|
||||
include/msgpack/adaptor/cpp11/array.hpp
|
||||
include/msgpack/adaptor/cpp11/array_char.hpp
|
||||
include/msgpack/adaptor/cpp11/forward_list.hpp
|
||||
include/msgpack/adaptor/cpp11/tuple.hpp
|
||||
include/msgpack/adaptor/define.hpp
|
||||
include/msgpack/adaptor/deque.hpp
|
||||
|
||||
66
include/msgpack/adaptor/cpp11/forward_list.hpp
Normal file
66
include/msgpack/adaptor/cpp11/forward_list.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 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_CPP11_FORWARD_LIST_HPP
|
||||
#define MSGPACK_CPP11_FORWARD_LIST_HPP
|
||||
|
||||
#include <forward_list>
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
template <typename T>
|
||||
inline std::forward_list<T>& operator>> (object const& o, std::forward_list<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
object* p = o.via.array.ptr;
|
||||
for (auto &e : v) {
|
||||
p->convert(e);
|
||||
++p;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::forward_list<T>& v)
|
||||
{
|
||||
o.pack_array(std::distance(v.begin(), v.end()));
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const std::forward_list<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = static_cast<object*>(o.zone->allocate_align(sizeof(object)*v.size()));
|
||||
for(auto const& e : v) *p++ = object(e, o.zone);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_FORWARD_LIST_HPP
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "adaptor/cpp11/array.hpp"
|
||||
#include "adaptor/cpp11/array_char.hpp"
|
||||
#include "adaptor/cpp11/forward_list.hpp"
|
||||
#include "adaptor/cpp11/tuple.hpp"
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
@@ -55,6 +55,7 @@ nobase_include_HEADERS += \
|
||||
../include/msgpack/adaptor/bool.hpp \
|
||||
../include/msgpack/adaptor/cpp11/array.hpp \
|
||||
../include/msgpack/adaptor/cpp11/array_char.hpp \
|
||||
../include/msgpack/adaptor/cpp11/forward_list.hpp \
|
||||
../include/msgpack/adaptor/cpp11/tuple.hpp \
|
||||
../include/msgpack/adaptor/define.hpp \
|
||||
../include/msgpack/adaptor/deque.hpp \
|
||||
|
||||
@@ -23,7 +23,7 @@ SET (check_PROGRAMS
|
||||
msgpack_tuple.cc
|
||||
msgpack_test.cpp
|
||||
msgpackc_test.cpp
|
||||
msgpackc_test_cpp11.cpp
|
||||
msgpack_test_cpp11.cpp
|
||||
reference.cc
|
||||
)
|
||||
|
||||
|
||||
@@ -63,6 +63,22 @@ TEST(MSGPACK_CPP11, simple_buffer_array_char)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MSGPACK_STL, simple_buffer_forward_list)
|
||||
{
|
||||
for (unsigned int k = 0; k < kLoop; k++) {
|
||||
forward_list<int> val1;
|
||||
for (unsigned int i = 0; i < kElements; i++)
|
||||
val1.push_front(rand());
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::unpacked ret;
|
||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||
forward_list<int> val2 = ret.get().as<forward_list<int> >();
|
||||
EXPECT_EQ(val1, val2);
|
||||
EXPECT_FALSE(ret.referenced());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TestEnumClassMemberClass
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user