Elektra
0.8.16
|
Key is an essential class that encapsulates key name , value and metainfo . More...
#include <key.hpp>
Public Member Functions | |
Key () | |
Constructs an empty, invalid key. More... | |
Key (ckdb::Key *k) | |
Constructs a key out of a C key. More... | |
Key (Key &k) | |
Takes a reference of another key. More... | |
Key (Key const &k) | |
Takes a reference of another key. More... | |
Key (const char *keyName,...) | |
A practical way to fully create a Key object in one step. More... | |
Key (const std::string keyName,...) | |
A practical way to fully create a Key object in one step. More... | |
Key (const char *keyName, va_list ap) | |
A practical way to fully create a Key object in one step. More... | |
void | operator++ (int) const |
Increment the viability of a key object. More... | |
void | operator++ () const |
Increment the viability of a key object. More... | |
void | operator-- (int) const |
Decrement the viability of a key object. More... | |
void | operator-- () const |
Decrement the viability of a key object. More... | |
ssize_t | getReferenceCounter () const |
Return how many references the key has. More... | |
Key & | operator= (ckdb::Key *k) |
Assign a C key. More... | |
Key & | operator= (const Key &k) |
Assign a key. More... | |
void | copy (const Key &other) |
Copy or Clear a key. More... | |
void | clear () |
Clears/Invalidates a key. More... | |
Key * | operator-> () |
ckdb::Key * | getKey () const |
Passes out the raw key pointer. More... | |
ckdb::Key * | operator* () const |
Is a abbreviation for getKey. More... | |
ckdb::Key * | release () |
Passes out the raw key pointer and resets internal key handle. More... | |
ckdb::Key * | dup () const |
Return a duplicate of a key. More... | |
~Key () | |
Destructs the key. More... | |
std::string | getName () const |
Returns a pointer to the abbreviated real internal key name. More... | |
ssize_t | getNameSize () const |
Bytes needed to store the key name without owner. More... | |
std::string | getBaseName () const |
Returns a pointer to the internal unescaped key name where the basename starts. More... | |
ssize_t | getBaseNameSize () const |
Calculates number of bytes needed to store basename of key . More... | |
void | setName (const std::string &newName) |
Set a new name to a key. More... | |
void | setBaseName (const std::string &baseName) |
Sets a base name for a key. More... | |
void | addBaseName (const std::string &baseName) |
Adds a base name for a key. More... | |
ssize_t | getFullNameSize () const |
Bytes needed to store the key name including user domain and ending NULL. More... | |
std::string | getFullName () const |
Get key full name, including the user domain name. More... | |
bool | operator== (const Key &k) const |
Compare the name of two keys. More... | |
bool | operator!= (const Key &k) const |
Compare the name of two keys. More... | |
bool | operator< (const Key &other) const |
Compare the name of two keys. More... | |
bool | operator<= (const Key &other) const |
Compare the name of two keys. More... | |
bool | operator> (const Key &other) const |
Compare the name of two keys. More... | |
bool | operator>= (const Key &other) const |
Compare the name of two keys. More... | |
bool | isNull () const |
Checks if C++ wrapper has an underlying key. More... | |
operator bool () const | |
This is for loops and lookups only. More... | |
bool | needSync () const |
Test if a key needs to be synced to backend storage. More... | |
template<class T > | |
T | get () const |
Get a key value. More... | |
template<class T > | |
void | set (T x) |
Set a key value. More... | |
std::string | getString () const |
void | setString (std::string newString) |
Set the value for key as newStringValue . More... | |
ssize_t | getStringSize () const |
Returns the number of bytes needed to store the key value, including the NULL terminator. More... | |
func_t | getFunc () const |
Elektra can store function pointers as binary. More... | |
const void * | getValue () const |
Return a pointer to the real internal key value. More... | |
std::string | getBinary () const |
Get the value of a key as a binary. More... | |
ssize_t | getBinarySize () const |
Returns the number of bytes needed to store the key value, including the NULL terminator. More... | |
ssize_t | setBinary (const void *newBinary, size_t dataSize) |
Set the value of a key as a binary. More... | |
bool | hasMeta (const std::string &metaName) const |
template<class T > | |
T | getMeta (const std::string &metaName) const |
Returns the Value of a Meta-Information given by name. More... | |
template<class T > | |
void | setMeta (const std::string &metaName, T x) |
Set metadata for key. More... | |
void | delMeta (const std::string &metaName) |
Delete metadata for key. More... | |
void | copyMeta (const Key &other, const std::string &metaName) |
Do a shallow copy of meta data from source to dest. More... | |
void | copyAllMeta (const Key &other) |
Do a shallow copy of all meta data from source to dest. More... | |
void | rewindMeta () const |
Rewind the internal iterator to first meta data. More... | |
const Key | nextMeta () |
Iterate to the next meta information. More... | |
const Key | currentMeta () const |
Returns the Value of a Meta-Information which is current. More... | |
bool | isValid () const |
std::string | getNamespace () const |
bool | isSystem () const |
Name starts with "system". More... | |
bool | isUser () const |
Name starts with "user". More... | |
bool | isString () const |
Check if a key is string type. More... | |
bool | isBinary () const |
Check if a key is binary type. More... | |
bool | isInactive () const |
Check whether a key is inactive. More... | |
bool | isBelow (const Key &k) const |
Check if the key check is below the key key or not. More... | |
bool | isBelowOrSame (const Key &k) const |
Check if a key is below or same or not. More... | |
bool | isDirectBelow (const Key &k) const |
Check if the key check is direct below the key key or not. More... | |
Key is an essential class that encapsulates key name , value and metainfo .
To use it include:
Key properties are:
Key
structure is not defined in kdb.h, only declared. So you can only declare pointers
to Keys
in your program, and allocate and free memory for them with keyNew() and keyDel() respectively.This class is an wrapper for an optional, refcounted ckdb::Key. It is like an shared_ptr<ckdb::Key>, but the shared_ptr functionality is already within the Key and exposed with this wrapper.
|
inline |
|
inline |
|
inline |
Takes a reference of another key.
The key will not be copied, but the reference counter will be increased.
k | the key to work with |
|
inline |
Takes a reference of another key.
The key will not be copied, but the reference counter will be increased.
k | the key to work with |
|
inlineexplicit |
A practical way to fully create a Key object in one step.
To just get a key object, simple do:
If you want the key object to contain a name, value, comment and other meta info read on.
You can call it in many different ways depending on the attribute tags you pass as parameters. Tags are represented as keyswitch_t values, and tell keyNew() which Key attribute comes next.
We can also give an empty key name and a KEY_END tag with the same effect as before:
But we can also give the key a proper name right from the start:
So, keyNew() allocates memory for a key object and keyDel() cleans everything up.
keyNew() processes the given argument list even further. The Key attribute tags are the following:
keyName
is 0.name | a valid name to the key, or NULL to get a simple initialized, but really empty, object |
NULL | on allocation error or if an invalid name was passed (see keySetName()). |
bad_alloc | if key could not be constructed (allocation problems) |
keyName | the name of the new key |
|
inlineexplicit |
A practical way to fully create a Key object in one step.
To just get a key object, simple do:
If you want the key object to contain a name, value, comment and other meta info read on.
You can call it in many different ways depending on the attribute tags you pass as parameters. Tags are represented as keyswitch_t values, and tell keyNew() which Key attribute comes next.
We can also give an empty key name and a KEY_END tag with the same effect as before:
But we can also give the key a proper name right from the start:
So, keyNew() allocates memory for a key object and keyDel() cleans everything up.
keyNew() processes the given argument list even further. The Key attribute tags are the following:
keyName
is 0.name | a valid name to the key, or NULL to get a simple initialized, but really empty, object |
NULL | on allocation error or if an invalid name was passed (see keySetName()). |
bad_alloc | if key could not be constructed (allocation problems) |
keyName | the name of the new key |
|
inlineexplicit |
A practical way to fully create a Key object in one step.
To just get a key object, simple do:
If you want the key object to contain a name, value, comment and other meta info read on.
You can call it in many different ways depending on the attribute tags you pass as parameters. Tags are represented as keyswitch_t values, and tell keyNew() which Key attribute comes next.
We can also give an empty key name and a KEY_END tag with the same effect as before:
But we can also give the key a proper name right from the start:
So, keyNew() allocates memory for a key object and keyDel() cleans everything up.
keyNew() processes the given argument list even further. The Key attribute tags are the following:
keyName
is 0.name | a valid name to the key, or NULL to get a simple initialized, but really empty, object |
NULL | on allocation error or if an invalid name was passed (see keySetName()). |
bad_alloc | if key could not be constructed (allocation problems) |
keyName | the name of the new key |
ap | the variable argument list pointer |
|
inline |
Destructs the key.
|
inline |
Adds a base name for a key.
Adds baseName
(that will be escaped) to the current key name. A new baseName will be added, no other part of the key name will be affected.
Assumes that key
is a directory and will append baseName
to it. The function adds the path separator for concatenating.
So if key
has name "system/dir1/dir2"
and this method is called with baseName
"mykey"
, the resulting key will have the name "system/dir1/dir2/mykey"
.
When baseName
is 0 nothing will happen and the size of the name is returned.
The escaping rules apply as in above .
A simple example is:
E.g. if you add . it will be escaped:
key | the key object to work with |
baseName | the string to append to the name |
-1 | if the key had no name |
-1 | on NULL pointers |
-1 | if key was inserted to a keyset before |
KeyInvalidName | if the name is not valid |
|
inline |
Clears/Invalidates a key.
Afterwards the object is empty again.
Key Object Cleaner. Will reset all internal data.
After this call you will receive a fresh key.
The reference counter will stay unmodified.
returns | 0 on success |
-1 | on null pointer |
key | the key object to work with |
|
inline |
Copy or Clear a key.
Most often you may prefer keyDup() which allocates a new key and returns a duplication of another key.
But when you need to copy into an existing key, e.g. because it was passed by a pointer in a function you can do so:
The reference counter will not be changed for both keys. Affiliation to keysets are also not affected.
The meta data will be duplicated for the destination key. So it will not take much additional space, even with lots of metadata.
When you pass a NULL-pointer as source the data of dest will be cleaned completely (except reference counter, see keyClear()) and you get a fresh dest key:
If you want to copy everything, except e.g. the value you can use keyCopy() too:
Restrain from coping everything yourself, because it will lead to wrong metadata and is not able to copy empty or cascading names:
dest | the key which will be written to |
source | the key which should be copied or NULL to clean the destination key |
-1 | on failure when a NULL pointer was passed for dest or a dynamic property could not be written. The content will be unmodified then. |
0 | when dest was cleaned |
1 | when source was successfully copied |
|
inline |
Do a shallow copy of all meta data from source to dest.
The key dest will additionally have all meta data the source had. Meta data not present in source will not be changed. Meta data which was present in source and dest will be overwritten.
For example the meta data type is copied into the Key k:
The main purpose of this function is for plugins or applications which want to add the same meta data to n keys. When you do that with keySetMeta() it will take n times the memory for the key. This can be considerable amount of memory for many keys with some meta data for each.
To avoid that problem you can use keyCopyAllMeta() or keyCopyMeta():
1 | if was successfully copied |
0 | if source did not have any meta data |
-1 | on null pointer of dest or source |
-1 | on memory problems |
dest | the destination where the meta data should be copied too |
source | the key where the meta data should be copied from |
|
inline |
Do a shallow copy of meta data from source to dest.
The key dest will have the same meta data referred with metaName afterwards then source.
For example the meta data type is copied into the Key k.
The main purpose of this function is for plugins or applications which want to add the same meta data to n keys. When you do that with keySetMeta() it will take n times the memory for the key. This can be considerable amount of memory for many keys with some meta data for each.
To avoid that problem you can use keyCopyAllMeta() or keyCopyMeta().
1 | if was successfully copied |
0 | if the meta data in dest was removed too |
-1 | on null pointers (source or dest) |
-1 | on memory problems |
dest | the destination where the meta data should be copied too |
source | the key where the meta data should be copied from |
metaName | the name of the meta data which should be copied |
|
inline |
Returns the Value of a Meta-Information which is current.
The pointer is NULL if you reached the end or after ksRewind().
key | the key object to work with |
key's
cursor 0 | on NULL pointer |
|
inline |
Delete metadata for key.
|
inline |
Return a duplicate of a key.
Memory will be allocated as needed for dynamic properties.
The new key will not be member of any KeySet and will start with a new reference counter at 0. A subsequent keyDel() will delete the key.
Like for a new key after keyNew() a subsequent ksAppend() makes a KeySet to take care of the lifecycle of the key.
Duplication of keys should be preferred to keyNew(), because data like owner can be filled with a copy of the key instead of asking the environment. It can also be optimized in the checks, because the keyname is known to be valid.
source | has to be an initialized source Key |
0 | failure or on NULL pointer |
|
inline |
Get a key value.
You can write your own template specialication, e.g.:
It should be the same as get().
KeyException | on null key or not a valid size |
KeyTypeMismatch | if key holds binary data and not a string |
This method tries to serialise the string to the given type.
|
inline |
Returns a pointer to the internal unescaped key name where the basename
starts.
This is a much more efficient version of keyGetBaseName() and you should use it if you are responsible enough to not mess up things. The name might change or even point to a wrong place after a keySetName(). So make sure to copy the memory before the name changes.
keyBaseName() returns "" when there is no keyBaseName. The reason is
And there is also support for really empty basenames:
key | the object to obtain the basename from |
"" | when the key has no (base)name |
0 | on NULL pointer |
|
inline |
Calculates number of bytes needed to store basename of key
.
Key names that have only root names (e.g. "system"
or "user"
or "user:domain"
) does not have basenames, thus the function will return 1 bytes to store "".
Basenames are denoted as:
system/some/thing/basename
-> basename
user:domain/some/thing/base\/name
> base\/name
key | the key object to work with |
key's
basename including ending NULL
|
inline |
Get the value of a key as a binary.
"" | on null pointers (size == 0) and on data only containing \0 |
KeyException | on invalid binary size |
KeyTypeMismatch | if key is string and not a binary |
If the type is not binary -1 will be returned.
When the binary data is empty (this is not the same as ""!) 0 will be returned and the returnedBinary will not be changed.
For string values see keyGetString() and keyIsString().
When the returnedBinary is to small to hold the data (its maximum size is given by maxSize), the returnedBinary will not be changed and -1 is returned.
key | the object to gather the value from |
returnedBinary | pre-allocated memory to store a copy of the key value |
maxSize | number of bytes of pre-allocated memory in returnedBinary |
returnedBinary
0 | if the binary is empty |
-1 | on NULL pointers |
-1 | if maxSize is 0 |
-1 | if maxSize is too small for string |
-1 | if maxSize is larger than SSIZE_MAX |
-1 | on type mismatch: binary expected, but found string |
|
inline |
Returns the number of bytes needed to store the key value, including the NULL terminator.
It returns the correct size, independent of the Key Type. If it is a binary there might be '\0' values in it.
For an empty string you need one byte to store the ending NULL. For that reason 1 is returned. This is not true for binary data, so there might be returned 0 too.
A binary key has no '\0' termination. String types have it, so to there length will be added 1 to have enough space to store it.
This method can be used with elektraMalloc() before keyGetString() or keyGetBinary() is called.
key | the key object to work with |
1 | when there is no data and type is not binary |
0 | when there is no data and type is binary |
-1 | on null pointer |
|
inline |
Get key full name, including the user domain name.
1 | on empty name |
-1 | on NULL pointers |
-1 | if maxSize is 0 or larger than SSIZE_MAX |
key | the key object |
returnedName | pre-allocated memory to write the key name |
maxSize | maximum number of bytes that will fit in returnedName, including the final NULL |
KeyException | if key is null |
|
inline |
Bytes needed to store the key name including user domain and ending NULL.
key | the key object to work with |
1 | on empty name |
-1 | on NULL pointer |
|
inline |
Elektra can store function pointers as binary.
This function returns such a function pointer.
KeyTypeMismatch | if no binary data found, or binary data has not correct length |
|
inline |
Passes out the raw key pointer.
This pointer can be used to directly change the underlying key object.
|
inline |
Returns the Value of a Meta-Information given by name.
This is a much more efficient version of keyGetMeta(). But unlike with keyGetMeta you are not allowed to modify the resulting string.
key | the key object to work with |
metaName | the name of the meta information you want the value from |
0 | if the key or metaName is 0 |
0 | if no such metaName is found |
You can specify your own template specialisation:
KeyTypeConversion | if meta data could not be parsed |
If no meta is available:
|
inline |
Returns a pointer to the abbreviated real internal key
name.
This is a much more efficient version of keyGetName() and can use it if you are responsible enough to not mess up things. You are not allowed to change anything in the returned array. The content of that string may change after keySetName() and similar functions. If you need a copy of the name, consider using keyGetName().
The name will be without owner, see keyGetFullName() if you need the name with its owner.
"" | when there is no keyName. The reason is |
Valid key names are:
spec/something
for specification of other keys.proc/something
for in-memory keys, e.g. commandline.dir/something
for dir keys in current working directorysystem/something
for system keys in /etc or /user/something
for user keys in home directoryuser:username/something
for other users (deprecated: kdbGet() + kdbSet() currently unsupported)/something
for cascading keys (actually refers to one of the above, see also ksLookup())
key | the key object to work with |
"" | when there is no (a empty) keyname |
0 | on NULL pointer |
KeyException | if key is null |
|
inline |
Bytes needed to store the key name without owner.
For an empty key name you need one byte to store the ending NULL. For that reason 1 is returned.
key | the key object to work with |
1 | if there is is no key Name |
-1 | on NULL pointer |
|
inline |
Will return slash for cascading names.
|
inline |
Return how many references the key has.
The reference counting is the essential property of keys to make sure that they can be put safely into data structures. E.g. if you put a Key into a KeySet:
You can even add the key to more KeySets:
If you increment only by one with keyIncRef() the same as said above is valid:
or use keyIncRef() more than once:
The key won't be deleted by a keyDel() as long refcounter is not 0.
The references will be incremented on successful calls to ksAppendKey() or ksAppend().
For your own applications you can use keyIncRef() and keyDecRef() for reference counting, too.
key | the key object to work with |
-1 | on null pointer |
|
inline |
It should be the same as get().
KeyException | on null key or not a valid size |
KeyTypeMismatch | if key holds binary data and not a string |
|
inline |
Returns the number of bytes needed to store the key value, including the NULL terminator.
It returns the correct size, independent of the Key Type. If it is a binary there might be '\0' values in it.
For an empty string you need one byte to store the ending NULL. For that reason 1 is returned. This is not true for binary data, so there might be returned 0 too.
A binary key has no '\0' termination. String types have it, so to there length will be added 1 to have enough space to store it.
This method can be used with elektraMalloc() before keyGetString() or keyGetBinary() is called.
key | the key object to work with |
1 | when there is no data and type is not binary |
0 | when there is no data and type is binary |
-1 | on null pointer |
|
inline |
Return a pointer to the real internal key
value.
This is a much more efficient version of keyGetString() keyGetBinary(), and you should use it if you are responsible enough to not mess up things. You are not allowed to modify anything in the returned string. If you need a copy of the Value, consider to use keyGetString() or keyGetBinary() instead.
If key
is string (keyIsString()), you may cast the returned as a "char *"
because you'll get a NULL terminated regular string.
keyValue() returns "" in string mode when there is no value. The reason is
If the data is binary, the size of the value must be determined by keyGetValueSize(), any strlen() operations are not suitable to determine the size.
keyValue() returns 0 in binary mode when there is no value. The reason is
key | the key object to work with |
"" | when there is no data and key is not binary |
0 | where there is no data and key is binary |
0 | on NULL pointer |
|
inline |
true | if there is a metadata with given name |
false | if no such metadata exists |
|
inline |
Check if the key check is below the key key or not.
k | the other key |
Example:
key user/sw/app check user/sw/app/key
returns true because check is below key
Example:
key user/sw/app check user/sw/app/folder/key
returns also true because check is indirect below key
Obviously, there is no key above a namespace (e.g. user, system, /):
key * check user
key | the key object to work with |
check | the key to find the relative position of |
1 | if check is below key |
0 | if it is not below or if it is the same key |
|
inline |
Check if a key is below or same or not.
k | the other key |
key | the key object to work with |
|
inline |
Check if a key is binary type.
The function checks if the key is a binary. Opposed to string values binary values can have '\0' inside the value and may not be terminated by a null character. Their disadvantage is that you need to pass their size.
Make sure to use this function and don't test the binary type another way to ensure compatibility and to write less error prone programs.
1 | if it is binary |
0 | if it is not |
-1 | on NULL pointer |
key | the key to check |
|
inline |
Check if the key check is direct below the key key or not.
k | the other key |
Example: key user/sw/app check user/sw/app/key returns true because check is below key Example: key user/sw/app check user/sw/app/folder/key does not return true, because there is only a indirect relation
key | the key object to work with |
check | the key to find the relative position of |
1 | if check is below key |
0 | if it is not below or if it is the same key |
-1 | on null pointer |
|
inline |
Check whether a key is inactive.
In Elektra terminology a hierarchy of keys is inactive if the rootkey's basename starts with '.'. So a key is also inactive if it is below an inactive key. For example, user/key/.hidden is inactive and so is user/.hidden/below.
Inactive keys should not have any meaning to applications, they are only a convention reserved for users and administrators. To automatically remove all inactive keys for an application, consider to use the hidden plugin.
key | the key object to work with |
1 | if the key is inactive |
0 | if the key is active |
-1 | on NULL pointer or when key has no name |
|
inline |
Checks if C++ wrapper has an underlying key.
|
inline |
Check if a key is string type.
String values are null terminated and are not allowed to have any '\0' characters inside the string.
Make sure to use this function and don't test the string type another way to ensure compatibility and to write less error prone programs.
1 | if it is string |
0 | if it is not |
-1 | on NULL pointer |
key | the key to check |
|
inline |
Name starts with "system".
true | if it is a system key |
false | otherwise |
|
inline |
Name starts with "user".
true | if it is a user key |
false | otherwise |
|
inline |
An invalid key has no name. The name of valid keys either start with user or system.
true | if the key has a valid name |
false | if the key has an invalid name |
|
inline |
Test if a key needs to be synced to backend storage.
If any key modification took place the key will be flagged so that kdbSet() knows which keys were modified and which not.
After keyNew() the flag will normally be set, but after kdbGet() and kdbSet() the flag will be removed. When you modify the key the flag will be set again.
In your application you can make use of that flag to know if you changed something in a key after a kdbGet() or kdbSet().
key | the key object to work with |
1 | if key was changed in memory, 0 otherwise |
-1 | on NULL pointer |
|
inline |
Iterate to the next meta information.
Keys have an internal cursor that can be reset with keyRewindMeta(). Every time keyNextMeta() is called the cursor is incremented and the new current Name of Meta Information is returned.
You'll get a NULL pointer if the meta information after the end of the Key was reached. On subsequent calls of keyNextMeta() it will still return the NULL pointer.
The key
internal cursor will be changed, so it is not const.
key | the key object to work with |
0 | when the end is reached |
0 | on NULL pointer |
|
inline |
|
inline |
Compare the name of two keys.
The comparison is based on a strcmp of the keynames, and iff they match a strcmp of the owner will be used to distuingish. If even this matches the keys are found to be exactly the same and 0 is returned. These two keys can't be used in the same KeySet.
keyCmp() defines the sorting order for a KeySet.
The following 3 points are the rules for null values:
If the name is equal then:
Often is enough to know if the other key is less then or greater then the other one. But Sometimes you need more precise information, see keyRel().
Given any Keys k1 and k2 constructed with keyNew(), following equation hold true:
Here are some more examples:
And even more:
Do not strcmp the keyName() yourself because the result differs from simple ascii comparison.
k1 | the first key object to compare with |
k2 | the second key object to compare with |
true | != 0 |
|
inline |
Is a abbreviation for getKey.
Passes out the raw key pointer. This pointer can be used to directly change the underlying key object.
|
inline |
Increment the viability of a key object.
This function is intended for applications using their own reference counter for key objects. With it you can increment the reference and thus avoid destruction of the object in a subsequent keyDel().
The reference counter can't be incremented once it reached SSIZE_MAX. In that situation nothing will happen and SSIZE_MAX will be returned.
-1 | on null pointer |
SSIZE_MAX | when maximum exceeded |
key | the key object to work with |
|
inline |
Increment the viability of a key object.
This function is intended for applications using their own reference counter for key objects. With it you can increment the reference and thus avoid destruction of the object in a subsequent keyDel().
The reference counter can't be incremented once it reached SSIZE_MAX. In that situation nothing will happen and SSIZE_MAX will be returned.
-1 | on null pointer |
SSIZE_MAX | when maximum exceeded |
key | the key object to work with |
|
inline |
Decrement the viability of a key object.
The references will be decremented for ksPop() or successful calls of ksLookup() with the option KDB_O_POP. It will also be decremented with an following keyDel() in the case that an old key is replaced with another key with the same name.
The reference counter can't be decremented once it reached 0. In that situation nothing will happen and 0 will be returned.
-1 | on null pointer |
0 | when the key is ready to be freed |
key | the key object to work with |
|
inline |
Decrement the viability of a key object.
The references will be decremented for ksPop() or successful calls of ksLookup() with the option KDB_O_POP. It will also be decremented with an following keyDel() in the case that an old key is replaced with another key with the same name.
The reference counter can't be decremented once it reached 0. In that situation nothing will happen and 0 will be returned.
-1 | on null pointer |
0 | when the key is ready to be freed |
key | the key object to work with |
|
inline |
|
inline |
Compare the name of two keys.
The comparison is based on a strcmp of the keynames, and iff they match a strcmp of the owner will be used to distuingish. If even this matches the keys are found to be exactly the same and 0 is returned. These two keys can't be used in the same KeySet.
keyCmp() defines the sorting order for a KeySet.
The following 3 points are the rules for null values:
If the name is equal then:
Often is enough to know if the other key is less then or greater then the other one. But Sometimes you need more precise information, see keyRel().
Given any Keys k1 and k2 constructed with keyNew(), following equation hold true:
Here are some more examples:
And even more:
Do not strcmp the keyName() yourself because the result differs from simple ascii comparison.
k1 | the first key object to compare with |
k2 | the second key object to compare with |
true | < 0 |
|
inline |
Compare the name of two keys.
The comparison is based on a strcmp of the keynames, and iff they match a strcmp of the owner will be used to distuingish. If even this matches the keys are found to be exactly the same and 0 is returned. These two keys can't be used in the same KeySet.
keyCmp() defines the sorting order for a KeySet.
The following 3 points are the rules for null values:
If the name is equal then:
Often is enough to know if the other key is less then or greater then the other one. But Sometimes you need more precise information, see keyRel().
Given any Keys k1 and k2 constructed with keyNew(), following equation hold true:
Here are some more examples:
And even more:
Do not strcmp the keyName() yourself because the result differs from simple ascii comparison.
k1 | the first key object to compare with |
k2 | the second key object to compare with |
true | <= 0 |
|
inline |
Assign a C key.
Will call del() on the old key.
|
inline |
Compare the name of two keys.
The comparison is based on a strcmp of the keynames, and iff they match a strcmp of the owner will be used to distuingish. If even this matches the keys are found to be exactly the same and 0 is returned. These two keys can't be used in the same KeySet.
keyCmp() defines the sorting order for a KeySet.
The following 3 points are the rules for null values:
If the name is equal then:
Often is enough to know if the other key is less then or greater then the other one. But Sometimes you need more precise information, see keyRel().
Given any Keys k1 and k2 constructed with keyNew(), following equation hold true:
Here are some more examples:
And even more:
Do not strcmp the keyName() yourself because the result differs from simple ascii comparison.
k1 | the first key object to compare with |
k2 | the second key object to compare with |
true | == 0 |
|
inline |
Compare the name of two keys.
The comparison is based on a strcmp of the keynames, and iff they match a strcmp of the owner will be used to distuingish. If even this matches the keys are found to be exactly the same and 0 is returned. These two keys can't be used in the same KeySet.
keyCmp() defines the sorting order for a KeySet.
The following 3 points are the rules for null values:
If the name is equal then:
Often is enough to know if the other key is less then or greater then the other one. But Sometimes you need more precise information, see keyRel().
Given any Keys k1 and k2 constructed with keyNew(), following equation hold true:
Here are some more examples:
And even more:
Do not strcmp the keyName() yourself because the result differs from simple ascii comparison.
k1 | the first key object to compare with |
k2 | the second key object to compare with |
true | > 0 |
|
inline |
Compare the name of two keys.
The comparison is based on a strcmp of the keynames, and iff they match a strcmp of the owner will be used to distuingish. If even this matches the keys are found to be exactly the same and 0 is returned. These two keys can't be used in the same KeySet.
keyCmp() defines the sorting order for a KeySet.
The following 3 points are the rules for null values:
If the name is equal then:
Often is enough to know if the other key is less then or greater then the other one. But Sometimes you need more precise information, see keyRel().
Given any Keys k1 and k2 constructed with keyNew(), following equation hold true:
Here are some more examples:
And even more:
Do not strcmp the keyName() yourself because the result differs from simple ascii comparison.
k1 | the first key object to compare with |
k2 | the second key object to compare with |
true | >= 0 |
|
inline |
Passes out the raw key pointer and resets internal key handle.
0 | if no key is held (null pointer), no action is done then. |
|
inline |
Rewind the internal iterator to first meta data.
Use it to set the cursor to the beginning of the Key Meta Infos. keyCurrentMeta() will then always return NULL afterwards. So you want to keyNextMeta() first.
key | the key object to work with |
0 | on success |
0 | if there is no meta information for that key (keyNextMeta() will always return 0 in that case) |
-1 | on NULL pointer |
|
inline |
Set a key value.
Set the value for key
as newStringValue
. The function will allocate and save a private copy of newStringValue
, so the parameter can be freed after the call.
String values will be saved in backend storage, when kdbSetKey() will be called, in UTF-8 universal encoding, regardless of the program's current encoding, when iconv plugin is present.
key | the key to set the string value |
newStringValue | NULL-terminated text string to be set as key's value |
1 | if newStringValue is a NULL pointer, this will make the string empty (string only containing null termination) |
-1 | if key is a NULL pointer |
This method tries to deserialise the string to the given type.
|
inline |
Sets a base name for a key.
Sets baseName
as the new basename for key
. Only the baseName will be affected and no other part of the key.
All text after the last '/'
in the key
keyname is erased and baseName
is appended.
So let us suppose key
has name "system/dir1/dir2/key1"
. If baseName
is "key2"
, the resulting key name will be "system/dir1/dir2/key2"
. If baseName
is empty or NULL, the resulting key name will be "system/dir1/dir2"
.
This function does proper escaping on the supplied name argument.
You can use all names to set as basename (e.g. . (dot), .. (dot-dot), % and "" (empty)). They will be properly escaped.
A simple example is:
If you want to add and not change the basename, use keyAddBaseName() instead. If you do not want escaping, use keyAddName() instead.
To add an inactive key name, use:
When you want to add an array item, use:
key | the key object to work with |
baseName | the string used to overwrite the basename of the key |
-1 | on NULL pointers |
-1 | if key was inserted to a keyset before |
KeyInvalidName | if the name is not valid |
|
inline |
Set the value of a key as a binary.
A private copy of newBinary
will allocated and saved inside key
, so the parameter can be deallocated after the call.
Binary values might be encoded in another way then string values depending on the plugin. Typically character encodings should not take place on binary data. Consider using a string key instead.
When newBinary is a NULL pointer the binary will be freed and 0 will be returned.
key | the object on which to set the value |
newBinary | is a pointer to any binary data or NULL to free the previous set data |
dataSize | number of bytes to copy from newBinary |
0 | when the internal binary was freed and is now a null pointer |
-1 | if key is a NULL pointer |
-1 | when dataSize is 0 (but newBinary not NULL) or larger than SSIZE_MAX |
|
inline |
Set metadata for key.
Set a new Meta-Information. Will set a new Meta-Information pair consisting of metaName and newMetaString.
Will add a new Pair for Meta-Information if metaName was not added up to now.
It will modify a existing Pair of Meta-Information if the the metaName was inserted already.
It will remove a meta information if newMetaString is 0.
key | the key object to work with |
metaName | the name of the meta information where you want to change the value |
newMetaString | the new value for the meta information |
-1 | on error if key or metaName is 0, out of memory or names are not valid |
0 | if the Meta-Information for metaName was removed |
Use delMeta() to avoid these issues.
|
inline |
Set a new name to a key.
A valid name is one of the forms:
spec/something
for specification of other keys.proc/something
for in-memory keys, e.g. commandline.dir/something
for dir keys in current working directorysystem/something
for system keys in /etc or /user/something
for user keys in home directoryuser:username/something
for other users (deprecated: kdbGet() + kdbSet() currently unsupported)/something
for cascading keys (actually refers to one of the above, see also ksLookup())An invalid name either has an invalid namespace or a wrongly escaped \ at the end of the name.
See key names for the exact rules.
The last form has explicitly set the owner, to let the library know in which user folder to save the key. A owner is a user name. If it is not defined (the second form) current user is used.
You should always follow the guidelines for key tree structure creation.
A private copy of the key name will be stored, and the newName
parameter can be freed after this call.
.., . and / will be handled as in filesystem paths. A valid name will be build out of the (valid) name what you pass, e.g. user///sw/../sw//././MyApp -> user/sw/MyApp
On invalid names, NULL or "" the name will be "" afterwards.
size | in bytes of this new key name including ending NULL |
0 | if newName is an empty string or a NULL pointer (name will be empty afterwards) |
-1 | if newName is invalid (name will be empty afterwards) |
-1 | if key was inserted to a keyset before |
key | the key object to work with |
newName | the new key name |
KeyInvalidName | if the name is not valid |
|
inline |
Set the value for key
as newStringValue
.
The function will allocate and save a private copy of newStringValue
, so the parameter can be freed after the call.
String values will be saved in backend storage, when kdbSetKey() will be called, in UTF-8 universal encoding, regardless of the program's current encoding, when iconv plugin is present.
key | the key to set the string value |
newStringValue | NULL-terminated text string to be set as key's value |
1 | if newStringValue is a NULL pointer, this will make the string empty (string only containing null termination) |
-1 | if key is a NULL pointer |