Skip to content

Commit 27a9d19

Browse files
committed
Added new example.
1 parent 4466bda commit 27a9d19

File tree

4 files changed

+70
-52
lines changed

4 files changed

+70
-52
lines changed

CMakeLists.txt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,25 @@ IF (MSGPACK_32BIT)
8888
ENDIF ()
8989
ENDIF ()
9090

91+
OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples." ON)
92+
9193
IF (MSGPACK_BOOST)
9294
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_BOOST ${CMAKE_CXX_FLAGS}")
93-
SET (Boost_USE_STATIC_LIBS ON) # only find static libs
94-
SET (Boost_USE_MULTITHREADED ON)
95-
SET (Boost_USE_STATIC_RUNTIME OFF)
96-
FIND_PACKAGE (Boost COMPONENTS chrono timer system)
97-
IF (Boost_INCLUDE_DIRS)
98-
INCLUDE_DIRECTORIES (
99-
${Boost_INCLUDE_DIRS}
100-
)
101-
ENDIF ()
102-
INCLUDE_DIRECTORIES (
103-
${MSGPACK_BOOST_DIR}
104-
)
95+
ENDIF ()
96+
97+
SET (Boost_USE_STATIC_LIBS ON) # only find static libs
98+
SET (Boost_USE_MULTITHREADED ON)
99+
SET (Boost_USE_STATIC_RUNTIME OFF)
100+
FIND_PACKAGE (Boost COMPONENTS chrono context timer system)
101+
IF (Boost_INCLUDE_DIRS)
102+
INCLUDE_DIRECTORIES (
103+
${Boost_INCLUDE_DIRS}
104+
)
105+
ENDIF ()
106+
IF (MSGPACK_BOOST_DIR)
107+
INCLUDE_DIRECTORIES (
108+
${MSGPACK_BOOST_DIR}
109+
)
105110
ENDIF ()
106111

107112
IF (MSGPACK_CHAR_SIGN)
@@ -141,7 +146,6 @@ FIND_PACKAGE (Threads)
141146
IF (GTEST_FOUND AND ZLIB_FOUND AND THREADS_FOUND)
142147
OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." ON)
143148
ENDIF ()
144-
OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples." ON)
145149

146150
OPTION (MSGPACK_ENABLE_CXX "Enable C++ interface." ON)
147151
OPTION (MSGPACK_ENABLE_SHARED "Build shared libaries in addition to static libraries." ON)

example/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ ADD_SUBDIRECTORY (c)
22
ADD_SUBDIRECTORY (cpp03)
33
ADD_SUBDIRECTORY (cpp11)
44
ADD_SUBDIRECTORY (boost)
5+
ADD_SUBDIRECTORY (x3)

example/cpp03/CMakeLists.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ IF (NOT MSVC)
2222
)
2323
ENDIF ()
2424

25-
IF (MSGPACK_BOOST)
26-
IF (NOT MSVC)
27-
LIST (APPEND with_boost_lib_PROGRAMS
28-
speed_test.cpp
29-
speed_test_nested_array.cpp
30-
)
31-
ENDIF ()
25+
IF (Boost_TIMER_LIBRARY AND Boost_CHRONO_LIBRARY AND Boost_SYSTEM_LIBRARY)
26+
LIST (APPEND with_boost_lib_PROGRAMS
27+
speed_test.cpp
28+
speed_test_nested_array.cpp
29+
)
3230
ENDIF ()
3331

3432
FOREACH (source_file ${exec_PROGRAMS})
@@ -56,10 +54,10 @@ FOREACH (source_file ${with_pthread_PROGRAMS})
5654
${source_file}
5755
)
5856
TARGET_LINK_LIBRARIES (${source_file_we}
59-
pthread
57+
${CMAKE_THREAD_LIBS_INIT}
6058
)
6159
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
62-
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -g -O3 -pthread")
60+
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -g -O3")
6361
ENDIF ()
6462
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
6563
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")

