Analizo
view release on metacpan or search on metacpan
t/samples/mlpack-3.0.0/parse_command_line.hpp view on Meta::CPAN
/*
**ANALIZO NOTE**
This file was copied here from mlpack project as is just to be used as input on
analizo testsuite in order to fix the issue #120.
- https://github.com/analizo/analizo/issues/120
mlpack repository:
- https://github.com/mlpack/mlpack
Original file was copied from the tag mlpack-3.0.0 from mlpack git repository
and it is located on the path below.
- src/mlpack/bindings/cli/parse_command_line.hpp
Link to the original file on GitHub:
- https://github.com/mlpack/mlpack/blob/mlpack-3.0.0/src/mlpack/bindings/cli/parse_command_line.hpp
See full copyrigth info at:
- https://github.com/mlpack/mlpack/blob/mlpack-3.0.0/COPYRIGHT.txt
*/
/**
* @file parse_command_line.hpp
* @author Ryan Curtin
* @author Matthew Amidon
*
* Parse the command line options.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP
#define MLPACK_BINDINGS_CLI_PARSE_COMMAND_LINE_HPP
#include <mlpack/core.hpp>
#include <boost/program_options.hpp>
#include "print_help.hpp"
namespace mlpack {
namespace bindings {
namespace cli {
// Add default parameters that are included in every program.
PARAM_FLAG("help", "Default help info.", "h");
PARAM_STRING_IN("info", "Get help on a specific module or option.", "", "");
PARAM_FLAG("verbose", "Display informational messages and the full list of "
"parameters and timers at the end of execution.", "v");
PARAM_FLAG("version", "Display the version of mlpack.", "V");
/**
* Parse the command line, setting all of the options inside of the CLI object
* to their appropriate given values.
*/
void ParseCommandLine(int argc, char** argv)
{
// First, we need to build the boost::program_options variables for parsing.
using namespace boost::program_options;
options_description desc;
variables_map vmap;
// Go through list of options in order to add them.
std::map<std::string, util::ParamData>& parameters = CLI::Parameters();
typedef std::map<std::string, util::ParamData>::const_iterator IteratorType;
std::map<std::string, std::string> boostNameMap;
for (IteratorType it = parameters.begin(); it != parameters.end(); ++it)
{
// Add the parameter to desc.
const util::ParamData& d = it->second;
CLI::GetSingleton().functionMap[d.tname]["AddToPO"](d, NULL,
(void*) &desc);
// Generate the name the user passes on the command line.
std::string boostName;
CLI::GetSingleton().functionMap[d.tname]["MapParameterName"](d, NULL,
(void*) &boostName);
boostNameMap[boostName] = d.name;
}
// Mark that we did parsing.
CLI::GetSingleton().didParse = true;
// Parse the command line, then place the values in the right place.
try
{
basic_parsed_options<char> bpo(parse_command_line(argc, argv, desc));
// Iterate over all the options, looking for duplicate parameters. If we
// find any, remove the duplicates. Note that vector options can have
// duplicates, so we check for those with max_tokens().
for (size_t i = 0; i < bpo.options.size(); ++i)
{
for (size_t j = i + 1; j < bpo.options.size(); ++j)
{
if ((bpo.options[i].string_key == bpo.options[j].string_key) &&
(desc.find(bpo.options[i].string_key,
false).semantic()->max_tokens() <= 1))
{
// If a duplicate is found, check to see if either one has a value.
if (bpo.options[i].value.size() == 0 &&
bpo.options[j].value.size() == 0)
t/samples/mlpack-3.0.0/parse_command_line.hpp view on Meta::CPAN
}
// Default help message.
if (CLI::HasParam("help"))
{
Log::Info.ignoreInput = false;
PrintHelp();
exit(0); // The user doesn't want to run the program, he wants help.
}
// Info on a specific parameter.
if (CLI::HasParam("info"))
{
Log::Info.ignoreInput = false;
std::string str = CLI::GetParam<std::string>("info");
// The info node should always be there, but the user may not have specified
// anything.
if (str != "")
{
PrintHelp(str);
exit(0);
}
// Otherwise just print the generalized help.
PrintHelp();
exit(0);
}
// Print whether or not we have debugging symbols. This won't show anything
// if we have not compiled in debugging mode.
Log::Debug << "Compiled with debugging symbols." << std::endl;
if (CLI::HasParam("verbose"))
{
// Give [INFO ] output.
Log::Info.ignoreInput = false;
}
// Now, issue an error if we forgot any required options.
for (std::map<std::string, util::ParamData>::const_iterator iter =
parameters.begin(); iter != parameters.end(); ++iter)
{
const util::ParamData d = iter->second;
if (d.required)
{
const std::string boostName;
CLI::GetSingleton().functionMap[d.tname]["MapParameterName"](d, NULL,
(void*) &boostName);
if (!vmap.count(boostName))
{
Log::Fatal << "Required option --" << boostName << " is undefined."
<< std::endl;
}
}
}
}
} // namespace cli
} // namespace bindings
} // namespace mlpack
#endif
( run in 1.163 second using v1.01-cache-2.11-cpan-2398b32b56e )