table of contents
- unstable 0.8.14-5.1
api(3elektra) | Elektra | api(3elektra) |
NAME¶
api - API Proposals for Elektra
for kdb.h.
Functions¶
ssize_t keySetStringF (Key *key, const char *format,...)
Set a formatted string. int elektraArrayIncName (Key *key)
Increment the name of the key by one. int elektraKsToMemArray
(KeySet *ks, Key **buffer)
Builds an array of pointers to the keys in the supplied keyset. 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 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. elektraNamespace
keyGetNamespace (const Key *key)
For currently valid namespaces see elektraNamespace.
int keyLock (Key *key, enum elektraLockOptions
what)
Permanently locks a part of the key. KeySet * elektraArrayGet
(const Key *arrayParent, KeySet *keys)
Return all the array keys below the given arrayparent The arrayparent
itself is not returned. Key * elektraArrayGetNextKey (KeySet
*arrayKeys)
Return the next key in the given array. KeySet *
elektraKeyGetMetaKeySet (const Key *key)
Return meta data as keyset. Key * ksPrev (KeySet *ks)
Returns the previous Key in a KeySet. Key * ksPopAtCursor
(KeySet *ks, cursor_t pos)
Pop key at given cursor position.
Detailed Description¶
for kdb.h.
Warning:
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.
Function Documentation¶
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.
Parameters:
keys the keyset containing the array keys.
Returns:
Return values:
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.
Precondition:
The caller has to keyDel the resulting key.
Parameters:
Returns:
Return values:
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
Parameters:
Return values:
0 on success
KeySet* elektraKeyGetMetaKeySet (const Key * key)¶
Return meta data as keyset.
Parameters:
Returns:
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
Parameters:
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
Returns:
Return values:
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:
1 KeySet *ks = somekeyset; 2 Key **keyArray = calloc (ksGetSize(ks), sizeof (Key *)); 3 elektraKsToMemArray (ks, keyArray); 4 ... work with the array ... 5 free (keyArray);
Parameters:
buffer the buffer to put the result into
Returns:
a negative number on null pointers or if an error occurred
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.
Returns:
The first key is removed in the resulting keyset.
elektraNamespace keyGetNamespace (const Key * key)¶
For currently valid namespaces see elektraNamespace.
Since:
To handle every possible cases (including namespaces) a key can have:
switch (keyGetNamespace(k)) { case KEY_NS_SPEC:
printf ("spec namespace0);
break; case KEY_NS_PROC:
printf ("proc namespace0);
break; case KEY_NS_DIR:
printf ("dir namespace0);
break; case KEY_NS_USER:
printf ("user namespace0);
break; case KEY_NS_SYSTEM:
printf ("system namespace0);
break; case KEY_NS_EMPTY:
printf ("empty name0);
break; case KEY_NS_NONE:
printf ("no key0);
break; case KEY_NS_META:
printf ("meta key0);
break; case KEY_NS_CASCADING:
printf ("cascading key0);
break; }
To loop over all valid namespaces use:
for (elektraNamespace ns=KEY_NS_FIRST; ns<=KEY_NS_LAST; ++ns) {
// work with namespace
printf ("%d0, ns); }
Note:
Parameters:
Returns:
int keyLock (Key * key, enum elektraLockOptions what)¶
Permanently locks a part of the key. This can be:
- KEY_FLAG_LOCK_NAME to lock the name
- KEY_FLAG_LOCK_VALUE to lock the value
- KEY_FLAG_LOCK_META to lock the meta data
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.
Parameters:
See also:
Return values:
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.
Parameters:
format NULL-terminated text format string
... more arguments
Returns:
Key* ksPopAtCursor (KeySet * ks, cursor_t pos)¶
Pop key at given cursor position.
Parameters:
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:
1 cursor_t c = ksGetCursor(ks); 2 keyDel (ksPopAtCursor(ks, c)); 3 ksSetCursor(ks, c); 4 ksPrev(ks); // to have correct key after next ksNext()
Warning:
Returns:
Return values:
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.
Returns:
See also:
Author¶
Generated automatically by Doxygen for Elektra from the source code.
Sun May 29 2016 | Version 0.8.14 |