Creates a new table which is a “clone” (exact copy) of an existing table
Synopsis
Result
clone_handle (≥ 0) A handle to the clone table
Parameters
handle Handle to the table to be cloned
Discussion
Viewing a table as a set of key/value pairs, this function creates a new table (with the same flags word as the original) containing copies of all the original table’s key/value pairs. The two tables are completely independent, i.e. future changes to one won’t affect the other.
Note that if there are any CCTK_POINTER and/or CCTK_FPOINTER values in the table, they are “shallow copied”, i.e. the (pointer) values in the table are copied. This results in the clone table’s pointer values pointing to the same places as the original table’s pointer values. Be careful with this! In particular, if you’re using pointer values in the table to keep track of malloc() memory, be careful not to free() the same block of memory twice!
Note that table iterators are not guaranteed to sequence through the original and clone tables in the same order. (This is a special case of the more general “non-guarantee” in the Section of table iterators in the Users’ Guide: the order of table iterators may differ even between different tables with identical key/value contents.)
See Also
Util_TableCreate() [B57] create a table
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableDestroy() [B67] destroy a table
Errors
UTIL_ERROR_NO_MEMORY unable to allocate memory
UTIL_ERROR_TABLE_BAD_FLAGS flags word is negative in the to-be-cloned table (this indicates an internal error
in the table routines, and should never happen)
Examples
Creates a new (empty) table
Synopsis
Result
handle (≥ 0) A handle to the newly-created table
Parameters
flags (≥ 0) A flags word for the table. This should be the inclusive-or of zero or more of the
UTIL_TABLE_FLAGS_* bit masks (defined in "util_Table.h"). For Fortran users, note that inclusive-or is the
same as sum here, since the bit masks are all disjoint.
Discussion
We require the flags word to be non-negative so that other functions can distinguish flags from (negative) error codes.
Any User-defined flag words should use only bit positions at or above
UTIL_TABLE_FLAGS_USER_DEFINED_BASE, i.e. all bit positions below this are reserved for present of future
Cactus use.
At present there is only a single flags-word bit mask defined in "util_Table.h":
See Also
Util_StrCmpi() [B27] compare two strings, ignoring upper/lower case
Util_TableClone() [B52] create a new table which is a “clone” (exact copy) of an existing table
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableDestroy() [B67] destroy a table
Errors
UTIL_ERROR_NO_MEMORY unable to allocate memory
UTIL_ERROR_TABLE_BAD_FLAGS flags word is negative
Examples
Creates a new table (with the case-insensitive flag set) and sets values in it based on a string argument (interpreted with “parameter-file” semantics)
Synopsis
Result
handle (≥ 0) a handle to the newly-created table
Parameters
string a pointer to a C-style null-terminated string specifying the table contents; see the description
for Util_TableSetFromString() for a full description of the syntax and semantics of this string
See Also
Util_TableClone() [B52] Create a new table which is a “clone” (exact copy) of an existing table
Util_TableCreate() [B57] create a table
Util_TableSetFromString() [B139] sets values in a table based on a string argument
Errors
UTIL_ERROR_NO_MEMORY unable to allocate memory
UTIL_ERROR_BAD_KEY invalid input: key contains invalid character
UTIL_ERROR_BAD_INPUT invalid input: can’t parse input string
other error codes this function may also return any error codes returned by Util_TableCreate() or
Util_TableSetFromString()
Examples
Deletes a specified key/value entry from a table
Synopsis
Result
0 ok (key existed before this call, and has now been deleted)
Parameters
handle (≥ 0) handle to the table
key a pointer to the key (a C-style null-terminated string)
Discussion
This function invalidates any iterators for the table which are not in the “null-pointer” state.
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_TABLE_NO_SUCH_KEY no such key in table
Destroys a table
Synopsis
Result
0 ok
Parameters
handle (≥ 0) handle to the table
Discussion
Of course, this function invalidates any and all iterators for the table. :)
See Also
Util_TableClone() [B52] Create a new table which is a “clone” (exact copy) of an existing table
Util_TableCreate() [B57] create a table
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
Examples
This is a family of functions, one for each Cactus data type, to get the single (1-element array) value, or more generally the first array element of the value, associated with a specified key in a key/value table.
Synopsis
where XXX is one of POINTER, FPOINTER1, CHAR, BYTE, INT, INT1, INT2, INT4, INT8, REAL, REAL4, REAL8, REAL16, COMPLEX, COMPLEX8, COMPLEX16, COMPLEX32 (not all of these may be supported on any given system)
where CCTK_XXX may be any data type supported by C (above) except CCTK_CHAR (Fortran doesn’t have a separate “character” data type; use CCTK_BYTE instead)
Result
N_elements the number of array elements in the value
Parameters
handle (≥ 0) handle to the table
value a pointer to where this function should store a copy of the value (or more generally the first
array element of the value) associated with the specified key, or NULL pointer to skip storing this
key a pointer to the key (a C-style null-terminated string)
Discussion
Note that it is not an error for the value to actually have > 1 array elements; in this case only the first element is stored. The rationale for this design is that the caller may know or suspect that the value is a large array, but may only want the first array element; in this case this design avoids the caller having to allocate a large buffer unnecessarily.
In contrast, it is an error for the value to actually be an empty (0-length) array, because then there is no “first array element” to get.
It is also an error for the value to actually have a different type than CCTK_XXX.
If any error code is returned, the user’s value buffer (pointed to by value if this is non-NULL) is unchanged.
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*Array() get an array value
Util_TableGetString() [B87] get a character-string value
Util_TableSet*() set a single (1-element array) value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetFromString() [B139] convenience routine to set key/value entries in a table based on a
parameter-file–like character string
Util_TableSetString() [B152] set a character-string value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_TABLE_NO_SUCH_KEY no such key in table
UTIL_ERROR_TABLE_WRONG_DATA_TYPE value has data type other than CCTK_TYPE
UTIL_ERROR_TABLE_VALUE_IS_EMPTY value is an empty (0-element) array
Examples
This is a family of functions, one for each Cactus data type, to get a copy of the value associated with a specified key, and store it (more accurately, as much of it as will fit) in a specified array
Synopsis
where XXX is one of POINTER, FPOINTER2, CHAR, BYTE, INT, INT1, INT2, INT4, INT8, REAL, REAL4, REAL8, REAL16, COMPLEX, COMPLEX8, COMPLEX16, COMPLEX32 (not all of these may be supported on any given system)
where CCTK_XXX may be any data type supported by C (above)
Result
N_elements the number of array elements in the value
Parameters
handle (≥ 0) handle to the table
N_array the number of array elements in array[] (must be ≥ 0 if array != NULL)
array a pointer to where this function should store (up to N_array elements of) a copy of the value associated
with the specified key, or NULL pointer to skip storing this
key a pointer to the key (a C-style null-terminated string)
Discussion
Note that it is not an error for the value to actually have > N_array array elements; in this case only the first N_array elements are stored. The caller can detect this by comparing the return value with N_array. The rationale for this design is that the caller may know or suspect that the value is a large array, but may only want the first few array elements; in this case this design avoids the caller having to allocate a large buffer unnecessarily.
It is also not an error for the value to actually have < N_array array elements; again the caller can detect this by comparing the return value with N_array.
It is an error for the value to actually have a different type than CCTK_XXX.
If any error code is returned, the user’s value buffer (pointed to by array if this is non-NULL) is unchanged.
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value, or more generally the first array element of an array
value
Util_TableGetGeneric() [B79] get a single (1-element array) value with generic data type
Util_TableGetGenericArray() [B83] get an array value with generic data type
Util_TableGetString() [B87] get a character-string value
Util_TableSet*() set a single (1-element array) value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetFromString() [B139] convenience routine to set key/value entries in a table based on a
parameter-file–like character string
Util_TableSetString() [B152] set a character-string value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_BAD_INPUT array != NULL and N_array < 0
UTIL_ERROR_TABLE_NO_SUCH_KEY no such key in table
UTIL_ERROR_TABLE_WRONG_DATA_TYPE value has data type other than CCTK_TYPE
Examples
Get the single (1-element array) value, or more generally the first array element of the value, associated with a specified key in a key/value table; the value’s data type is generic. That is, the value is specified by a CCTK_VARIABLE_* type code and a void * pointer.
Synopsis
Result
N_elements the number of array elements in the value
Parameters
handle (≥ 0) handle to the table
type_code the value’s type code (one of the CCTK_VARIABLE_* constants from "cctk_Constants.h")
value a pointer to where this function should store a copy of the value (or more generally the first
array element of the value) associated with the specified key, or NULL pointer to skip storing this
key a pointer to the key (a C-style null-terminated string)
Discussion
Note that it is not an error for the value to actually have > 1 array elements; in this case only the first element is stored. The rationale for this design is that the caller may know or suspect that the value is a large array, but may only want the first array element; in this case this design avoids the caller having to allocate a large buffer unnecessarily.
In contrast, it is an error for the value to actually be an empty (0-length) array, because then there is no “first array element” to get.
It is also an error for the value to actually have a different type than that specified by type_code.
If any error code is returned, the user’s value buffer (pointed to by value if this is non-NULL) is unchanged.
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value
Util_TableGet*Array() get an array value
Util_TableGetString() [B87] get a character-string value
Util_TableQueryValueInfo() [B121] query key present/absent in table, and optionally type and/or number of
elements
Util_TableSet*() set a single (1-element array) value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetFromString() [B139] convenience routine to set key/value entries in a table based on a
parameter-file–like character string
Util_TableSetString() [B152] set a character-string value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_TABLE_NO_SUCH_KEY no such key in table
UTIL_ERROR_TABLE_WRONG_DATA_TYPE value has data type other than CCTK_TYPE
UTIL_ERROR_TABLE_VALUE_IS_EMPTY value is an empty (0-element) array
Examples
Get a copy of the value associated with a specified key, and store it (more accurately, as much of it as will fit) in a specified array; the array’s data type is generic. That is the array is specified by a CCTK_VARIABLE_* type code, a count of the number of array elements, and a void * pointer.
Synopsis
Result
N_elements the number of array elements in the value
Parameters
handle (≥ 0) handle to the table
type_code the value’s type code (one of the CCTK_VARIABLE_* constants from "cctk_Constants.h")
N_array the number of array elements in array[] (must be ≥ 0 if array != NULL)
array a pointer to where this function should store (up to N_array elements of) a copy of the value associated
with the specified key, or NULL pointer to skip storing this
key a pointer to the key (a C-style null-terminated string)
Discussion
Note that it is not an error for the value to actually have > N_array array elements; in this case only the first N_array elements are stored. The caller can detect this by comparing the return value with N_array. The rationale for this design is that the caller may know or suspect that the value is a large array, but may only want the first few array elements; in this case this design avoids the caller having to allocate a large buffer unnecessarily.
It is also not an error for the value to actually have < N_array array elements; again the caller can detect this by comparing the return value with N_array.
It is an error for the value to actually have a different type than that specified by type_code.
If any error code is returned, the user’s value buffer (pointed to by array if this is non-NULL) is unchanged.
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value, or more generally the first array element of an array
value
Util_TableGetGeneric() [B79] get a single (1-element array) value with generic data type
Util_TableGetGenericArray() [B83] get an array value with generic data type
Util_TableGetString() [B87] get a character-string value
Util_TableQueryValueInfo() [B121] query key present/absent in table, and optionally type and/or number of
elements
Util_TableSet*() set a single (1-element array) value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetFromString() [B139] convenience routine to set key/value entries in a table based on a
parameter-file–like character string
Util_TableSetString() [B152] set a character-string value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_BAD_INPUT array != NULL and N_array < 0
UTIL_ERROR_TABLE_NO_SUCH_KEY no such key in table
UTIL_ERROR_TABLE_WRONG_DATA_TYPE value has data type other than CCTK_TYPE
Examples
Gets a copy of the character-string value associated with a specified key in a table, and stores it (more accurately, as much of it as will fit) in a specified character string
Synopsis
Result
Results are the same as all the other Util_TableGet*() functions:
length the length of the string (C strlen semantics, i.e. not including the terminating null character)
Parameters
handle (≥ 0) handle to the table
buffer_length the length (sizeof) of buffer[] (must be ≥ 1 if buffer != NULL)
buffer a pointer to a buffer into which this function should store (at most buffer_length-1 characters of) the
value, terminated by a null character as usual for C strings, or NULL pointer to skip storing this
key a pointer to the key (a C-style null-terminated string)
Discussion
This function assumes that the string is stored as an array of CCTK_CHARs, not including a terminating null character.
This function differs from Util_TableGetCharArray() in two ways: It explicitly provides a terminating null character for C-style strings, and it explicitly checks for the string being too long to fit in the buffer (in which case it returns UTIL_ERROR_TABLE_STRING_TRUNCATED).
If the error code UTIL_ERROR_TABLE_STRING_TRUNCATED is returned, then the first buffer_length-1 characters of the string are returned in the user’s buffer (assuming buffer is non-NULL), followed by a null character to properly terminate the string in the buffer. If any other error code is returned, the user’s value buffer (pointed to by buffer if this is non-NULL) is unchanged.
To find out how long the string is (and thus how big of a buffer you need to allocate to avoid having the string truncated), you can call this function with buffer_length = 0 and buffer = NULL (or actually anything you want); the return result will give the string length.
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value, or more generally the first array element of an array
value
Util_TableGet*Array() get an array value
Util_TableGetCharArray() [B75] get an array-of-CCTK_CHAR value
Util_TableGetGeneric() [B79] get a single (1-element array) value with generic data type
Util_TableGetGenericArray() [B83] get an array value with generic data type
Util_TableSet*() set a single (1-element array) value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetString() [B152] set a character-string value
Util_TableSetFromString() [B139] convenience routine to set key/value entries in a table based on a
parameter-file–like character string
Util_TableSetCharArray() [B135] set an array-of-CCTK_CHAR value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_BAD_INPUT buffer != NULL and buffer_length ≤ 0
UTIL_ERROR_TABLE_NO_SUCH_KEY no such key in table
UTIL_ERROR_TABLE_WRONG_DATA_TYPE value has data type other than CCTK_CHAR
UTIL_ERROR_TABLE_STRING_TRUNCATED buffer != NULL and value was truncated to fit in buffer[]
Examples
Advance a table iterator to the next entry in the table
Synopsis
Result
1 ok (iterator now points to some table entry)
0 ok (iterator has just advanced past the last table entry, and is now in the ”null-pointer” state)
Parameters
ihandle (≥ 0) handle to the table iterator
Discussion
If we view an iterator as an abstraction of a pointer into the table, then this function is the abstraction of the C “++” operation applied to the pointer, except that this function automagically sets the iterator to the ”null-pointer” state when it advances past the last table entry.
Note that bad things (garbage results, core dumps) may happen if you call this function on an iterator which has been invalidated by a change in the table’s contents.
Errors
UTIL_ERROR_BAD_HANDLE iterator handle is invalid
Examples
Creates a new table iterator which is a “clone” (exact copy) of an existing table iterator
Synopsis
Result
clone_ihandle (≥ 0) A handle to the clone table iterator
Parameters
ihandle handle to the table iterator to be cloned
Discussion
This function creates a new iterator which points to the same place in the same table as the original iterator. If the original iterator is in the “null-pointer” state, then the clone is also in this state.
Note that bad things (garbage results, core dumps) may happen if you call this function on an iterator which has been invalidated by a change in the table’s contents.
See Also
Util_TableClone() [B52] create a new table which is a “clone” (exact copy) of an existing table
Util_TableItCreate() [B96] create a table iterator
Util_TableItDestroy() [B98] destroy a table iterator
Errors
UTIL_ERROR_BAD_HANDLE iterator handle to be cloned, is invalid
UTIL_ERROR_NO_MEMORY unable to allocate memory
Examples
Create a new table iterator
Synopsis
Result
ihandle (≥ 0) handle to the table iterator
Parameters
handle (≥ 0) handle to the table over which the iterator should iterate
Discussion
This function creates a new table iterator. The iterator initially points at the starting table entry.
See Also
Util_TableItDestroy() [B98] destroy a table iterator
Errors
UTIL_ERROR_BAD_HANDLE table handle is invalid
UTIL_ERROR_NO_MEMORY unable to allocate memory
Examples
Destroy a table iterator
Synopsis
Result
0 ok
Parameters
ihandle (≥ 0) handle to the table iterator
Discussion
See Also
Util_TableItCreate() [B96] create a table iterator
Errors
UTIL_ERROR_BAD_HANDLE iterator handle is invalid
UTIL_ERROR_NO_MEMORY unable to allocate memory
Examples
Query whether a table iterator is not in the “null-pointer” state
Synopsis
Result
1 iterator is not in the “null-pointer” state, i.e. iterator points to some table entry
0 iterator is in the “null-pointer” state
Parameters
ihandle (≥ 0) handle to the table iterator
Discussion
If no errors occur, Util_TableItQueryIsNonNull(ihandle) is the same as
1 - Util_TableItQueryIsNull(ihandle).
Note that bad things (garbage results, core dumps) may happen if you call this function on an iterator which has been invalidated by a change in the table’s contents.
See Also
Util_TableItQueryIsNull() [B103] query whether a table iterator is in the “null-pointer” state
Errors
UTIL_ERROR_BAD_HANDLE iterator handle is invalid
Examples
Query whether a table iterator is in the “null-pointer” state
Synopsis
Result
1 iterator is in the “null-pointer” state
0 iterator is not in the “null-pointer” state, i.e. iterator points to some table entry
Parameters
ihandle (≥ 0) handle to the table iterator
Discussion
If no errors occur, Util_TableItQueryIsNull(ihandle) is the same as 1 - Util_TableItQueryIsNonNull(ihandle).
Note that bad things (garbage results, core dumps) may happen if you call this function on an iterator which has been invalidated by a change in the table’s contents.
See Also
Util_TableItQueryIsNonNull() [B100] query whether a table iterator is not in the “null-pointer” state,
i.e. whether the iterator points to some table entry
Errors
UTIL_ERROR_BAD_HANDLE iterator handle is invalid
Examples
Query the key and the type and number of elements of the value corresponding to that key, of the table entry to which an iterator points
Synopsis
Result
key_length The string length of the key (this has C strlen semantics, i.e. it does not include a terminating
null character)
Parameters
ihandle (≥ 0) handle to the table iterator
key_buffer_length the length (sizeof) of key_buffer[] (must be ≥ 1 if key_buffer != NULL)
key_buffer a pointer to a buffer into which this function should store (at most key_buffer_length-1
characters of) the key, terminated by a null character as usual for C strings, or NULL pointer to skip storing this
type_code a pointer to where this function should store the value’s type code (one of the CCTK_VARIABLE_*
constants from "cctk_Constants.h"), or a NULL pointer to skip storing this.
N_elements a pointer to where this function should store the number of array elements in the value, or a NULL
pointer to skip storing this.
Discussion
The usual use of an iterator is to iterate through all the entries of a table, calling this function on each entry, then taking further action based on the results.
Note that bad things (garbage results, core dumps) may happen if you call this function on an iterator which has been invalidated by a change in the table’s contents.
If the error code UTIL_ERROR_TABLE_STRING_TRUNCATED is returned, then the first key_buffer_length-1 characters of the key are returned in the user’s key buffer (assuming key_buffer is non-NULL), followed by a null character to properly terminate the string in the buffer. If any other error code is returned, the user’s key buffer (pointed to by key_buffer if this is non-NULL) is unchanged.
See Also
Util_TableQueryValueInfo() [B121] query key present/absent in table, and optionally type and/or number of
elements, but using the key instead of an iterator
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_ITERATOR_IS_NULL iterator is in ”null-pointer” state
UTIL_ERROR_TABLE_STRING_TRUNCATED key_buffer != NULL and key was truncated to fit in key_buffer
Examples
Query what table a table iterator iterates over
Synopsis
Result
handle (≥ 0) handle to the table over which the iterator iterates
Parameters
ihandle (≥ 0) handle to the table iterator
Discussion
Note that it is always ok to call this function, regardless of whether or not the iterator is in the “null-pointer” state.
It’s also ok to call this function even when the iterator has been invalidated by a change in the table’s contents.
See Also
Util_TableItCreate() [B96] create an iterator (which iterates over a specified table)
Errors
UTIL_ERROR_BAD_HANDLE iterator handle is invalid
Reset a table iterator to point to the starting table entry
Synopsis
Result
Results are the same as calling Util_TableItQueryIsNonNull() on the iterator after the reset:
1 iterator is not in the “null-pointer” state, i.e. iterator points to some table entry
0 iterator is in the “null-pointer” state (this happens if and only if the table is empty)
Parameters
ihandle (≥ 0) handle to the table iterator
Discussion
Note that it is always ok to call this function, regardless of whether or not the iterator is in the “null-pointer” state.
It’s also ok to call this function even when the iterator has been invalidated by a change in the table’s contents.
See Also
Util_TableItSetToNull() [B116] set an iterator to the “null-pointer” state
Util_TableItSetToKey() [B114] set an iterator to point to a specified table entry
Errors
UTIL_ERROR_BAD_HANDLE iterator handle is invalid
Set a table iterator to point to a specified table entry
Synopsis
Result
0 ok
Parameters
ihandle (≥ 0) handle to the table iterator
Discussion
This function has the same effect as calling Util_TableItResetToStart() followed by calling Util_TableItAdvance() zero or more times to make the iterator point to the desired table entry. However, this function will typically be (much) more efficient than that sequence.
Note that it is always ok to call this function, regardless of whether or not the iterator is in the “null-pointer” state.
It’s also ok to call this function even when the iterator has been invalidated by a change in the table’s contents.
See Also
Util_TableItResetToStart() [B112] reset an iterator to point to the starting table entry
Util_TableItSetToNull() [B116] set a table iterator to the ”null-pointer” state
Errors
UTIL_ERROR_BAD_HANDLE iterator handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_TABLE_NO_SUCH_KEY no such key in table
Set a table iterator to the ”null-pointer” state
Synopsis
Result
0 ok
Parameters
ihandle (≥ 0) handle to the table iterator
Discussion
Note that it is always ok to call this function, regardless of whether or not the iterator is already in the “null-pointer” state.
It’s also ok to call this function even when the iterator has been invalidated by a change in the table’s contents.
See Also
Util_TableItResetToStart() [B112] reset an iterator to point to the starting table entry
Util_TableItSetToKey() [B114] set an iterator to point to a specified table entry
Errors
UTIL_ERROR_BAD_HANDLE iterator handle is invalid
Query a table’s flags word
Synopsis
Result
flags (≥ 0) the flags word
Parameters
handle (≥ 0) handle to the table
Discussion
See Util_TableCreate() for further discussion of the semantics of flag words.
See Also
Util_TableClone() [B52] create a new table which is a “clone” (exact copy) of an existing table
Util_TableCreate() [B57] create a table (flags word specified explicitly)
Util_TableCreateFromString() [B61] convenience routine to create a table (with certain default flags) and set
key/value entries in it based on a parameter-file–like character string
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
Examples
Query whether or not a specified key is in the table, and optionally the type and/or number of elements of the value corresponding to this key
Synopsis
Result
1 ok (key is in table)
0 ok (no such key in table)
(in this case nothing is stored in *type_code and *N_elements)
Parameters
handle (≥ 0) handle to the table
type_code a pointer to where this function should store the value’s type code (one of the CCTK_VARIABLE_*
constants from "cctk_Constants.h"), or a NULL pointer to skip storing this.
N_elements a pointer to where this function should store the number of array elements in the value, or a NULL
pointer to skip storing this.
key a pointer to the key (a C-style null-terminated string)
Discussion
Unlike all the other table query functions, this function returns 0 for “no such key in table”. The rationale for this design is that by passing NULL pointers for type_code and N_elements, this function is then a Boolean “is key in table?” predicate.
If any error code is returned, the user’s buffers (pointed to by type_code and N_elements if these are non-NULL) are unchanged.
See Also
Util_TableItQueryKeyValueInfo() [B106] query key present/absent in table, and optionally type and/or
number of elements, but using an iterator instead of the key
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ‘/’ character
Examples
Query the maximum key length in a table
Synopsis
Result
max_key_length (≥ 0) The string length of the longest key in the table (this has C strlen semantics, i.e. it
does not include a terminating null character)
Parameters
handle (≥ 0) handle to the table
Discussion
This function is useful if you’re going to iterate through a table, and you want to allocate a buffer which is guaranteed to be big enough to hold any key in the table.
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
Examples
Query the number of key/value entries in a table
Synopsis
Result
N_Keys (≥ 0) the number of key/value entries in the table
Parameters
handle (≥ 0) handle to the table
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
This is a family of functions, one for each Cactus data type, to set the value associated with a specified key to be a specified single (1-element array) value
Synopsis
where XXX is one of POINTER, FPOINTER3, CHAR, BYTE, INT, INT1, INT2, INT4, INT8, REAL, REAL4, REAL8, REAL16, COMPLEX, COMPLEX8, COMPLEX16, COMPLEX32 (not all of these may be supported on any given system)
where CCTK_XXX may be any data type supported by C (above) except CCTK_CHAR (Fortran doesn’t have a separate “character” data type; use CCTK_BYTE instead)
Result
1 ok (key was already in table before this call, old value was replaced)
(it doesn’t matter what the old value’s type_code and N_elements were, i.e. these do not have to match the
new value)
0 ok (key was not in table before this call)
Parameters
handle (≥ 0) handle to the table
value the value to be associated with the key
key a pointer to the key (a C-style null-terminated string)
Discussion
The key may be any C character string which does not contain a slash character (’/’).
The value is stored as a 1-element array.
This function invalidates any iterators for the table which are not in the “null-pointer” state.
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value, or more generally the first array element of an array
value
Util_TableGet*Array() get an array value
Util_TableGetGeneric() [B79] get a single (1-element array) value with generic data type
Util_TableGetGenericArray() [B83] get an array value with generic data type
Util_TableGetString() [B87] get a character-string value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetFromString() [B139] convenience routine to set key/value entries in a table based on a
parameter-file–like character string
Util_TableSetString() [B152] set a character-string value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_NO_MEMORY unable to allocate memory
Examples
This is a family of functions, one for each Cactus data type, to set the value associated with a specified key to be a copy of a specified array
Synopsis
where XXX is one of POINTER, FPOINTER4, CHAR, BYTE, INT, INT1, INT2, INT4, INT8, REAL, REAL4, REAL8, REAL16, COMPLEX, COMPLEX8, COMPLEX16, COMPLEX32 (not all of these may be supported on any given system)
where CCTK_XXX may be any data type supported by C (above)
Result
1 ok (key was already in table before this call, old value was replaced)
(it doesn’t matter what the old value’s type_code and N_elements were, i.e. these do not have to match the
new value)
0 ok (key was not in table before this call)
Parameters
handle (≥ 0) handle to the table
N_elements (≥ 0) the number of array elements in array[]
array a pointer to the array (a copy of which) is to be associated with the key
key a pointer to the key (a C-style null-terminated string)
Discussion
The key may be any C character string which does not contain a slash character (’/’).
Note that empty (0-element) arrays are ok.
This function invalidates any iterators for the table which are not in the “null-pointer” state.
Note that the table makes (stores) a copy of the array you pass in, so it’s somewhat inefficient to store a large array (e.g. a grid function) this way. If this is a problem, consider storing a CCTK_POINTER (pointing to the array) in the table instead. (Of course, this requires that you ensure that the pointed-to data is still valid whenever that CCTK_POINTER is used.)
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value, or more generally the first array element of an array
value
Util_TableGet*Array() get an array value
Util_TableGetGeneric() [B79] get a single (1-element array) value with generic data type
Util_TableGetGenericArray() [B83] get an array value with generic data type
Util_TableGetString() [B87] get a character-string value
Util_TableSet*() set a single (1-element array) value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetFromString() [B139] convenience routine to set key/value entries in a table based on a
parameter-file–like character string
Util_TableSetString() [B152] set a character-string value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_BAD_INPUT N_elements < 0
UTIL_ERROR_NO_MEMORY unable to allocate memory
Examples
Sets values in a table based on a string argument, which is interpreted with “parameter-file” semantics
Synopsis
Result
count (≥ 0) the number of key/value entries set
Parameters
string a pointer to a C-style null-terminated string specifying the table entries to be set (see below for details
on the string contents)
Discussion
The string should contain a sequence of zero or more key=value “assignments”, separated by whitespace. This function processes these assignments in left-to-right order, setting corresponding key/value entries in the table.
The present implementation only recognises integer, real, and character-string values (not complex), and integer
and real arrays. To be precise, the string must match the following BNF:
string → | assign* |
assign → | whitespace* |
assign → | whitespace* key whitespace* = whitespace* value delimiter |
key → | any string not containing ’/’ or ’=’ or whitespace |
value → | array |
array → | { int_value* } |
int_value → | anything recognized as a valid integer by strdol(3) in base 10 |
real_value → | anything not recognized as a valid integer by strtol(3) but recognized as valid by strdod(3) |
string_value → | a C-style string enclosed in ”double quotes” (C-style character escape codes are allowed, i.e. bell (’\a’), backspace (’\b’), form-feed (’\f’), newline (’\n’), carriage-return (’\r’), tab (’\t’), vertical-tab (’\v’), backslash (’\\’), single-quote (’\’’), double-quote (’\"’), question-mark (’\?’)) |
string_value → | a C-style string enclosed in ’single quotes’ (C-style character escape codes are not allowed, i.e. every character within the string is interpreted literally) |
delimiter → | end-of-string |
whitespace → | blank (’ ’)
|
Notice also that the keys allowed by this function are somewhat more restricted than those allowed by the other Util_TableSet*() functions, in that this function disallows keys containing ’=’ and/or whitespace.
If any error code is returned, assignments lexicographically earlier in the input string than where the error was detected will already have been made in the table. Unfortunately, there is no easy way to find out where the error was detected. :(
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value, or more generally the first array element of an array
value
Util_TableGet*Array() get an array value
Util_TableGetGeneric() [B79] get a single (1-element array) value with generic data type
Util_TableGetGenericArray() [B83] get an array value with generic data type
Util_TableGetString() [B87] get a character-string value
Util_TableSet*() set a single (1-element array) value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetString() [B152] set a character-string value
Errors
UTIL_ERROR_NO_MEMORY unable to allocate memory
UTIL_ERROR_BAD_KEY invalid input: key contains invalid character
UTIL_ERROR_BAD_INPUT invalid input: can’t parse input string
UTIL_ERROR_NO_MIXED_TYPE_ARRAY invalid input: different array values have different datatypes
other error codes this function may also return any error codes returned by Util_TableSetString(),
Util_TableSetInt(), Util_TableSetReal(), Util_TableSetIntArray(), or Util_TableSetRealArray().
Examples
Set the value associated with a specified key to be a specified single (1-element array) value, whose data type is generic. That is, the value is specified by a CCTK_VARIABLE_* type code and a void * pointer.
Synopsis
Result
1 ok (key was already in table before this call, old value was replaced)
(it doesn’t matter what the old value’s type_code and N_elements were, i.e. these do not have to match the
new value)
0 ok (key was not in table before this call)
Parameters
handle (≥ 0) handle to the table
type_code the array elements’ type code (one of the CCTK_VARIABLE_* constants from "cctk_Constants.h")
value_ptr a pointer to the value to be associated with the key
key a pointer to the key (a C-style null-terminated string)
Discussion
The key may be any C character string which does not contain a slash character (’/’).
The value is stored as a 1-element array.
This function invalidates any iterators for the table which are not in the “null-pointer” state.
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value, or more generally the first array element of an array
value
Util_TableGet*Array() get an array value
Util_TableGetGeneric() [B79] get a single (1-element array) value with generic data type
Util_TableGetGenericArray() [B83] get an array value with generic data type
Util_TableGetString() [B87] get a character-string value
Util_TableSet*() set a single (1-element array) value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetFromString() [B139] convenience routine to set key/value entries in a table based on a
parameter-file–like character string
Util_TableSetString() [B152] set a character-string value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_BAD_INPUT type_code is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_NO_MEMORY unable to allocate memory
Examples
Set the value associated with a specified key to be a copy of a specified array, whose data type is generic. That is, the array is specified by a CCTK_VARIABLE_* type code, a count of the number of array elements, and a void * pointer.
Synopsis
Result
1 ok (key was already in table before this call, old value was replaced)
(it doesn’t matter what the old value’s type_code and N_elements were, i.e. these do not have to match the
new value)
0 ok (key was not in table before this call)
Parameters
handle (≥ 0) handle to the table
type_code the array elements’ type code (one of the CCTK_VARIABLE_* constants from "cctk_Constants.h")
N_elements (≥ 0) the number of array elements in array[]
value_ptr a pointer to the value to be associated with the key
key a pointer to the key (a C-style null-terminated string)
Discussion
The key may be any C character string which does not contain a slash character (’/’).
The value is stored as a 1-element array.
This function invalidates any iterators for the table which are not in the “null-pointer” state.
Note that the table makes (stores) a copy of the array you pass in, so it’s somewhat inefficient to store a large array (e.g. a grid function) this way. If this is a problem, consider storing a CCTK_POINTER (pointing to the array) in the table instead. (Of course, this requires that you ensure that the pointed-to data is still valid whenever that CCTK_POINTER is used.)
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value, or more generally the first array element of an array
value
Util_TableGet*Array() get an array value
Util_TableGetGeneric() [B79] get a single (1-element array) value with generic data type
Util_TableGetGenericArray() [B83] get an array value with generic data type
Util_TableGetString() [B87] get a character-string value
Util_TableSet*() set a single (1-element array) value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetFromString() [B139] convenience routine to set key/value entries in a table based on a
parameter-file–like character string
Util_TableSetString() [B152] set a character-string value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_BAD_INPUT type_code is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_NO_MEMORY unable to allocate memory
Examples
Sets the value associated with a specified key in a table, to be a copy of a specified C-style null-terminated character string
Synopsis
Result
Results are the same as all the other Util_TableSet*() functions:
1 ok (key was already in table before this call, old value was replaced)
(it doesn’t matter what the old value’s type_code and N_elements were, i.e. these do not have to match the
new value)
0 ok (key was not in table before this call)
Parameters
handle (≥ 0) handle to the table
string a pointer to the string (a C-style null-terminated string)
key a pointer to the key (a C-style null-terminated string)
Discussion
The key may be any C character string which does not contain a slash character (’/’).
The string is stored as an array of strlen(string) CCTK_CHARs. It does not include a terminating null character.
This function is very similar to Util_TableSetCharArray().
This function invalidates any iterators for the table which are not in the “null-pointer” state.
See Also
Util_TableCreateFromString() [B61] convenience routine to create a table and set key/value entries in it
based on a parameter-file–like character string
Util_TableGet*() get a single (1-element array) value, or more generally the first array element of an array
value
Util_TableGet*Array() get an array value
Util_TableGetGeneric() [B79] get a single (1-element array) value with generic data type
Util_TableGetGenericArray() [B83] get an array value with generic data type
Util_TableGetString() [B87] get a character-string value
Util_TableSetCharArray() [B135] get an array-of-CCTK_CHAR value
Util_TableSet*() set a single (1-element array) value
Util_TableSet*Array() set an array value
Util_TableSetGeneric() [B144] set a single (1-element array) value with generic data type
Util_TableSetGenericArray() [B148] set an array value with generic data type
Util_TableSetCharArray() [B135] set an array-of-CCTK_CHAR value
Errors
UTIL_ERROR_BAD_HANDLE handle is invalid
UTIL_ERROR_TABLE_BAD_KEY key contains ’/’ character
UTIL_ERROR_NO_MEMORY unable to allocate memory
Examples
1For backwards compatability the function Util_TableGetFnPointer() is also provided as an alias for Util_TableGetFPointer(). This is deprecated as of Cactus 4.0 beta 13.
2For backwards compatability the function Util_TableGetFnPointerArray() is also provided as an alias for Util_TableGetFPointerArray(). This is deprecated as of Cactus 4.0 beta 13.
3For backwards compatability the function Util_TableSetFnPointer() is also provided as an alias for Util_TableSetFPointer(). This is deprecated as of Cactus 4.0 beta 13.
4For backwards compatability the function Util_TableSetFnPointerArray() is also provided as an alias for Util_TableSetFPointerArray(). This is deprecated as of Cactus 4.0 beta 13.