Elektra  0.8.16
Functions
API Proposals for Elektra

for kdb.h. More...

Collaboration diagram for API Proposals for Elektra:

Functions

ssize_t keySetStringF (Key *key, const char *format,...)
 Set a formatted string. More...
 
int elektraKsToMemArray (KeySet *ks, Key **buffer)
 Builds an array of pointers to the keys in the supplied keyset. More...
 
KeySet * ksRenameKeys (KeySet *config, const Key *name)
 Takes the first key and cuts off this common part for all other keys, instead name will be prepended. More...
 
int keyLock (Key *key, option_t what)
 Permanently locks a part of the key. 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...
 

Detailed Description

for kdb.h.

Warning
Do not use these methods if you do not want to depend on exactly the Elektra version your binary was built for.

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* elektraKeyGetMetaKeySet ( const Key *  key)

Return meta data as keyset.

Parameters
keythe key object to work with
Returns
a duplication of the keyset representing the meta data
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 elektraFree (keyArray);
Parameters
ksthe keyset object to work with
bufferthe buffer to put the result into
Returns
the number of elements in the array if successful
a negative number on null pointers or if an error occurred
int keyLock ( Key *  key,
option_t  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
keywhich name should be locked
See also
keyNew(), keyDup(), ksAppendKey()
Return values
>0the bits that were successfully locked
0if everything was locked before
-1if it could not be locked (nullpointer)
ssize_t keySetStringF ( Key *  key,
const char *  format,
  ... 
)

Set a formatted string.

Parameters
keythe key to set the string value
formatNULL-terminated text format string
...more arguments
Returns
the size of the string as set (with including 0)
Key* ksPopAtCursor ( KeySet *  ks,
cursor_t  pos 
)

Pop key at given cursor position.

Parameters
ksthe keyset to pop key from
cwhere 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
do not use, will be superseded by external iterator API
Returns
the popped key
Return values
0if 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.

Returns
the new current Key
See also
ksRewind(), ksCurrent()
KeySet* ksRenameKeys ( KeySet *  config,
const Key *  name 
)

Takes the first key and cuts off this common part for all other keys, instead name will be prepended.

Returns
a new allocated keyset with keys in user namespace.

The first key is removed in the resulting keyset.