void dict_route_dictionary(t_dict_route *x, t_symbol *s) { t_dictionary *d = dictobj_findregistered_retain(s); if (!d) { object_error((t_object*)x, "unable to reference dictionary named %s", s); return; } if (proxy_getinlet((t_object*)x) == 0) { // left inlet : validate the input against the schema long validates = false; t_atom a; validates = dictobj_validate(x->schema_dict, d); atom_setsym(&a, s); if (validates) outlet_anything(x->outlet_dict, _sym_dictionary, 1, &a); else outlet_anything(x->outlet_nomatch, _sym_dictionary, 1, &a); } else { // right inlet : set the contents of the schema with a copy of the incoming dictionary if (d) { dictionary_clear(x->schema_dict); dictionary_clone_to_existing(d, x->schema_dict); } } dictobj_release(d); }
t_my_err _dict_recurse_begin_cmd(t_dict_recurse *x, t_atom *dict_ato, t_symbol *cmd_sym) { TRACE("_dict_recurse_begin_cmd"); // Test if the object is already busy MY_ASSERT_ERR(x->is_busy, ERR_LOCKED, "%s: The object is still busy.", cmd_sym->s_name); // Arg 0: The name of the dictionary to process x->dict_sym = atom_getsym(dict_ato); x->dict = dictobj_findregistered_retain(x->dict_sym); MY_ASSERT_ERR(!x->dict, ERR_DICT_NONE, "%s: Arg 1: Unable to reference the dictionary named \"%s\".", cmd_sym->s_name, x->dict_sym->s_name); // Copy the name of the root dictionary into the path strncpy_zero(x->path, x->dict_sym->s_name, x->path_len_max); // Set the trailing variables x->type_iter = VALUE_TYPE_DICT; x->dict_iter = x->dict; // Set the object to busy status x->is_busy = true; return ERR_NONE; }
/** append in_dict_cont_entry (sym: dictionary) (sym: search key) (sym: search value) (sym: replace key) (sym: replace value) append in_dict_cont_entry_d (sym: dictionary) (sym: search key) (sym: search value) (sym: replace key) (sym: replace dict) append in_dict_from_key (sym: dictionary) (sym: search key) (sym: replace key) (sym: replace dict) */ void dict_recurse_append(t_dict_recurse *x, t_symbol *sym, long argc, t_atom *argv) { TRACE("dict_recurse_append"); t_symbol *search_key_sym = gensym(""); t_symbol *search_val_sym = gensym(""); // Arg 1: Find a key, all entries with the key in, a value, or a dictionary t_symbol *cmd_arg = atom_getsym(argv); t_symbol *cmd_sym = gensym(""); if (cmd_arg == gensym("in_dict_cont_entry")) { x->command = CMD_APPEND_IN_DICT_CONT_ENTRY; cmd_sym = gensym("append in_dict_cont_entry"); } else if (cmd_arg == gensym("in_dict_cont_entry_d")) { x->command = CMD_APPEND_IN_DICT_CONT_ENTRY_D; cmd_sym = gensym("append in_dict_cont_entry_d"); } else if (cmd_arg == gensym("in_dict_from_key")) { x->command = CMD_APPEND_IN_DICT_FROM_KEY; cmd_sym = gensym("append in_dict_from_key"); } else { MY_ASSERT(1, "replace: Arg 0: Invalid argument."); } switch (x->command) { // append in_dict_cont_entry (sym: dictionary) (sym: search key) (sym: search value) (sym: replace key) (sym: replace value) case CMD_APPEND_IN_DICT_CONT_ENTRY: search_key_sym = atom_getsym(argv + 2); search_val_sym = atom_getsym(argv + 3); x->replace_key_sym = atom_getsym(argv + 4); x->replace_val_sym = atom_getsym(argv + 5); MY_ASSERT(search_key_sym == gensym(""), "%s: Arg 2: Invalid argument.", cmd_sym->s_name); MY_ASSERT(search_val_sym == gensym(""), "%s: Arg 3: Invalid argument.", cmd_sym->s_name); MY_ASSERT(x->replace_key_sym == gensym(""), "%s: Arg 4: Invalid argument.", cmd_sym->s_name); MY_ASSERT(x->replace_val_sym == gensym(""), "%s: Arg 5: Invalid argument.", cmd_sym->s_name); regexpr_set(x->search_key_expr, search_key_sym); regexpr_set(x->search_val_expr, search_val_sym); break; // append in_dict_cont_entry_d (sym: dictionary) (sym: search key) (sym: search value) (sym: replace key) (sym: replace dict) case CMD_APPEND_IN_DICT_CONT_ENTRY_D: search_key_sym = atom_getsym(argv + 2); search_val_sym = atom_getsym(argv + 3); x->replace_key_sym = atom_getsym(argv + 4); x->replace_dict_sym = atom_getsym(argv + 5); MY_ASSERT(search_key_sym == gensym(""), "%s: Arg 2: Invalid argument.", cmd_sym->s_name); MY_ASSERT(search_val_sym == gensym(""), "%s: Arg 3: Invalid argument.", cmd_sym->s_name); MY_ASSERT(x->replace_key_sym == gensym(""), "%s: Arg 4: Invalid argument.", cmd_sym->s_name); MY_ASSERT(x->replace_dict_sym == gensym(""), "%s: Arg 5: Invalid argument.", cmd_sym->s_name); regexpr_set(x->search_key_expr, search_key_sym); regexpr_set(x->search_val_expr, search_val_sym); x->replace_dict = dictobj_findregistered_retain(x->replace_dict_sym); MY_ASSERT(!x->replace_dict, "%s: Arg 5: Unable to reference the dictionary named \"%s\".", cmd_sym->s_name, x->replace_dict_sym->s_name); break; // append in_dict_from_key (sym: dictionary) (sym: search key) (sym: replace key) (sym: replace dict) case CMD_APPEND_IN_DICT_FROM_KEY: search_key_sym = atom_getsym(argv + 2); x->replace_key_sym = atom_getsym(argv + 3); x->replace_dict_sym = atom_getsym(argv + 4); MY_ASSERT(search_key_sym == gensym(""), "%s: Arg 2: Invalid argument.", cmd_sym->s_name); MY_ASSERT(x->replace_key_sym == gensym(""), "%s: Arg 3: Invalid argument.", cmd_sym->s_name); MY_ASSERT(x->replace_dict_sym == gensym(""), "%s: Arg 4: Invalid argument.", cmd_sym->s_name); regexpr_set(x->search_key_expr, search_key_sym); x->replace_dict = dictobj_findregistered_retain(x->replace_dict_sym); MY_ASSERT(!x->replace_dict, "%s: Arg 4: Unable to reference the dictionary named \"%s\".", cmd_sym->s_name, x->replace_dict_sym->s_name); break; default: break; } // Initialize the object variables if (_dict_recurse_begin_cmd(x, argv + 1, cmd_sym) != ERR_NONE) { return; } // Start the recursion _dict_recurse_dict(x, x->dict, 0); // Notify that the dictionary has been modified if (x->count > 0) { object_notify(x->dict, gensym("modified"), NULL); } // Post a summary for the command POST("%s: %i entr%s appended in \"%s\".", cmd_sym->s_name, x->count, (x->count == 1) ? "y" : "ies", x->dict_sym->s_name); // End the command _dict_recurse_end_cmd(x); }