summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2022-08-15 15:16:58 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2022-08-15 15:16:58 +0200
commitf96dcf11d1831035b8f0dd701bc58264edde0759 (patch)
treecdd7adbfd62122918ebc4c17ab2fc9294711307d
parent27bcd70692f6955060e66b8a8e8f29df7d38bbde (diff)
downloadsigc++-f96dcf11d1831035b8f0dd701bc58264edde0759.tar.gz
Fix build with -Dbuild-deprecated-api=false
Fixes #82
-rw-r--r--examples/meson.build2
-rw-r--r--meson.build2
-rw-r--r--tests/test_cpp11_lambda.cc12
-rw-r--r--tests/test_disconnect.cc15
-rw-r--r--tests/test_track_obj.cc30
5 files changed, 51 insertions, 10 deletions
diff --git a/examples/meson.build b/examples/meson.build
index c55bfdd..3c575ae 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -20,7 +20,7 @@ foreach ex : examples
endforeach
exe_file = executable(ex_name, ex_sources,
- cpp_args: '-DSIGCXX_DISABLE_DEPRECATED',
+ cpp_args: '-DSIGCXX_DISABLE_DEPRECATED=1',
dependencies: sigcxx_own_dep,
implicit_include_directories: false,
build_by_default: build_examples
diff --git a/meson.build b/meson.build
index 31cf8ab..25db8a9 100644
--- a/meson.build
+++ b/meson.build
@@ -221,7 +221,7 @@ pkg_conf_data.set('PACKAGE_VERSION', meson.project_version())
pkg_conf_data.set('SIGCXX_API_VERSION', sigcxx_api_version)
if not build_deprecated_api
- pkg_conf_data.set('SIGCXX_DISABLE_DEPRECATED', true)
+ pkg_conf_data.set('SIGCXX_DISABLE_DEPRECATED', 1)
endif
pkg_conf_data.set('SIGCXX_MAJOR_VERSION', sigcxx_major_version)
pkg_conf_data.set('SIGCXX_MINOR_VERSION', sigcxx_minor_version)
diff --git a/tests/test_cpp11_lambda.cc b/tests/test_cpp11_lambda.cc
index 2e4acf8..42b6caa 100644
--- a/tests/test_cpp11_lambda.cc
+++ b/tests/test_cpp11_lambda.cc
@@ -32,7 +32,7 @@
// The only real disadvantage of the C++11 lambda expressions is that a slot that
// contains an object derived from sigc::trackable is not automatically disconnected
// when the object is deleted, if a reference to the object is stored in a C++11
-// lambda expression, connected to the slot. But if you use sigc::track_obj(),
+// lambda expression, connected to the slot. But if you use sigc::track_object(),
// the slot is automatically disconnected. Thus, the disadvantage is insignificant.
//
// To test the C++11 lambda expressions with gcc 4.6.3 (and probably some later
@@ -265,13 +265,13 @@ int main(int argc, char* argv[])
// Here's an area where the libsigc++ lambda expressions are advantageous.
// If you want to auto-disconnect a slot with a C++11 lambda expression
// that contains references to sigc::trackable-derived objects, you must use
- // sigc::track_obj().
+ // sigc::track_object().
sigc::slot<void, std::ostringstream&> sl1;
{
book guest_book("karl");
//sl1 = (sigc::var(std::cout) << std::ref(guest_book) << sigc::var("\n"));
// sl1 = [&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; }; // no auto-disconnect
- sl1 = sigc::track_obj([&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; }, guest_book);
+ sl1 = sigc::track_object([&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; }, guest_book);
sl1(result_stream);
util->check_result(result_stream, "karl\n");
@@ -323,7 +323,7 @@ int main(int argc, char* argv[])
//sl2 = sigc::group(&egon, std::ref(guest_book));
// sl2 = [&guest_book] () { egon(guest_book); }; // no auto-disconnect
// sl2 = std::bind(&egon, std::ref(guest_book)); // does not compile (gcc 4.6.3)
- sl2 = sigc::track_obj([&guest_book] () { egon(guest_book); }, guest_book);
+ sl2 = sigc::track_object([&guest_book] () { egon(guest_book); }, guest_book);
sl2();
util->check_result(result_stream, "egon(string 'karl')");
@@ -343,7 +343,7 @@ int main(int argc, char* argv[])
// sl2 = std::bind(&egon, std::ref(guest_book)); // does not compile (gcc 4.6.3)
auto fn2 = std::bind(&egon, std::ref(guest_book));
//sl2 = fn2; // no auto-disconnect
- sl2 = sigc::track_obj(fn2, guest_book);
+ sl2 = sigc::track_object(fn2, guest_book);
sl2();
util->check_result(result_stream, "egon(string 'charlie')");
@@ -487,7 +487,7 @@ int main(int argc, char* argv[])
// disconnected automatically if some_bar goes out of scope
//some_signal.connect([&some_bar](){ foo_group4(some_bar); }); // no auto-disconnect
//some_signal.connect(sigc::bind(&foo_group4, std::ref(some_bar))); // auto-disconnects, but we prefer C++11 lambda
- some_signal.connect(sigc::track_obj([&some_bar](){ foo_group4(some_bar); }, some_bar));
+ some_signal.connect(sigc::track_object([&some_bar](){ foo_group4(some_bar); }, some_bar));
some_signal.emit();
util->check_result(result_stream, "foo_group4(bar_group4&)");
}
diff --git a/tests/test_disconnect.cc b/tests/test_disconnect.cc
index 85b1680..2d040d8 100644
--- a/tests/test_disconnect.cc
+++ b/tests/test_disconnect.cc
@@ -2,6 +2,12 @@
* Assigned to public domain. Use as you wish without restriction.
*/
+// sigc::signal<>.slots() is deprecated, but let's keep the test if possible.
+// If libsigc++ is configured with -Dbuild-deprecated-api=false
+// (--disable-deprecated-api), SIGCXX_DISABLE_DEPRECATED is defined in
+// sigc++config.h. An undef at the start of this file has no effect.
+#undef SIGCXX_DISABLE_DEPRECATED
+
#include "testutilities.h"
#include <sigc++/trackable.h>
#include <sigc++/signal.h>
@@ -103,11 +109,20 @@ int main(int argc, char* argv[])
util->check_result(result_stream, "sig is connected to foo, bar (size=2): foo(2) bar(2) ");
A a; // iterators stay valid after further connections.
+#ifndef SIGCXX_DISABLE_DEPRECATED
cona = sig.slots().insert(conbar, sigc::mem_fun1(a, &A::foo));
+#else
+ cona = sig.connect(sigc::mem_fun1(a, &A::foo));
+#endif
result_stream << "sig is connected to foo, A::foo, bar (size=" << sig.size() << "): ";
sig(3);
+#ifndef SIGCXX_DISABLE_DEPRECATED
util->check_result(result_stream,
"sig is connected to foo, A::foo, bar (size=3): foo(3) A::foo(3) bar(3) ");
+#else
+ util->check_result(result_stream,
+ "sig is connected to foo, A::foo, bar (size=3): foo(3) bar(3) A::foo(3) ");
+#endif
conbar->disconnect(); // manual disconnection
result_stream << "sig is connected to foo, A::foo (size=" << sig.size() << "): ";
diff --git a/tests/test_track_obj.cc b/tests/test_track_obj.cc
index 3a7cf41..55c7635 100644
--- a/tests/test_track_obj.cc
+++ b/tests/test_track_obj.cc
@@ -28,6 +28,12 @@
//
// If test_track_obj writes nothing and the return code is 0, the test has passed.
+// sigc::track_obj() is deprecated, but let's keep the test if possible.
+// If libsigc++ is configured with -Dbuild-deprecated-api=false
+// (--disable-deprecated-api), SIGCXX_DISABLE_DEPRECATED is defined in
+// sigc++config.h. An undef at the start of this file has no effect.
+#undef SIGCXX_DISABLE_DEPRECATED
+
#include "testutilities.h"
#include <string>
#include <iostream>
@@ -36,7 +42,6 @@
#include <sigc++/adaptors/track_obj.h>
#include <sigc++/signal.h>
-
namespace
{
std::ostringstream result_stream;
@@ -127,7 +132,11 @@ int main(int argc, char* argv[])
sigc::slot<std::string, int> sl2;
{
bar_group4 bar4;
+#ifndef SIGCXX_DISABLE_DEPRECATED
sl1 = sigc::track_obj(Functor1(bar4), bar4);
+#else
+ sl1 = sigc::track_object(Functor1(bar4), bar4);
+#endif
sl2 = sigc::track_object(Functor1(bar4), bar4);
result_stream << sl1(-2) << ", " << sl2(2);
util->check_result(result_stream, "negative, positive");
@@ -143,7 +152,11 @@ int main(int argc, char* argv[])
auto psl4 = new sigc::slot<std::string, int, std::string>;
bar_group4* pbar4 = new bar_group4;
book* pbook4 = new book("A Book");
+#ifndef SIGCXX_DISABLE_DEPRECATED
*psl3 = sigc::track_obj(Functor2(*pbar4, *pbook4), *pbar4, *pbook4);
+#else
+ *psl3 = sigc::track_object(Functor2(*pbar4, *pbook4), *pbar4, *pbook4);
+#endif
*psl4 = sigc::track_object(Functor2(*pbar4, *pbook4), *pbar4, *pbook4);
result_stream << (*psl3)(0, "Book title: ") << ", " << (*psl4)(1, "Title: ");
util->check_result(result_stream, "zero, Book title: A Book, positive, Title: A Book");
@@ -170,8 +183,13 @@ int main(int argc, char* argv[])
{
book guest_book("karl");
// sl1 = [&guest_book](std::ostringstream& stream){ stream << guest_book << "\n"; }; // no auto-disconnect
+#ifndef SIGCXX_DISABLE_DEPRECATED
sl11 = sigc::track_obj(
[&guest_book](std::ostringstream& stream) { stream << guest_book; }, guest_book);
+#else
+ sl11 = sigc::track_object(
+ [&guest_book](std::ostringstream& stream) { stream << guest_book; }, guest_book);
+#endif
sl12 = sigc::track_object(
[&guest_book](std::ostringstream& stream) { stream << guest_book; }, guest_book);
sl11(result_stream);
@@ -191,8 +209,12 @@ int main(int argc, char* argv[])
book guest_book("karl");
// sl2 = [&guest_book] () { egon(guest_book); }; // no auto-disconnect
// sl2 = std::bind(&egon, std::ref(guest_book)); // does not compile (gcc 4.6.3)
+#ifndef SIGCXX_DISABLE_DEPRECATED
sl21 = sigc::track_obj([&guest_book]() { egon(guest_book); }, guest_book);
- sl22 = sigc::track_obj([&guest_book]() { egon(guest_book); }, guest_book);
+#else
+ sl21 = sigc::track_object([&guest_book]() { egon(guest_book); }, guest_book);
+#endif
+ sl22 = sigc::track_object([&guest_book]() { egon(guest_book); }, guest_book);
sl21();
sl22();
util->check_result(result_stream, "egon(string 'karl')egon(string 'egon was here')");
@@ -217,7 +239,11 @@ int main(int argc, char* argv[])
// disconnected automatically if some_bar goes out of scope
//some_signal.connect([&some_bar](){ foo_group4(some_bar); }); // no auto-disconnect
//some_signal.connect(sigc::bind(&foo_group4, std::ref(some_bar))); // auto-disconnects, but we prefer C++11 lambda
+#ifndef SIGCXX_DISABLE_DEPRECATED
some_signal.connect(sigc::track_obj([&some_bar](){ foo_group4(some_bar); }, some_bar));
+#else
+ some_signal.connect(sigc::track_object([&some_bar](){ foo_group4(some_bar); }, some_bar));
+#endif
some_signal.connect(sigc::track_object([&some_bar](){ foo_group4(some_bar); }, some_bar));
some_signal.emit();
util->check_result(result_stream, "foo_group4(bar_group4&)foo_group4(bar_group4&)");