[mlpack-svn] r10356 - mlpack/trunk/src/mlpack/core/io

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Nov 23 02:37:40 EST 2011


Author: rcurtin
Date: 2011-11-23 02:37:39 -0500 (Wed, 23 Nov 2011)
New Revision: 10356

Removed:
   mlpack/trunk/src/mlpack/core/io/nulloutstream.cpp
Modified:
   mlpack/trunk/src/mlpack/core/io/CMakeLists.txt
   mlpack/trunk/src/mlpack/core/io/cli.cpp
   mlpack/trunk/src/mlpack/core/io/cli.hpp
   mlpack/trunk/src/mlpack/core/io/cli_deleter.cpp
   mlpack/trunk/src/mlpack/core/io/cli_deleter.hpp
   mlpack/trunk/src/mlpack/core/io/cli_impl.hpp
   mlpack/trunk/src/mlpack/core/io/log.hpp
   mlpack/trunk/src/mlpack/core/io/nulloutstream.hpp
   mlpack/trunk/src/mlpack/core/io/option.hpp
   mlpack/trunk/src/mlpack/core/io/option_impl.hpp
   mlpack/trunk/src/mlpack/core/io/optionshierarchy.cpp
   mlpack/trunk/src/mlpack/core/io/optionshierarchy.hpp
   mlpack/trunk/src/mlpack/core/io/prefixedoutstream.hpp
   mlpack/trunk/src/mlpack/core/io/prefixedoutstream_impl.hpp
Log:
Update style for #153; it was not completely done.


Modified: mlpack/trunk/src/mlpack/core/io/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/io/CMakeLists.txt	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/CMakeLists.txt	2011-11-23 07:37:39 UTC (rev 10356)
@@ -16,7 +16,6 @@
   optionshierarchy.hpp
   optionshierarchy.cpp
   nulloutstream.hpp
-  nulloutstream.cpp
   prefixedoutstream.hpp
   prefixedoutstream.cpp
   prefixedoutstream_impl.hpp

Modified: mlpack/trunk/src/mlpack/core/io/cli.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/cli.cpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/cli.cpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -1,7 +1,9 @@
-#include "cli.hpp" 
-#include "log.hpp"
-#include "../utilities/timers.hpp"
-
+/**
+ * @file cli.cpp
+ * @author Matthew Amidon
+ *
+ * Implementation of the CLI module for parsing parameters.
+ */
 #include <list>
 #include <boost/program_options.hpp>
 #include <boost/any.hpp>
@@ -11,18 +13,22 @@
 #include <execinfo.h>
 
 #ifndef _WIN32
-  #include <sys/time.h> //linux
+  #include <sys/time.h> // For Linux.
 #else
-  #include <winsock.h> //timeval on windows
-  #include <windows.h> //GetSystemTimeAsFileTime on windows
-//gettimeofday has no equivalent will need to write extra code for that.
+  #include <winsock.h> // timeval on Windows.
+  #include <windows.h> // GetSystemTimeAsFileTime() on Windows.
+// gettimeofday() has no equivalent; we will need to write extra code for that.
   #if defined(_MSC_VER) || defined(_MSC_EXTENSCLINS)
     #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
   #else
     #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
   #endif
-#endif //_WIN32
+#endif // _WIN32
 
+#include "cli.hpp"
+#include "log.hpp"
+#include "../utilities/timers.hpp"
+
 #include "option.hpp"
 
 using namespace mlpack;
@@ -30,7 +36,7 @@
 
 CLI* CLI::singleton = NULL;
 
-/* For clarity, we will alias boost's namespace */
+/* For clarity, we will alias boost's namespace. */
 namespace po = boost::program_options;
 
 // Fake ProgramDoc in case none is supplied.
@@ -39,41 +45,47 @@
 /* Constructors, Destructors, Copy */
 /* Make the constructor private, to preclude unauthorized instances */
 CLI::CLI() : desc("Allowed Options") , hierarchy("Allowed Options"),
