本文整理汇总了C++中KeySet::next方法的典型用法代码示例。如果您正苦于以下问题:C++ KeySet::next方法的具体用法?C++ KeySet::next怎么用?C++ KeySet::next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeySet
的用法示例。
在下文中一共展示了KeySet::next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parentKey
TEST_F (Simple, GetAppendMeta)
{
using namespace kdb;
KDB kdb;
KeySet ks;
ks.append (Key ("meta/key", KEY_META_NAME, KEY_END));
Key parentKey (testRoot, KEY_END);
kdb.get (ks, parentKey);
ASSERT_EQ (ks.size (), 1) << "no key stayed";
ks.rewind ();
ks.next ();
EXPECT_EQ (ks.current ().getName (), "meta/key") << "name of element in keyset wrong";
EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong";
kdb.set (ks, parentKey);
ks.rewind ();
ks.next ();
EXPECT_EQ (ks.current ().getName (), "meta/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);
ASSERT_EQ (ks2.size (), 0) << "got keys from freshly mounted backends";
}
示例2: 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;
}
示例3: 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));
}
}
}
示例4: 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;
}
示例5: 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;
}
示例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: 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;
}
示例9: 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));
}
}
}
示例10: check
bool check (KeySet &ks)
{
Key k;
while (k = ks.next())
{
if (!check(k)) return false;
}
return true;
}
示例11: 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);
}
}
}
示例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:
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());
}
}
示例15: serialise
void serialise(ostream &ofs, KeySet & output)
{
ofs << '{' << endl;
output.rewind();
while (Key k = output.next())
{
ofs << "\t{" << endl;
ofs << "\t\t" << k.getName() << " = " << k.getString() << endl;
k.rewindMeta();
while (const Key m = k.nextMeta())
{
ofs << "\t\t{" << endl;
ofs << "\t\t\t" << m.getName() << " = " << m.getString() << endl;
ofs << "\t\t}" << endl;
}
ofs << "\t}" << endl;
}
ofs << '}' << endl;
}