[mlpack-svn] r15302 - mlpack/trunk/src/mlpack/core/util

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Jun 24 16:41:16 EDT 2013


Author: rcurtin
Date: 2013-06-24 16:41:16 -0400 (Mon, 24 Jun 2013)
New Revision: 15302

Modified:
   mlpack/trunk/src/mlpack/core/util/cli.cpp
   mlpack/trunk/src/mlpack/core/util/cli_impl.hpp
Log:
Make CLI::GetParam<bool> return the same value as CLI::HasParam().


Modified: mlpack/trunk/src/mlpack/core/util/cli.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/cli.cpp	2013-06-24 20:39:01 UTC (rev 15301)
+++ mlpack/trunk/src/mlpack/core/util/cli.cpp	2013-06-24 20:41:16 UTC (rev 15302)
@@ -84,8 +84,6 @@
   return;
 }
 
-/* Methods */
-
 /**
  * Adds a parameter to the hierarchy. Use char* and not std::string since the
  * vast majority of use cases will be literal strings.
@@ -138,7 +136,7 @@
  */
 void CLI::AddAlias(const std::string& alias, const std::string& original)
 {
-  //Conduct the mapping
+  // Conduct the mapping.
   if (alias.length())
   {
     amap_t& amap = GetSingleton().aliasValues;
@@ -153,10 +151,10 @@
                  const std::string& description,
                  const std::string& alias)
 {
-  // Reuse functionality from add
+  // Reuse functionality from Add().
   Add(identifier, description, alias, false);
 
-  // Insert the proper metadata in gmap.
+  // Insert the proper metadata into gmap.
   gmap_t& gmap = GetSingleton().globalValues;
 
   ParamData data;
@@ -181,9 +179,8 @@
 }
 
 /**
- * Parses the parameters for 'help' and 'info'
- * If found, will print out the appropriate information
- * and kill the program.
+ * Parses the parameters for 'help' and 'info' If found, will print out the
+ * appropriate information and kill the program.
  */
 void CLI::DefaultMessages()
 {
@@ -246,6 +243,15 @@
  */
 bool CLI::HasParam(const std::string& key)
 {
+  return GetParam<bool>(key);
+}
+
+/**
+ * GetParam<bool>() is equivalent to HasParam().
+ */
+template<>
+bool& CLI::GetParam<bool>(const std::string& key)
+{
   std::string used_key = key;
   po::variables_map vmap = GetSingleton().vmap;
   gmap_t& gmap = GetSingleton().globalValues;
@@ -263,8 +269,15 @@
   if (isInGmap)
     return gmap[used_key].wasPassed;
 
-  // The parameter was not passed in; return false.
-  return false;
+  // The parameter was not passed in; terminate the program.
+  Log::Fatal << "Parameter '--" << key << "' does not exist in this program."
+      << std::endl;
+
+  // These lines will never be reached, but must be here to make the compiler
+  // happy.
+  bool* trash = new bool;
+  *trash = false;
+  return *trash;
 }
 
 /**

Modified: mlpack/trunk/src/mlpack/core/util/cli_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/cli_impl.hpp	2013-06-24 20:39:01 UTC (rev 15301)
+++ mlpack/trunk/src/mlpack/core/util/cli_impl.hpp	2013-06-24 20:41:16 UTC (rev 15302)
@@ -64,6 +64,9 @@
     GetSingleton().requiredOptions.push_front(path);
 }
 
+// We specialize this in cli.cpp.
+template<>
+bool& CLI::GetParam<bool>(const std::string& identifier);
 
 /**
  * @brief Returns the value of the specified parameter.




More information about the mlpack-svn mailing list