/usr/include/elektra/kdb.hpp is in libelektra-dev 0.8.14-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | #ifndef ELEKTRA_KDB_HPP
#define ELEKTRA_KDB_HPP
#include <string>
#include <key.hpp>
#include <keyset.hpp>
#include <kdbexcept.hpp>
#include <kdb.h>
/**
* @brief This is the main namespace for the C++ binding and libraries.
*
* Classes or Functions directly below this namespace are header-only.
* Sub namespaces are intended for libraries and you need to link
* the library if you want to use them.
* - @see kdb::tools
*/
namespace kdb
{
/**
* @copydoc KDB
*
* @brief Access to the key database.
*
* @invariant the object holds an valid connection to the key database
* or is empty
*/
class KDB
{
public:
KDB ();
KDB (Key & errorKey);
~KDB () throw();
void open(Key & errorKey);
void close(Key & errorKey) throw();
inline int get (KeySet & returned, std::string const & keyname);
inline int get (KeySet & returned, Key & parentKey);
inline int set (KeySet & returned, std::string const & keyname);
inline int set (KeySet & returned, Key & parentKey);
private:
ckdb::KDB* handle; ///< holds an kdb handle
};
/**
* Constructs a class KDB.
*
* @throw KDBException if database could not be opened
*
* @copydoc kdbOpen
*/
inline KDB::KDB ()
{
Key errorKey;
open(errorKey);
}
/**
* Constructs a class KDB.
*
* @param errorKey is useful if you want to get the warnings in
* the successful case, when no exception is thrown.
*
* @throw KDBException if database could not be opened
*
* @copydoc kdbOpen
*/
inline KDB::KDB (Key &errorKey)
{
open(errorKey);
}
/**
* The destructor closes the database.
*
* @copydoc kdbClose
*/
inline KDB::~KDB () throw()
{
Key errorKey;
try {
close (errorKey);
}
catch (...)
{
// silently drop potential warnings/errors
}
}
/**
* Open the database
*
* @param errorKey is useful if you want to get the warnings in
* the successful case, when no exception is thrown.
*
* @copydoc kdbOpen
*/
inline void KDB::open (Key &errorKey)
{
handle = ckdb::kdbOpen(errorKey.getKey());
if (!handle)
{
throw kdb::KDBException(errorKey);
}
}
/**
* Open the database.
*
* The return value does not matter because its only a null pointer check.
*
* @param errorKey is useful if you want to get the warnings
*
* @copydoc kdbClose
*/
inline void KDB::close (Key & errorKey) throw()
{
ckdb::kdbClose(handle, errorKey.getKey());
handle = 0;
}
/**
* @class doxygenKDBReturn
* @brief
*
* @retval 0 if no key was updated
* @retval 1 if user or system keys were updated
* @retval 2 if user and system keys were updated
*/
/**
* Get all keys below keyname inside returned.
*
* @copydoc kdbGet
*
* @include cpp_example_get.cpp
*
* @param returned the keyset where the keys will be in
* @param keyname the root keyname which should be used to get keys below it
*
* @copydetails doxygenKDBReturn
*
* @throw KDBException if there were problems with the database
*
* @see KDB::get (KeySet & returned, Key & parentKey)
*/
inline int KDB::get (KeySet & returned, std::string const & keyname)
{
Key parentKey (keyname.c_str(), KEY_CASCADING_NAME, KEY_END);
return get(returned, parentKey);
}
/**
* Get all keys below parentKey inside returned.
*
* @copydoc kdbGet
*
* @param returned the keyset where the keys will be in
* @param parentKey the parentKey of returned
*
* @copydetails doxygenKDBReturn
*
* @throw KDBException if there were problems with the database
*/
inline int KDB::get (KeySet & returned, Key & parentKey)
{
int ret = ckdb::kdbGet (handle, returned.getKeySet(), parentKey.getKey());
if (ret == -1)
{
throw KDBException(parentKey);
}
return ret;
}
/**
* Set all keys below keyname.
*
* If the keyname of the parentKey is invalid (e.g. empty) all keys will be set.
*
* @copydoc kdbSet
*
* @copydetails doxygenKDBReturn
*
* @param returned the keyset where the keys will be in
* @param keyname the keyname below the names should be set
*
* @throw KDBException if there were problems with the database
*/
inline int KDB::set (KeySet & returned, std::string const & keyname)
{
Key parentKey (keyname.c_str(), KEY_CASCADING_NAME, KEY_END);
return set (returned, parentKey);
}
/**
* Set all keys below parentKey.
*
* If the keyname of the parentKey is invalid (e.g. empty) all keys will be set.
*
* @copydoc kdbSet
*
* @copydetails doxygenKDBReturn
*
* @param returned the keyset where the keys are passed to the user
* @param parentKey the parentKey of returned
*
* @throw KDBException if there were problems with the database
*/
inline int KDB::set (KeySet & returned, Key & parentKey)
{
int ret = ckdb::kdbSet(handle, returned.getKeySet(), parentKey.getKey());
if (ret == -1)
{
throw KDBException(parentKey);
}
return ret;
}
} // end of namespace kdb
#endif
|