Added support for cv-qualifiers in Callback class

Additionally, the following changes were don to avoid combinatorial
explosion in function overloads as a result of adding cv-qualifiers:
- Added convenience function for inferred type
- Deprecated callback overloads qhere cv-qualifiers are not scalable

Supported overloads:
callback(void (*f)(A...));
callback(const Callback<R(A...)> &);
callback(T *t,                void (*f)(T*, A...));
callback(const T *t,          void (*f)(const T*, A...));
callback(volatile T *t,       void (*f)(volatile T*, A...));
callback(const volatile T *t, void (*f)(const volatile T*, A...));
callback(T *t,                void (T::*f)(A...));
callback(const T *t,          void (T::*f)(A...) const);
callback(volatile T *t,       void (T::*f)(A...) volatile);
callback(const volatile T *t, void (T::*f)(A...) const volatile);
pull/2496/head
Christopher Haster 2016-08-18 13:28:57 -05:00
parent 030261f2c4
commit 45d25ed493
9 changed files with 2131 additions and 967 deletions

View File

@ -8,17 +8,17 @@ using namespace utest::v1;
// static functions
template <typename T>
T static_func5(T a0, T a1, T a2, T a3, T a4) { return a0 | a1 | a2 | a3 | a4; }
template <typename T>
T static_func4(T a0, T a1, T a2, T a3) { return a0 | a1 | a2 | a3; }
template <typename T>
T static_func3(T a0, T a1, T a2) { return a0 | a1 | a2; }
template <typename T>
T static_func2(T a0, T a1) { return a0 | a1; }
template <typename T>
T static_func1(T a0) { return a0; }
template <typename T>
T static_func0() { return 0; }
template <typename T>
T static_func1(T a0) { return 0 | a0; }
template <typename T>
T static_func2(T a0, T a1) { return 0 | a0 | a1; }
template <typename T>
T static_func3(T a0, T a1, T a2) { return 0 | a0 | a1 | a2; }
template <typename T>
T static_func4(T a0, T a1, T a2, T a3) { return 0 | a0 | a1 | a2 | a3; }
template <typename T>
T static_func5(T a0, T a1, T a2, T a3, T a4) { return 0 | a0 | a1 | a2 | a3 | a4; }
// class functions
template <typename T>
@ -26,134 +26,95 @@ struct Thing {
T t;
Thing() : t(0x80) {}
T member_func5(T a0, T a1, T a2, T a3, T a4) { return t | a0 | a1 | a2 | a3 | a4; }
T member_func4(T a0, T a1, T a2, T a3) { return t | a0 | a1 | a2 | a3; }
T member_func3(T a0, T a1, T a2) { return t | a0 | a1 | a2; }
T member_func2(T a0, T a1) { return t | a0 | a1; }
T member_func1(T a0) { return t | a0; }
T member_func0() { return t; }
T member_func1(T a0) { return t | a0; }
T member_func2(T a0, T a1) { return t | a0 | a1; }
T member_func3(T a0, T a1, T a2) { return t | a0 | a1 | a2; }
T member_func4(T a0, T a1, T a2, T a3) { return t | a0 | a1 | a2 | a3; }
T member_func5(T a0, T a1, T a2, T a3, T a4) { return t | a0 | a1 | a2 | a3 | a4; }
T const_member_func0() const { return t; }
T const_member_func1(T a0) const { return t | a0; }
T const_member_func2(T a0, T a1) const { return t | a0 | a1; }
T const_member_func3(T a0, T a1, T a2) const { return t | a0 | a1 | a2; }
T const_member_func4(T a0, T a1, T a2, T a3) const { return t | a0 | a1 | a2 | a3; }
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const { return t | a0 | a1 | a2 | a3 | a4; }
T volatile_member_func0() volatile { return t; }
T volatile_member_func1(T a0) volatile { return t | a0; }
T volatile_member_func2(T a0, T a1) volatile { return t | a0 | a1; }
T volatile_member_func3(T a0, T a1, T a2) volatile { return t | a0 | a1 | a2; }
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile { return t | a0 | a1 | a2 | a3; }
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile { return t | a0 | a1 | a2 | a3 | a4; }
T const_volatile_member_func0() const volatile { return t; }
T const_volatile_member_func1(T a0) const volatile { return t | a0; }
T const_volatile_member_func2(T a0, T a1) const volatile { return t | a0 | a1; }
T const_volatile_member_func3(T a0, T a1, T a2) const volatile { return t | a0 | a1 | a2; }
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile { return t | a0 | a1 | a2 | a3; }
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile { return t | a0 | a1 | a2 | a3 | a4; }
};
// bound functions
template <typename T>
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T bound_func3(Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
template <typename T>
T bound_func2(Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
T bound_func0(Thing<T> *t) { return t->t; }
template <typename T>
T bound_func1(Thing<T> *t, T a0) { return t->t | a0; }
template <typename T>
T bound_func0(Thing<T> *t) { return t->t; }
T bound_func2(Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
template <typename T>
T bound_func3(Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
template <typename T>
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
// const bound functions
template <typename T>
T const_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T const_func4(const Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T const_func3(const Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
template <typename T>
T const_func2(const Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
T const_func0(const Thing<T> *t) { return t->t; }
template <typename T>
T const_func1(const Thing<T> *t, T a0) { return t->t | a0; }
template <typename T>
T const_func0(const Thing<T> *t) { return t->t; }
T const_func2(const Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
template <typename T>
T const_func3(const Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
template <typename T>
T const_func4(const Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T const_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
// volatile bound functions
template <typename T>
T volatile_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T volatile_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T volatile_func3(volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
template <typename T>
T volatile_func2(volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
T volatile_func0(volatile Thing<T> *t) { return t->t; }
template <typename T>
T volatile_func1(volatile Thing<T> *t, T a0) { return t->t | a0; }
template <typename T>
T volatile_func0(volatile Thing<T> *t) { return t->t; }
T volatile_func2(volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
template <typename T>
T volatile_func3(volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
template <typename T>
T volatile_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T volatile_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
// const volatil bound functions
// const volatile bound functions
template <typename T>
T const_volatile_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T const_volatile_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T const_volatile_func3(const volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
template <typename T>
T const_volatile_func2(const volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
T const_volatile_func0(const volatile Thing<T> *t) { return t->t; }
template <typename T>
T const_volatile_func1(const volatile Thing<T> *t, T a0) { return t->t | a0; }
template <typename T>
T const_volatile_func0(const volatile Thing<T> *t) { return t->t; }
T const_volatile_func2(const volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
template <typename T>
T const_volatile_func3(const volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
template <typename T>
T const_volatile_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T const_volatile_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
// function call and result verification
template <typename T>
struct Verifier {
static void verify5(Callback<T(T,T,T,T,T)> func) {
T result = func(0x01, 0x02, 0x04, 0x08, 0x10);
TEST_ASSERT_EQUAL(result, 0x1f);
}
template <typename O, typename M>
static void verify5(O *obj, M method) {
Callback<T(T,T,T,T,T)> func(obj, method);
T result = func(0x01, 0x02, 0x04, 0x08, 0x10);
TEST_ASSERT_EQUAL(result, 0x9f);
}
static void verify4(Callback<T(T,T,T,T)> func) {
T result = func(0x01, 0x02, 0x04, 0x08);
TEST_ASSERT_EQUAL(result, 0x0f);
}
template <typename O, typename M>
static void verify4(O *obj, M method) {
Callback<T(T,T,T,T)> func(obj, method);
T result = func(0x01, 0x02, 0x04, 0x08);
TEST_ASSERT_EQUAL(result, 0x8f);
}
static void verify3(Callback<T(T,T,T)> func) {
T result = func(0x01, 0x02, 0x04);
TEST_ASSERT_EQUAL(result, 0x07);
}
template <typename O, typename M>
static void verify3(O *obj, M method) {
Callback<T(T,T,T)> func(obj, method);
T result = func(0x01, 0x02, 0x04);
TEST_ASSERT_EQUAL(result, 0x87);
}
static void verify2(Callback<T(T,T)> func) {
T result = func(0x01, 0x02);
TEST_ASSERT_EQUAL(result, 0x03);
}
template <typename O, typename M>
static void verify2(O *obj, M method) {
Callback<T(T,T)> func(obj, method);
T result = func(0x01, 0x02);
TEST_ASSERT_EQUAL(result, 0x83);
}
static void verify1(Callback<T(T)> func) {
T result = func(0x01);
TEST_ASSERT_EQUAL(result, 0x01);
}
template <typename O, typename M>
static void verify1(O *obj, M method) {
Callback<T(T)> func(obj, method);
T result = func(0x01);
TEST_ASSERT_EQUAL(result, 0x81);
}
static void verify0(Callback<T()> func) {
T result = func();
TEST_ASSERT_EQUAL(result, 0x00);
@ -165,76 +126,97 @@ struct Verifier {
T result = func();
TEST_ASSERT_EQUAL(result, 0x80);
}
static void verify1(Callback<T(T)> func) {
T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
}
template <typename O, typename M>
static void verify1(O *obj, M method) {
Callback<T(T)> func(obj, method);
T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0));
}
static void verify2(Callback<T(T, T)> func) {
T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
}
template <typename O, typename M>
static void verify2(O *obj, M method) {
Callback<T(T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1));
}
static void verify3(Callback<T(T, T, T)> func) {
T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
}
template <typename O, typename M>
static void verify3(O *obj, M method) {
Callback<T(T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2));
}
static void verify4(Callback<T(T, T, T, T)> func) {
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
}
template <typename O, typename M>
static void verify4(O *obj, M method) {
Callback<T(T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
}
static void verify5(Callback<T(T, T, T, T, T)> func) {
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
}
template <typename O, typename M>
static void verify5(O *obj, M method) {
Callback<T(T, T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
}
};
// test dispatch
template <typename T>
void test_dispatch5() {
void test_dispatch0() {
Thing<T> thing;
Verifier<T>::verify5(static_func5<T>);
Verifier<T>::verify5(&thing, &Thing<T>::member_func5);
Verifier<T>::verify5(&thing, &bound_func5<T>);
Verifier<T>::verify5((const Thing<T>*)&thing, &const_func5<T>);
Verifier<T>::verify5((volatile Thing<T>*)&thing, &volatile_func5<T>);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &const_volatile_func5<T>);
Verifier<T>::verify0(static_func0<T>);
Verifier<T>::verify0(&thing, &Thing<T>::member_func0);
Verifier<T>::verify0((const Thing<T>*)&thing, &Thing<T>::const_member_func0);
Verifier<T>::verify0((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func0);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func0);
Verifier<T>::verify0(&thing, &bound_func0<T>);
Verifier<T>::verify0((const Thing<T>*)&thing, &const_func0<T>);
Verifier<T>::verify0((volatile Thing<T>*)&thing, &volatile_func0<T>);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &const_volatile_func0<T>);
Verifier<T>::verify0(callback(static_func0<T>));
Verifier<T>::verify0(callback(&thing, &Thing<T>::member_func0));
Verifier<T>::verify0(callback((const Thing<T>*)&thing, &Thing<T>::const_member_func0));
Verifier<T>::verify0(callback((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func0));
Verifier<T>::verify0(callback((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func0));
Verifier<T>::verify0(callback(&thing, &bound_func0<T>));
Verifier<T>::verify0(callback((const Thing<T>*)&thing, &const_func0<T>));
Verifier<T>::verify0(callback((volatile Thing<T>*)&thing, &volatile_func0<T>));
Verifier<T>::verify0(callback((const volatile Thing<T>*)&thing, &const_volatile_func0<T>));
Callback<T(T,T,T,T,T)> callback(static_func5);
Verifier<T>::verify5(callback);
callback.attach(&thing, &bound_func5<T>);
Verifier<T>::verify5(&callback, &Callback<T(T,T,T,T,T)>::call);
Verifier<T>::verify5((void*)&callback, &Callback<T(T,T,T,T,T)>::thunk);
}
template <typename T>
void test_dispatch4() {
Thing<T> thing;
Verifier<T>::verify4(static_func4<T>);
Verifier<T>::verify4(&thing, &Thing<T>::member_func4);
Verifier<T>::verify4(&thing, &bound_func4<T>);
Verifier<T>::verify4((const Thing<T>*)&thing, &const_func4<T>);
Verifier<T>::verify4((volatile Thing<T>*)&thing, &volatile_func4<T>);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &const_volatile_func4<T>);
Callback<T(T,T,T,T)> callback(static_func4);
Verifier<T>::verify4(callback);
callback.attach(&thing, &bound_func4<T>);
Verifier<T>::verify4(&callback, &Callback<T(T,T,T,T)>::call);
Verifier<T>::verify4((void*)&callback, &Callback<T(T,T,T,T)>::thunk);
}
template <typename T>
void test_dispatch3() {
Thing<T> thing;
Verifier<T>::verify3(static_func3<T>);
Verifier<T>::verify3(&thing, &Thing<T>::member_func3);
Verifier<T>::verify3(&thing, &bound_func3<T>);
Verifier<T>::verify3((const Thing<T>*)&thing, &const_func3<T>);
Verifier<T>::verify3((volatile Thing<T>*)&thing, &volatile_func3<T>);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &const_volatile_func3<T>);
Callback<T(T,T,T)> callback(static_func3);
Verifier<T>::verify3(callback);
callback.attach(&thing, &bound_func3<T>);
Verifier<T>::verify3(&callback, &Callback<T(T,T,T)>::call);
Verifier<T>::verify3((void*)&callback, &Callback<T(T,T,T)>::thunk);
}
template <typename T>
void test_dispatch2() {
Thing<T> thing;
Verifier<T>::verify2(static_func2<T>);
Verifier<T>::verify2(&thing, &Thing<T>::member_func2);
Verifier<T>::verify2(&thing, &bound_func2<T>);
Verifier<T>::verify2((const Thing<T>*)&thing, &const_func2<T>);
Verifier<T>::verify2((volatile Thing<T>*)&thing, &volatile_func2<T>);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &const_volatile_func2<T>);
Callback<T(T,T)> callback(static_func2);
Verifier<T>::verify2(callback);
callback.attach(&thing, &bound_func2<T>);
Verifier<T>::verify2(&callback, &Callback<T(T,T)>::call);
Verifier<T>::verify2((void*)&callback, &Callback<T(T,T)>::thunk);
Callback<T()> callback(static_func0);
Verifier<T>::verify0(callback);
callback.attach(&thing, &bound_func0<T>);
Verifier<T>::verify0(&callback, &Callback<T()>::call);
Verifier<T>::verify0((void*)&callback, &Callback<T()>::thunk);
}
template <typename T>
@ -242,10 +224,22 @@ void test_dispatch1() {
Thing<T> thing;
Verifier<T>::verify1(static_func1<T>);
Verifier<T>::verify1(&thing, &Thing<T>::member_func1);
Verifier<T>::verify1((const Thing<T>*)&thing, &Thing<T>::const_member_func1);
Verifier<T>::verify1((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func1);
Verifier<T>::verify1((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func1);
Verifier<T>::verify1(&thing, &bound_func1<T>);
Verifier<T>::verify1((const Thing<T>*)&thing, &const_func1<T>);
Verifier<T>::verify1((volatile Thing<T>*)&thing, &volatile_func1<T>);
Verifier<T>::verify1((const volatile Thing<T>*)&thing, &const_volatile_func1<T>);
Verifier<T>::verify1(callback(static_func1<T>));
Verifier<T>::verify1(callback(&thing, &Thing<T>::member_func1));
Verifier<T>::verify1(callback((const Thing<T>*)&thing, &Thing<T>::const_member_func1));
Verifier<T>::verify1(callback((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func1));
Verifier<T>::verify1(callback((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func1));
Verifier<T>::verify1(callback(&thing, &bound_func1<T>));
Verifier<T>::verify1(callback((const Thing<T>*)&thing, &const_func1<T>));
Verifier<T>::verify1(callback((volatile Thing<T>*)&thing, &volatile_func1<T>));
Verifier<T>::verify1(callback((const volatile Thing<T>*)&thing, &const_volatile_func1<T>));
Callback<T(T)> callback(static_func1);
Verifier<T>::verify1(callback);
@ -255,20 +249,119 @@ void test_dispatch1() {
}
template <typename T>
void test_dispatch0() {
void test_dispatch2() {
Thing<T> thing;
Verifier<T>::verify0(static_func0<T>);
Verifier<T>::verify0(&thing, &Thing<T>::member_func0);
Verifier<T>::verify0(&thing, &bound_func0<T>);
Verifier<T>::verify0((const Thing<T>*)&thing, &const_func0<T>);
Verifier<T>::verify0((volatile Thing<T>*)&thing, &volatile_func0<T>);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &const_volatile_func0<T>);
Verifier<T>::verify2(static_func2<T>);
Verifier<T>::verify2(&thing, &Thing<T>::member_func2);
Verifier<T>::verify2((const Thing<T>*)&thing, &Thing<T>::const_member_func2);
Verifier<T>::verify2((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func2);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func2);
Verifier<T>::verify2(&thing, &bound_func2<T>);
Verifier<T>::verify2((const Thing<T>*)&thing, &const_func2<T>);
Verifier<T>::verify2((volatile Thing<T>*)&thing, &volatile_func2<T>);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &const_volatile_func2<T>);
Verifier<T>::verify2(callback(static_func2<T>));
Verifier<T>::verify2(callback(&thing, &Thing<T>::member_func2));
Verifier<T>::verify2(callback((const Thing<T>*)&thing, &Thing<T>::const_member_func2));
Verifier<T>::verify2(callback((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func2));
Verifier<T>::verify2(callback((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func2));
Verifier<T>::verify2(callback(&thing, &bound_func2<T>));
Verifier<T>::verify2(callback((const Thing<T>*)&thing, &const_func2<T>));
Verifier<T>::verify2(callback((volatile Thing<T>*)&thing, &volatile_func2<T>));
Verifier<T>::verify2(callback((const volatile Thing<T>*)&thing, &const_volatile_func2<T>));
Callback<T()> callback(static_func0);
Verifier<T>::verify0(callback);
callback.attach(&thing, &bound_func0<T>);
Verifier<T>::verify0(&callback, &Callback<T()>::call);
Verifier<T>::verify0((void*)&callback, &Callback<T()>::thunk);
Callback<T(T, T)> callback(static_func2);
Verifier<T>::verify2(callback);
callback.attach(&thing, &bound_func2<T>);
Verifier<T>::verify2(&callback, &Callback<T(T, T)>::call);
Verifier<T>::verify2((void*)&callback, &Callback<T(T, T)>::thunk);
}
template <typename T>
void test_dispatch3() {
Thing<T> thing;
Verifier<T>::verify3(static_func3<T>);
Verifier<T>::verify3(&thing, &Thing<T>::member_func3);
Verifier<T>::verify3((const Thing<T>*)&thing, &Thing<T>::const_member_func3);
Verifier<T>::verify3((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func3);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func3);
Verifier<T>::verify3(&thing, &bound_func3<T>);
Verifier<T>::verify3((const Thing<T>*)&thing, &const_func3<T>);
Verifier<T>::verify3((volatile Thing<T>*)&thing, &volatile_func3<T>);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &const_volatile_func3<T>);
Verifier<T>::verify3(callback(static_func3<T>));
Verifier<T>::verify3(callback(&thing, &Thing<T>::member_func3));
Verifier<T>::verify3(callback((const Thing<T>*)&thing, &Thing<T>::const_member_func3));
Verifier<T>::verify3(callback((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func3));
Verifier<T>::verify3(callback((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func3));
Verifier<T>::verify3(callback(&thing, &bound_func3<T>));
Verifier<T>::verify3(callback((const Thing<T>*)&thing, &const_func3<T>));
Verifier<T>::verify3(callback((volatile Thing<T>*)&thing, &volatile_func3<T>));
Verifier<T>::verify3(callback((const volatile Thing<T>*)&thing, &const_volatile_func3<T>));
Callback<T(T, T, T)> callback(static_func3);
Verifier<T>::verify3(callback);
callback.attach(&thing, &bound_func3<T>);
Verifier<T>::verify3(&callback, &Callback<T(T, T, T)>::call);
Verifier<T>::verify3((void*)&callback, &Callback<T(T, T, T)>::thunk);
}
template <typename T>
void test_dispatch4() {
Thing<T> thing;
Verifier<T>::verify4(static_func4<T>);
Verifier<T>::verify4(&thing, &Thing<T>::member_func4);
Verifier<T>::verify4((const Thing<T>*)&thing, &Thing<T>::const_member_func4);
Verifier<T>::verify4((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func4);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func4);
Verifier<T>::verify4(&thing, &bound_func4<T>);
Verifier<T>::verify4((const Thing<T>*)&thing, &const_func4<T>);
Verifier<T>::verify4((volatile Thing<T>*)&thing, &volatile_func4<T>);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &const_volatile_func4<T>);
Verifier<T>::verify4(callback(static_func4<T>));
Verifier<T>::verify4(callback(&thing, &Thing<T>::member_func4));
Verifier<T>::verify4(callback((const Thing<T>*)&thing, &Thing<T>::const_member_func4));
Verifier<T>::verify4(callback((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func4));
Verifier<T>::verify4(callback((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func4));
Verifier<T>::verify4(callback(&thing, &bound_func4<T>));
Verifier<T>::verify4(callback((const Thing<T>*)&thing, &const_func4<T>));
Verifier<T>::verify4(callback((volatile Thing<T>*)&thing, &volatile_func4<T>));
Verifier<T>::verify4(callback((const volatile Thing<T>*)&thing, &const_volatile_func4<T>));
Callback<T(T, T, T, T)> callback(static_func4);
Verifier<T>::verify4(callback);
callback.attach(&thing, &bound_func4<T>);
Verifier<T>::verify4(&callback, &Callback<T(T, T, T, T)>::call);
Verifier<T>::verify4((void*)&callback, &Callback<T(T, T, T, T)>::thunk);
}
template <typename T>
void test_dispatch5() {
Thing<T> thing;
Verifier<T>::verify5(static_func5<T>);
Verifier<T>::verify5(&thing, &Thing<T>::member_func5);
Verifier<T>::verify5((const Thing<T>*)&thing, &Thing<T>::const_member_func5);
Verifier<T>::verify5((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func5);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func5);
Verifier<T>::verify5(&thing, &bound_func5<T>);
Verifier<T>::verify5((const Thing<T>*)&thing, &const_func5<T>);
Verifier<T>::verify5((volatile Thing<T>*)&thing, &volatile_func5<T>);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &const_volatile_func5<T>);
Verifier<T>::verify5(callback(static_func5<T>));
Verifier<T>::verify5(callback(&thing, &Thing<T>::member_func5));
Verifier<T>::verify5(callback((const Thing<T>*)&thing, &Thing<T>::const_member_func5));
Verifier<T>::verify5(callback((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func5));
Verifier<T>::verify5(callback((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func5));
Verifier<T>::verify5(callback(&thing, &bound_func5<T>));
Verifier<T>::verify5(callback((const Thing<T>*)&thing, &const_func5<T>));
Verifier<T>::verify5(callback((volatile Thing<T>*)&thing, &volatile_func5<T>));
Verifier<T>::verify5(callback((const volatile Thing<T>*)&thing, &const_volatile_func5<T>));
Callback<T(T, T, T, T, T)> callback(static_func5);
Verifier<T>::verify5(callback);
callback.attach(&thing, &bound_func5<T>);
Verifier<T>::verify5(&callback, &Callback<T(T, T, T, T, T)>::call);
Verifier<T>::verify5((void*)&callback, &Callback<T(T, T, T, T, T)>::thunk);
}
template <typename T>
@ -295,26 +388,26 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
}
Case cases[] = {
Case("Testing callbacks with 5 ints", test_dispatch5<int>),
Case("Testing callbacks with 4 ints", test_dispatch4<int>),
Case("Testing callbacks with 3 ints", test_dispatch3<int>),
Case("Testing callbacks with 2 ints", test_dispatch2<int>),
Case("Testing callbacks with 1 ints", test_dispatch1<int>),
Case("Testing callbacks with 0 ints", test_dispatch0<int>),
Case("Testing callbacks with 1 ints", test_dispatch1<int>),
Case("Testing callbacks with 2 ints", test_dispatch2<int>),
Case("Testing callbacks with 3 ints", test_dispatch3<int>),
Case("Testing callbacks with 4 ints", test_dispatch4<int>),
Case("Testing callbacks with 5 ints", test_dispatch5<int>),
Case("Testing callbacks with 5 uchars", test_dispatch5<unsigned char>),
Case("Testing callbacks with 4 uchars", test_dispatch4<unsigned char>),
Case("Testing callbacks with 3 uchars", test_dispatch3<unsigned char>),
Case("Testing callbacks with 2 uchars", test_dispatch2<unsigned char>),
Case("Testing callbacks with 1 uchars", test_dispatch1<unsigned char>),
Case("Testing callbacks with 0 uchars", test_dispatch0<unsigned char>),
Case("Testing callbacks with 1 uchars", test_dispatch1<unsigned char>),
Case("Testing callbacks with 2 uchars", test_dispatch2<unsigned char>),
Case("Testing callbacks with 3 uchars", test_dispatch3<unsigned char>),
Case("Testing callbacks with 4 uchars", test_dispatch4<unsigned char>),
Case("Testing callbacks with 5 uchars", test_dispatch5<unsigned char>),
Case("Testing callbacks with 5 uint64s", test_dispatch5<uint64_t>),
Case("Testing callbacks with 4 uint64s", test_dispatch4<uint64_t>),
Case("Testing callbacks with 3 uint64s", test_dispatch3<uint64_t>),
Case("Testing callbacks with 2 uint64s", test_dispatch2<uint64_t>),
Case("Testing callbacks with 1 uint64s", test_dispatch1<uint64_t>),
Case("Testing callbacks with 0 uint64s", test_dispatch0<uint64_t>),
Case("Testing callbacks with 1 uint64s", test_dispatch1<uint64_t>),
Case("Testing callbacks with 2 uint64s", test_dispatch2<uint64_t>),
Case("Testing callbacks with 3 uint64s", test_dispatch3<uint64_t>),
Case("Testing callbacks with 4 uint64s", test_dispatch4<uint64_t>),
Case("Testing callbacks with 5 uint64s", test_dispatch5<uint64_t>),
Case("Testing FunctionPointerArg1 compatibility", test_fparg1<int>),
Case("Testing FunctionPointer compatibility", test_fparg0<int>),

View File

@ -21,6 +21,7 @@
#include "network-socket/NetworkStack.h"
#include "rtos/Mutex.h"
#include "Callback.h"
#include "toolchain.h"
/** Abstract socket class
@ -168,10 +169,17 @@ public:
*
* @param obj Pointer to object to call method on
* @param method Method to call on state change
*
* @deprecated
* The attach function does not support cv-qualifiers. Replaced by
* attach(callback(obj, method)).
*/
template <typename T, typename M>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The attach function does not support cv-qualifiers. Replaced by "
"attach(callback(obj, method)).")
void attach(T *obj, M method) {
attach(mbed::Callback<void()>(obj, method));
attach(mbed::callback(obj, method));
}
protected:

View File

@ -17,6 +17,7 @@
#define MBED_CALLCHAIN_H
#include "Callback.h"
#include "toolchain.h"
#include <string.h>
namespace mbed {
@ -87,10 +88,17 @@ public:
*
* @returns
* The function object created for 'obj' and 'method'
*
* @deprecated
* The add function does not support cv-qualifiers. Replaced by
* add(callback(obj, method)).
*/
template<typename T, typename M>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The add function does not support cv-qualifiers. Replaced by "
"add(callback(obj, method)).")
pFunctionPointer_t add(T *obj, M method) {
return add(Callback<void()>(obj, method));
return add(callback(obj, method));
}
/** Add a function at the beginning of the chain
@ -109,10 +117,17 @@ public:
*
* @returns
* The function object created for 'tptr' and 'mptr'
*
* @deprecated
* The add_front function does not support cv-qualifiers. Replaced by
* add_front(callback(obj, method)).
*/
template<typename T, typename M>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The add_front function does not support cv-qualifiers. Replaced by "
"add_front(callback(obj, method)).")
pFunctionPointer_t add_front(T *obj, M method) {
return add_front(Callback<void()>(obj, method));
return add_front(callback(obj, method));
}
/** Get the number of functions in the chain

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,7 @@
#include "gpio_irq_api.h"
#include "Callback.h"
#include "critical.h"
#include "toolchain.h"
namespace mbed {
@ -88,11 +89,17 @@ public:
*
* @param obj pointer to the object to call the member function on
* @param method pointer to the member function to be called
* @deprecated
* The rise function does not support cv-qualifiers. Replaced by
* rise(callback(obj, method)).
*/
template<typename T, typename M>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The rise function does not support cv-qualifiers. Replaced by "
"rise(callback(obj, method)).")
void rise(T *obj, M method) {
core_util_critical_section_enter();
rise(Callback<void()>(obj, method));
rise(callback(obj, method));
core_util_critical_section_exit();
}
@ -106,11 +113,17 @@ public:
*
* @param obj pointer to the object to call the member function on
* @param method pointer to the member function to be called
* @deprecated
* The rise function does not support cv-qualifiers. Replaced by
* rise(callback(obj, method)).
*/
template<typename T, typename M>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The fall function does not support cv-qualifiers. Replaced by "
"fall(callback(obj, method)).")
void fall(T *obj, M method) {
core_util_critical_section_enter();
fall(Callback<void()>(obj, method));
fall(callback(obj, method));
core_util_critical_section_exit();
}

View File

@ -23,6 +23,7 @@
#include "Stream.h"
#include "Callback.h"
#include "serial_api.h"
#include "toolchain.h"
#if DEVICE_SERIAL_ASYNCH
#include "CThunk.h"
@ -101,10 +102,16 @@ public:
* @param obj pointer to the object to call the member function on
* @param method pointer to the member function to be called
* @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
* @deprecated
* The attach function does not support cv-qualifiers. Replaced by
* attach(callback(obj, method), type).
*/
template<typename T>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The attach function does not support cv-qualifiers. Replaced by "
"attach(callback(obj, method), type).")
void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) {
attach(Callback<void()>(obj, method), type);
attach(callback(obj, method), type);
}
/** Attach a member function to call whenever a serial interrupt is generated
@ -112,10 +119,16 @@ public:
* @param obj pointer to the object to call the member function on
* @param method pointer to the member function to be called
* @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
* @deprecated
* The attach function does not support cv-qualifiers. Replaced by
* attach(callback(obj, method), type).
*/
template<typename T>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The attach function does not support cv-qualifiers. Replaced by "
"attach(callback(obj, method), type).")
void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) {
attach(Callback<void()>(obj, method), type);
attach(callback(obj, method), type);
}
/** Generate a break condition on the serial line

View File

@ -18,6 +18,7 @@
#include "TimerEvent.h"
#include "Callback.h"
#include "toolchain.h"
namespace mbed {
@ -80,10 +81,16 @@ public:
* @param obj pointer to the object to call the member function on
* @param method pointer to the member function to be called
* @param t the time between calls in seconds
* @deprecated
* The attach function does not support cv-qualifiers. Replaced by
* attach(callback(obj, method), t).
*/
template<typename T, typename M>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The attach function does not support cv-qualifiers. Replaced by "
"attach(callback(obj, method), t).")
void attach(T *obj, M method, float t) {
attach(Callback<void()>(obj, method), t);
attach(callback(obj, method), t);
}
/** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
@ -101,8 +108,14 @@ public:
* @param tptr pointer to the object to call the member function on
* @param mptr pointer to the member function to be called
* @param t the time between calls in micro-seconds
* @deprecated
* The attach_us function does not support cv-qualifiers. Replaced by
* attach_us(callback(obj, method), t).
*/
template<typename T, typename M>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The attach_us function does not support cv-qualifiers. Replaced by "
"attach_us(callback(obj, method), t).")
void attach_us(T *obj, M method, timestamp_t t) {
attach_us(Callback<void()>(obj, method), t);
}

View File

@ -47,7 +47,7 @@ public:
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"Replaced with RtosTimer(Callback<void()>, os_timer_type)")
RtosTimer(void (*func)(void const *argument), os_timer_type type=osTimerPeriodic, void *argument=NULL) {
constructor(mbed::Callback<void()>(argument, (void (*)(void *))func), type);
constructor(mbed::callback(argument, (void (*)(void *))func), type);
}
/** Create timer.
@ -62,10 +62,16 @@ public:
@param obj pointer to the object to call the member function on.
@param method member function to be executed by this timer.
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
@deprecated
The RtosTimer constructor does not support cv-qualifiers. Replaced by
RtosTimer(callback(obj, method), os_timer_type).
*/
template <typename T, typename M>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The RtosTimer constructor does not support cv-qualifiers. Replaced by "
"RtosTimer(callback(obj, method), os_timer_type).")
RtosTimer(T *obj, M method, os_timer_type type=osTimerPeriodic) {
constructor(mbed::Callback<void()>(obj, method), type);
constructor(mbed::callback(obj, method), type);
}
/** Stop the timer.

View File

@ -90,7 +90,7 @@ public:
osPriority priority=osPriorityNormal,
uint32_t stack_size=DEFAULT_STACK_SIZE,
unsigned char *stack_pointer=NULL) {
constructor(mbed::Callback<void()>(obj, method),
constructor(mbed::callback(obj, method),
priority, stack_size, stack_pointer);
}
@ -116,7 +116,7 @@ public:
osPriority priority=osPriorityNormal,
uint32_t stack_size=DEFAULT_STACK_SIZE,
unsigned char *stack_pointer=NULL) {
constructor(mbed::Callback<void()>(obj, method),
constructor(mbed::callback(obj, method),
priority, stack_size, stack_pointer);
}
@ -141,7 +141,7 @@ public:
osPriority priority=osPriorityNormal,
uint32_t stack_size=DEFAULT_STACK_SIZE,
unsigned char *stack_pointer=NULL) {
constructor(mbed::Callback<void()>(argument, (void (*)(void *))task),
constructor(mbed::callback(argument, (void (*)(void *))task),
priority, stack_size, stack_pointer);
}
@ -155,10 +155,16 @@ public:
@param obj argument to task
@param method function to be executed by this thread.
@return status code that indicates the execution status of the function.
@deprecated
The start function does not support cv-qualifiers. Replaced by
start(callback(obj, method)).
*/
template <typename T, typename M>
MBED_DEPRECATED_SINCE("mbed-os-5.1",
"The start function does not support cv-qualifiers. Replaced by "
"start(callback(obj, method)).")
osStatus start(T *obj, M method) {
return start(mbed::Callback<void()>(obj, method));
return start(mbed::callback(obj, method));
}
/** Wait for thread to terminate