Update example comments.

This commit is contained in:
Patrick Pelissier committed 2022-10-23 21:01:44 +02:00
1 parent 4de7da1c05
commit 15f58d5738
7 files changed
+22 -5

No files matched your search

+1
View File
@@ -96,6 +96,7 @@ static void data_node_clear(data_node *obj)
and gives the minimum oplist allowing M*LIB to handle
properly the object 'data_node' with the API convention
to respect for calling the methods.
The Manual defines the different supported API.
*/
ARRAY_DEF(/* the array prefix */ array_data_node,
/* the object type */ data_node,
+5
View File
@@ -1,5 +1,10 @@
#include "m-core.h"
/* This example show how to use the M_LET_IF macro
that enables to construct an object and continue
if the construction succeeds.
*/
// Stubs defined for the example. Real code will use soundio library.
struct SoundIo { int x; };
struct SoundIoDevice { int x; };
+3 -2
View File
@@ -28,11 +28,11 @@ int main(void)
M_LET (grow, list_string_t)
M_LET (tmpstr, string_t) { // And let's create also a string_t
// add string elements to the list
// add string elements to the list in different ways
list_string_push_back (grow, STRING_CTE("AB"));
string_printf(tmpstr, "%d", 12);
list_string_push_back (grow, tmpstr);
list_string_push_back (grow, STRING_CTE("CD"));
list_string_emplace_back (grow, "CD");
// Serialize the list of string into a big string.
list_string_get_str (tmpstr, grow, false);
@@ -75,6 +75,7 @@ int main(void)
// Split a string into a list.
string_set_str(tmpstr, "HELLO;JOHN;HOW;ARE;YOU");
astring_split(grow, tmpstr, ';');
// Iterate over the splitted list
for M_EACH (item, grow, list_string_t) {
printf ("Split Item = %s\n", string_get_cstr(*item) );
}
+8 -1
View File
@@ -3,7 +3,14 @@
#include "m-array.h"
#include "m-string.h"
// Let's create an array of string_t and register it globaly
/* This example show ARRAY_DEF usage with string,
M_LET macro usage with complex initialization condition:
how to initialize a dynamic array and initialize it with the given arguments.
It show also the M_EACH keywork
*/
// Let's create a dynamic array of string_t and register it globaly
// a so called std::vector<std::string> in C++
ARRAY_DEF(vector_string, string_t)
#define M_OPL_vector_string_t() ARRAY_OPLIST(vector_string, STRING_OPLIST)
+2 -1
View File
@@ -26,13 +26,14 @@ int main(void)
// Count the words.
M_LET(map, dict_str_t) {
// Count the words:
// Count the words into the dictionnary 'map'
for M_EACH(w, words, vector_str_t) {
(*dict_str_safe_get(map, *w)) ++;
}
// Print the count:
for M_EACH(p, map, dict_str_t) {
// In C11 version we can use the M_PRINT macro that simplifies formatting.
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
M_PRINT(p->value, " occurences of ", p->key, "\n");
#else
+1 -1
View File
@@ -38,7 +38,7 @@ M_TREE_DEF(tree, dir_t)
static tree_it_t
add_directory(tree_it_t parent, const string_t dirname)
{
// Miss: return dir_emplace_child(parent, 0, dirname); to simplify this function.
// TODO: return dir_emplace_child(parent, 0, dirname); to simplify this function.
// which is too complex for what she does.
dir_t data;
tree_it_t it;
+2
View File
@@ -2,6 +2,8 @@
#include "m-tuple.h"
#include "m-array.h"
/* Basic example to show JSON serialization */
// Let's define a 'person' composed of several fields.
TUPLE_DEF2(person,
(surname, string_t),