mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-13 22:50:19 +02:00
Added examples to cmake building process.
Set /WX flas that is warnings as errors on MSVC build. Updated linux, osx, msvc build to refer to appropriate boost libraries.
This commit is contained in:
15
.travis.yml
15
.travis.yml
@@ -12,12 +12,12 @@ os:
|
||||
- linux
|
||||
before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:h-rayflood/llvm; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:h-rayflood/llvm-upper; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update; fi
|
||||
install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq gcc-4.8-multilib g++-4.8-multilib; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --allow-unauthenticated -qq clang-3.5; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --allow-unauthenticated -qq clang-3.6; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 90; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y lib32gcc1; fi
|
||||
@@ -27,10 +27,13 @@ install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y bzip2; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y libc6-dbg; fi
|
||||
- wget https://googletest.googlecode.com/files/gtest-1.7.0.zip
|
||||
- wget http://sourceforge.net/projects/boost/files/boost/1.58.0/
|
||||
- wget http://valgrind.org/downloads/valgrind-3.10.1.tar.bz2 && tar xjf valgrind-3.10.1.tar.bz2 && cd valgrind-3.10.1 && ./configure && make && sudo make install && cd ..
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then unzip -q gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && g++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && g++ -m32 src/gtest-all.cc -I. -Iinclude -c && g++ -m32 src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mkdir /usr/local/lib32 && sudo mv *.a /usr/local/lib32 && cd .. && wget http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.zip && unzip -q boost_1_58_0.zip && sudo mkdir /usr/local/boost && sudo cp -r boost_1_58_0/boost /usr/local/boost/; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then unzip -q gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && clang++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && cd .. && wget http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.zip && unzip -q boost_1_58_0.zip && sudo mkdir /usr/local/boost && sudo cp -r boost_1_58_0/boost /usr/local/boost/; fi
|
||||
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew unlink boost; fi
|
||||
- if [ "$BOOST" == "boost" ]; then wget http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.zip && unzip -q boost_1_58_0.zip && cd boost_1_58_0 && ./bootstrap.sh && ./b2 --with-timer --with-chrono address-model="$ARCH" > /dev/null && sudo ./b2 --with-timer --with-chrono address-model="$ARCH" install > /dev/null && cd ..; fi
|
||||
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then unzip -q gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && g++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && g++ -m32 src/gtest-all.cc -I. -Iinclude -c && g++ -m32 src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mkdir /usr/local/lib32 && sudo mv *.a /usr/local/lib32 && cd ..; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then unzip -q gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && clang++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && cd ..; fi
|
||||
|
||||
env:
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost"
|
||||
@@ -43,7 +46,7 @@ env:
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost"
|
||||
|
||||
before_script:
|
||||
- export PATH=/usr/local/bin:$PATH && rm -rf install1
|
||||
- export PATH=/usr/local/bin:$PATH && rm -rf install
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
|
@@ -55,6 +55,10 @@ ENDIF ()
|
||||
|
||||
IF (MSGPACK_BOOST)
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_BOOST ${CMAKE_CXX_FLAGS}")
|
||||
SET (Boost_USE_STATIC_LIBS ON) # only find static libs
|
||||
SET (Boost_USE_MULTITHREADED ON)
|
||||
SET (Boost_USE_STATIC_RUNTIME OFF)
|
||||
FIND_PACKAGE (Boost COMPONENTS chrono timer system)
|
||||
ENDIF ()
|
||||
|
||||
FILE (GLOB_RECURSE PREDEF_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost/*.h)
|
||||
@@ -221,7 +225,6 @@ INCLUDE_DIRECTORIES (
|
||||
./
|
||||
include/
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/
|
||||
${MSGPACK_BOOST_DIR}
|
||||
)
|
||||
|
||||
ADD_LIBRARY (msgpack SHARED
|
||||
@@ -253,9 +256,9 @@ IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" ST
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
@@ -267,6 +270,8 @@ IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
|
||||
SET(CMAKE_INSTALL_LIBDIR lib)
|
||||
ENDIF ()
|
||||
|
||||
ADD_SUBDIRECTORY (example)
|
||||
|
||||
INSTALL (TARGETS msgpack msgpack-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
INSTALL (DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
IF (NOT MSVC)
|
||||
|
@@ -24,7 +24,7 @@ before_build:
|
||||
build_script:
|
||||
- md build
|
||||
- cd build
|
||||
- cmake -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8 ..
|
||||
- cmake -DMSGPACK_BOOST=ON -DMSGPACK_BOOST_DIR=C:\Libraries\boost -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8 ..
|
||||
- cmake --build . --config Release
|
||||
|
||||
test_script:
|
||||
|
3
example/CMakeLists.txt
Normal file
3
example/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
ADD_SUBDIRECTORY (c)
|
||||
ADD_SUBDIRECTORY (cpp03)
|
||||
ADD_SUBDIRECTORY (cpp11)
|
32
example/c/CMakeLists.txt
Normal file
32
example/c/CMakeLists.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
INCLUDE_DIRECTORIES (
|
||||
../include
|
||||
)
|
||||
|
||||
LIST (APPEND exec_PROGRAMS
|
||||
lib_buffer_unpack.c
|
||||
simple_c.c
|
||||
speed_test_uint32_array.c
|
||||
speed_test_uint64_array.c
|
||||
user_buffer_unpack.c
|
||||
)
|
||||
|
||||
FOREACH (source_file ${exec_PROGRAMS})
|
||||
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
|
||||
ADD_EXECUTABLE (
|
||||
${source_file_we}
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we}
|
||||
msgpack
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -Wno-mismatched-tags -g -O3")
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDFOREACH ()
|
@@ -7,14 +7,14 @@ void test()
|
||||
msgpack_packer * pk;
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
|
||||
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
int idx = 0;
|
||||
size_t idx = 0;
|
||||
for (; idx < size; ++idx)
|
||||
msgpack_pack_uint32(pk, 1);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ void test()
|
||||
msgpack_sbuffer_destroy(&buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(void)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < 10; ++i) test();
|
||||
|
@@ -15,7 +15,7 @@ void test()
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
int idx = 0;
|
||||
size_t idx = 0;
|
||||
for (; idx < size; ++idx)
|
||||
msgpack_pack_uint64(pk, test_u64);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ void test()
|
||||
msgpack_sbuffer_destroy(&buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(void)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < 10; ++i) test();
|
||||
|
107
example/cpp03/CMakeLists.txt
Normal file
107
example/cpp03/CMakeLists.txt
Normal file
@@ -0,0 +1,107 @@
|
||||
LIST (APPEND exec_PROGRAMS
|
||||
class_intrusive.cpp
|
||||
class_intrusive_map.cpp
|
||||
class_non_intrusive.cpp
|
||||
custom.cpp
|
||||
enum.cpp
|
||||
map_based_versionup.cpp
|
||||
protocol.cpp
|
||||
protocol_new.cpp
|
||||
reuse_zone.cpp
|
||||
simple.cpp
|
||||
)
|
||||
|
||||
IF (NOT MSVC)
|
||||
LIST (APPEND with_pthread_PROGRAMS
|
||||
stream.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_BOOST)
|
||||
IF (NOT MSVC)
|
||||
LIST (APPEND with_boost_lib_PROGRAMS
|
||||
speed_test.cpp
|
||||
speed_test_nested_array.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
FOREACH (source_file ${exec_PROGRAMS})
|
||||
INCLUDE_DIRECTORIES (
|
||||
../include
|
||||
${MSGPACK_BOOST_DIR}
|
||||
)
|
||||
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
|
||||
ADD_EXECUTABLE (
|
||||
${source_file_we}
|
||||
${source_file}
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++03 -Wall -Wextra -Werror -Wno-mismatched-tags -g -O3")
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDFOREACH ()
|
||||
|
||||
FOREACH (source_file ${with_pthread_PROGRAMS})
|
||||
INCLUDE_DIRECTORIES (
|
||||
../include
|
||||
${MSGPACK_BOOST_DIR}
|
||||
)
|
||||
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
|
||||
ADD_EXECUTABLE (
|
||||
${source_file_we}
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we}
|
||||
pthread
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++03 -Wall -Wextra -Werror -Wno-mismatched-tags -g -O3 -pthread")
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDFOREACH ()
|
||||
|
||||
FOREACH (source_file ${with_boost_lib_PROGRAMS})
|
||||
INCLUDE_DIRECTORIES (
|
||||
../include
|
||||
${Boost_INCLUDE_DIRS}
|
||||
)
|
||||
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
|
||||
ADD_EXECUTABLE (
|
||||
${source_file_we}
|
||||
${source_file}
|
||||
)
|
||||
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
|
||||
TARGET_LINK_LIBRARIES (${source_file_we}
|
||||
${Boost_TIMER_LIBRARY}
|
||||
${Boost_CHRONO_LIBRARY}
|
||||
${Boost_SYSTEM_LIBRARY}
|
||||
)
|
||||
IF (NOT MSVC AND NOT APPLE)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we}
|
||||
rt
|
||||
)
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++03 -Wall -Wextra -Werror -Wno-mismatched-tags -g -O3")
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDFOREACH ()
|
80
example/cpp03/class_intrusive_map.cpp
Normal file
80
example/cpp03/class_intrusive_map.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
|
||||
class my_class {
|
||||
public:
|
||||
my_class() {} // When you want to convert from msgpack::object to my_class,
|
||||
// my_class should be default constractible.
|
||||
my_class(std::string const& name, int age):name_(name), age_(age) {}
|
||||
|
||||
friend bool operator==(my_class const& lhs, my_class const& rhs) {
|
||||
return lhs.name_ == rhs.name_ && lhs.age_ == rhs.age_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
int age_;
|
||||
|
||||
public:
|
||||
MSGPACK_DEFINE(name_, age_);
|
||||
};
|
||||
|
||||
void print(std::string const& buf) {
|
||||
for (std::string::const_iterator it = buf.begin(), end = buf.end();
|
||||
it != end;
|
||||
++it) {
|
||||
std::cout
|
||||
<< std::setw(2)
|
||||
<< std::hex
|
||||
<< std::setfill('0')
|
||||
<< (static_cast<int>(*it) & 0xff)
|
||||
<< ' ';
|
||||
}
|
||||
std::cout << std::dec << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
{ // pack, unpack
|
||||
my_class my("John Smith", 42);
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, my);
|
||||
|
||||
print(ss.str());
|
||||
|
||||
msgpack::unpacked unp;
|
||||
msgpack::unpack(unp, ss.str().data(), ss.str().size());
|
||||
msgpack::object obj = unp.get();
|
||||
std::cout << obj << std::endl;
|
||||
assert(obj.as<my_class>() == my);
|
||||
}
|
||||
{ // create object with zone
|
||||
my_class my("John Smith", 42);
|
||||
msgpack::zone z;
|
||||
msgpack::object obj(my, z);
|
||||
std::cout << obj << std::endl;
|
||||
assert(obj.as<my_class>() == my);
|
||||
}
|
||||
}
|
@@ -29,7 +29,7 @@ template <typename T, std::size_t level>
|
||||
struct vecvec {
|
||||
typedef std::vector<typename vecvec<T, level - 1>::type> type;
|
||||
static void fill(type& v, std::size_t num_of_elems, T const& val) {
|
||||
for (int elem = 0; elem < num_of_elems; ++elem) {
|
||||
for (std::size_t elem = 0; elem < num_of_elems; ++elem) {
|
||||
typename vecvec<T, level - 1>::type child;
|
||||
vecvec<T, level - 1>::fill(child, num_of_elems, val);
|
||||
v.push_back(child);
|
||||
@@ -41,7 +41,7 @@ template <typename T>
|
||||
struct vecvec<T, 0> {
|
||||
typedef std::vector<T> type;
|
||||
static void fill(type& v, std::size_t num_of_elems, T const& val) {
|
||||
for (int elem = 0; elem < num_of_elems; ++elem) {
|
||||
for (std::size_t elem = 0; elem < num_of_elems; ++elem) {
|
||||
v.push_back(val);
|
||||
}
|
||||
}
|
||||
@@ -50,9 +50,9 @@ struct vecvec<T, 0> {
|
||||
void test_array_of_array() {
|
||||
std::cout << "[TEST][array_of_array]" << std::endl;
|
||||
// setup
|
||||
int const depth = 16;
|
||||
int const depth = 4;
|
||||
std::cout << "Setting up array data..." << std::endl;
|
||||
typename vecvec<int, depth>::type v1;
|
||||
vecvec<int, depth>::type v1;
|
||||
vecvec<int, depth>::fill(v1, 3, 42);
|
||||
|
||||
std::cout << "Start packing..." << std::endl;
|
||||
@@ -77,7 +77,7 @@ void test_array_of_array() {
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
std::cout << "Unpack finished..." << std::endl;
|
||||
typename vecvec<int, depth>::type v2;
|
||||
vecvec<int, depth>::type v2;
|
||||
std::cout << "Start converting..." << std::endl;
|
||||
{
|
||||
boost::timer::cpu_timer timer;
|
||||
|
@@ -122,7 +122,7 @@ private:
|
||||
int main(void)
|
||||
{
|
||||
int pair[2];
|
||||
pipe(pair);
|
||||
if (pipe(pair) != 0) return -1;
|
||||
|
||||
// run server thread
|
||||
Server srv(pair[0]);
|
||||
|
28
example/cpp11/CMakeLists.txt
Normal file
28
example/cpp11/CMakeLists.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
IF (MSGPACK_CXX11)
|
||||
INCLUDE_DIRECTORIES (
|
||||
../include
|
||||
)
|
||||
|
||||
LIST (APPEND exec_PROGRAMS
|
||||
container.cpp
|
||||
non_def_con_class.cpp
|
||||
)
|
||||
|
||||
FOREACH (source_file ${exec_PROGRAMS})
|
||||
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
|
||||
ADD_EXECUTABLE (
|
||||
${source_file_we}
|
||||
${source_file}
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11 -Wall -Wextra -Werror -Wno-mismatched-tags -g -O3")
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDFOREACH ()
|
||||
ENDIF ()
|
@@ -29,7 +29,7 @@
|
||||
#include <msgpack.hpp>
|
||||
|
||||
void array() {
|
||||
std::array<int, 5> a { 1, 2, 3, 4, 5 };
|
||||
std::array<int, 5> a { { 1, 2, 3, 4, 5 } };
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, a);
|
||||
|
||||
@@ -77,7 +77,7 @@ void forward_list() {
|
||||
}
|
||||
|
||||
void combi() {
|
||||
std::array<int, 5> a { 1, 2, 3, 4, 5 };
|
||||
std::array<int, 5> a { { 1, 2, 3, 4, 5 } };
|
||||
std::tuple<bool, std::string, int> t {true, "ABC", 42};
|
||||
std::unordered_map<std::string, int> m { {"ABC", 1}, {"DEF", 3} };
|
||||
std::unordered_set<std::string> s { "ABC", "DEF" };
|
||||
|
@@ -5,6 +5,7 @@ FIND_PACKAGE (Threads REQUIRED)
|
||||
INCLUDE_DIRECTORIES (
|
||||
${GTEST_INCLUDE_DIRS}
|
||||
${ZLIB_INCLUDE_DIRS}
|
||||
${MSGPACK_BOOST_DIR}
|
||||
)
|
||||
|
||||
LIST (APPEND check_PROGRAMS
|
||||
@@ -69,8 +70,8 @@ FOREACH (source_file ${check_PROGRAMS})
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -Wno-mismatched-tags -g -O3")
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4] /WX")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
|
||||
ENDIF ()
|
||||
|
Reference in New Issue
Block a user