Max 5 API Reference
00001 /* 00002 * obdictionary.h 00003 * 00004 * Copyright 2006 Cycling '74. All rights reserved. 00005 * 00006 */ 00007 00008 #ifndef __OBDICTIONARY_H__ 00009 #define __OBDICTIONARY_H__ 00010 00011 00012 #ifdef __cplusplus 00013 extern "C" { 00014 #endif // __cplusplus 00015 00016 #if C74_PRAGMA_STRUCT_PACKPUSH 00017 #pragma pack(push, 2) 00018 #elif C74_PRAGMA_STRUCT_PACK 00019 #pragma pack(2) 00020 #endif 00021 00022 00023 /** A dictionary entry. This struct is provided for debugging convenience, 00024 but should be considered opaque and is subject to change without notice. 00025 00026 @ingroup dictionary 00027 @see t_dictionary 00028 */ 00029 typedef struct _dictionary_entry { 00030 t_object e_obj; 00031 t_symbol *e_key; // redundant with hashtab, but allows getting key during linklist traversal 00032 t_atom e_value; 00033 } t_dictionary_entry; 00034 00035 00036 /** The dictionary object. This struct is provided for debugging convenience, 00037 but should be considered opaque and is subject to change without notice. 00038 00039 @ingroup dictionary 00040 @see t_dictionary 00041 */ 00042 typedef struct _dictionary 00043 { 00044 t_object d_obj; 00045 t_hashtab *d_hashtab; 00046 t_linklist *d_linklist; 00047 } t_dictionary; 00048 00049 #if C74_PRAGMA_STRUCT_PACKPUSH 00050 #pragma pack(pop) 00051 #elif C74_PRAGMA_STRUCT_PACK 00052 #pragma pack() 00053 #endif 00054 00055 00056 /** 00057 Create a new linklist object. 00058 You can free the linklist by calling object_free(). 00059 However, you should keep in mind the guidelines provided in @ref when_to_free_a_dictionary. 00060 00061 @ingroup dictionary 00062 @return Pointer to the new dictionary object. 00063 00064 @see object_free() 00065 */ 00066 t_dictionary* dictionary_new(); 00067 00068 00069 // private 00070 t_dictionary* dictionary_prototypefromclass(t_class *c); 00071 00072 00073 /** 00074 Add a long integer value to the dictionary. 00075 00076 @ingroup dictionary 00077 @param d The dictionary instance. 00078 @param key The name of the key used to index the new value. 00079 All keys must be unique. If the key name already exists, 00080 then the existing value associated with the key will be freed prior to the new value's assignment. 00081 @param value The new value to append to the dictionary. 00082 @return A Max error code. 00083 */ 00084 t_max_err dictionary_appendlong(t_dictionary *d, t_symbol *key, long value); 00085 00086 00087 /** 00088 Add a double-precision float value to the dictionary. 00089 00090 @ingroup dictionary 00091 @param d The dictionary instance. 00092 @param key The name of the key used to index the new value. 00093 All keys must be unique. If the key name already exists, 00094 then the existing value associated with the key will be freed prior to the new value's assignment. 00095 @param value The new value to append to the dictionary. 00096 @return A Max error code. 00097 */ 00098 t_max_err dictionary_appendfloat(t_dictionary *d, t_symbol *key, double value); 00099 00100 00101 /** 00102 Add a #t_symbol* value to the dictionary. 00103 00104 @ingroup dictionary 00105 @param d The dictionary instance. 00106 @param key The name of the key used to index the new value. 00107 All keys must be unique. If the key name already exists, 00108 then the existing value associated with the key will be freed prior to the new value's assignment. 00109 @param value The new value to append to the dictionary. 00110 @return A Max error code. 00111 */ 00112 t_max_err dictionary_appendsym(t_dictionary *d, t_symbol *key, t_symbol *value); 00113 00114 00115 /** 00116 Add a #t_atom* value to the dictionary. 00117 00118 @ingroup dictionary 00119 @param d The dictionary instance. 00120 @param key The name of the key used to index the new value. 00121 All keys must be unique. If the key name already exists, 00122 then the existing value associated with the key will be freed prior to the new value's assignment. 00123 @param value The new value to append to the dictionary. 00124 @return A Max error code. 00125 */ 00126 t_max_err dictionary_appendatom(t_dictionary *d, t_symbol *key, t_atom *value); 00127 00128 00129 // private 00130 t_max_err dictionary_appendattribute(t_dictionary *d, t_symbol *key, t_symbol *attrname, t_object *obj); 00131 00132 00133 /** 00134 Add a C-string to the dictionary. Internally this uses the #t_symbol object. 00135 It is useful to use the #t_string in dictionaries rather than the #t_symbol 00136 to avoid bloating Max's symbol table unnecessarily. 00137 00138 @ingroup dictionary 00139 @param d The dictionary instance. 00140 @param key The name of the key used to index the new value. 00141 All keys must be unique. If the key name already exists, 00142 then the existing value associated with the key will be freed prior to the new value's assignment. 00143 @param value The new value to append to the dictionary. 00144 @return A Max error code. 00145 */ 00146 t_max_err dictionary_appendstring(t_dictionary *d, t_symbol *key, const char *value); 00147 00148 00149 /** 00150 Add an array of atoms to the dictionary. 00151 Internally these atoms will be copied into a #t_atomarray object, which will be appended to the dictionary 00152 with the given key. 00153 00154 @ingroup dictionary 00155 @param d The dictionary instance. 00156 @param key The name of the key used to index the new value. 00157 All keys must be unique. If the key name already exists, 00158 then the existing value associated with the key will be freed prior to the new value's assignment. 00159 @param argc The number of atoms to append to the dictionary. 00160 @param argv The address of the first atom in the array to append to the dictionary. 00161 @return A Max error code. 00162 */ 00163 t_max_err dictionary_appendatoms(t_dictionary *d, t_symbol *key, long argc, t_atom *argv); 00164 00165 00166 /** 00167 Add an @ref atomarray object to the dictionary. 00168 Note that from this point on that you should not free the #t_atomarray*, because the atomarray is now owned by 00169 the dictionary, and freeing the dictionary will free the atomarray as discussed in @ref when_to_free_a_dictionary. 00170 00171 @ingroup dictionary 00172 @param d The dictionary instance. 00173 @param key The name of the key used to index the new value. 00174 All keys must be unique. If the key name already exists, 00175 then the existing value associated with the key will be freed prior to the new value's assignment. 00176 @param value The new value to append to the dictionary. 00177 @return A Max error code. 00178 */ 00179 t_max_err dictionary_appendatomarray(t_dictionary *d, t_symbol *key, t_object *value); 00180 00181 00182 /** 00183 Add a dictionary object to the dictionary. 00184 Note that from this point on that you should not free the #t_dictionary* that is being added, 00185 because the newly-added dictionary is now owned by the dictionary to which it has been added, 00186 as discussed in @ref when_to_free_a_dictionary. 00187 00188 @ingroup dictionary 00189 @param d The dictionary instance. 00190 @param key The name of the key used to index the new value. 00191 All keys must be unique. If the key name already exists, 00192 then the existing value associated with the key will be freed prior to the new value's assignment. 00193 @param value The new value to append to the dictionary. 00194 @return A Max error code. 00195 */ 00196 t_max_err dictionary_appenddictionary(t_dictionary *d, t_symbol *key, t_object *value); 00197 00198 00199 /** 00200 Add an object to the dictionary. 00201 Note that from this point on that you should not free the #t_object* that is being added, 00202 because the newly-added object is now owned by the dictionary to which it has been added, 00203 as discussed in @ref when_to_free_a_dictionary. 00204 00205 @ingroup dictionary 00206 @param d The dictionary instance. 00207 @param key The name of the key used to index the new value. 00208 All keys must be unique. If the key name already exists, 00209 then the existing value associated with the key will be freed prior to the new value's assignment. 00210 @param value The new value to append to the dictionary. 00211 @return A Max error code. 00212 */ 00213 t_max_err dictionary_appendobject(t_dictionary *d, t_symbol *key, t_object *value); 00214 00215 00216 t_max_err dictionary_appendobject_flags(t_dictionary *d, t_symbol *key, t_object *value, long flags); 00217 00218 00219 t_max_err dictionary_appendbinbuf(t_dictionary *d, t_symbol *key, void *value); 00220 00221 00222 /** 00223 Retrieve a long integer from the dictionary. 00224 00225 @ingroup dictionary 00226 @param d The dictionary instance. 00227 @param key The key associated with the value to lookup. 00228 @param value The address of variable to hold the value associated with the key. 00229 @return A Max error code. 00230 */ 00231 t_max_err dictionary_getlong(t_dictionary *d, t_symbol *key, long *value); 00232 00233 00234 /** 00235 Retrieve a double-precision float from the dictionary. 00236 00237 @ingroup dictionary 00238 @param d The dictionary instance. 00239 @param key The key associated with the value to lookup. 00240 @param value The address of variable to hold the value associated with the key. 00241 @return A Max error code. 00242 */ 00243 t_max_err dictionary_getfloat(t_dictionary *d, t_symbol *key, double *value); 00244 00245 00246 /** 00247 Retrieve a #t_symbol* from the dictionary. 00248 00249 @ingroup dictionary 00250 @param d The dictionary instance. 00251 @param key The key associated with the value to lookup. 00252 @param value The address of variable to hold the value associated with the key. 00253 @return A Max error code. 00254 */ 00255 t_max_err dictionary_getsym(t_dictionary *d, t_symbol *key, t_symbol **value); 00256 00257 00258 /** 00259 Copy a #t_atom from the dictionary. 00260 00261 @ingroup dictionary 00262 @param d The dictionary instance. 00263 @param key The key associated with the value to lookup. 00264 @param value The address of variable to hold the value associated with the key. 00265 @return A Max error code. 00266 */ 00267 t_max_err dictionary_getatom(t_dictionary *d, t_symbol *key, t_atom *value); 00268 00269 00270 // private 00271 t_max_err dictionary_getattribute(t_dictionary *d, t_symbol *key, t_symbol *attrname, t_object *obj); 00272 00273 00274 /** 00275 Retrieve a C-string pointer from the dictionary. 00276 The retrieved pointer references the string in the dictionary, it is not a copy. 00277 00278 @ingroup dictionary 00279 @param d The dictionary instance. 00280 @param key The key associated with the value to lookup. 00281 @param value The address of variable to hold the value associated with the key. 00282 @return A Max error code. 00283 */ 00284 t_max_err dictionary_getstring(t_dictionary *d, t_symbol *key, const char **value); 00285 00286 00287 /** 00288 Retrieve the address of a #t_atom array of in the dictionary. 00289 The retrieved pointer references the t_atoms in the dictionary. 00290 To fetch a copy of the t_atoms from the dictionary, use dictionary_copyatoms(). 00291 00292 @ingroup dictionary 00293 @param d The dictionary instance. 00294 @param key The key associated with the value to lookup. 00295 @param argc The address of a variable to hold the number of atoms in the array. 00296 @param argv The address of a variable to hold a pointer to the first atom in the array. 00297 @return A Max error code. 00298 00299 @see dictionary_copyatoms() 00300 */ 00301 t_max_err dictionary_getatoms(t_dictionary *d, t_symbol *key, long *argc, t_atom **argv); 00302 00303 00304 /** 00305 Retrieve copies of a #t_atom array in the dictionary. 00306 The retrieved pointer of t_atoms in the dictionary has memory allocated and copied to it from within the function. 00307 You are responsible for freeing it with sysmem_freeptr(). 00308 00309 @ingroup dictionary 00310 @param d The dictionary instance. 00311 @param key The key associated with the value to lookup. 00312 @param argc The address of a variable to hold the number of atoms in the array. 00313 @param argv The address of a variable to hold a pointer to the first atom in the array. 00314 You should initialize this pointer to NULL prior to passing it to dictionary_copyatoms(). 00315 @return A Max error code. 00316 00317 @see dictionary_getatoms() 00318 */ 00319 t_max_err dictionary_copyatoms(t_dictionary *d, t_symbol *key, long *argc, t_atom **argv); 00320 00321 00322 /** 00323 Retrieve a #t_atomarray pointer from the dictionary. 00324 00325 @ingroup dictionary 00326 @param d The dictionary instance. 00327 @param key The key associated with the value to lookup. 00328 @param value The address of variable to hold the value associated with the key. 00329 @return A Max error code. 00330 */ 00331 t_max_err dictionary_getatomarray(t_dictionary *d, t_symbol *key, t_object **value); 00332 00333 00334 /** 00335 Retrieve a #t_dictionary pointer from the dictionary. 00336 00337 @ingroup dictionary 00338 @param d The dictionary instance. 00339 @param key The key associated with the value to lookup. 00340 @param value The address of variable to hold the value associated with the key. 00341 @return A Max error code. 00342 */ 00343 t_max_err dictionary_getdictionary(t_dictionary *d, t_symbol *key, t_object **value); 00344 00345 00346 /** 00347 Retrieve a #t_object pointer from the dictionary. 00348 00349 @ingroup dictionary 00350 @param d The dictionary instance. 00351 @param key The key associated with the value to lookup. 00352 @param value The address of variable to hold the value associated with the key. 00353 @return A Max error code. 00354 */ 00355 t_max_err dictionary_getobject(t_dictionary *d, t_symbol *key, t_object **value); 00356 00357 00358 /** 00359 Test a key to set if the data stored with that key contains a #t_string object. 00360 00361 @ingroup dictionary 00362 @param d The dictionary instance. 00363 @param key The key associated with the value to test. 00364 @return Returns true if the key contains a #t_string, otherwise returns false. 00365 */ 00366 long dictionary_entryisstring(t_dictionary *d, t_symbol *key); 00367 00368 00369 /** 00370 Test a key to set if the data stored with that key contains a #t_atomarray object. 00371 00372 @ingroup dictionary 00373 @param d The dictionary instance. 00374 @param key The key associated with the value to test. 00375 @return Returns true if the key contains a #t_atomarray, otherwise returns false. 00376 */ 00377 long dictionary_entryisatomarray(t_dictionary *d, t_symbol *key); 00378 00379 00380 /** 00381 Test a key to set if the data stored with that key contains a #t_dictionary object. 00382 00383 @ingroup dictionary 00384 @param d The dictionary instance. 00385 @param key The key associated with the value to test. 00386 @return Returns true if the key contains a #t_dictionary, otherwise returns false. 00387 */ 00388 long dictionary_entryisdictionary(t_dictionary *d, t_symbol *key); 00389 00390 00391 /** 00392 Test a key to set if it exists in the dictionary. 00393 00394 @ingroup dictionary 00395 @param d The dictionary instance. 00396 @param key The key associated with the value to test. 00397 @return Returns true if the key exists, otherwise returns false. 00398 */ 00399 long dictionary_hasentry(t_dictionary *d, t_symbol *key); 00400 00401 00402 /** 00403 Return the number of keys in a dictionary. 00404 00405 @ingroup dictionary 00406 @param d The dictionary instance. 00407 @return The number of keys in the dictionary. 00408 */ 00409 long dictionary_getentrycount(t_dictionary *d); 00410 00411 00412 /** 00413 Retrieve all of the key names stored in a dictionary. 00414 00415 The numkeys and keys parameters should be initialized to zero. 00416 The dictionary_getkeys() method will allocate memory for the keys it returns. 00417 You are then responsible for freeing this memory using dictionary_freekeys(). 00418 <em>You must use dictionary_freekeys(), not some other method for freeing the memory.</em> 00419 00420 @ingroup dictionary 00421 @param d The dictionary instance. 00422 @param numkeys The address of a long where the number of keys retrieved will be set. 00423 @param keys The address of the first of an array #t_symbol pointers where the retrieved keys will be set. 00424 @return A max error code. 00425 00426 @remark The following example demonstrates fetching all of the keys from a dictionary named 'd' 00427 in order to iterate through each item stored in the dictionary. 00428 @code 00429 t_symbol **keys = NULL; 00430 long numkeys = 0; 00431 long i; 00432 t_object *anItem; 00433 00434 dictionary_getkeys(d, &numkeys, &keys); 00435 for(i=0; i<numkeys; i++){ 00436 // do something with the keys... 00437 } 00438 if(keys) 00439 dictionary_freekeys(d, numkeys, keys); 00440 @endcode 00441 00442 @see dictionary_freekeys() 00443 */ 00444 t_max_err dictionary_getkeys(t_dictionary *d, long *numkeys, t_symbol ***keys); 00445 00446 00447 /** 00448 Free memory allocated by the dictionary_getkeys() method. 00449 00450 @ingroup dictionary 00451 @param d The dictionary instance. 00452 @param numkeys The address of a long where the number of keys retrieved will be set. 00453 @param keys The address of the first of an array #t_symbol pointers where the retrieved keys will be set. 00454 @return A max error code. 00455 00456 @see dictionary_getkeys() 00457 */ 00458 void dictionary_freekeys(t_dictionary *d, long numkeys, t_symbol **keys); 00459 00460 00461 /** 00462 Remove a value from the dictionary. 00463 This method will free the object in the dictionary. 00464 If freeing the object is inappropriate or undesirable, use dictionary_chuckentry() instead. 00465 00466 @ingroup dictionary 00467 @param d The dictionary instance. 00468 @param key The key associated with the value to delete. 00469 @return A max error code. 00470 00471 @see dictionary_chuckentry() 00472 @see dictionary_clear() 00473 */ 00474 t_max_err dictionary_deleteentry(t_dictionary *d, t_symbol *key); 00475 00476 00477 /** 00478 Remove a value from the dictionary without freeing it. 00479 00480 @ingroup dictionary 00481 @param d The dictionary instance. 00482 @param key The key associated with the value to delete. 00483 @return A max error code. 00484 00485 @see dictionary_deleteentry() 00486 */ 00487 t_max_err dictionary_chuckentry(t_dictionary *d, t_symbol *key); // remove a value from the dictionary without deleting it 00488 00489 00490 /** 00491 Delete all values from a dictionary. 00492 This method will free the objects in the dictionary. 00493 If freeing the objects is inappropriate or undesirable then you should iterate through 00494 the dictionary and use dictionary_chuckentry() instead. 00495 00496 @ingroup dictionary 00497 @param d The dictionary instance. 00498 @return A max error code. 00499 00500 @see dictionary_getkeys() 00501 @see dictionary_chuckentry() 00502 @see dictionary_deleteentry() 00503 */ 00504 t_max_err dictionary_clear(t_dictionary *d); 00505 00506 00507 // funall will pass the t_dictionary_entry pointer to the fun 00508 // use the methods below to access the fields 00509 00510 /** 00511 Call the specified function for every entry in the dictionary. 00512 00513 @ingroup dictionary 00514 @param d The dictionary instance. 00515 @param fun The function to call, specified as function pointer cast to a Max #method. 00516 @param arg An argument that you would like to pass to the function being called. 00517 00518 @remark The dictionary_funall() method will call your function for every entry in the dictionary. 00519 It will pass both a pointer to the #t_dictionary_entry, and any argument that you provide. 00520 The following example shows a function that could be called by dictionary_funall(). 00521 @code 00522 void my_function(t_dictionary_entry *entry, void* my_arg) 00523 { 00524 t_symbol *key; 00525 t_atom value; 00526 00527 key = dictionary_entry_getkey(entry); 00528 dictionary_entry_getvalue(entry, &value); 00529 00530 // do something with key, value, and my_arg... 00531 } 00532 @endcode 00533 @see dictionary_entry_getkey() 00534 @see dictionary_entry_getvalue() 00535 */ 00536 void dictionary_funall(t_dictionary *d, method fun, void *arg); 00537 00538 00539 /** 00540 Given a #t_dictionary_entry*, return the key associated with that entry. 00541 00542 @ingroup dictionary 00543 @param x The dictionary entry. 00544 @return The key associated with the entry. 00545 00546 @see dictionary_entry_getvalue() 00547 @see dictionary_funall() 00548 */ 00549 t_symbol* dictionary_entry_getkey(t_dictionary_entry *x); 00550 00551 00552 /** 00553 Given a #t_dictionary_entry*, return the value associated with that entry. 00554 00555 @ingroup dictionary 00556 @param x The dictionary entry. 00557 @param value The address of a #t_atom to which the value will be copied. 00558 00559 @see dictionary_entry_getkey() 00560 @see dictionary_funall() 00561 */ 00562 void dictionary_entry_getvalue(t_dictionary_entry *x, t_atom *value); 00563 00564 00565 00566 /** 00567 Given 2 dictionaries, copy the keys unique to one of the dictionaries to the other dictionary. 00568 00569 @ingroup dictionary 00570 @param d A dictionary instance. This will be the destination for any values that are copied. 00571 @param copyfrom A dictionary instance from which we will copy any values with unique keys. 00572 @return A Max error code. 00573 00574 @see dictionary_copyentries() 00575 */ 00576 t_max_err dictionary_copyunique(t_dictionary *d, t_dictionary *copyfrom); 00577 00578 00579 00580 /** 00581 Retrieve a long integer from the dictionary. 00582 If the named key doesn't exist, then return a specified default value. 00583 00584 @ingroup dictionary 00585 @param d The dictionary instance. 00586 @param key The key associated with the value to lookup. 00587 @param value The address of variable to hold the value associated with the key. 00588 @param def The default value to return in the absence of the key existing in the dictionary. 00589 @return A Max error code. 00590 00591 @see dictionary_getlong() 00592 */ 00593 t_max_err dictionary_getdeflong(t_dictionary *d, t_symbol *key, long *value, long def); 00594 00595 00596 /** 00597 Retrieve a double-precision float from the dictionary. 00598 If the named key doesn't exist, then return a specified default value. 00599 00600 @ingroup dictionary 00601 @param d The dictionary instance. 00602 @param key The key associated with the value to lookup. 00603 @param value The address of variable to hold the value associated with the key. 00604 @param def The default value to return in the absence of the key existing in the dictionary. 00605 @return A Max error code. 00606 00607 @see dictionary_getfloat() 00608 */ 00609 t_max_err dictionary_getdeffloat(t_dictionary *d, t_symbol *key, double *value, double def); 00610 00611 00612 /** 00613 Retrieve a #t_symbol* from the dictionary. 00614 If the named key doesn't exist, then return a specified default value. 00615 00616 @ingroup dictionary 00617 @param d The dictionary instance. 00618 @param key The key associated with the value to lookup. 00619 @param value The address of variable to hold the value associated with the key. 00620 @param def The default value to return in the absence of the key existing in the dictionary. 00621 @return A Max error code. 00622 00623 @see dictionary_getsym() 00624 */ 00625 t_max_err dictionary_getdefsym(t_dictionary *d, t_symbol *key, t_symbol **value, t_symbol *def); 00626 00627 00628 /** 00629 Retrieve a #t_atom* from the dictionary. 00630 If the named key doesn't exist, then return a specified default value. 00631 00632 @ingroup dictionary 00633 @param d The dictionary instance. 00634 @param key The key associated with the value to lookup. 00635 @param value The address of variable to hold the value associated with the key. 00636 @param def The default value to return in the absence of the key existing in the dictionary. 00637 @return A Max error code. 00638 00639 @see dictionary_getatom() 00640 */ 00641 t_max_err dictionary_getdefatom(t_dictionary *d, t_symbol *key, t_atom *value, t_atom *def); 00642 00643 00644 /** 00645 Retrieve a C-string from the dictionary. 00646 If the named key doesn't exist, then return a specified default value. 00647 00648 @ingroup dictionary 00649 @param d The dictionary instance. 00650 @param key The key associated with the value to lookup. 00651 @param value The address of variable to hold the value associated with the key. 00652 @param def The default value to return in the absence of the key existing in the dictionary. 00653 @return A Max error code. 00654 00655 @see dictionary_getstring() 00656 */ 00657 t_max_err dictionary_getdefstring(t_dictionary *d, t_symbol *key, const char **value, char *def); 00658 00659 00660 /** 00661 Retrieve the address of a #t_atom array of in the dictionary. 00662 The retrieved pointer references the t_atoms in the dictionary. 00663 To fetch a copy of the t_atoms from the dictionary, use dictionary_copyatoms(). 00664 If the named key doesn't exist, then return a default array of atoms, specified as a #t_atomarray*. 00665 00666 @ingroup dictionary 00667 @param d The dictionary instance. 00668 @param key The key associated with the value to lookup. 00669 @param argc The address of a variable to hold the number of atoms in the array. 00670 @param argv The address of a variable to hold a pointer to the first atom in the array. 00671 @param def The default values specified as an instance of the #t_atomarray object. 00672 @return A Max error code. 00673 00674 @see dictionary_getatoms() 00675 @see dictionary_copydefatoms() 00676 */ 00677 t_max_err dictionary_getdefatoms(t_dictionary *d, t_symbol *key, long *argc, t_atom **argv, t_atom *def); 00678 00679 00680 /** 00681 Retrieve copies of a #t_atom array in the dictionary. 00682 The retrieved pointer of t_atoms in the dictionary has memory allocated and copied to it from within the function. 00683 You are responsible for freeing it with sysmem_freeptr(). 00684 If the named key doesn't exist, then copy a default array of atoms, specified as a #t_atomarray*. 00685 00686 @ingroup dictionary 00687 @param d The dictionary instance. 00688 @param key The key associated with the value to lookup. 00689 @param argc The address of a variable to hold the number of atoms in the array. 00690 @param argv The address of a variable to hold a pointer to the first atom in the array. 00691 You should initialize this pointer to NULL prior to passing it to dictionary_copyatoms(). 00692 @param def The default values specified as an instance of the #t_atomarray object. 00693 @return A Max error code. 00694 00695 @see dictionary_getdefatoms() 00696 @see dictionary_copyatoms() 00697 */ 00698 t_max_err dictionary_copydefatoms(t_dictionary *d, t_symbol *key, long *argc, t_atom **argv, t_atom *def); 00699 00700 00701 00702 /** 00703 Print the contents of a dictionary to the Max window. 00704 00705 @ingroup dictionary 00706 @param d The dictionary instance. 00707 @param recurse If non-zero, the dictionary will be recursively unravelled to the Max window. 00708 Otherwise it will only print the top level. 00709 @param console If non-zero, the dictionary will be posted to the console rather than the Max window. 00710 On the Mac you can view this using Console.app. 00711 On Windows you can use the free DbgView program which can be downloaded from Microsoft. 00712 @return A Max error code. 00713 */ 00714 t_max_err dictionary_dump(t_dictionary *d, long recurse, long console); 00715 00716 00717 /** 00718 Copy specified entries from one dictionary to another. 00719 00720 @ingroup dictionary 00721 @param src The source dictionary from which to copy entries. 00722 @param dst The destination dictionary to which the entries will be copied. 00723 @param keys The address of the first of an array of #t_symbol* that specifies which keys to copy. 00724 @return A Max error code. 00725 00726 @see dictionary_copyunique() 00727 */ 00728 t_max_err dictionary_copyentries(t_dictionary *src, t_dictionary *dst, t_symbol **keys); 00729 00730 00731 /** 00732 Create a new dictionary populated with values using a combination of attribute and sprintf syntax. 00733 00734 @ingroup dictionary 00735 @param fmt An sprintf-style format string specifying key-value pairs with attribute nomenclature. 00736 @param ... One or more arguments which are to be substituted into the format string. 00737 @return A new dictionary instance. 00738 00739 @remark Max attribute syntax is used to define key-value pairs. For example, 00740 @code 00741 "@key1 value @key2 another_value" 00742 @endcode 00743 00744 @remark One common use of this to create dictionary that represents an element of a patcher, 00745 or even an entire patcher itself. The example below creates a dictionary that can 00746 be passed to a function like newobject_fromdictionary() to create a new object. 00747 @code 00748 t_dictionary *d; 00749 char text[4]; 00750 00751 strncpy_zero(text, "foo", 4); 00752 00753 d = dictionary_sprintf("@maxclass comment @varname _name \ 00754 @text \"%s\" @patching_rect %.2f %.2f %.2f %.2f \ 00755 @fontsize %f @textcolor %f %f %f 1.0 \ 00756 @fontname %s @bgcolor 0.001 0.001 0.001 0.", 00757 text, 20.0, 20.0, 200.0, 24.0, 00758 18, 0.9, 0.9, 0.9, "Arial"); 00759 00760 // do something with the dictionary here. 00761 00762 object_free(d); 00763 @endcode 00764 00765 @see newobject_sprintf() 00766 @see newobject_fromdictionary() 00767 @see atom_setparse() 00768 */ 00769 t_dictionary *dictionary_sprintf(char *fmt, ...); 00770 00771 00772 /** 00773 Create a new object in a specified patcher with values using a combination of attribute and sprintf syntax. 00774 00775 @ingroup obj 00776 @param patcher An instance of a patcher object. 00777 @param fmt An sprintf-style format string specifying key-value pairs with attribute nomenclature. 00778 @param ... One or more arguments which are to be substituted into the format string. 00779 @return A pointer to the newly created object instance, or NULL if creation of the object fails. 00780 00781 @remark Max attribute syntax is used to define key-value pairs. For example, 00782 @code 00783 "@key1 value @key2 another_value" 00784 @endcode 00785 00786 @remark The example below creates a new object that in a patcher whose 00787 object pointer is stored in a variable called "aPatcher". 00788 @code 00789 t_object *my_comment; 00790 char text[4]; 00791 00792 strncpy_zero(text, "foo", 4); 00793 00794 my_comment = newobject_sprintf(aPatcher, "@maxclass comment @varname _name \ 00795 @text \"%s\" @patching_rect %.2f %.2f %.2f %.2f \ 00796 @fontsize %f @textcolor %f %f %f 1.0 \ 00797 @fontname %s @bgcolor 0.001 0.001 0.001 0.", 00798 text, 20.0, 20.0, 200.0, 24.0, 00799 18, 0.9, 0.9, 0.9, "Arial"); 00800 @endcode 00801 00802 @see dictionary_sprintf() 00803 @see newobject_fromdictionary() 00804 @see atom_setparse() 00805 */ 00806 t_object *newobject_sprintf(t_object *patcher, char *fmt, ...); 00807 00808 00809 /** 00810 Place a new object into a patcher. The new object will be created based on a specification 00811 contained in a @ref dictionary. 00812 00813 Create a new dictionary populated with values using a combination of attribute and sprintf syntax. 00814 00815 @ingroup obj 00816 @param patcher An instance of a patcher object. 00817 @param d A dictionary containing an object specification. 00818 @return A pointer to the newly created object instance, or NULL if creation of the object fails. 00819 00820 @remark Max attribute syntax is used to define key-value pairs. For example, 00821 @code 00822 "@key1 value @key2 another_value" 00823 @endcode 00824 00825 @remark The example below creates a new object that in a patcher whose 00826 object pointer is stored in a variable called "aPatcher". 00827 @code 00828 t_dictionary *d; 00829 t_object *o; 00830 char text[4]; 00831 00832 strncpy_zero(text, "foo", 4); 00833 00834 d = dictionary_sprintf("@maxclass comment @varname _name \ 00835 @text \"%s\" @patching_rect %.2f %.2f %.2f %.2f \ 00836 @fontsize %f @textcolor %f %f %f 1.0 \ 00837 @fontname %s @bgcolor 0.001 0.001 0.001 0.", 00838 text, 20.0, 20.0, 200.0, 24.0, 00839 18, 0.9, 0.9, 0.9, "Arial"); 00840 00841 o = newobject_fromdictionary(aPatcher, d); 00842 @endcode 00843 00844 @see newobject_sprintf() 00845 @see newobject_fromdictionary() 00846 @see atom_setparse() 00847 */ 00848 t_object *newobject_fromdictionary(t_object *patcher, t_dictionary *d); 00849 00850 00851 #ifdef __cplusplus 00852 } 00853 #endif // __cplusplus 00854 00855 #endif //__OBDICTIONARY_H__
Copyright © 2008, Cycling '74