-    did_parse(false), doc(&empty_program_doc) {
+    did_parse(false), doc(&empty_program_doc)
+{
   return;
 }
 
-/*
+/**
  * Initialize desc with a particular name.
  *
  * @param optionsName Name of the module, as far as boost is concerned.
  */
 CLI::CLI(std::string& optionsName) :
     desc(optionsName.c_str()), hierarchy(optionsName.c_str()),
-    did_parse(false), doc(&empty_program_doc) {
+    did_parse(false), doc(&empty_program_doc)
+{
   return;
 }
 
 // Private copy constructor; don't want copies floating around.
 CLI::CLI(const CLI& other) : desc(other.desc),
-    did_parse(false), doc(&empty_program_doc) {
+    did_parse(false), doc(&empty_program_doc)
+{
   return;
 }
 
-CLI::~CLI() {
+CLI::~CLI()
+{
   // Terminate the program timer.
   Timers::StopTimer("total_time");
 
   // Did the user ask for verbose output?  If so we need to print everything.
   // But only if the user did not ask for help or info.
-  if (GetParam<bool>("verbose")) {
+  if (GetParam<bool>("verbose"))
+  {
     Log::Info << "Execution parameters:" << std::endl;
     hierarchy.PrintLeaves();
 
     Log::Info << "Program timers:" << std::endl;
     std::map<std::string, timeval> times = Timers::GetAllTimers();
     std::map<std::string, timeval>::iterator iter;
-    for(iter = times.begin(); iter != times.end(); iter++) {
+    for (iter = times.begin(); iter != times.end(); iter++)
+    {
       Log::Info << "  " << iter->first << ": ";
       Timers::PrintTimer(iter->first.c_str());
     }
@@ -90,10 +102,9 @@
 
 /* Methods */
 
-/*
- * Adds a parameter to the hierarchy. Use char* and not
- * std::string since the vast majority of use cases will
- * be literal strings.
+/**
+ * Adds a parameter to the hierarchy. Use char* and not std::string since the
+ * vast majority of use cases will be literal strings.
  *
  * @param identifier The name of the parameter.
  * @param description Short string description of the parameter.
@@ -103,14 +114,14 @@
 void CLI::Add(const char* identifier,
              const char* description,
              const char* parent,
-             bool required) {
-
+             bool required)
+{
   po::options_description& desc = CLI::GetSingleton().desc;
 
   // Generate the full pathname and insert the node into the hierarchy.
   std::string tmp = TYPENAME(bool);
   std::string path =
-    CLI::GetSingleton().ManageHierarchy(identifier, parent, tmp, description);
+      CLI::GetSingleton().ManageHierarchy(identifier, parent, tmp, description);
 
   // Add the option to boost::program_options.
   desc.add_options()
@@ -123,53 +134,53 @@
   return;
 }
 
-
 /*
- * @brief Adds a flag paramater to CLI.
+ * @brief Adds a flag parameter to CLI.
  */
-
 void CLI::AddFlag(const char* identifier,
                  const char* description,
-                 const char* parent) {
+                 const char* parent)
+{
   po::options_description& desc = CLI::GetSingleton().desc;
 
   //Generate the full pathname and insert node into the hierarchy
   std::string tname = TYPENAME(bool);
-  std::string path =
-    CLI::GetSingleton().ManageHierarchy(identifier, parent, tname, description);
+  std::string path = CLI::GetSingleton().ManageHierarchy(identifier, parent,
+      tname, description);
 
-  //Add the option to boost program_options
+  // Add the option to boost::program_options.
   desc.add_options()
     (path.c_str(), po::value<bool>()->implicit_value(true), description);
 }
 
-/*
+/**
  * See if the specified flag was found while parsing.
  *
  * @param identifier The name of the parameter in question.
  */
-bool CLI::HasParam(const char* identifier) {
+bool CLI::HasParam(const char* identifier)
+{
   std::string key = std::string(identifier);
 
   //Does the parameter exist at all?
   int isInVmap = GetSingleton().vmap.count(key);
   int isInGmap = GetSingleton().globalValues.count(key);
 
-  //Lets check if the parameter is boolean, if it is we just want to see
-  //If it was passed at program initiation.
+  // Check if the parameter is boolean; if it is, we just want to see if it was
+  // passed at program initiation.
   OptionsHierarchy* node = CLI::GetSingleton().hierarchy.FindNode(key);
-  if(node) {//Sanity check
+  if (node) // Sanity check.
+  {
     OptionsData data = node->GetNodeData();
-    if(data.tname == std::string(TYPENAME(bool))) //Actually check if its bool
+    if (data.tname == std::string(TYPENAME(bool))) //Actually check if its bool
       return CLI::GetParam<bool>(identifier);
   }
 
-  //Return true if we have a defined value for identifier
+  // Return true if we have a defined value for identifier.
   return (isInVmap || isInGmap);
 }
 
-
-/*
+/**
  * Searches for unqualified parameters, when one is found prepend the default
  * module path onto it.
  *
@@ -177,18 +188,20 @@
  * @param argv 2D array of the parameter strings themselves
  * @return some valid modified strings
  */
-std::vector<std::string> CLI::InsertDefaultModule(int argc, char** argv) {
+std::vector<std::string> CLI::InsertDefaultModule(int argc, char** argv)
+{
   std::vector<std::string> ret;
   std::string path = GetSingleton().doc->defaultModule;
   path = SanitizeString(path.c_str());
 
-  for(int i = 1; i < argc; i++) {//First parameter is just the program name.
+  for (int i = 1; i < argc; i++) // Ignore first parameter (program name).
+  {
     std::string str = argv[i];
 
-    //Are we lacking any qualifiers?
-    if(str.find('/') == std::string::npos &&
-       str.compare("--help") != 0 &&
-       str.compare("--info") != 0)
+    // Are we lacking any qualifiers?
+    if (str.find('/') == std::string::npos &&
+        str.compare("--help") != 0 &&
+        str.compare("--info") != 0)
       str = "--"+path+str.substr(2,str.length());
 
     ret.push_back(str);
@@ -197,13 +210,14 @@
   return ret;
 }
 
-/*
+/**
  * Grab the description of the specified node.
  *
  * @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(const char* identifier)
+{
   std::string tmp = std::string(identifier);
   OptionsHierarchy* h = GetSingleton().hierarchy.FindNode(tmp);
 
@@ -214,20 +228,22 @@
   return d.desc;
 }
 
-std::vector<std::string> CLI::GetFolder(const char* folder) {
+std::vector<std::string> CLI::GetFolder(const char* folder)
+{
   std::string str = folder;
   return GetSingleton().hierarchy.GetRelativePaths(str);
 }
 
-//Returns the sole instance of this class
-CLI& CLI::GetSingleton() {
-  if (singleton == NULL) {
+// Returns the sole instance of this class.
+CLI& CLI::GetSingleton()
+{
+  if (singleton == NULL)
     singleton = new CLI();
-  }
+
   return *singleton;
 }
 
-/*
+/**
  * Properly formats strings such that there aren't too few or too many '/'s.
  *
  * @param id The name of the parameter, eg bar in foo/bar.
@@ -237,10 +253,10 @@
  * @param desc String description of the parameter.
  */
 std::string CLI::ManageHierarchy(const char* id,
-                                const char* parent,
-                                std::string& tname,
-                                const char* desc) {
-
+                                 const char* parent,
+                                 std::string& tname,
+                                 const char* desc)
+{
   std::string path(id);
 
   path = SanitizeString(parent) + id;
@@ -250,7 +266,7 @@
   return path;
 }
 
-/***
+/**
  * Add a parameter to the hierarchy.  We assume the string has already been
  * sanity-checked.
  *
@@ -259,12 +275,13 @@
  * @param desc String description of the parameter (optional).
  */
 void CLI::AddToHierarchy(std::string& path, std::string& tname,
-                        const char* desc) {
+                        const char* desc)
+{
   // Make sure we don't overwrite any data.
   if (hierarchy.FindNode(path) != NULL)
     return;
 
-  // Add the sanity checked string to the hierarchy
+  // Add the sanity checked string to the hierarchy.
   std::string d(desc);
   if (d.length() == 0)
     hierarchy.AppendNode(path, tname);
@@ -272,13 +289,14 @@
     hierarchy.AppendNode(path, tname, d);
 }
 
-/*
+/**
  * Parses the commandline for arguments.
  *
  * @param argc The number of arguments on the commandline.
  * @param argv The array of arguments as strings
  */
-void CLI::ParseCommandLine(int argc, char** line) {
+void CLI::ParseCommandLine(int argc, char** line)
+{
   po::variables_map& vmap = GetSingleton().vmap;
   po::options_description& desc = GetSingleton().desc;
 
@@ -286,11 +304,15 @@
   std::vector<std::string> in = InsertDefaultModule(argc, line);
 
   // Parse the command line, place the options & values into vmap
-  try {
+  try
+  {
     po::store(po::parse_command_line(argc, line, desc), vmap);
-  } catch(std::exception& ex) {
+  }
+  catch (std::exception& ex)
+  {
     Log::Fatal << ex.what() << std::endl;
   }
+
   // Flush the buffer, make sure changes are propagated to vmap
   po::notify(vmap);
   UpdateGmap();
@@ -300,22 +322,27 @@
   Timers::StartTimer("total_time");
 }
 
-/*
+/**
  * Parses a stream for arguments
  *
  * @param stream The stream to be parsed.
  */
-void CLI::ParseStream(std::istream& stream) {
+void CLI::ParseStream(std::istream& stream)
+{
   po::variables_map& vmap = GetSingleton().vmap;
   po::options_description& desc = GetSingleton().desc;
 
-  // Parse the stream, place options & values into vmap
-  try {
+  // Parse the stream; place options & values into vmap.
+  try
+  {
     po::store(po::parse_config_file(stream, desc), vmap);
-  } catch (std::exception& ex) {
+  }
+  catch (std::exception& ex)
+  {
     Log::Fatal << ex.what() << std::endl;
   }
-  // Flush the buffer, make sure changes are propagated to vmap
+
+  // Flush the buffer; make sure changes are propagated to vmap.
   po::notify(vmap);
 
   UpdateGmap();
@@ -325,20 +352,21 @@
   Timers::StartTimer("total_time");
 }
 
-/*
- * Parses the values given on the command line,
- * overriding any default values.
+/**
+ * Parses the values given on the command line, overriding any default values.
  */
-void CLI::UpdateGmap() {
+void CLI::UpdateGmap()
+{
   std::map<std::string, boost::any>& gmap = GetSingleton().globalValues;
   po::variables_map& vmap = GetSingleton().vmap;
 
-  //Iterate through Gmap, and overwrite default values with anything found on
-  //command line.
+  // Iterate through Gmap, and overwrite default values with anything found on
+  // command line.
   std::map<std::string, boost::any>::iterator i;
-  for (i = gmap.begin(); i != gmap.end(); i++) {
+  for (i = gmap.begin(); i != gmap.end(); i++)
+  {
     po::variable_value tmp = vmap[i->first];
-    if (!tmp.empty()) //We need to overwrite gmap.
+    if (!tmp.empty()) // We need to overwrite gmap.
       gmap[i->first] = tmp.value();
   }
 }
@@ -349,35 +377,41 @@
  *
  * @param doc Pointer to the ProgramDoc object.
  */
-void CLI::RegisterProgramDoc(ProgramDoc* doc) {
+void CLI::RegisterProgramDoc(ProgramDoc* doc)
+{
   // Only register the doc if it is not the dummy object we created at the
   // beginning of the file (as a default value in case this is never called).
   if (doc != &empty_program_doc)
     GetSingleton().doc = doc;
 }
 
-/***
+/**
  * Destroy the CLI object.  This resets the pointer to the singleton, so in case
  * someone tries to access it after destruction, a new one will be made (the
  * program will not fail).
  */
-void CLI::Destroy() {
-  if (singleton != NULL) {
+void CLI::Destroy()
+{
+  if (singleton != NULL)
+  {
     delete singleton;
     singleton = NULL; // Reset pointer.
   }
 }
 
-/*
+/**
  * Parses the parameters for 'help' and 'info'
  * If found, will print out the appropriate information
  * and kill the program.
  */
-void CLI::DefaultMessages() {
+void CLI::DefaultMessages()
+{
   // Default help message
-  if (GetParam<bool>("help")) {
+  if (GetParam<bool>("help"))
+  {
     // A little snippet about the program itself, if we have it.
-    if (GetSingleton().doc != &empty_program_doc) {
+    if (GetSingleton().doc != &empty_program_doc)
+    {
       std::cout << GetSingleton().doc->programName << std::endl << std::endl;
       std::cout << "  " << OptionsHierarchy::HyphenateString(
         GetSingleton().doc->documentation, 2) << std::endl << std::endl;
@@ -386,11 +420,14 @@
     GetSingleton().hierarchy.PrintAllHelp();
     exit(0); // The user doesn't want to run the program, he wants help.
   }
-  if (HasParam("info")) {
+
+  if (HasParam("info"))
+  {
     std::string str = GetParam<std::string>("info");
     // The info node should always be there, but the user may not have specified
     // anything.
-    if (str != "") {
+    if (str != "")
+    {
       OptionsHierarchy* node = GetSingleton().hierarchy.FindNode(str);
       if(node != NULL)
         node->PrintNodeHelp();
@@ -399,6 +436,7 @@
       exit(0);
     }
   }
+
   if (GetParam<bool>("verbose"))
     Log::Info.ignoreInput = false;
 
@@ -408,53 +446,55 @@
   Log::Debug << "Compiled with debugging symbols." << std::endl;
 }
 
-/*
- * Checks that all parameters specified as required
- * have been specified on the command line.
- * If they havent, prints an error message and kills the
- * program.
+/**
+ * Checks that all parameters specified as required have been specified on the
+ * command line.  If they havent, prints an error message and kills the program.
  */
-void CLI::RequiredOptions() {
+void CLI::RequiredOptions()
+{
   po::variables_map& vmap = GetSingleton().vmap;
   std::list<std::string> rOpt = GetSingleton().requiredOptions;
 
   //Now, warn the user if they missed any required options
   std::list<std::string>::iterator iter;
   for (iter = rOpt.begin(); iter != rOpt.end(); iter++) {
-  std::string str = *iter;
-  if (!vmap.count(str))
-  {// If a required option isn't there...
-    Timers::StopTimer("total_time"); //Execution stop here, pretty much.
-    Log::Fatal << "Required option --" << str.c_str() << " is undefined."
-      << std::endl;
+    std::string str = *iter;
+    if (!vmap.count(str))
+    { // If a required option isn't there...
+      Timers::StopTimer("total_time"); // Execution stop here, pretty much.
+      Log::Fatal << "Required option --" << str.c_str() << " is undefined."
+          << std::endl;
+    }
   }
-  }
 }
 
-/* Prints out the current hierachy */
-void CLI::Print() {
+/* Prints out the current hierarchy. */
+void CLI::Print()
+{
   CLI::GetSingleton().hierarchy.PrintAll();
 }
 
 /* Cleans up input pathnames, rendering strings such as /foo/bar
       and foo/bar/ equivalent inputs */
-std::string CLI::SanitizeString(const char* str) {
-  if (str != NULL) {
+std::string CLI::SanitizeString(const char* str)
+{
+  if (str != NULL)
+  {
     std::string p(str);
-    //Lets sanity check string, remove superfluous '/' prefixes
+    // Sanity check the string -- remove superfluous '/' prefixes.
     if (p.find_first_of("/") == 0)
-      p = p.substr(1,p.length()-1);
-    //Add necessary '/' suffixes to parent
-    if (p.find_last_of("/") != p.length()-1)
-      p = p+"/";
+      p = p.substr(1, p.length() - 1);
+
+    // Add necessary '/' suffixes to parent.
+    if (p.find_last_of("/") != p.length() - 1)
+      p += "/";
+
     return p;
   }
 
   return std::string("");
 }
 
-
-
 // Add help parameter.
 PARAM_FLAG("help", "Default help info.", "");
 PARAM_STRING("info", "Get help on a specific module or option.", "", "");

Modified: mlpack/trunk/src/mlpack/core/io/cli.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/cli.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/cli.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -395,15 +395,16 @@
 
 namespace po = boost::program_options;
 
-namespace mlpack 
-{
+namespace mlpack {
 
+namespace io {
+
 // Externally defined in option.hpp, this class holds information about the
 // program being run.
-namespace io {
 class ProgramDoc;
-};
 
+}; // namespace io
+
 /**
  * @brief Parses the command line for parameters and holds user-specified
  *     parameters.
@@ -538,7 +539,7 @@
  * collisions are still possible, and they produce bizarre error messages. See
  * http://mlpack.org/ticket/74 for more information.
  */
-class CLI 
+class CLI
 {
  public:
   /**

Modified: mlpack/trunk/src/mlpack/core/io/cli_deleter.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/cli_deleter.cpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/cli_deleter.cpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -1,4 +1,4 @@
-/***
+/**
  * @file io_deleter.cc
  * @author Ryan Curtin
  *

Modified: mlpack/trunk/src/mlpack/core/io/cli_deleter.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/cli_deleter.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/cli_deleter.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -7,10 +7,8 @@
 #ifndef __MLPACK_CORE_IO_CLI_DELETER_HPP
 #define __MLPACK_CORE_IO_CLI_DELETER_HPP
 
-namespace mlpack
-{
-namespace io
-{
+namespace mlpack {
+namespace io {
 
 /**
  * Extremely simple class whose only job is to delete the existing CLI object at

Modified: mlpack/trunk/src/mlpack/core/io/cli_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/cli_impl.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/cli_impl.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -11,11 +11,10 @@
 #ifndef __MLPACK_CORE_IO_CLI_IMPL_HPP
 #define __MLPACK_CORE_IO_CLI_IMPL_HPP
 
-//Include option.hpp here because it requires CLI but is also templated.
+// Include option.hpp here because it requires CLI but is also templated.
 #include "option.hpp"
 
-namespace mlpack 
-{
+namespace mlpack {
 
 /**
  * @brief Adds a parameter to CLI, making it accessibile via GetParam &
@@ -33,7 +32,7 @@
 void CLI::Add(const char* identifier,
              const char* description,
              const char* parent,
-             bool required) 
+             bool required)
 {
 
   po::options_description& desc = CLI::GetSingleton().desc;
@@ -75,17 +74,17 @@
 
   // If we have the option, set its value.
   if (vmap.count(key) && !gmap.count(key))
-  {
     gmap[key] = boost::any(vmap[identifier].as<T>());
-  }
 
   // We may have whatever is on the commandline, but what if the programmer has
   // made modifications?
   if (!gmap.count(key))
-  { // The programmer hasn't done anything; register it
+  {
+    // The programmer hasn't done anything; register it.
     gmap[key] = boost::any(tmp);
     *boost::any_cast<T>(&gmap[key]) = tmp;
   }
+
   tmp = *boost::any_cast<T>(&gmap[key]);
   return *boost::any_cast<T>(&gmap[key]);
 }

Modified: mlpack/trunk/src/mlpack/core/io/log.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/log.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/log.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -10,8 +10,7 @@
 #include "prefixedoutstream.hpp"
 #include "nulloutstream.hpp"
 
-namespace mlpack
-{
+namespace mlpack {
 
 /**
  * Provides a convenient way to give formatted output.
@@ -53,8 +52,7 @@
    * If not, halts program execution and prints a custom error message.
    * Does nothing in non-debug mode.
    */
-  static void Assert(bool condition,
-      const char* message="Assert Failed.");
+  static void Assert(bool condition, const char* message = "Assert Failed.");
 
 
   // We only use PrefixedOutStream if the program is compiled with debug
@@ -66,6 +64,7 @@
   //! Dumps debug output into the bit nether regions.
   static io::NullOutStream Debug;
 #endif
+
   //! Prints informational messages if --verbose is specified, prefixed with
   //! [INFO ].
   static io::PrefixedOutStream Info;

Deleted: mlpack/trunk/src/mlpack/core/io/nulloutstream.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/nulloutstream.cpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/nulloutstream.cpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -1,75 +0,0 @@
-/**
- * @file nulloutstream.cpp
- * @author Ryan Curtin
- * @author Matthew Amidon
- *
- * Implementation of NullOutStream functions.
- */
-#include "nulloutstream.hpp"
-
-using namespace mlpack::io;
-
-NullOutStream::NullOutStream()
-{ /* Nothing to do */ }
-
-NullOutStream::NullOutStream(const NullOutStream& other)
-{ /* Nothing to do */ }
-
-NullOutStream& NullOutStream::operator<< (bool val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (short val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (unsigned short val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (int val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (unsigned int val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (long val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (unsigned long val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (float val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (double val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (long double val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (void* val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (std::string& str)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (const char* str)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (std::streambuf* val)
-{ return *this; }
-
-NullOutStream& NullOutStream::operator<< (std::ostream& (*pf) (std::ostream&))
-{
-  return *this;
-}
-
-NullOutStream& NullOutStream::operator<< (std::ios& (*pf) (std::ios&))
-{
-  return *this;
-}
-
-NullOutStream& NullOutStream::operator<< (std::ios_base& (*pf) (std::ios_base&))
-{
-  return *this;
-}
-
-

Modified: mlpack/trunk/src/mlpack/core/io/nulloutstream.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/nulloutstream.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/nulloutstream.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -5,8 +5,8 @@
  *
  * Definition of the NullOutStream class.
  */
-#ifndef __MLPACK_CORE_IO_NULL_OUT_STREAM_HPP
-#define __MLPACK_CORE_IO_NULL_OUT_STREAM_HPP
+#ifndef __MLPACK_CORE_IO_NULLOUTSTREAM_HPP
+#define __MLPACK_CORE_IO_NULLOUTSTREAM_HPP
 
 #include <iostream>
 #include <streambuf>
@@ -24,47 +24,49 @@
   /**
    * Does nothing.
    */
-  NullOutStream();
+  NullOutStream() { }
 
   /**
    * Does nothing.
    */
-  NullOutStream(const NullOutStream& other);
+  NullOutStream(const NullOutStream& other) { }
 
   //! Does nothing.
-  NullOutStream& operator<<(bool val);
+  NullOutStream& operator<<(bool val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(short val);
+  NullOutStream& operator<<(short val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(unsigned short val);
+  NullOutStream& operator<<(unsigned short val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(int val);
+  NullOutStream& operator<<(int val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(unsigned int val);
+  NullOutStream& operator<<(unsigned int val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(long val);
+  NullOutStream& operator<<(long val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(unsigned long val);
+  NullOutStream& operator<<(unsigned long val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(float val);
+  NullOutStream& operator<<(float val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(double val);
+  NullOutStream& operator<<(double val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(long double val);
+  NullOutStream& operator<<(long double val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(void* val);
+  NullOutStream& operator<<(void* val) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(const char* str);
+  NullOutStream& operator<<(const char* str) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(std::string& str);
+  NullOutStream& operator<<(std::string& str) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(std::streambuf* sb);
+  NullOutStream& operator<<(std::streambuf* sb) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(std::ostream& (*pf) (std::ostream&));
+  NullOutStream& operator<<(std::ostream& (*pf) (std::ostream&))
+  { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(std::ios& (*pf) (std::ios&));
+  NullOutStream& operator<<(std::ios& (*pf) (std::ios&)) { return *this; }
   //! Does nothing.
-  NullOutStream& operator<<(std::ios_base& (*pf) (std::ios_base&));
+  NullOutStream& operator<<(std::ios_base& (*pf) (std::ios_base&))
+  { return *this; }
 
   //! Does nothing.
   template<typename T>

Modified: mlpack/trunk/src/mlpack/core/io/option.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/option.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/option.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -1,4 +1,4 @@
-/***
+/**
  * @file option.hpp
  * @author Matthew Amidon
  *
@@ -12,10 +12,8 @@
 
 #include "cli.hpp"
 
-namespace mlpack
-{
-namespace io
-{
+namespace mlpack {
+namespace io {
 
 /**
  * A static object whose constructor registers a parameter with the CLI class.

Modified: mlpack/trunk/src/mlpack/core/io/option_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/option_impl.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/option_impl.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -4,18 +4,15 @@
  *
  * Implementation of template functions for the Option class.
  */
-#ifndef __MLPACK_CORE_IO_OPTION_HPP
-#error "Do not include this file directly."
-#endif
-
 #ifndef __MLPACK_CORE_IO_OPTION_IMPL_HPP
 #define __MLPACK_CORE_IO_OPTION_IMPL_HPP
 
-namespace mlpack
-{
-namespace io
-{
+// Just in case it has not been included.
+#include "option.hpp"
 
+namespace mlpack {
+namespace io {
+
 /**
  * Registers a parameter with CLI.
  */
@@ -28,13 +25,17 @@
                 bool required)
 {
   if (ignoreTemplate)
+  {
     CLI::Add(identifier, description, parent, required);
+  }
   else
   {
     CLI::Add<N>(identifier, description, parent, required);
 
     // Create the full pathname to set the default value.
-    std::string pathname = CLI::SanitizeString(parent) + std::string(identifier);
+    std::string pathname = CLI::SanitizeString(parent) +
+        std::string(identifier);
+
     CLI::GetParam<N>(pathname.c_str()) = defaultValue;
   }
 }

Modified: mlpack/trunk/src/mlpack/core/io/optionshierarchy.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/optionshierarchy.cpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/optionshierarchy.cpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -25,7 +25,7 @@
   return;
 }
 
-/*
+/**
  * Constructs an empty OptionsHierarchy node
  *
  * @param name The name of the node to be created.
@@ -38,7 +38,7 @@
   return;
 }
 
-/*
+/**
  * Constructs an equivalent node to the given one.
  *
  * @param other The node to be copied
@@ -48,7 +48,7 @@
   return;
 }
 
-/*
+/**
  * Destroys the node.
  */
 OptionsHierarchy::~OptionsHierarchy()
@@ -56,7 +56,7 @@
   return;
 }
 
-/*
+/**
  * Will never fail, as given paths are relative to current node
  * and will be generated if not found.
  *
@@ -73,7 +73,7 @@
   AppendNode(pathname, tname, tmp, d);
 }
 
-/*
+/**
  * Will never fail, as given paths are relative to current node
  * and will be generated if not found.
  *
@@ -92,7 +92,7 @@
   AppendNode(pathname, tname, description, d);
 }
 
-/*
+/**
  * Will never fail, as given paths are relative to current node
  * and will be generated if not found.
  *
@@ -106,7 +106,8 @@
 {
   string name = GetName(pathname);
   string path = GetPath(pathname);
-  //Append the new name, if it isn't already there
+
+  // Append the new name, if it isn't already there.
   if (children.count(name) == 0)
     children[name] = OptionsHierarchy(name.c_str());
 
@@ -116,10 +117,11 @@
     return;
   }
 
-  //Recurse until path is done
+  // Recurse until path is done.
   children[name].AppendNode(path, tname, description, data);
 }
-/*
+
+/**
  * Will return the node associated with a pathname
  *
  * @param pathname The full pathname of the node,
@@ -148,7 +150,7 @@
   return NULL;
 }
 
-/*
+/**
  * Returns the various data associated with a node.  Passed by copy,
  * since this is only for unit testing.
  *
@@ -160,24 +162,26 @@
   return nodeData;
 }
 
-/* Returns the path bar/fizz in the pathname foo/bar/fizz
-  *
-  * @param pathname The full pathname of the parameter,
-  *   eg foo/bar in foo/bar.
-  *
-  * @return The identifiers of all nodes after the next node in the path,
-  *   eg fizz/bar in foo/fizz/bar.
-  */
+/**
+ * Returns the path bar/fizz in the pathname foo/bar/fizz
+ *
+ * @param pathname The full pathname of the parameter, e.g. foo/bar in foo/bar.
+ *
+ * @return The identifiers of all nodes after the next node in the path,
+ *   eg fizz/bar in foo/fizz/bar.
+ */
 string OptionsHierarchy::GetPath(string& pathname)
 {
-  //Want to make sure we return a valid string
+  // Make sure we return a valid string.
   if (pathname.find('/') == pathname.npos)
     return string("");
-  //Get the rest of the node name Eg foo/bar in root/foo/bar
-  return pathname.substr(pathname.find('/')+1,pathname.length());
+
+  // Get the rest of the node name Eg foo/bar in root/foo/bar.
+  return pathname.substr(pathname.find('/') + 1,pathname.length());
 }
 
-/* Returns the name foo in the pathname foo/bar/fizz
+/**
+ * Returns the name foo in the pathname foo/bar/fizz
  *
  * @param pathname The full pathname of the parameter,
  *   eg foo/bar in foo/bar.
@@ -187,15 +191,15 @@
  */
 string OptionsHierarchy::GetName(string& pathname)
 {
-  //Want to makesure we return a valid string
+  // Make sure we return a valid string.
   if (pathname.find('/') == pathname.npos)
     return pathname;
-  //Get the topmost node name in this path Eg root in root/foo/bar
+
+  // Get the topmost node name in this path Eg root in root/foo/bar.
   return pathname.substr(0, pathname.find('/'));
 }
 
-
-/*
+/**
  * Obtains a vector containing relative pathnames of nodes subordinant to
  * the one specified in the parameter.
  *
@@ -208,27 +212,27 @@
 {
   std::vector<std::string> ret;
 
-  //Obtain the starting node.
+  // Obtain the starting node.
   OptionsHierarchy* node = FindNode(pathname);
   if(node == NULL)
     return ret;
 
-  //Start adding it's children etc.
+  // Start adding its children.
   return GetRelativePathsHelper(*node);
 }
 
-std::vector<std::string>
-  OptionsHierarchy::GetRelativePathsHelper(OptionsHierarchy& node)
+std::vector<std::string> OptionsHierarchy::GetRelativePathsHelper(
+    OptionsHierarchy& node)
 {
   std::vector<std::string> ret;
   std::vector<std::string> tmp;
 
   tmp.push_back(node.nodeData.node);
   ChildMap::iterator iter;
-  for(iter = node.children.begin(); iter != node.children.end(); iter++)
+  for (iter = node.children.begin(); iter != node.children.end(); iter++)
     tmp = GetRelativePathsHelper((*iter).second);
 
-  while(tmp.size())
+  while (tmp.size())
   {
     ret.push_back(tmp.back());
     tmp.pop_back();
@@ -236,15 +240,16 @@
 
   return ret;
 }
-/*
- * Prints a node, followed by it's entries and submodules.
+
+/**
+ * Prints a node, followed by its entries and submodules.
  */
 void OptionsHierarchy::Print()
 {
-  //Print the node, append '/' if that node is not a leaf
+  // Print the node, append '/' if that node is not a leaf.
   PrintNode();
 
-  //Begin formatted output
+  // Begin formatted output.
   cout << "Entries:" << endl;
   PrintLeaves();
 
@@ -252,7 +257,7 @@
   PrintBranches();
 }
 
-/*
+/**
  * Prints every node and it's value, if any.
  */
 void OptionsHierarchy::PrintAll()
@@ -265,7 +270,7 @@
   }
 }
 
-/*
+/**
  * Prints every node and it's description.
  */
 void OptionsHierarchy::PrintAllHelp()
@@ -278,6 +283,7 @@
 
   // Now print all the children.
   map<string, OptionsHierarchy>::iterator iter;
+
   // First print modules.
   for (iter = children.begin(); iter != children.end(); iter++)
   {
@@ -328,7 +334,8 @@
       // timer.
       if (iter->second.nodeData.tname != TYPENAME(timeval))
         iter->second.PrintNode();
-    } else
+    }
+    else
     {
       iter->second.PrintLeaves();
     }
@@ -345,7 +352,8 @@
     {
       if (iter->second.nodeData.tname == TYPENAME(timeval))
         iter->second.PrintNode();
-    } else
+    }
+    else
     {
       iter->second.PrintTimers();
     }
@@ -369,7 +377,8 @@
     if (value == "")
       value = "\"\""; // So that the user isn't presented with an empty space.
     Log::Info << value;
-  } else if (nodeData.tname == TYPENAME(float))
+  }
+  else if (nodeData.tname == TYPENAME(float))
     Log::Info << CLI::GetParam<float>(nodeData.node.c_str());
   else if (nodeData.tname == TYPENAME(double))
     Log::Info << CLI::GetParam<double>(nodeData.node.c_str());
@@ -425,7 +434,7 @@
   Log::Info << endl;
 }
 
-/*
+/**
  * Prints a node and its description.  The format is similar to that help given
  * by the ImageMagick suite of programs.
  */
@@ -480,7 +489,8 @@
       cout << HyphenateString(nodeData.desc, 30) << endl;
     else
       cout << "Undocumented option." << endl;
-  } else
+  }
+  else
   {
     cout << endl << std::string(30, ' ');
     if (nodeData.desc.length() > 0)
@@ -518,7 +528,8 @@
       if (str.length() - pos < margin)
       {
         splitpos = str.length(); // The rest fits on one line.
-      } else
+      }
+      else
       {
         splitpos = str.rfind(' ', margin + pos); // Find nearest space.
         if (splitpos <= pos || splitpos == string::npos) // Not found.

Modified: mlpack/trunk/src/mlpack/core/io/optionshierarchy.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/optionshierarchy.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/optionshierarchy.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -12,10 +12,8 @@
 #include <string>
 #include <vector>
 
-namespace mlpack
-{
-namespace io
-{
+namespace mlpack {
+namespace io {
 
 /**
  * Aids in the extensibility of OptionsHierarchy by focusing the potential

Modified: mlpack/trunk/src/mlpack/core/io/prefixedoutstream.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/prefixedoutstream.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/prefixedoutstream.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -5,8 +5,8 @@
  *
  * Declaration of the PrefixedOutStream class.
  */
-#ifndef __MLPACK_CORE_IO_PREFIXED_OUT_STREAM_HPP
-#define __MLPACK_CORE_IO_PREFIXED_OUT_STREAM_HPP
+#ifndef __MLPACK_CORE_IO_PREFIXEDOUTSTREAM_HPP
+#define __MLPACK_CORE_IO_PREFIXEDOUTSTREAM_HPP
 
 #include <iostream>
 #include <iomanip>
@@ -15,10 +15,8 @@
 
 #include <boost/lexical_cast.hpp>
 
-namespace mlpack
-{
-namespace io
-{
+namespace mlpack {
+namespace io {
 
 /**
  * Allows us to output to an ostream with a prefix at the beginning of each

Modified: mlpack/trunk/src/mlpack/core/io/prefixedoutstream_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/prefixedoutstream_impl.hpp	2011-11-23 07:06:17 UTC (rev 10355)
+++ mlpack/trunk/src/mlpack/core/io/prefixedoutstream_impl.hpp	2011-11-23 07:37:39 UTC (rev 10356)
@@ -5,18 +5,23 @@
  *
  * Implementation of templated PrefixedOutStream member functions.
  */
-#ifndef __MLPACK_CORE_IO_PREFIXED_OUT_STREAM_IMPL_HPP
-#define __MLPACK_CORE_IO_PREFIXED_OUT_STREAM_IMPL_HPP
+#ifndef __MLPACK_CORE_IO_PREFIXEDOUTSTREAM_IMPL_HPP
+#define __MLPACK_CORE_IO_PREFIXEDOUTSTREAM_IMPL_HPP
 
+// Just in case it hasn't been included.
+#include "prefixedoutstream.hpp"
+
 template<typename T>
-PrefixedOutStream& PrefixedOutStream::operator<<(T s) {
+PrefixedOutStream& PrefixedOutStream::operator<<(T s)
+{
   BaseLogic<T>(s);
 
   return *this;
 }
 
 template<typename T>
-void PrefixedOutStream::BaseLogic(T val) {
+void PrefixedOutStream::BaseLogic(T val)
+{
   // We will use this to track whether or not we need to terminate at the end of
   // this call (only for streams which terminate after a newline).
   bool newlined = false;
@@ -25,12 +30,14 @@
   PrefixIfNeeded();
 
   // Now we try to output the T (whatever it is).
-  try {
+  try
+  {
     std::string line = boost::lexical_cast<std::string>(val);
 
     // If the length of the casted thing was 0, it may have been a stream
     // manipulator, so send it directly to the stream and don't ask questions.
-    if (line.length() == 0) {
+    if (line.length() == 0)
+    {
       // The prefix cannot be necessary at this point.
       if (!ignoreInput) // Only if the user wants it.
         destination << val;
@@ -43,31 +50,40 @@
     // looking.
     size_t nl;
     size_t pos = 0;
-    while ((nl = line.find('\n', pos)) != std::string::npos) {
+    while ((nl = line.find('\n', pos)) != std::string::npos)
+    {
       PrefixIfNeeded();
-      if (!ignoreInput) { // Only if the user wants it.
+
+      // Only output if the user wants it.
+      if (!ignoreInput)
+      {
         destination << line.substr(pos, nl - pos);
         destination << std::endl;
         newlined = true;
       }
+
       carriageReturned = true; // Regardless of whether or not we display it.
 
       pos = nl + 1;
     }
 
-    if (pos != line.length()) { // We need to display the rest.
+    if (pos != line.length()) // We need to display the rest.
+    {
       PrefixIfNeeded();
       if (!ignoreInput)
         destination << line.substr(pos);
     }
-
-  } catch (boost::bad_lexical_cast &e) {
+  }
+  catch (boost::bad_lexical_cast &e)
+  {
     // Warn the user that there was a failure.
     PrefixIfNeeded();
     if (!ignoreInput)
+    {
       destination << "Failed lexical_cast<std::string>(T) for output; output"
           " not shown." << std::endl;
       newlined = true;
+    }
   }
 
   // If we displayed a newline and we need to terminate afterwards, do that.
@@ -76,9 +92,11 @@
 }
 
 // This is an inline function (that is why it is here and not in .cc).
-void PrefixedOutStream::PrefixIfNeeded() {
+void PrefixedOutStream::PrefixIfNeeded()
+{
   // If we need to, output a prefix.
-  if (carriageReturned) {
+  if (carriageReturned)
+  {
     if (!ignoreInput) // But only if we are allowed to.
       destination << prefix;
 
@@ -86,4 +104,4 @@
   }
 }
 
-#endif //MLPACK_CLI_PREFIXED_OUT_STREAM_IMPL_H
+#endif // MLPACK_CLI_PREFIXEDOUTSTREAM_IMPL_H




More information about the mlpack-svn mailing list