本文整理汇总了C++中KeySet::rewind方法的典型用法代码示例。如果您正苦于以下问题:C++ KeySet::rewind方法的具体用法?C++ KeySet::rewind怎么用?C++ KeySet::rewind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeySet
的用法示例。
在下文中一共展示了KeySet::rewind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parentKey
TEST_F (Simple, GetSystem)
{
using namespace kdb;
KDB kdb;
KeySet ks;
Key parentKey ("system" + testRoot, KEY_END);
ks.append (Key (parentKey.getName () + "/key", KEY_END));
EXPECT_NE (kdb.get (ks, parentKey), -1);
ASSERT_EQ (ks.size (), 1) << "no key stayed" << ks;
ks.rewind ();
ks.next ();
EXPECT_EQ (ks.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong";
EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong";
ASSERT_NE (kdb.set (ks, parentKey), -1);
ks.rewind ();
ks.next ();
EXPECT_EQ (ks.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong";
EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong";
kdb.close (parentKey);
KeySet ks2;
kdb.open (parentKey);
kdb.get (ks2, parentKey);
ks.rewind ();
ks.next ();
EXPECT_EQ (ks.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong";
EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong";
}
示例2: execute
int CpCommand::execute (Cmdline const & cl)
{
if (cl.arguments.size () != 2)
{
throw invalid_argument ("wrong number of arguments, 2 needed");
}
KeySet conf;
Key sourceKey = cl.createKey (0);
if (!sourceKey.isValid ())
{
throw invalid_argument ("Source given is not a valid keyname");
}
Key destKey = cl.createKey (1);
if (!destKey.isValid ())
{
throw invalid_argument ("Destination given is not a valid keyname");
}
string newDirName = destKey.getName ();
kdb.get (conf, sourceKey);
kdb.get (conf, destKey);
KeySet tmpConf = conf;
KeySet oldConf;
oldConf.append (tmpConf.cut (sourceKey));
KeySet newConf;
oldConf.rewind ();
std::string sourceName = sourceKey.getName ();
if (cl.verbose) cout << "common name: " << sourceName << endl;
if (cl.recursive)
{
// copy all keys with new name
Key k;
while ((k = oldConf.next ()))
{
Key rk = rename_key (k, sourceName, newDirName, cl.verbose);
copySingleKey (cl, rk, tmpConf, newConf);
}
}
else
{
// just copy one key
Key k = oldConf.next ();
Key rk = rename_key (k, sourceName, newDirName, cl.verbose);
copySingleKey (cl, rk, tmpConf, newConf);
}
newConf.append (tmpConf); // these are unrelated keys
newConf.append (oldConf); // these are the original keys
newConf.rewind ();
kdb.set (newConf, destKey);
return 0;
}
示例3: getBackendInfo
/**
* @brief give info about current mounted backends
*
* @param mountConf a keyset that contains everything below
* Backends::mountpointsPath
*
* @return an vector of information about mounted backends
*/
Backends::BackendInfoVector Backends::getBackendInfo (KeySet mountConf)
{
std::vector<BackendInfo> ret;
Key rootKey (Backends::mountpointsPath, KEY_END);
Key cur;
mountConf.rewind ();
while ((cur = mountConf.next ()))
{
if (cur.isDirectBelow (rootKey))
{
BackendInfo bi;
Key path = mountConf.lookup (cur.getName () + "/config/path");
if (path)
{
bi.path = path.getString ();
}
Key mp = mountConf.lookup (cur.getName () + "/mountpoint");
if (mp)
{
bi.mountpoint = mp.getString ();
}
bi.name = cur.getBaseName ();
ret.push_back (bi);
}
}
return ret;
}
示例4: readSpecification
void SpecReader::readSpecification (KeySet const & cks)
{
KeySet ks;
Key mp;
// only accept keys in 'spec' namespace
for (Key k : cks)
{
if (k.isSpec ())
{
ks.append (k);
}
}
ks.rewind (); // we need old fashioned loop, because it can handle ks.cut during iteration
for (Key k = ks.next (); k; k = ks.next ())
{
// search for mountpoint
Key m = k.getMeta<const Key> ("mountpoint");
if (m)
{
SpecMountpointReader smr (backends, bbi);
backends[k] = smr.readMountpointSpecification (ks.cut (k));
}
}
}
示例5: mergeKeySet
MergeResult ThreeWayMerge::mergeKeySet(const MergeTask& task)
{
MergeResult result;
detectConflicts (task, result);
detectConflicts (task.reverse (), result, true);
if (!result.hasConflicts()) return result;
// TODO: test this behaviour (would probably need mocks)
Key current;
KeySet conflicts = result.getConflictSet();
conflicts.rewind();
while ((current = conflicts.next ()))
{
for (vector<MergeConflictStrategy *>::iterator it = strategies.begin (); it != strategies.end (); ++it)
{
(*it)->resolveConflict (task, current, result);
if (!result.isConflict(current))
break;
}
}
return result;
}
示例6: mergeKeySet
MergeResult ThreeWayMerge::mergeKeySet (const MergeTask & task)
{
MergeResult result;
detectConflicts (task, result);
detectConflicts (task.reverse (), result, true);
if (!result.hasConflicts ()) return result;
// TODO: test this behaviour (would probably need mocks)
Key current;
KeySet conflicts = result.getConflictSet ();
conflicts.rewind ();
while ((current = conflicts.next ()))
{
for (auto & elem : strategies)
{
(elem)->resolveConflict (task, current, result);
if (!result.isConflict (current)) break;
}
}
return result;
}
示例7: cloneMountpoint
void RemountCommand::cloneMountpoint(Cmdline const & cl)
{
Key existingParent (Backends::getBasePath(existingName), KEY_END);
Key newParent (Backends::getBasePath(mp), KEY_END);
KeySet existingBackend = mountConf.cut(existingParent);
mountConf.append(existingBackend);
KeySet newBackend(existingBackend.size(), KS_END);
string configPath = newParent.getName() + "/config/path";
string mpPath = newParent.getName() + "/mountpoint";
existingBackend.rewind();
while (Key current = existingBackend.next())
{
Key newKey = rebaseKey (current, existingParent, newParent);
newBackend.append(newKey);
if (newKey.getName() == mpPath)
{
newKey.setString(mp);
}
if (newKey.getName() == configPath)
{
newKey.setString(cl.arguments[0]);
}
}
mountConf.append(newBackend);
}
示例8: readMountpointSpecification
SpecBackendBuilder SpecMountpointReader::readMountpointSpecification (KeySet const & cks)
{
ks = cks;
mp = ks.head ().dup ();
Key rmp (mp.dup ());
helper::removeNamespace (rmp);
bb.setMountpoint (rmp, mountConf);
processKey (mp);
bb.nodes++; // count mp
ks.lookup (mp, KDB_O_POP);
ks.rewind (); // we need old fashioned loop, because it can handle ks.cut during iteration
for (Key k = ks.next (); k; k = ks.next ())
{
// search for mountpoint
Key m = k.getMeta<const Key> ("mountpoint");
if (m)
{
SpecMountpointReader smr (backends, bbi);
backends[k] = smr.readMountpointSpecification (ks.cut (k));
continue;
}
processKey (k);
bb.nodes++;
}
bb.setBackendConfig (backendConfig);
bb.useConfigFile (mp.getMeta<std::string> ("mountpoint"));
return bb;
}
示例9: KeySet
TEST(Backend, SimpleBackend)
{
using namespace kdb;
using namespace kdb::tools;
Backend b;
b.setMountpoint(Key("/", KEY_CASCADING_NAME, KEY_END), KeySet(0, KS_END));
EXPECT_EQ(b.getMountpoint(), "/");
b.addPlugin("resolver");
b.addPlugin("dump");
b.useConfigFile("abc");
EXPECT_TRUE(b.validated());
KeySet mountConfig;
b.serialize(mountConfig);
// outputGTest(mountConfig, "mountConfig");
mountConfig.rewind();
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\/") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "This is a configuration for a backend, see subkeys for more information") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//config") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//config/path") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "abc") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//errorplugins") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//errorplugins/#5#resolver#resolver#") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//getplugins") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//getplugins/#0#resolver") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//getplugins/#5#dump#dump#") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//mountpoint") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "/") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//setplugins") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//setplugins/#0#resolver") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//setplugins/#5#dump") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_EQ(mountConfig.current().getName(), "system/elektra/mountpoints/\\//setplugins/#7#resolver") << "name of element in keyset wrong";
EXPECT_EQ(mountConfig.current().getString(), "") << "string of element in keyset wrong";
}
示例10: resolveConflict
void MetaMergeStrategy::resolveConflict(const MergeTask& task, Key& conflictKey, MergeResult& result)
{
conflictKey.rewindMeta();
Key currentMeta;
string baseLookup = rebasePath (conflictKey, task.mergeRoot, task.baseParent);
string ourLookup = rebasePath (conflictKey, task.mergeRoot, task.ourParent);
string theirLookup = rebasePath (conflictKey, task.mergeRoot, task.theirParent);
Key baseKey = task.base.lookup(baseLookup);
Key ourKey = task.ours.lookup(ourLookup);
Key theirKey = task.theirs.lookup(theirLookup);
Key root ("user/", KEY_END);
KeySet baseMeta = getMetaKeys (baseKey);
KeySet ourMeta = getMetaKeys (ourKey);
KeySet theirMeta = getMetaKeys (theirKey);
MergeTask metaTask(BaseMergeKeys (baseMeta, root), OurMergeKeys (ourMeta, root),
TheirMergeKeys (theirMeta, root), root);
MergeResult metaResult = innerMerger.mergeKeySet(metaTask);
KeySet mergedMeta = metaResult.getMergedKeys();
Key current;
mergedMeta.rewind();
while ((current = mergedMeta.next()))
{
string metaName = current.getName().substr(string("user/").length());
conflictKey.setMeta(metaName, current.getString());
}
ConflictOperation ourOperation = getOurConflictOperation(conflictKey);
ConflictOperation theirOperation = getTheirConflictOperation(conflictKey);
if (!metaResult.hasConflicts ())
{
if (ourOperation == CONFLICT_META && theirOperation == CONFLICT_META)
{
// TODO: addConflict deletes the key content
// without this strategy restoring the value the value would be lost
// this happens only for CONFLICT_META <--> CONFLICT_META conflicts
// add a test for this behaviour
copyKeyValue(ourKey, conflictKey);
result.resolveConflict (conflictKey);
result.addMergeKey (conflictKey);
}
}
}
示例11: b
TEST(MergeResult, ResolveConflictDeletesConflictMeta)
{
using namespace kdb;
using namespace kdb::tools;
Backend b("my_backend", "/");
b.addPlugin("resolver");
b.addPlugin("dump");
b.validated();
Key rootKey(Backends::mountpointsPath, KEY_END);
KeySet mountConfig;
b.serialise(rootKey, mountConfig);
// outputGTest(mountConfig, "mountConfig");
mountConfig.rewind();
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "serialised Backend") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/errorplugins") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/errorplugins/#5#resolver#resolver#") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/getplugins") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/getplugins/#0#resolver") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/getplugins/#5#dump#dump#") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/mountpoint") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "/") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/setplugins") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/setplugins/#0#resolver") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/setplugins/#5#dump") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "") << "string of element in keyset wrong";
mountConfig.next();
EXPECT_TRUE(mountConfig.current().getName() == "system/elektra/mountpoints/my_backend/setplugins/#7#resolver") << "name of element in keyset wrong";
EXPECT_TRUE(mountConfig.current().getString() == "") << "string of element in keyset wrong";
}
示例12:
TEST_F (Simple, GetAppendNamespaces)
{
using namespace kdb;
for (size_t i = 0; i < namespaces.size (); ++i)
{
KDB kdb;
KeySet ks;
ks.append (Key (namespaces[i].name + testRoot + "key", KEY_END));
kdb.get (ks, testRoot);
ASSERT_EQ (ks.size (), 1) << "did not got key appended first with namespace " << namespaces[i].name;
ks.rewind ();
ks.next ();
EXPECT_EQ (ks.current ().getName (), namespaces[i].name + "/tests/kdb/key") << "name of element in keyset wrong";
EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong";
}
}
示例13: root
TEST_F(ThreeWayMergeTest, CascadingParentsCauseNoCascadingKeys)
{
Key root("/", KEY_END);
MergeResult result = merger.mergeKeySet(MergeTask(BaseMergeKeys(base, Key("/parentb", KEY_END)),
OurMergeKeys(ours, Key("/parento", KEY_END)),
TheirMergeKeys (theirs, Key("/parentt", KEY_END)),
root));
EXPECT_FALSE(result.hasConflicts()) << "Invalid conflict detected";
Key current;
KeySet merged = result.getMergedKeys ();
merged.rewind();
while ((current = merged.next ()))
{
EXPECT_FALSE(current.getNamespace() == "/");
}
}
示例14: readSpecification
void SpecReader::readSpecification (KeySet const & cks)
{
KeySet ks (cks);
Key mp;
ks.rewind (); // we need old fashioned loop, because it can handle ks.cut during iteration
for (Key k = ks.next (); k; k = ks.next ())
{
// search for mountpoint
Key m = k.getMeta<const Key> ("mountpoint");
if (m)
{
SpecMountpointReader smr (backends, bbi);
backends[k] = smr.readMountpointSpecification (ks.cut (k));
}
}
}
示例15:
TEST_F(ThreeWayMergeTest, EqualKeySetsWontCauseSync)
{
unsyncKeys(ours);
unsyncKeys(theirs);
unsyncKeys(base);
MergeResult result = merger.mergeKeySet (base, ours, theirs, ourParent);
EXPECT_FALSE(result.hasConflicts()) << "Invalid conflict detected";
KeySet merged = result.getMergedKeys();
Key current;
merged.rewind();
while ((current = merged.next ()))
{
EXPECT_FALSE(current.needSync());
}
}