Skip to content

Commit

Permalink
add removeNamespace, getParentKey
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2718 committed Aug 18, 2021
1 parent 1cb1616 commit 11c2283
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/tools/kdb/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,26 @@ kdb::Key Cmdline::createKey (int pos, bool allowCascading) const
return root;
}


/**
* @brief return a parent key to use with kdbGet/kdbSet
*
* @param key the key of interest
*
* @return a newly created key to use with kdbGet/kdbSet. If -f was specified, a simple copy will be returned, otherwise a copy without a namespace will be returned.
*/
kdb::Key Cmdline::getParentKey (kdb::Key const & key) const
{
if (force)
{
return key.dup ();
}
else
{
return removeNamespace (key);
}
}

/**
* @brief resolve the bookmark with the given name
*
Expand Down
1 change: 1 addition & 0 deletions src/tools/kdb/cmdline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Cmdline
std::string profile;

kdb::Key createKey (int pos, bool allowCascading = true) const;
kdb::Key getParentKey (kdb::Key const & key) const;
kdb::Key resolveBookmark (std::string name) const;

kdb::KeySet getPluginsConfig (std::string basepath = "user:/") const;
Expand Down
12 changes: 12 additions & 0 deletions src/tools/kdb/mergehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ Key prependNamespace (Key const & root, std::string const & ns)
return ret;
}

Key removeNamespace (Key const & root)
{
Key ret = root.dup ();
if (!ret.isCascading ())
{
string keyName = ret.getName ();
string cascadingName = keyName.substr (keyName.find(":") + 1);
ret.setName (cascadingName);
}
return ret;
}

void applyMeta (KeySet & imported, KeySet const & base)
{
for (auto k : imported)
Expand Down
1 change: 1 addition & 0 deletions src/tools/kdb/mergehelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using namespace kdb::tools::merging;

kdb::KeySet prependNamespace (kdb::KeySet const & resultKeys, std::string const & ns);
kdb::Key prependNamespace (kdb::Key const & root, std::string const & ns);
kdb::Key removeNamespace (kdb::Key const & root);
void applyMeta (kdb::KeySet & imported, kdb::KeySet const & base);

class MergeHelper
Expand Down

0 comments on commit 11c2283

Please sign in to comment.