include/msgpack/v2/x3_parse.hpp

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,16 @@ const auto mp_object_def =
332332
)
333333
]
334334
>>
335-
x3:: raw [
335+
x3::raw [
336336
*(x3::eps [more] >> x3::char_)
337337
>> x3::eps [done]
338338
][
339339
(
340340
[](auto& ctx){
341341
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
342342
auto const& str = _attr(ctx);
343-
app_specific.vis.visit_str(str.size() ? &str[0] : nullptr, str.size());
343+
std::size_t size = std::distance(str.begin(), str.end());
344+
app_specific.vis.visit_str(size ? &str.front() : nullptr, size);
344345
}
345346
)
346347
]
@@ -355,15 +356,16 @@ const auto mp_object_def =
355356
)
356357
]
357358
>>
358-
x3:: raw [
359+
x3::raw [
359360
*(x3::eps [more] >> x3::char_)
360361
>> x3::eps [done]
361362
][
362363
(
363364
[](auto& ctx){
364365
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
365366
auto const& str = _attr(ctx);
366-
app_specific.vis.visit_str(str.size() ? &str[0] : nullptr, str.size());
367+
std::size_t size = std::distance(str.begin(), str.end());
368+
app_specific.vis.visit_str(size ? &str.front() : nullptr, size);
367369
}
368370
)
369371
]
@@ -378,15 +380,16 @@ const auto mp_object_def =
378380
)
379381
]
380382
>>
381-
x3:: raw [
383+
x3::raw [
382384
*(x3::eps [more] >> x3::char_)
383385
>> x3::eps [done]
384386
][
385387
(
386388
[](auto& ctx){
387389
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
388390
auto const& str = _attr(ctx);
389-
app_specific.vis.visit_str(str.size() ? &str[0] : nullptr, str.size());
391+
std::size_t size = std::distance(str.begin(), str.end());
392+
app_specific.vis.visit_str(size ? &str.front() : nullptr, size);
390393
}
391394
)
392395
]
@@ -401,15 +404,16 @@ const auto mp_object_def =
401404
)
402405
]
403406
>>
404-
x3:: raw [
407+
x3::raw [
405408
*(x3::eps [more] >> x3::char_)
406409
>> x3::eps [done]
407410
][
408411
(
409412
[](auto& ctx){
410413
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
411414
auto const& str = _attr(ctx);
412-
app_specific.vis.visit_str(str.size() ? &str[0] : nullptr, str.size());
415+
std::size_t size = std::distance(str.begin(), str.end());
416+
app_specific.vis.visit_str(size ? &str.front() : nullptr, size);
413417
}
414418
)
415419
]
@@ -424,15 +428,16 @@ const auto mp_object_def =
424428
)
425429
]
426430
>>
427-
x3:: raw [
431+
x3::raw [
428432
*(x3::eps [more] >> x3::char_)
429433
>> x3::eps [done]
430434
][
431435
(
432436
[](auto& ctx){
433437
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
434438
auto const& bin = _attr(ctx);
435-
app_specific.vis.visit_bin(bin.size() ? &bin[0] : nullptr, bin.size());
439+
std::size_t size = std::distance(bin.begin(), bin.end());
440+
app_specific.vis.visit_bin(size ? &bin.front() : nullptr, size);
436441
}
437442
)
438443
]
@@ -447,15 +452,16 @@ const auto mp_object_def =
447452
)
448453
]
449454
>>
450-
x3:: raw [
455+
x3::raw [
451456
*(x3::eps [more] >> x3::char_)
452457
>> x3::eps [done]
453458
][
454459
(
455460
[](auto& ctx){
456461
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
457462
auto const& bin = _attr(ctx);
458-
app_specific.vis.visit_bin(bin.size() ? &bin[0] : nullptr, bin.size());
463+
std::size_t size = std::distance(bin.begin(), bin.end());
464+
app_specific.vis.visit_bin(size ? &bin.front() : nullptr, size);
459465
}
460466
)
461467
]
@@ -470,15 +476,16 @@ const auto mp_object_def =
470476
)
471477
]
472478
>>
473-
x3:: raw [
479+
x3::raw [
474480
*(x3::eps [more] >> x3::char_)
475481
>> x3::eps [done]
476482
][
477483
(
478484
[](auto& ctx){
479485
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
480486
auto const& bin = _attr(ctx);
481-
app_specific.vis.visit_bin(bin.size() ? &bin[0] : nullptr, bin.size());
487+
std::size_t size = std::distance(bin.begin(), bin.end());
488+
app_specific.vis.visit_bin(size ? &bin.front() : nullptr, size);
482489
}
483490
)
484491
]
@@ -577,15 +584,16 @@ const auto mp_object_def =
577584
)
578585
]
579586
>>
580-
x3:: raw [
587+
x3::raw [
581588
*(x3::eps [more] >> x3::char_)
582589
>> x3::eps [done]
583590
][
584591
(
585592
[](auto& ctx){
586593
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
587594
auto const& ext = _attr(ctx);
588-
app_specific.vis.visit_ext(ext.size() ? &ext[0] : nullptr, ext.size());
595+
std::size_t size = std::distance(ext.begin(), ext.end());
596+
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
589597
}
590598
)
591599
]
@@ -600,15 +608,16 @@ const auto mp_object_def =
600608
)
601609
]
602610
>>
603-
x3:: raw [
611+
x3::raw [
604612
*(x3::eps [more] >> x3::char_)
605613
>> x3::eps [done]
606614
][
607615
(
608616
[](auto& ctx){
609617
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
610618
auto const& ext = _attr(ctx);
611-
app_specific.vis.visit_ext(ext.size() ? &ext[0] : nullptr, ext.size());
619+
std::size_t size = std::distance(ext.begin(), ext.end());
620+
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
612621
}
613622
)
614623
]
@@ -623,15 +632,16 @@ const auto mp_object_def =
623632
)
624633
]
625634
>>
626-
x3:: raw [
635+
x3::raw [
627636
*(x3::eps [more] >> x3::char_)
628637
>> x3::eps [done]
629638
][
630639
(
631640
[](auto& ctx){
632641
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
633642
auto const& ext = _attr(ctx);
634-
app_specific.vis.visit_ext(ext.size() ? &ext[0] : nullptr, ext.size());
643+
std::size_t size = std::distance(ext.begin(), ext.end());
644+
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
635645
}
636646
)
637647
]
@@ -646,15 +656,16 @@ const auto mp_object_def =
646656
)
647657
]
648658
>>
649-
x3:: raw [
659+
x3::raw [
650660
*(x3::eps [more] >> x3::char_)
651661
>> x3::eps [done]
652662
][
653663
(
654664
[](auto& ctx){
655665
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
656666
auto const& ext = _attr(ctx);
657-
app_specific.vis.visit_ext(ext.size() ? &ext[0] : nullptr, ext.size());
667+
std::size_t size = std::distance(ext.begin(), ext.end());
668+
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
658669
}
659670
)
660671
]
@@ -669,15 +680,16 @@ const auto mp_object_def =
669680
)
670681
]
671682
>>
672-
x3:: raw [
683+
x3::raw [
673684
*(x3::eps [more] >> x3::char_)
674685
>> x3::eps [done]
675686
][
676687
(
677688
[](auto& ctx){
678689
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
679690
auto const& ext = _attr(ctx);
680-
app_specific.vis.visit_ext(ext.size() ? &ext[0] : nullptr, ext.size());
691+
std::size_t size = std::distance(ext.begin(), ext.end());
692+
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
681693
}
682694
)
683695
]
@@ -692,15 +704,16 @@ const auto mp_object_def =
692704
)
693705
]
694706
>>
695-
x3:: raw [
707+
x3::raw [
696708
*(x3::eps [more] >> x3::char_)
697709
>> x3::eps [done]
698710
][
699711
(
700712
[](auto& ctx){
701713
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
702714
auto const& ext = _attr(ctx);
703-
app_specific.vis.visit_ext(ext.size() ? &ext[0] : nullptr, ext.size());
715+
std::size_t size = std::distance(ext.begin(), ext.end());
716+
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
704717
}
705718
)
706719
]
@@ -715,15 +728,16 @@ const auto mp_object_def =
715728
)
716729
]
717730
>>
718-
x3:: raw [
731+
x3::raw [
719732
*(x3::eps [more] >> x3::char_)
720733
>> x3::eps [done]
721734
][
722735
(
723736
[](auto& ctx){
724737
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
725738
auto const& ext = _attr(ctx);
726-
app_specific.vis.visit_ext(ext.size() ? &ext[0] : nullptr, ext.size());
739+
std::size_t size = std::distance(ext.begin(), ext.end());
740+
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
727741
}
728742
)
729743
]
@@ -738,15 +752,16 @@ const auto mp_object_def =
738752
)
739753
]
740754
>>
741-
x3:: raw [
755+
x3::raw [
742756
*(x3::eps [more] >> x3::char_)
743757
>> x3::eps [done]
744758
][
745759
(
746760
[](auto& ctx){
747761
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
748762
auto const& ext = _attr(ctx);
749-
app_specific.vis.visit_ext(ext.size() ? &ext[0] : nullptr, ext.size());
763+
std::size_t size = std::distance(ext.begin(), ext.end());
764+
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
750765
}
751766
)
752767
];

0 commit comments

Comments
 (0)