Elektra
0.8.14
|
for kdb.h. More...
Functions | |
ssize_t | keySetStringF (Key *key, const char *format,...) |
Set a formatted string. More... | |
int | elektraArrayIncName (Key *key) |
Increment the name of the key by one. More... | |
int | elektraKsToMemArray (KeySet *ks, Key **buffer) |
Builds an array of pointers to the keys in the supplied keyset. More... | |
int | elektraKsFilter (KeySet *result, KeySet *input, int(*filter)(const Key *k, void *argument), void *argument) |
return only those keys from the given keyset that pass the supplied filter function with the supplied argument More... | |
KeySet * | elektraRenameKeys (KeySet *config, const char *name) |
Takes the first key and cuts off this common part for all other keys, instead name will be prepended. More... | |
elektraNamespace | keyGetNamespace (const Key *key) |
For currently valid namespaces see elektraNamespace. More... | |
int | keyLock (Key *key, enum elektraLockOptions what) |
Permanently locks a part of the key. More... | |
KeySet * | elektraArrayGet (const Key *arrayParent, KeySet *keys) |
Return all the array keys below the given arrayparent The arrayparent itself is not returned. More... | |
Key * | elektraArrayGetNextKey (KeySet *arrayKeys) |
Return the next key in the given array. More... | |
KeySet * | elektraKeyGetMetaKeySet (const Key *key) |
Return meta data as keyset. More... | |
Key * | ksPrev (KeySet *ks) |
Returns the previous Key in a KeySet. More... | |
Key * | ksPopAtCursor (KeySet *ks, cursor_t pos) |
Pop key at given cursor position. More... | |
for kdb.h.
These methods are a technical preview of what might be added in future Elektra releases. It is a requirement that methods are first added here, before they are added to the public API.
Usually, names in proposal stage should be prefixed with elektra to clearly mark that the signature is likely to be changed and not yet ABI compatible.
KeySet* elektraArrayGet | ( | const Key * | arrayParent, |
KeySet * | keys | ||
) |
Return all the array keys below the given arrayparent The arrayparent itself is not returned.
For example, if user/config/# is an array, user/config is the array parent. Only the direct array keys will be returned. This means that for example user/config/#1/key will not be included, but only user/config/#1.
A new keyset will be allocated for the resulting keys. This means that the caller must ksDel the resulting keyset.
arrayParent | the parent of the array to be returned |
keys | the keyset containing the array keys. |
NULL | on NULL pointers |
Key* elektraArrayGetNextKey | ( | KeySet * | arrayKeys | ) |
Return the next key in the given array.
The function will automatically allocate memory for a new key and name it accordingly.
The caller has to keyDel the resulting key.
arraykeys | the array where the new key will belong to |
NULL | if the passed array is empty |
NULL | on NULL pointers or if an error occurs |
int elektraArrayIncName | ( | Key * | key | ) |
Increment the name of the key by one.
Alphabetical order will remain
e.g. user/abc/#9 will be changed to user/abc/#_10
For the start: user/abc/# will be changed to user/abc/#0
key | which base name will be incremented |
-1 | on error (e.g. too large array, not validated array) |
0 | on success |
KeySet* elektraKeyGetMetaKeySet | ( | const Key * | key | ) |
Return meta data as keyset.
key | the key object to work with |
int elektraKsFilter | ( | KeySet * | result, |
KeySet * | input, | ||
int(*)(const Key *k, void *argument) | filter, | ||
void * | argument | ||
) |
return only those keys from the given keyset that pass the supplied filter function with the supplied argument
result | the keyset that should contain the filtered keys |
input | the keyset whose keys should be filtered |
filter | a function pointer to a function that will be used to filter the keyset. A key will be taken if the function returns a value greater than 0. |
argument | an argument that will be passed to the filter function each time it is called |
NULL | on NULL pointer |
int elektraKsToMemArray | ( | KeySet * | ks, |
Key ** | buffer | ||
) |
Builds an array of pointers to the keys in the supplied keyset.
The keys are not copied, calling keyDel may remove them from the keyset.
The size of the buffer can be easily allocated via ksGetSize. Example:
ks | the keyset object to work with |
buffer | the buffer to put the result into |
KeySet* elektraRenameKeys | ( | KeySet * | config, |
const char * | name | ||
) |
Takes the first key and cuts off this common part for all other keys, instead name will be prepended.
The first key is removed in the resulting keyset.
elektraNamespace keyGetNamespace | ( | const Key * | key | ) |
For currently valid namespaces see elektraNamespace.
To handle every possible cases (including namespaces) a key can have:
To loop over all valid namespaces use:
key | the key object to work with |
int keyLock | ( | Key * | key, |
enum elektraLockOptions | what | ||
) |
Permanently locks a part of the key.
This can be:
To unlock the key, duplicate it.
It is also possible to lock when the key is created with keyNew().
Some data structures need to lock the key (most likely its name), so that the ordering does not get confused.
key | which name should be locked |
>0 | the bits that were successfully locked |
0 | if everything was locked before |
-1 | if it could not be locked (nullpointer) |
ssize_t keySetStringF | ( | Key * | key, |
const char * | format, | ||
... | |||
) |
Set a formatted string.
key | the key to set the string value |
format | NULL-terminated text format string |
... | more arguments |
Key* ksPopAtCursor | ( | KeySet * | ks, |
cursor_t | pos | ||
) |
Pop key at given cursor position.
ks | the keyset to pop key from |
c | where to pop |
The internal cursor will be rewinded using ksRewind(). You can use ksGetCursor() and ksSetCursor() jump back to the previous position. e.g. to pop at current position within ksNext() loop:
0 | if ks is 0 |
Key* ksPrev | ( | KeySet * | ks | ) |
Returns the previous Key in a KeySet.
KeySets have an internal cursor that can be reset with ksRewind(). Every time ksPrev() is called the cursor is decremented and the new current Key is returned.
You'll get a NULL pointer if the key before begin of the KeySet was reached.
Don't delete the key, use ksPop() if you want to delete it.