From aeda0e950ce080d9ae73c8d7703c0193c0061825 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 3 Feb 2019 11:03:46 +0100 Subject: Update signal_test to analyze object copying to transport signals --- test/signal_test.cpp | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/test/signal_test.cpp b/test/signal_test.cpp index 4370623..a34ed21 100644 --- a/test/signal_test.cpp +++ b/test/signal_test.cpp @@ -7,6 +7,27 @@ using namespace flat::core; +struct custom_type +{ + const char f; + + custom_type(char _f) : f(_f) { + npdebug("instanciated custom_type"); + } + + custom_type(const custom_type& other) : f(other.f) { + npdebug("copy constructed custom_type (bad)"); + } + + custom_type(custom_type&& other) : f(other.f) { + npdebug("move constructed custom_type (efficient)"); + } + + ~custom_type() { + npdebug("deleted custom_type instance"); + } +}; + void got_signal(int x, double y) { std::cout << "got signal with x=" << x << " and y=" << y << std::endl; @@ -30,22 +51,29 @@ public: std::cout << "emitting signal with n=" << n << std::endl; m_chan.emit(signal(n)); } + + void send_custom(const custom_type& c) { + std::cout << "emitting custom_type" << std::endl; + m_chan.emit(signal(c)); + } }; class test_listener { private: - template - using listener_of = typename std::shared_ptr>; + template + using listener_of = typename std::shared_ptr>; listener_of str_lis; listener_of num_lis; + listener_of cus_lis; public: test_listener(channel& ch) : str_lis(ch.connect(&test_listener::got_string, this)), - num_lis(ch.connect(&test_listener::got_number, this)) + num_lis(ch.connect(&test_listener::got_number, this)), + cus_lis(ch.connect(&test_listener::got_custom, this)) {} void got_string(std::string msg) { @@ -55,6 +83,10 @@ public: void got_number(int n) { std::cout << "got signal with n=" << n << std::endl; } + + void got_custom(custom_type c) { + std::cout << "got signal with custom_type" << std::endl; + } }; @@ -75,8 +107,7 @@ int main() { // auto lambda_lis = chan.connect([](char a) { // npdebug("got signal with a=", a); // }); - - chan.emit(signal('f')); + // chan.emit(signal('f')); // call job to propagate signals broadcaster(); @@ -87,6 +118,7 @@ int main() { e.send_str("hello world!"); e.send_num(42); + e.send_custom(custom_type('e')); // call job to propagate signals broadcaster(); -- cgit v1.2.1