diff --git a/README.md b/README.md index 0b58916c..1cfdb576 100644 --- a/README.md +++ b/README.md @@ -1931,11 +1931,16 @@ This method is created only if all oplists of the tuple define MOVE method. Clear the tuple 'tuple (aka destructor). -##### const type1 *name\_get\_element1(const name\_t tuple) +##### const type1 *name\_cget\_at\_element1(const name\_t tuple) Return a constant pointer to the element 'element1' of the tuple. There is as many methods as there are elements. +##### type1 *name\_get\_at\_element1(const name\_t tuple) + +Return a pointer to the element 'element1' of the tuple. +There is as many methods as there are elements. + ##### void name\_set\_element1(name\_t tuple, type1 element1) Set the element of the tuple to 'element1' @@ -2067,7 +2072,12 @@ Initialize and set the variant 'variant' to the type and value of 'elementN'. Set the variant 'variant' to the type and value of 'elementN'. -##### typeN * name\_get_elementN(name\_t variant) +##### const typeN * name\_cget\_at\_elementN(name\_t variant) + +Return a pointer to the 'varian' viewed as of type 'typeN'. +If the variant isn't an object of such type, it returns NULL. + +##### typeN * name\_get\_at\_elementN(name\_t variant) Return a pointer to the 'varian' viewed as of type 'typeN'. If the variant isn't an object of such type, it returns NULL. diff --git a/doc/API.txt b/doc/API.txt index c8873e03..b36d050a 100644 --- a/doc/API.txt +++ b/doc/API.txt @@ -23,4 +23,8 @@ V0.2.*: * worker_start takes a 'worker_t' as an additional parameter * M_PRINT_ARG & M_FPRINT_ARG don't put a final semicolon at the end of their expansion anymore (cleaner and no longer needed with the new available tools). + * For the TUPLE and the VARIANT + change name of _get_ ## field into _get_at_ ## fields + Since there is a name collision with other methods + if a field is named 'str'. diff --git a/m-tuple.h b/m-tuple.h index 0c3547f8..efe2313e 100644 --- a/m-tuple.h +++ b/m-tuple.h @@ -222,8 +222,11 @@ namespace m_tuple { #define TUPLE_DEFINE_GETTER_FIELD(name, ...) \ M_MAP2(TUPLE_DEFINE_GETTER_FIELD_PROTO, name, __VA_ARGS__) #define TUPLE_DEFINE_GETTER_FIELD_PROTO(name, a) \ - static inline TUPLE_GET_TYPE a const * M_C3(name, _get_, TUPLE_GET_FIELD a) \ - (M_C(name,_t) const my) { \ + static inline TUPLE_GET_TYPE a * M_C3(name, _get_at_, TUPLE_GET_FIELD a) \ + (M_C(name,_t) my) { \ + return &(my->TUPLE_GET_FIELD a);} \ + static inline TUPLE_GET_TYPE a const * M_C3(name, _cget_at_, TUPLE_GET_FIELD a) \ + (M_C(name,_t) const my) { \ return &(my->TUPLE_GET_FIELD a);} diff --git a/m-variant.h b/m-variant.h index 550dd714..bbae16dc 100644 --- a/m-variant.h +++ b/m-variant.h @@ -250,6 +250,13 @@ return NULL; \ } \ return &my -> value . VARIANTI_GET_FIELD a; \ + } \ + static inline VARIANTI_GET_TYPE a const * \ + M_C3(name, _cget_, VARIANTI_GET_FIELD a)(M_C(name,_t) const my) { \ + if (my->type != M_C4(name, _, VARIANTI_GET_FIELD a, _value) ) { \ + return NULL; \ + } \ + return &my -> value . VARIANTI_GET_FIELD a; \ }