本文整理汇总了C++中KDB::get方法的典型用法代码示例。如果您正苦于以下问题:C++ KDB::get方法的具体用法?C++ KDB::get怎么用?C++ KDB::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KDB
的用法示例。
在下文中一共展示了KDB::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parentKey
TEST_F (Simple, SetSystemGetAppend2)
{
using namespace kdb;
KDB kdb;
KeySet ks;
Key parentKey (testRoot, KEY_END);
ks.append (Key ("system" + testRoot + "key", KEY_VALUE, "value1", KEY_END));
kdb.get (ks, parentKey);
ASSERT_EQ (ks.size (), 1) << "got keys from freshly mounted backends";
ks.rewind ();
ks.next ();
EXPECT_EQ (ks.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong";
EXPECT_EQ (ks.current ().getString (), "value1") << "string of element in keyset wrong";
kdb.set (ks, parentKey);
kdb.close (parentKey);
KeySet ks2;
ks2.append (Key ("system" + testRoot + "key2", KEY_VALUE, "value2", KEY_END));
kdb.open (parentKey);
kdb.get (ks2, parentKey);
ks2.rewind ();
ks2.next ();
ASSERT_EQ (ks2.size (), 1) << "wrong size";
EXPECT_EQ (ks2.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong";
EXPECT_EQ (ks2.current ().getString (), "value1") << "string of element in keyset wrong";
}
示例2: main
int main(int argc, char**argv)
{
using namespace kdb;
KDB kdb;
KeySet ks;
kdb.get(ks, "/test/lift");
kdb.get(ks, "/test/material_lift");
kdb.get(ks, "/test/heavy_material_lift");
kdb.get(ks, "/test/person_lift");
Parameters par(ks);
std::cout << std::boolalpha;
std::cout << "delay: " << par.getTestLiftEmergencyDelay() << std::endl;
std::cout << "stops: " << par.getTestLiftEmergencyActionStops() << std::endl;
// std::cout << "algorithm: " << par.getTestLiftAlgorithm() << std::endl;
std::cout << "height #3: " << par.getTestLiftFloor3Height() << std::endl;
std::cout << "limit: " << par.getTestLiftLimit() << std::endl;
bool write = par.getTestLiftWrite();
par.setTestLiftWrite(false);
// write back to user/test/lift, see comments in lift.c
if (write)
{
kdb.set(ks, "user/test/lift");
}
return 0;
}
示例3:
TEST_F (Simple, RemoveFile)
{
using namespace kdb;
KDB kdb;
KeySet ks;
kdb.get (ks, testRoot);
ks.append (Key ("system" + testRoot + "remove", KEY_END));
ASSERT_EQ (ks.size (), 1) << "could not append key\n" << ks;
kdb.set (ks, testRoot);
ASSERT_EQ (ks.size (), 1) << "key gone after kdb.set?\n" << ks;
struct stat buf;
ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), 0) << "found no file";
Key parentKey;
kdb.close (parentKey);
kdb.open (parentKey);
kdb.get (ks, testRoot);
ks.clear ();
ASSERT_EQ (ks.size (), 0) << "keyset should be empty after clearing it\n" << ks;
kdb.set (ks, testRoot);
ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), -1) << "found wrong file";
}
示例4: main
int main()
{
using namespace kdb;
KDB kdb;
KeySet ks;
Context c;
kdb.get(ks, "/test/lift");
kdb.get(ks, "/test/material_lift");
kdb.get(ks, "/test/heavy_material_lift");
kdb.get(ks, "/test/person_lift");
Parameters par(ks,c);
std::cout << std::boolalpha;
std::cout << "delay: " << par.test.lift.emergency.delay << std::endl;
std::cout << "stops: " << par.test.lift.emergency.action.stops << std::endl;
kdb::test::Lift const & lift = par.test.lift;
std::cout << "height #3: " << lift.floor.n3.height << std::endl;
std::cout << "limit: " << par.test.lift.limit << std::endl;
bool write = lift.write;
par.test.lift.write = false;
// write back to user/test/lift, see comments in lift.c
if(write)
{
kdb.set(ks, "user/test/lift");
}
return 0;
}
示例5: doBasicTest
void TestCommand::doBasicTest ()
{
{
KDB kdb;
Key t = root.dup ();
t.addBaseName ("basic");
t.setString ("BasicString");
KeySet basic;
basic.append (t);
KeySet test;
kdb.get (test, root);
kdb.set (basic, root);
}
{
KDB kdb;
Key t = root.dup ();
t.addBaseName ("basic");
t.setString ("BasicString");
KeySet test;
kdb.get (test, root);
nrTest++;
if (!test.lookup (t))
{
nrError++;
cerr << "Basic test failed" << endl;
}
}
}
示例6: main
int main()
{
using namespace kdb;
KDB kdb;
KeySet ks;
kdb.get(ks, "/test/lift");
kdb.get(ks, "/test/material_lift");
kdb.get(ks, "/test/heavy_material_lift");
kdb.get(ks, "/test/person_lift");
Parameters par(ks);
std::cout << std::boolalpha;
std::cout << "delay: " << par.test().lift().emergency().getDelay() << std::endl;
std::cout << "stops: " << par.test().lift().emergency().action().getStops() << std::endl;
// std::cout << "algorithm: " << par.getTestLiftAlgorithm() << std::endl;
kdb::test::Lift const & lift = par.test().lift();
std::cout << "height #3: " << lift.floor().n3().getHeight() << std::endl;
std::cout << "limit: " << par.test().lift().getLimit() << std::endl;
bool write = lift.getWrite();
par.test().lift().setWrite(false);
// write back to user/test/lift, see comments in lift.c
if(write)
{
kdb.set(ks, "user/test/lift");
}
return 0;
}
示例7: doStringTest
void TestCommand::doStringTest ()
{
vector<string> teststrings;
teststrings.push_back ("");
teststrings.push_back ("value");
teststrings.push_back ("value with spaces");
teststrings.push_back (" a very long value with many spaces and basically very very long, but only text ... ");
for (int i = 1; i < 256; ++i)
teststrings.back () += " very very long, but only text ... ";
for (auto & teststring : teststrings)
{
{
KDB kdb;
Key t = root.dup ();
t.addBaseName ("string");
t.setString (teststring);
KeySet basic;
basic.append (t);
KeySet test;
kdb.get (test, root);
kdb.set (basic, root);
}
{
KDB kdb;
KeySet test;
kdb.get (test, root);
Key t = root.dup ();
t.addBaseName ("string");
Key res = test.lookup (t);
nrTest++;
if (!res)
{
nrError++;
cerr << "String test failed (key not found)" << t.getName () << endl;
continue;
}
nrTest++;
if (res.getString () != teststring)
{
nrError++;
cerr << "String test failed (value is not equal)" << endl;
cerr << "We got: \"" << res.getString () << "\"" << endl;
cerr << "We wanted: \"" << teststring << "\"" << endl;
}
}
}
}
示例8: mountBackend
kdb::Key mountBackend (int iteration)
{
using namespace kdb;
using namespace kdb::tools;
Key mp = getMountpointForIteration<VARIANT> (iteration);
std::string cf = "benchmark_" + plugin_variant_names[VARIANT] + "_" + std::to_string (iteration) + ".ecf";
unlink (cf.c_str ());
KDB kdb;
KeySet mountConfig;
kdb.get (mountConfig, "system/elektra/mountpoints");
MountBackendBuilder b;
b.setMountpoint (mp, KeySet (0, KS_END));
b.addPlugin (PluginSpec ("resolver"));
b.useConfigFile (cf);
b.addPlugin (PluginSpec ("dump"));
if (VARIANT != NO_CRYPTO)
{
KeySet pluginConfig;
pluginConfig.append (Key ("user/encrypt/key", KEY_VALUE, GPG_TEST_KEY_ID, KEY_END));
pluginConfig.append (Key ("user/gpg/unit_test", KEY_VALUE, "1", KEY_END));
b.addPlugin (PluginSpec (plugin_variant_names[VARIANT], pluginConfig));
}
b.validated ();
b.serialize (mountConfig);
kdb.set (mountConfig, "system/elektra/mountpoints");
kdb.close ();
return mp;
}
示例9: mountPoints
QString GUIBackend::mountPoints () const
{
Key parentKey (Backends::mountpointsPath, KEY_END);
KeySet mountConf;
KDB kdb (parentKey);
try
{
kdb.get (mountConf, parentKey);
}
catch (KDBException const & ex)
{
emit showMessage (tr ("Error"), tr ("Could not read from configuration."), QString (ex.what ()));
return "";
}
Backends::BackendInfoVector vec = Backends::getBackendInfo (mountConf);
QStringList mPoints;
mPoints.append ("system/elektra");
foreach (BackendInfo info, vec)
{
QString backend = QString::fromStdString (info.name);
if (backend.startsWith ("/"))
{
mPoints.append ("dir" + backend);
mPoints.append ("user" + backend);
mPoints.append ("system" + backend);
}
else
{
mPoints.append (backend);
}
}
示例10: test_kdbGetSet
void test_kdbGetSet()
{
cout << "testing kdbSet() and kdbGet()" << endl;
{
KeySet ks_set (5,
*Key ("user/tests/key3", KEY_DIR, KEY_END),
*Key ("user/tests/key3/1", KEY_END),
*Key ("user/tests/key3/2", KEY_END),
*Key ("user/tests/key3/3", KEY_VALUE, "value", KEY_END),
KS_END);
KeySet ks;
KDB kdb;
kdb.get (ks, "user/tests/key3");
ks.append(ks_set);
kdb.set (ks, "user/tests/key3");
}
// check if they were written
{
KDB kdb;
KeySet ks;
kdb.get (ks, "user/tests/key3");
exit_if_fail(ks.lookup("user/tests/key3/3"), "could not find previously written key");
succeed_if(ks.lookup("user/tests/key3/3").get<std::string>() == "value", "could not get value");
succeed_if(!ks.lookup("user/tests/key3/3").needSync(), "should not need sync");
}
// now remove keys (cleanup)
{
KeySet ks;
KDB kdb;
kdb.get (ks, "user/tests/key3");
ks.cut(Key("user/tests/key3", KEY_END));
kdb.set (ks, "user/tests/key3");
}
// check if its gone now
{
KDB kdb;
KeySet ks;
kdb.get (ks, "user/tests/key3");
succeed_if(!ks.lookup("user/tests/key3/3"), "key was not removed");
}
}
示例11: main
int main ()
{
using namespace kdb;
KDB kdb;
KeySet conf;
kdb.get (conf, "/");
std::cout << conf;
kdb.set (conf, "/");
}
示例12: updateEntry
/**
* @brief Allows for updating of a database entry.
*
* Will renew the entry and all its subkeys (configuration).
*
* @param entry A custom Entry object holding current information.
* @return true if the entry was updated, false if not
* @throw kdbrest::exception::EntryNotFoundException in case the entry
* to update does not exist.
*/
bool StorageEngine::updateEntry (model::Entry & entry)
{
using namespace kdb;
// register exclusive access
boost::unique_lock<boost::shared_mutex> lock (m_mutex_entryCache);
bool found = false;
std::vector<model::Entry> & entries = this->m_entryCache;
unsigned int i = 0;
while (i < entries.size ())
{
if (entries[i].getName ().compare (entry.getName ()) == 0)
{
found = true;
break;
}
i++;
}
if (!found)
{
throw exception::EntryNotFoundException ();
}
KDB kdb;
KeySet ks;
kdb.get (ks, entry.getName ());
Key k = ks.lookup (entry.getName ());
if (!k)
{
throw kdbrest::exception::EntryNotFoundException ();
}
ks.cut (entry);
ks.append (entry);
ks.append (entry.getSubkeys ());
if (kdb.set (ks, entry.getName ()) >= 1)
{
entries.erase (entries.begin () + i);
entries.push_back (entry);
return true;
}
else
{
return false;
}
}
示例13: main
int main()
{
using namespace kdb;
KDB kdb;
KeySet ks;
Coordinator c;
ThreadContext tc(c);
kdb.get(ks, "/test/lift");
kdb.get(ks, "/test/material_lift");
kdb.get(ks, "/test/heavy_material_lift");
kdb.get(ks, "/test/person_lift");
Environment <ContextPolicyIs<ThreadContext>> env(ks,tc);
// Environment <ContextPolicyIs<ThreadContext>, WritePolicyIs<ReadOnlyPolicy>> env(ks,tc);
std::cout << std::boolalpha;
std::cout << "delay: " << env.test.lift.emergency.delay << std::endl;
std::cout << "stops: " << env.test.lift.emergency.action.stops << std::endl;
// kdb::test::Lift <ContextPolicyIs<ThreadContext>, WritePolicyIs<ReadOnlyPolicy>> const & lift = env.test.lift;
kdb::test::Lift <ContextPolicyIs<ThreadContext>> const & lift = env.test.lift;
std::cout << "height #3: " << lift.floor.n3.height << std::endl;
std::cout << "limit: " << env.test.lift.limit << std::endl;
// kdb::test::lift::emergency::Delay <ContextPolicyIs<ThreadContext>, WritePolicyIs<ReadOnlyPolicy>> delay(ks, tc);
// delay = 20; // read only value!
bool write = lift.write;
env.test.lift.write = false;
// write back to user/test/lift, see comments in lift.c
if (write)
{
kdb.set(ks, "user/test/lift");
}
return 0;
}
示例14: deleteUser
/**
* @brief Allows for deleting of an user entry.
*
* Will delete the entry iteself as well as all subkeys (additional user information).
*
* @param user A custom User object that should be deleted.
* @return true if the user was deleted successfully, false otherwise
* @throw kdbrest::exception::UserNotFoundException in case the user
* to delete does not exist.
*/
bool StorageEngine::deleteUser (model::User & user)
{
using namespace kdb;
// register exclusive access
boost::unique_lock<boost::shared_mutex> lock (m_mutex_userCache);
bool found = false;
std::vector<model::User> & users = this->m_userCache;
unsigned int i = 0;
while (i < users.size ())
{
if (users[i].getName ().compare (user.getName ()) == 0)
{
found = true;
break;
}
i++;
}
if (!found)
{
throw exception::UserNotFoundException ();
}
KDB kdb;
KeySet ks;
kdb.get (ks, user.getName ());
Key k = ks.lookup (user.getName ());
if (!k)
{
throw kdbrest::exception::UserNotFoundException ();
}
ks.cut (user);
if (kdb.set (ks, user.getName ()) >= 1)
{
users.erase (users.begin () + i);
return true;
}
else
{
return false;
}
}
示例15: execute
int TestCommand::execute(Cmdline const& cl)
{
if (cl.arguments.size() < 1)
{
throw invalid_argument ("need at least one argument");
}
// do a basic check on every argument
for (size_t i=1; i<cl.arguments.size(); ++i)
{
string name = " ";
name += cl.arguments[i];
name += " ";
if (testNames.find(name) == std::string::npos)
{
throw invalid_argument ("test name " +
cl.arguments[i] +
" does not exist in:" +
testNames);
}
}
printWarnings(cerr, root);
root = cl.createKey(0);
KDB kdb;
KeySet original;
kdb.get(original, root);
original.rewind();
doTests(cl.arguments);
cerr << "We got " << nrError << " errors in " << nrTest << " testcases." << endl;
cout << "Test suite is now finished." << endl;
cout << "Now restoring the original keyset." << endl;
kdb.set(original, root);
printWarnings(cerr, root);
return nrError;
}