Elektra  0.8.4
Public Member Functions
kdb::KDB Class Reference

Opens the session with the Key database. More...

#include <kdb.hpp>

Public Member Functions

 KDB ()
 Opens the session with the Key database.
 
 KDB (Key &errorKey)
 Opens the session with the Key database.
 
 ~KDB () throw ()
 
 
void open (Key &errorKey)
 Opens the session with the Key database.
 
void close (Key &errorKey) throw ()
 
 
int get (KeySet &returned, std::string const &keyname)
 Retrieve keys in an atomic and universal way, all other kdbGet() Functions rely on that one.
 
int get (KeySet &returned, Key &parentKey)
 Retrieve keys in an atomic and universal way, all other kdbGet() Functions rely on that one.
 
int set (KeySet &returned, std::string const &keyname)
 
 
int set (KeySet &returned, Key &parentKey)
 
 

Detailed Description

Opens the session with the Key database.

Constructs a class KDB.

Exceptions
KDBExceptionif database could not be opened

The first step is to open the default backend. With it system/elektra/mountpoints will be loaded and all needed libraries and mountpoints will be determined. These libraries for backends will be loaded and with it the KDB datastructure will be initialized.You must always call this method before retrieving or commiting any keys to the database. In the end of the program, after using the key database, you must not forget to kdbClose(). You can use the atexit () handler for it.The pointer to the KDB structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.Get a KDB handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:

thread1
{
KDB * h;
h = kdbOpen(0);
// fetch keys and work with them
kdbClose(h, 0);
}
thread2
{
KDB * h;
h = kdbOpen(0);
// fetch keys and work with them
kdbClose(h, 0);
}
You don't need to use the kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects without any affairs with the backend key database or when your application loads plugins directly.
Parameters
errorKeythe key which holds errors and warnings which were issued must be given
See Also
kdbClose() to end all affairs to the Key database.
Returns
a KDB pointer on success
NULL on failure

Access to the key database.

Invariant
the object holds an valid connection to the key database or is empty

Constructor & Destructor Documentation

kdb::KDB::KDB ( )
inline

Opens the session with the Key database.

Constructs a class KDB.

Exceptions
KDBExceptionif database could not be opened

The first step is to open the default backend. With it system/elektra/mountpoints will be loaded and all needed libraries and mountpoints will be determined. These libraries for backends will be loaded and with it the KDB datastructure will be initialized.You must always call this method before retrieving or commiting any keys to the database. In the end of the program, after using the key database, you must not forget to kdbClose(). You can use the atexit () handler for it.The pointer to the KDB structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.Get a KDB handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:

thread1
{
KDB * h;
h = kdbOpen(0);
// fetch keys and work with them
kdbClose(h, 0);
}
thread2
{
KDB * h;
h = kdbOpen(0);
// fetch keys and work with them
kdbClose(h, 0);
}
You don't need to use the kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects without any affairs with the backend key database or when your application loads plugins directly.
Parameters
errorKeythe key which holds errors and warnings which were issued must be given
See Also
kdbClose() to end all affairs to the Key database.
Returns
a KDB pointer on success
NULL on failure

kdb::KDB::KDB ( Key errorKey)
inline

Opens the session with the Key database.

Constructs a class KDB.

Parameters
errorKeyis useful if you want to get the warnings in the successful case, when no exception is thrown.
Exceptions
KDBExceptionif database could not be opened

The first step is to open the default backend. With it system/elektra/mountpoints will be loaded and all needed libraries and mountpoints will be determined. These libraries for backends will be loaded and with it the KDB datastructure will be initialized.You must always call this method before retrieving or commiting any keys to the database. In the end of the program, after using the key database, you must not forget to kdbClose(). You can use the atexit () handler for it.The pointer to the KDB structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.Get a KDB handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:

thread1
{
KDB * h;
h = kdbOpen(0);
// fetch keys and work with them
kdbClose(h, 0);
}
thread2
{
KDB * h;
h = kdbOpen(0);
// fetch keys and work with them
kdbClose(h, 0);
}
You don't need to use the kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects without any affairs with the backend key database or when your application loads plugins directly.
Parameters
errorKeythe key which holds errors and warnings which were issued must be given
See Also
kdbClose() to end all affairs to the Key database.
Returns
a KDB pointer on success
NULL on failure

kdb::KDB::~KDB ( ) throw ()
inline

The destructor closes the database.

Closes the session with the Key database.You should call this method when you finished your affairs with the key database. You can manipulate Key and KeySet objects also after kdbClose(). You must not use any kdb* call afterwards. You can implement kdbClose() in the atexit() handler.This is the counterpart of kdbOpen().The handle parameter will be finalized and all resources associated to it will be freed. After a kdbClose(), this handle can't be used anymore, unless it gets initialized again with another call to kdbOpen().

See Also
kdbOpen()
Parameters
handlecontains internal information of opened key database
errorKeythe key which holds error information
Returns
0 on success
-1 on NULL pointer

