face+mgmt: simplify factories and FaceManager using C++11 features

Change-Id: I113a4c15ef82bff705f61f31b170f49727bc3794
Refs: #3258
diff --git a/core/config-file.hpp b/core/config-file.hpp
index ae9102e..f6e4aaf 100644
--- a/core/config-file.hpp
+++ b/core/config-file.hpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014-2015,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #ifndef NFD_CORE_CONFIG_FILE_HPP
 #define NFD_CORE_CONFIG_FILE_HPP
@@ -47,7 +48,6 @@
 class ConfigFile : noncopyable
 {
 public:
-
   class Error : public std::runtime_error
   {
   public:
@@ -55,10 +55,10 @@
     Error(const std::string& what)
       : std::runtime_error(what)
     {
-
     }
   };
 
+  explicit
   ConfigFile(UnknownConfigSectionHandler unknownSectionCallback = throwErrorOnUnknownSection);
 
   static void
@@ -73,22 +73,32 @@
                        const ConfigSection& section,
                        bool isDryRun);
 
-  /** @brief parse a config option that can be either "yes" or "no"
+  /**
+   * \brief parse a config option that can be either "yes" or "no"
    *
-   *  @throw ConfigFile::Error value is neither "yes" nor "no"
-   *  @return true if "yes", false if "no"
+   * \return true if "yes", false if "no"
+   * \throw Error the value is neither "yes" nor "no"
    */
   static bool
-  parseYesNo(const ConfigSection::const_iterator& i,
-             const std::string& optionName,
+  parseYesNo(const ConfigSection::value_type& option,
              const std::string& sectionName);
 
+  /**
+   * \brief parse a numeric (integral or floating point) config option
+   *
+   * \return the numeric value of the parsed option
+   * \throw Error the value cannot be converted to the specified type
+   */
+  template <typename T>
+  static typename std::enable_if<std::is_arithmetic<T>::value, T>::type
+  parseNumber(const ConfigSection::value_type& option,
+              const std::string& sectionName);
+
   /// \brief setup notification of configuration file sections
   void
   addSectionHandler(const std::string& sectionName,
                     ConfigSectionHandler subscriber);
 
-
   /**
    * \param filename file to parse
    * \param isDryRun true if performing a dry run of configuration, false otherwise
@@ -127,21 +137,31 @@
   parse(const ConfigSection& config, bool isDryRun, const std::string& filename);
 
 private:
-
   void
-  process(bool isDryRun, const std::string& filename);
+  process(bool isDryRun, const std::string& filename) const;
 
 private:
   UnknownConfigSectionHandler m_unknownSectionCallback;
-
-  typedef std::map<std::string, ConfigSectionHandler> SubscriptionTable;
-
-  SubscriptionTable m_subscriptions;
-
+  std::map<std::string, ConfigSectionHandler> m_subscriptions;
   ConfigSection m_global;
 };
 
-} // namespace nfd
+template <typename T>
+inline typename std::enable_if<std::is_arithmetic<T>::value, T>::type
+ConfigFile::parseNumber(const ConfigSection::value_type& option,
+                        const std::string& sectionName)
+{
+  auto value = option.second.get_value<std::string>();
 
+  try {
+    return boost::lexical_cast<T>(value);
+  }
+  catch (const boost::bad_lexical_cast&) {
+    BOOST_THROW_EXCEPTION(Error("Invalid value \"" + value + "\" for option \"" +
+                                option.first + "\" in \"" + sectionName + "\" section"));
+  }
+}
+
+} // namespace nfd
 
 #endif // NFD_CORE_CONFIG_FILE_HPP