Update Function Object interface
to make interface trivially copiable There is no need to perform a copy-protected type as there is no init/clear for this type. It is always created through an instance.
This commit is contained in:
1 parent
15492394ad
commit
7bf3ea3a87
3 files changed
+9
-5
No files matched your search
@@ -8008,7 +8008,8 @@ Example:
|
|||||||
{
|
{
|
||||||
sumint_t s;
|
sumint_t s;
|
||||||
sumint_init_with(s, 16);
|
sumint_init_with(s, 16);
|
||||||
int n = f(sumint_as_interface(s));
|
interface_t interface = sumint_as_interface(s);
|
||||||
|
int n = f(interface);
|
||||||
printf("sum=%d\n", n);
|
printf("sum=%d\n", n);
|
||||||
sumint_clear(s);
|
sumint_clear(s);
|
||||||
}
|
}
|
||||||
@@ -8037,6 +8038,7 @@ It will define the following type and functions:
|
|||||||
|
|
||||||
Type representing an interface to such function object.
|
Type representing an interface to such function object.
|
||||||
There is only one method for such type (see below).
|
There is only one method for such type (see below).
|
||||||
|
It is a pointer to an hidded structure and can be assigned.
|
||||||
|
|
||||||
##### retcode\_type name\_call(name\_t interface, type\_of\_param1, type\_of\_param 2, ...)
|
##### retcode\_type name\_call(name\_t interface, type\_of\_param1, type\_of\_param 2, ...)
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -156,7 +156,7 @@
|
|||||||
\
|
\
|
||||||
typedef struct M_F(name, _s) { \
|
typedef struct M_F(name, _s) { \
|
||||||
M_F(name, _callback_ct) callback; \
|
M_F(name, _callback_ct) callback; \
|
||||||
} interface_t[1]; \
|
} *interface_t; \
|
||||||
\
|
\
|
||||||
/* Internal type for oplist & instance */ \
|
/* Internal type for oplist & instance */ \
|
||||||
typedef interface_t M_F(name, _ct); \
|
typedef interface_t M_F(name, _ct); \
|
||||||
@@ -192,7 +192,7 @@
|
|||||||
\
|
\
|
||||||
typedef struct M_F(name, _s) { \
|
typedef struct M_F(name, _s) { \
|
||||||
M_F(name, _callback_ct) callback; \
|
M_F(name, _callback_ct) callback; \
|
||||||
} interface_t[1]; \
|
} *interface_t; \
|
||||||
\
|
\
|
||||||
/* Internal type for oplist & instance */ \
|
/* Internal type for oplist & instance */ \
|
||||||
typedef interface_t M_F(name, _ct); \
|
typedef interface_t M_F(name, _ct); \
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ static void test_instance11(void)
|
|||||||
instance11_t cmp;
|
instance11_t cmp;
|
||||||
int n = 2;
|
int n = 2;
|
||||||
instance11_init_with(cmp, -1, STRING_CTE("INIT") );
|
instance11_init_with(cmp, -1, STRING_CTE("INIT") );
|
||||||
int x = interface1_call(instance11_as_interface(cmp), 10, &n);
|
interface1_t interface = instance11_as_interface(cmp);
|
||||||
|
int x = interface1_call(interface, 10, &n);
|
||||||
assert(x == -8);
|
assert(x == -8);
|
||||||
assert(string_equal_str_p(cmp->c, "CALLED"));
|
assert(string_equal_str_p(cmp->c, "CALLED"));
|
||||||
instance11_clear(cmp);
|
instance11_clear(cmp);
|
||||||
@@ -111,7 +112,8 @@ static void test_instance21(void)
|
|||||||
{
|
{
|
||||||
instance21_t cmp;
|
instance21_t cmp;
|
||||||
instance21_init(cmp);
|
instance21_init(cmp);
|
||||||
int x = interface2_call(instance21_as_interface(cmp));
|
interface2_t interface = instance21_as_interface(cmp);
|
||||||
|
int x = interface2_call(interface);
|
||||||
assert(x == 1);
|
assert(x == 1);
|
||||||
instance21_clear(cmp);
|
instance21_clear(cmp);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user