Member Function Documentation

void kdb::KDB::close ( Key errorKey) throw ()
inline

Open the database.

The return value does not matter because its only a null pointer check.

Parameters
errorKeyis useful if you want to get the warnings

Closes the session with the Key database.You should call this method when you finished your affairs with the key database. You can manipulate Key and KeySet objects also after kdbClose(). You must not use any kdb* call afterwards. You can implement kdbClose() in the atexit() handler.This is the counterpart of kdbOpen().The handle parameter will be finalized and all resources associated to it will be freed. After a kdbClose(), this handle can't be used anymore, unless it gets initialized again with another call to kdbOpen().

See Also
kdbOpen()
Parameters
handlecontains internal information of opened key database
errorKeythe key which holds error information
Returns
0 on success
-1 on NULL pointer

int kdb::KDB::get ( KeySet returned,
std::string const &  keyname 
)
inline

Retrieve keys in an atomic and universal way, all other kdbGet() Functions rely on that one.

Get all keys below keyname inside returned.

The returned KeySet must be initialized. The returned KeySet may already contain some keys. The new retrieved keys will be appended using ksAppendKey().It will fully retrieve all keys under the parentKey folder, with all subfolders and their children.

#include <kdb.hpp>
#include <keyio.hpp>
using namespace kdb;
int main()
{
KeySet config;
KDB kdb;
kdb.get(config, "/sw/MyApp");
Key k = config.lookup("/sw/MyApp/mykey");
if (k)
{
std::cout << k << " is " << k.get<int>() << std::endl;
}
else
{
std::cerr << "No key found" << std::endl;
return 1;
}
}
Parameters
returnedthe keyset where the keys will be in
keynamethe root keyname which should be used to get keys below it

Return values
0if no key was updated
1if user or system keys were updated
2if user and system keys were updated

Exceptions
KDBExceptionif there were problems with the database
See Also
KDB::get (KeySet & returned, Key & parentKey)
int kdb::KDB::get ( KeySet returned,
Key parentKey 
)
inline

Retrieve keys in an atomic and universal way, all other kdbGet() Functions rely on that one.

Get all keys below parentKey inside returned.

The returned KeySet must be initialized. The returned KeySet may already contain some keys. The new retrieved keys will be appended using ksAppendKey().It will fully retrieve all keys under the parentKey folder, with all subfolders and their children.

Parameters
returnedthe keyset where the keys will be in
parentKeythe parentKey of returned

Return values
0if no key was updated
1if user or system keys were updated
2if user and system keys were updated

Exceptions
KDBExceptionif there were problems with the database
void kdb::KDB::open ( Key errorKey)
inline

Opens the session with the Key database.

Open the database

Parameters
errorKeyis useful if you want to get the warnings in the successful case, when no exception is thrown.

The first step is to open the default backend. With it system/elektra/mountpoints will be loaded and all needed libraries and mountpoints will be determined. These libraries for backends will be loaded and with it the KDB datastructure will be initialized.You must always call this method before retrieving or commiting any keys to the database. In the end of the program, after using the key database, you must not forget to kdbClose(). You can use the atexit () handler for it.The pointer to the KDB structure returned will be initialized like described above, and it must be passed along on any kdb*() method your application calls.Get a KDB handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it:

thread1
{
KDB * h;
h = kdbOpen(0);
// fetch keys and work with them
kdbClose(h, 0);
}
thread2
{
KDB * h;
h = kdbOpen(0);
// fetch keys and work with them
kdbClose(h, 0);
}
You don't need to use the kdbOpen() if you only want to manipulate plain in-memory Key or KeySet objects without any affairs with the backend key database or when your application loads plugins directly.
Parameters
errorKeythe key which holds errors and warnings which were issued must be given
See Also
kdbClose() to end all affairs to the Key database.
Returns
a KDB pointer on success
NULL on failure

int kdb::KDB::set ( KeySet returned,
std::string const &  keyname 
)
inline

Set all keys below keyname.

If the keyname of the parentKey is invalid (e.g. empty) all keys will be set.

Set keys in an atomic and universal way.All other kdbSet Functions rely on that one.

Return values
0if no key was updated
1if user or system keys were updated
2if user and system keys were updated

Parameters
returnedthe keyset where the keys will be in
keynamethe keyname below the names should be set
Exceptions
KDBExceptionif there were problems with the database
int kdb::KDB::set ( KeySet returned,
Key parentKey 
)
inline

Set all keys below parentKey.

If the keyname of the parentKey is invalid (e.g. empty) all keys will be set.

Set keys in an atomic and universal way.All other kdbSet Functions rely on that one.

Return values
0if no key was updated
1if user or system keys were updated
2if user and system keys were updated

Parameters
returnedthe keyset where the keys are passed to the user
parentKeythe parentKey of returned
Exceptions
KDBExceptionif there were problems with the database

The documentation for this class was generated from the following file: