diff --git a/example/cpp03/class_intrusive.cpp b/example/cpp03/class_intrusive.cpp index c27dcd4d..a5bb0819 100644 --- a/example/cpp03/class_intrusive.cpp +++ b/example/cpp03/class_intrusive.cpp @@ -1,10 +1,28 @@ +// MessagePack for C++ example +// +// Copyright (C) 2008-2015 FURUHASHI Sadayuki and 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 #include #include #include #include -#include +// msgpack.hpp is also ok +#include class my_class { @@ -39,6 +57,8 @@ void print(std::string const& buf) { std::cout << std::endl; } +#include + int main() { my_class my("John Smith", 42); std::stringstream ss; diff --git a/example/cpp03/class_non_intrusive.cpp b/example/cpp03/class_non_intrusive.cpp index c2eec5bf..57f10890 100644 --- a/example/cpp03/class_non_intrusive.cpp +++ b/example/cpp03/class_non_intrusive.cpp @@ -1,9 +1,27 @@ +// MessagePack for C++ example +// +// Copyright (C) 2008-2015 FURUHASHI Sadayuki and 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 #include #include #include #include +// msgpack.hpp should be included at after user declarations #include diff --git a/example/cpp03/custom.cpp b/example/cpp03/custom.cpp index 63cc4f4b..50296922 100644 --- a/example/cpp03/custom.cpp +++ b/example/cpp03/custom.cpp @@ -1,4 +1,22 @@ +// MessagePack for C++ example +// +// Copyright (C) 2008-2015 FURUHASHI Sadayuki and 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 +#include #include #include @@ -27,11 +45,11 @@ int main(void) old_class oc; new_class nc; - msgpack::sbuffer sbuf; + std::stringstream sbuf; msgpack::pack(sbuf, oc); msgpack::unpacked result; - msgpack::unpack(result, sbuf.data(), sbuf.size()); + msgpack::unpack(result, sbuf.str().data(), sbuf.str().size()); msgpack::object obj = result.get(); obj.convert(&nc); @@ -43,11 +61,11 @@ int main(void) new_class nc; old_class oc; - msgpack::sbuffer sbuf; + std::stringstream sbuf; msgpack::pack(sbuf, nc); msgpack::unpacked result; - msgpack::unpack(result, sbuf.data(), sbuf.size()); + msgpack::unpack(result, sbuf.str().data(), sbuf.str().size()); msgpack::object obj = result.get(); obj.convert(&oc); @@ -55,4 +73,3 @@ int main(void) std::cout << obj << " value=" << oc.value << std::endl; } } - diff --git a/example/cpp03/protocol.cpp b/example/cpp03/protocol.cpp index 5e08b291..b4462f5b 100644 --- a/example/cpp03/protocol.cpp +++ b/example/cpp03/protocol.cpp @@ -1,3 +1,20 @@ +// MessagePack for C++ example +// +// Copyright (C) 2008-2015 FURUHASHI Sadayuki and 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 #include #include @@ -84,4 +101,3 @@ int main(void) std::cout << "received: " << o << std::endl; } } - diff --git a/example/cpp03/simple.cpp b/example/cpp03/simple.cpp index 0dcb9d84..2eb4515a 100644 --- a/example/cpp03/simple.cpp +++ b/example/cpp03/simple.cpp @@ -1,3 +1,20 @@ +// MessagePack for C++ example +// +// Copyright (C) 2008-2015 FURUHASHI Sadayuki and 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 #include #include @@ -35,4 +52,3 @@ int main(void) return 0; } - diff --git a/example/cpp03/speed_test.cpp b/example/cpp03/speed_test.cpp index d13eb777..431fdc18 100644 --- a/example/cpp03/speed_test.cpp +++ b/example/cpp03/speed_test.cpp @@ -1,3 +1,20 @@ +// MessagePack for C++ example +// +// Copyright (C) 2013-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. +// + // g++ -std=c++11 -O3 -g -Ipath_to_msgpack_src -Ipath_to_boost speed_test.cc -Lpath_to_boost_lib -lboost_timer -lboost_system // export LD_LIBRARY_PATH=path_to_boost_lib @@ -52,4 +69,3 @@ int main(void) { test_map_pack_unpack(); } - diff --git a/example/cpp03/speed_test_nested_array.cpp b/example/cpp03/speed_test_nested_array.cpp index 40a87a99..c63249fa 100644 --- a/example/cpp03/speed_test_nested_array.cpp +++ b/example/cpp03/speed_test_nested_array.cpp @@ -1,3 +1,20 @@ +// MessagePack for C++ example +// +// Copyright (C) 2013-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. +// + // g++ -std=c++11 -O3 -g -Ipath_to_msgpack_src -Ipath_to_boost speed_test.cc -Lpath_to_boost_lib -lboost_timer -lboost_system // export LD_LIBRARY_PATH=path_to_boost_lib @@ -75,4 +92,3 @@ int main(void) { test_array_of_array(); } - diff --git a/example/cpp03/stream.cpp b/example/cpp03/stream.cpp index 326665cf..d5913614 100644 --- a/example/cpp03/stream.cpp +++ b/example/cpp03/stream.cpp @@ -1,3 +1,20 @@ +// MessagePack for C++ example +// +// Copyright (C) 2008-2015 FURUHASHI Sadayuki and 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 #include #include @@ -13,7 +30,7 @@ public: ~Server() { } - typedef msgpack::unique_ptr auto_zone; + typedef msgpack::unique_ptr unique_zone; void socket_readable() { @@ -37,7 +54,7 @@ public: msgpack::unpacked result; while (m_pac.next(&result)) { msgpack::object msg = result.get(); - auto_zone& life = result.zone(); + unique_zone& life = result.zone(); process_message(msg, life); } @@ -47,7 +64,7 @@ public: } private: - void process_message(msgpack::object msg, auto_zone& life) + void process_message(msgpack::object msg, unique_zone&) { std::cout << "message reached: " << msg << std::endl; } @@ -59,26 +76,27 @@ private: static void* run_server(void* arg) -try { - Server* srv = reinterpret_cast(arg); +{ + try { + Server* srv = reinterpret_cast(arg); - while(true) { - srv->socket_readable(); + while(true) { + srv->socket_readable(); + } + return NULL; + + } catch (std::exception& e) { + std::cerr << "error while processing client packet: " + << e.what() << std::endl; + return NULL; + + } catch (...) { + std::cerr << "error while processing client packet: " + << "unknown error" << std::endl; + return NULL; } - return NULL; - -} catch (std::exception& e) { - std::cerr << "error while processing client packet: " - << e.what() << std::endl; - return NULL; - -} catch (...) { - std::cerr << "error while processing client packet: " - << "unknown error" << std::endl; - return NULL; } - struct fwriter { fwriter(int fd) : m_fp( fdopen(fd, "w") ) { } @@ -130,4 +148,3 @@ int main(void) pthread_join(thread, NULL); } -