[mlpack-svn] r11657 - mlpack/trunk/src/mlpack/core/util
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Feb 29 14:46:47 EST 2012
Author: mamidon
Date: 2012-02-29 14:46:47 -0500 (Wed, 29 Feb 2012)
New Revision: 11657
Modified:
mlpack/trunk/src/mlpack/core/util/cli.cpp
mlpack/trunk/src/mlpack/core/util/cli.hpp
mlpack/trunk/src/mlpack/core/util/cli_impl.hpp
Log:
Removed c-strings in favor of std strings.
Modified: mlpack/trunk/src/mlpack/core/util/cli.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/cli.cpp 2012-02-29 19:32:05 UTC (rev 11656)
+++ mlpack/trunk/src/mlpack/core/util/cli.cpp 2012-02-29 19:46:47 UTC (rev 11657)
@@ -53,7 +53,7 @@
*
* @param optionsName Name of the module, as far as boost is concerned.
*/
-CLI::CLI(std::string& optionsName) :
+CLI::CLI(std::string optionsName) :
desc(optionsName.c_str()), didParse(false), doc(&emptyProgramDoc)
{
return;
@@ -109,23 +109,21 @@
* @param alias An alias for the parameter.
* @param required Indicates if parameter must be set on command line.
*/
-void CLI::Add(const char* identifier,
- const char* description,
- const char* alias,
+void CLI::Add(std::string path,
+ std::string description,
+ std::string alias,
bool required)
{
po::options_description& desc = CLI::GetSingleton().desc;
- std::string path = identifier;
- std::string stringAlias = alias;
// Must make use of boost option name syntax.
- std::string progOptId = stringAlias.length() ? path + "," + alias : path;
+ std::string progOptId = alias.length() ? path + "," + alias : path;
// Deal with a required alias.
- AddAlias(stringAlias, path);
+ AddAlias(alias, path);
// Add the option to boost::program_options.
- desc.add_options()(progOptId.c_str(), description);
+ desc.add_options()(progOptId.c_str(), description.c_str());
// Make sure the description, etc. ends up in gmap.
gmap_t& gmap = GetSingleton().globalValues;
@@ -165,9 +163,9 @@
/*
* @brief Adds a flag parameter to CLI.
*/
-void CLI::AddFlag(const char* identifier,
- const char* description,
- const char* alias)
+void CLI::AddFlag(std::string identifier,
+ std::string description,
+ std::string alias)
{
// Reuse functionality from add
Add(identifier, description, alias, false);
@@ -260,11 +258,10 @@
*
* @param identifier The name of the parameter in question.
*/
-bool CLI::HasParam(const char* identifier)
+bool CLI::HasParam(std::string key)
{
po::variables_map vmap = GetSingleton().vmap;
gmap_t& gmap = GetSingleton().globalValues;
- std::string key = identifier;
// Take any possible alias into account.
amap_t& amap = GetSingleton().aliasValues;
@@ -337,7 +334,7 @@
* @param identifier Name of the node in question.
* @return Description of the node in question.
*/
-std::string CLI::GetDescription(const char* identifier)
+std::string CLI::GetDescription(std::string identifier)
{
gmap_t& gmap = GetSingleton().globalValues;
std::string name = std::string(identifier);
Modified: mlpack/trunk/src/mlpack/core/util/cli.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/cli.hpp 2012-02-29 19:32:05 UTC (rev 11656)
+++ mlpack/trunk/src/mlpack/core/util/cli.hpp 2012-02-29 19:46:47 UTC (rev 11657)
@@ -524,9 +524,9 @@
* ("").
* @param required Indicates if parameter must be set on command line.
*/
- static void Add(const char* identifier,
- const char* description,
- const char* alias = "",
+ static void Add(std::string path,
+ std::string description,
+ std::string alias = "",
bool required = false);
/**
@@ -541,9 +541,9 @@
* @param required Indicates if parameter must be set on command line.
*/
template<class T>
- static void Add(const char* identifier,
- const char* description,
- const char* alias = "",
+ static void Add(std::string identifier,
+ std::string description,
+ std::string alias = "",
bool required = false);
/**
@@ -553,9 +553,9 @@
* @param description Short string description of the parameter.
* @param alias An alias for the parameter, defaults to "" which is no alias.
*/
- static void AddFlag(const char* identifier,
- const char* description,
- const char* alias = "");
+ static void AddFlag(std::string identifier,
+ std::string description,
+ std::string alias = "");
/**
* Parses the parameters for 'help' and 'info'.
@@ -577,7 +577,7 @@
* @param identifier The name of the parameter in question.
*/
template<typename T>
- static T& GetParam(const char* identifier);
+ static T& GetParam(std::string identifier);
/**
* Get the description of the specified node.
@@ -585,7 +585,7 @@
* @param identifier Name of the node in question.
* @return Description of the node in question.
*/
- static std::string GetDescription(const char* identifier);
+ static std::string GetDescription(std::string identifier);
/**
* Retrieve the singleton.
@@ -606,7 +606,7 @@
*
* @param identifier The name of the parameter in question.
*/
- static bool HasParam(const char* identifier);
+ static bool HasParam(std::string identifier);
/**
* Hyphenate a string or split it onto multiple 80-character lines, with some
@@ -731,7 +731,7 @@
* @param str Input string.
* @return Sanitized string.
*/
- static std::string SanitizeString(const char* str);
+ static std::string SanitizeString(std::string str);
/**
* Parses the values given on the command line, overriding any default values.
@@ -748,7 +748,7 @@
*
* @param optionsName Name of the module, as far as boost is concerned.
*/
- CLI(std::string& optionsName);
+ CLI(std::string optionsName);
//! Private copy constructor; we don't want copies floating around.
CLI(const CLI& other);
Modified: mlpack/trunk/src/mlpack/core/util/cli_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/cli_impl.hpp 2012-02-29 19:32:05 UTC (rev 11656)
+++ mlpack/trunk/src/mlpack/core/util/cli_impl.hpp 2012-02-29 19:46:47 UTC (rev 11657)
@@ -28,24 +28,22 @@
* unless the parameter is specified.
*/
template<typename T>
-void CLI::Add(const char* identifier,
- const char* description,
- const char* alias,
+void CLI::Add(std::string path,
+ std::string description,
+ std::string alias,
bool required)
{
po::options_description& desc = CLI::GetSingleton().desc;
- std::string path = identifier;
- std::string stringAlias = alias;
// Must make use of boost syntax here.
- std::string progOptId = stringAlias.length() ? path + "," + alias : path;
+ std::string progOptId = alias.length() ? path + "," + alias : path;
// Add the alias, if necessary
- AddAlias(stringAlias, path);
+ AddAlias(alias, path);
// Add the option to boost program_options.
desc.add_options()
- (progOptId.c_str(), po::value<T>(), description);
+ (progOptId.c_str(), po::value<T>(), description.c_str());
// Make sure the appropriate metadata is inserted into gmap.
gmap_t& gmap = GetSingleton().globalValues;
@@ -79,7 +77,7 @@
* valid.
*/
template<typename T>
-T& CLI::GetParam(const char* identifier)
+T& CLI::GetParam(std::string identifier)
{
// Used to ensure we have a valid value.
T tmp = T();
More information about the mlpack-svn
mailing list