Arrays are used to store data which is referenced sequentially or as a stack. Functions are provided to push and pop individual elements as well as to operate on the entire array.
Tables are used to store data which can be referenced by key. Limited capabilities are provided for tables with multiple elements which share a key; while key lookup will return only a single element, iteration is available. Additionally, a table can be compressed to resolve duplicates.
Both arrays and tables may store string or binary data; some features, such as concatenation or merging of elements, work only for string data.
Define Documentation
#define APR_ARRAY_IDX
(
ary,
i,
type
)
(((type *)(ary)->elts)[i])
A helper macro for accessing a member of an APR array.
Parameters:
ary
the array
i
the index into the array to return
type
the type of the objects stored in the array
Returns:
the item at index i
#define APR_ARRAY_PUSH
(
ary,
type
)
(*((type *)apr_array_push(ary)))
A helper macro for pushing elements into an APR array.
Parameters:
ary
the array
type
the type of the objects stored in the array
Returns:
the location where the new object should be placed
The data passed as the first argument to apr_table_[v]do()
key
The key from this iteration of the table
value
The value from this iteration of the table
Remarks:
Iteration continues while this callback function returns non-zero. To export the callback function for apr_table_[v]do() it must be declared in the _NONSTD convention.
The alternate apr_array_copy_hdr copies only the header, and arranges for the elements to be copied if (and only if) the code subsequently does a push or arraycat.
Generate a new string from the apr_pool_t containing the concatenated sequence of substrings referenced as elements within the array. The string will be empty if all substrings are empty or null, or if there are no elements in the array. If sep is non-NUL, it will be inserted between elements as a separator.
Add data to a table, regardless of whether there is another element with the same key.
Parameters:
t
The table to add to
key
The key to use
val
The value to add.
Remarks:
When adding data, this function does not make a copy of the key or the value, so care should be taken to ensure that the values will not change after they have been added.
Create a new table whose contents are deep copied from the given table. A deep copy operation copies all fields, and makes copies of dynamically allocated memory pointed to by the fields.
Iterate over a table running the provided function once for every element in the table. The varargs array must be a list of zero or more (char *) keys followed by a NULL pointer. If zero keys are given, the
Parameters:
comp
function will be invoked for every element in the table. Otherwise, the function is invoked only for those elements matching the keys specified.
If an invocation of the
Parameters:
comp
function returns zero, iteration will continue using the next specified key, if any.
comp
The function to run
rec
The data to pass as the first argument to the function
t
The table to iterate over
...
A varargs array of zero or more (char *) keys followed by NULL
Returns:
FALSE if one of the comp() iterations returned zero; TRUE if all iterations returned non-zero
Add data to a table by merging the value with data that has already been stored. The merging is done by concatenating the two values, separated by the string ", ".
Parameters:
t
The table to search for the data
key
The key to merge data for (case does not matter)
val
The data to add
Remarks:
If the key is not found, then this function acts like apr_table_add
Add data to a table by merging the value with data that has already been stored. The merging is done by concatenating the two values, separated by the string ", ".
Parameters:
t
The table to search for the data
key
The key to merge data for (case does not matter)
val
The data to add
Remarks:
If the key is not found, then this function acts like apr_table_addn
For each element in table b, either use setn or mergen to add the data to table a. Which method is used is determined by the flags passed in.
Parameters:
a
The table to add the data to.
b
The table to iterate over, adding its data to table a
flags
How to add the table to table a. One of: APR_OVERLAP_TABLES_SET Use apr_table_setn APR_OVERLAP_TABLES_MERGE Use apr_table_mergen
Remarks:
When merging duplicates, the two values are concatenated, separated by the string ", ".
This function is highly optimized, and uses less memory and CPU cycles than a function that just loops through table b calling other functions. Conceptually, apr_table_overlap does this:
Add a key/value pair to a table. If another element already exists with the same key, this will overwrite the old data.
Parameters:
t
The table to add the data to.
key
The key to use (case does not matter)
val
The value to add
Warning:
When adding data, this function does not make a copy of the key or the value, so care should be taken to ensure that the values will not change after they have been added..