From 686cb7de8ac03b70e9daffa0f3e25444f763121d Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 11 Mar 2017 16:50:36 +0100 Subject: [PATCH] Update example --- example/ex08.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/example/ex08.c b/example/ex08.c index 21e3c80a..f2ed2ea4 100644 --- a/example/ex08.c +++ b/example/ex08.c @@ -11,29 +11,33 @@ VARIANT_DEF2(integer, (n, long long, M_DEFAULT_OPLIST), (z, mpz_t, M_CLASSIC_OPLIST(mpz))) +/* Define the oplist associated to this variant */ #define INTEGER_OPLIST VARIANT_OPLIST(integer, M_DEFAULT_OPLIST, M_CLASSIC_OPLIST(mpz)) /* Define a dictionary of string --> integer named dict_my_t */ DICT_DEF2(my, string_t, STRING_OPLIST, integer_t, INTEGER_OPLIST) +/* Define the oplist associated to this dictionary */ #define MY_DICT_OPLIST DICT_OPLIST(my, STRING_OPLIST, INTEGER_OPLIST) /* Define an array of such dictionary named array_my_t */ ARRAY_DEF(my, dict_my_t, MY_DICT_OPLIST) +/* Define the oplist associated to this array of dictionary of variant */ #define MY_ARRAY_OPLIST ARRAY_OPLIST(my, MY_DICT_OPLIST) int main() { - M_LET(z, INTEGER_OPLIST) - M_LET(dict, MY_DICT_OPLIST) - M_LET(array, MY_ARRAY_OPLIST) + M_LET(z, INTEGER_OPLIST) /* Define & init & clear a variant of integer */ + M_LET(dict, MY_DICT_OPLIST) /* Define & init & clear a dictionary of variant */ + M_LET(array, MY_ARRAY_OPLIST) /* Define & init & clear an array of dictionary of variant */ + M_LET(gmp, M_CLASSIC_OPLIST(mpz)) /* M_LET allows even with non container type */ { - mpz_t gmp; - mpz_init_set_str(gmp, "25446846874687468746874687468746874686874", 10); + integer_set_n (z, 17LL); // Set z as the long long 17 + dict_my_set_at(dict, STRING_CTE("n1"), z); + mpz_set_str(gmp, "25446846874687468746874687468746874686874", 10); integer_set_z (z, gmp); // Since we didn't define MOVE operators for mpz_t, we can't use integer_move_z - mpz_clear(gmp); - dict_my_set_at(dict, STRING_CTE("n"), z); + dict_my_set_at(dict, STRING_CTE("n2"), z); array_my_push_back (array, dict); - } + } /* All variables are automaticaly cleared beyond this point */ }