本文整理汇总了C++中KDB类的典型用法代码示例。如果您正苦于以下问题:C++ KDB类的具体用法?C++ KDB怎么用?C++ KDB使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KDB类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: synopsis
Cmdline::Cmdline (int argc, char ** argv, Command * command)
: synopsis (command->getSynopsis ()), helpText (), invalidOpt (false),
/*XXX: Step 2: initialise your option here.*/
debug (), force (), load (), humanReadable (), help (), interactive (), minDepth (0), maxDepth (numeric_limits<int>::max ()),
noNewline (), test (), recursive (), resolver (KDB_RESOLVER), strategy ("preserve"), verbose (), quiet (), version (), withoutElektra (),
null (), first (true), second (true), third (true), withRecommends (false), all (), format (KDB_STORAGE), plugins ("sync"),
globalPlugins ("spec"), pluginsConfig (""), color ("auto"), ns (""), editor (), bookmarks (), profile ("current"),
executable (), commandName ()
{
extern int optind;
extern char * optarg;
int opt;
size_t optionPos;
helpText += command->getShortHelpText ();
helpText += "\n";
helpText += command->getLongHelpText ();
helpText += "\n";
string allOptions = command->getShortOptions ();
allOptions += "HVCp";
// Make sure to use the unsorted allOptions for getopt to preserve argument chars : and ::
std::set<string::value_type> unique_sorted_chars (allOptions.begin (), allOptions.end ());
string acceptedOptions (unique_sorted_chars.begin (), unique_sorted_chars.end ());
vector<option> long_options;
/*XXX: Step 3: give it a long name.*/
if (acceptedOptions.find ('a') != string::npos)
{
option o = { "all", no_argument, nullptr, 'a' };
long_options.push_back (o);
helpText += "-a --all Consider all of the keys.\n";
}
if (acceptedOptions.find ('d') != string::npos)
{
option o = { "debug", no_argument, nullptr, 'd' };
long_options.push_back (o);
helpText += "-d --debug Give debug information or ask debug questions (in interactive mode).\n";
}
if (acceptedOptions.find ('f') != string::npos)
{
option o = { "force", no_argument, nullptr, 'f' };
long_options.push_back (o);
helpText += "-f --force Force the action to be done.\n";
}
if (acceptedOptions.find ('l') != string::npos)
{
option o = { "load", no_argument, nullptr, 'f' };
long_options.push_back (o);
helpText += "-l --load Load plugin even if system/elektra is available.\n";
}
if (acceptedOptions.find ('h') != string::npos)
{
option o = { "human-readable", no_argument, nullptr, 'h' };
long_options.push_back (o);
helpText += "-h --human-readable Print numbers in an human readable way.\n";
}
if (acceptedOptions.find ('H') != string::npos)
{
option o = { "help", no_argument, nullptr, 'H' };
long_options.push_back (o);
helpText += "-H --help Show the man page.\n";
}
if (acceptedOptions.find ('i') != string::npos)
{
option o = { "interactive", no_argument, nullptr, 'i' };
long_options.push_back (o);
helpText += "-i --interactive Ask the user interactively.\n";
}
optionPos = acceptedOptions.find ('m');
if (optionPos != string::npos)
{
acceptedOptions.insert (optionPos + 1, ":");
option o = { "min-depth", required_argument, nullptr, 'm' };
long_options.push_back (o);
helpText += "-m --min-depth <min> Specify the minimum depth (default 0).\n";
}
optionPos = acceptedOptions.find ('M');
if (optionPos != string::npos)
{
acceptedOptions.insert (optionPos + 1, ":");
option o = { "max-depth", required_argument, nullptr, 'M' };
long_options.push_back (o);
helpText += "-M --max-depth <max> Specify the maximum depth (unlimited by default).\n";
}
if (acceptedOptions.find ('n') != string::npos)
{
option o = { "no-newline", no_argument, nullptr, 'n' };
long_options.push_back (o);
helpText += "-n --no-newline Suppress the newline at the end of the output.\n";
}
if (acceptedOptions.find ('t') != string::npos)
{
option o = { "test", no_argument, nullptr, 't' };
long_options.push_back (o);
//.........这里部分代码省略.........
示例2: invalid_argument
int MergeCommand::execute (Cmdline const & cl)
{
if (cl.arguments.size () < 4)
{
throw invalid_argument ("wrong number of arguments, 4 needed");
}
Key oursRoot = cl.createKey (0);
Key theirsRoot = cl.createKey (1);
Key baseRoot = cl.createKey (2);
Key resultRoot = cl.createKey (3);
KeySet ours;
KeySet theirs;
KeySet base;
{
KDB lkdb;
lkdb.get (ours, oursRoot);
ours = ours.cut (oursRoot);
ours.lookup (oursRoot, KDB_O_POP);
if (cl.verbose) std::cout << "we got ours: " << oursRoot << " with keys " << ours << std::endl;
}
{
KDB lkdb;
lkdb.get (theirs, theirsRoot);
theirs = theirs.cut (theirsRoot);
ours.lookup (oursRoot, KDB_O_POP);
if (cl.verbose) std::cout << "we got theirs: " << theirsRoot << " with keys " << theirs << std::endl;
}
{
KDB lkdb;
lkdb.get (base, baseRoot);
base = base.cut (baseRoot);
ours.lookup (oursRoot, KDB_O_POP);
if (cl.verbose) std::cout << "we got base: " << baseRoot << " with keys " << base << std::endl;
}
KeySet resultKeys;
kdb.get (resultKeys, resultRoot);
KeySet discard = resultKeys.cut (resultRoot);
if (discard.size () != 0)
{
if (cl.force)
{
if (cl.verbose)
{
std::cout << "will remove " << discard.size () << " keys, because -f was given" << std::endl;
}
}
else
{
std::cerr << discard.size () << " keys exist in merge resultroot, will quit. Use -f to override the keys there."
<< std::endl;
}
}
MergeHelper helper;
ThreeWayMerge merger;
helper.configureMerger (cl, merger);
MergeResult result = merger.mergeKeySet (
MergeTask (BaseMergeKeys (base, baseRoot), OurMergeKeys (ours, oursRoot), TheirMergeKeys (theirs, theirsRoot), resultRoot));
helper.reportResult (cl, result, cout, cerr);
int ret = 0;
if (!result.hasConflicts ())
{
resultKeys.append (result.getMergedKeys ());
kdb.set (resultKeys, resultRoot);
}
else
{
ret = -1;
}
return ret;
}
示例3: EditorNotAvailable
int EditorCommand::execute (Cmdline const & cl)
{
#ifdef _WIN32
throw EditorNotAvailable ();
#endif
int argc = cl.arguments.size ();
if (argc < 1)
{
throw invalid_argument ("wrong number of arguments, 1 needed");
}
Key root = cl.createKey (0);
KeySet ours;
KDB kdb;
kdb.get (ours, root);
KeySet oursToEdit = ours.cut (root);
KeySet original = oursToEdit.dup ();
if (cl.strategy == "validate")
{
prependNamespace (oursToEdit, cl.ns);
oursToEdit.cut (prependNamespace (root, cl.ns));
}
// export it to file
string format = cl.format;
if (argc > 1) format = cl.arguments[1];
Modules modules;
PluginPtr plugin = modules.load (format);
tmpFile ();
if (cl.verbose) std::cout << "filename set to " << filename << std::endl;
Key errorKey (root);
errorKey.setString (filename);
if (plugin->set (oursToEdit, errorKey) == -1)
{
printWarnings (cerr, errorKey);
printError (cerr, errorKey);
return 11;
}
printWarnings (cerr, errorKey);
// start editor
if (cl.verbose) std::cout << "running editor with " << filename << std::endl;
if (!cl.editor.empty ())
{
if (!runEditor (cl.editor, filename))
{
std::cerr << "Could not run editor " << cl.editor << std::endl;
return 12;
}
}
else
{
if (!runAllEditors (filename))
{
std::cerr << "Could not run any editor, please change /sw/elektra/kdb/#0/current/editor" << std::endl;
return 12;
}
}
// import from the file
KeySet importedKeys;
plugin->get (importedKeys, errorKey);
importedKeys = importedKeys.cut (root);
printWarnings (cerr, errorKey);
printError (cerr, errorKey);
if (cl.strategy == "validate")
{
applyMeta (importedKeys, original);
kdb.set (importedKeys, root);
printWarnings (cerr, root);
return 0;
}
ThreeWayMerge merger;
MergeHelper helper;
helper.configureMerger (cl, merger);
MergeResult result = merger.mergeKeySet (
MergeTask (BaseMergeKeys (oursToEdit, root), OurMergeKeys (oursToEdit, root), TheirMergeKeys (importedKeys, root), root));
helper.reportResult (cl, result, cout, cerr);
int ret = 13;
if (!result.hasConflicts ())
{
if (cl.verbose)
{
cout << "The merged keyset with strategy " << cl.strategy << " is:" << endl;
cout << result.getMergedKeys ();
}
//.........这里部分代码省略.........