tools: replace boost::any usage with ndn::any

Change-Id: I7048a64b7c17353037ea9a64a11366d2fae6fd49
diff --git a/tools/nfdc/command-arguments.hpp b/tools/nfdc/command-arguments.hpp
index a949f99..164a672 100644
--- a/tools/nfdc/command-arguments.hpp
+++ b/tools/nfdc/command-arguments.hpp
@@ -31,7 +31,6 @@
 
 #include <ndn-cxx/encoding/nfd-constants.hpp>
 
-#include <boost/any.hpp>
 #include <boost/logic/tribool.hpp>
 
 namespace nfd {
@@ -43,19 +42,9 @@
 
 /** \brief contains named command arguments
  */
-class CommandArguments : public std::map<std::string, boost::any>
+class CommandArguments : public std::map<std::string, ndn::any>
 {
 public:
-  /** \return the argument value, or a default value if the argument is omitted on command line
-   */
-  template<typename T>
-  T
-  get(const std::string& key, const T& defaultValue = T()) const
-  {
-    auto i = find(key);
-    return i == end() ? defaultValue : boost::any_cast<T>(i->second);
-  }
-
   /** \return the argument value, or nullopt if the argument is omitted on command line
    */
   template<typename T>
@@ -63,10 +52,16 @@
   getOptional(const std::string& key) const
   {
     auto i = find(key);
-    if (i == end()) {
-      return nullopt;
-    }
-    return boost::any_cast<T>(i->second);
+    return i == end() ? nullopt : ndn::make_optional(ndn::any_cast<T>(i->second));
+  }
+
+  /** \return the argument value, or a default value if the argument is omitted on command line
+   */
+  template<typename T>
+  T
+  get(const std::string& key, const T& defaultValue = T()) const
+  {
+    return getOptional<T>(key).value_or(defaultValue);
   }
 
   /** \brief get an optional boolean argument as tribool
@@ -76,10 +71,7 @@
   getTribool(const std::string& key) const
   {
     auto value = getOptional<bool>(key);
-    if (value) {
-      return *value;
-    }
-    return boost::logic::indeterminate;
+    return value ? boost::logic::tribool(*value) : boost::logic::indeterminate;
   }
 };
 
diff --git a/tools/nfdc/command-definition.cpp b/tools/nfdc/command-definition.cpp
index 27b30f2..9dce67a 100644
--- a/tools/nfdc/command-definition.cpp
+++ b/tools/nfdc/command-definition.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2017,  Regents of the University of California,
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -24,6 +24,7 @@
  */
 
 #include "command-definition.hpp"
+
 #include <ndn-cxx/util/logger.hpp>
 
 namespace nfd {
@@ -240,18 +241,17 @@
   BOOST_THROW_EXCEPTION(std::invalid_argument("unrecognized FacePersistency '" + s + "'"));
 }
 
-boost::any
+ndn::any
 CommandDefinition::parseValue(ArgValueType valueType, const std::string& token) const
 {
   switch (valueType) {
     case ArgValueType::NONE:
     case ArgValueType::ANY:
       BOOST_ASSERT(false);
-      return boost::any();
+      return {};
 
-    case ArgValueType::BOOLEAN: {
+    case ArgValueType::BOOLEAN:
       return parseBoolean(token);
-    }
 
     case ArgValueType::UNSIGNED: {
       // boost::lexical_cast<uint64_t> will accept negative number
@@ -290,7 +290,7 @@
   }
 
   BOOST_ASSERT(false);
-  return boost::any();
+  return {};
 }
 
 } // namespace nfdc
diff --git a/tools/nfdc/command-definition.hpp b/tools/nfdc/command-definition.hpp
index 5661ff2..c512948 100644
--- a/tools/nfdc/command-definition.hpp
+++ b/tools/nfdc/command-definition.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2017,  Regents of the University of California,
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -130,11 +130,7 @@
   class Error : public std::invalid_argument
   {
   public:
-    explicit
-    Error(const std::string& what)
-      : std::invalid_argument(what)
-    {
-    }
+    using std::invalid_argument::invalid_argument;
   };
 
   CommandDefinition(const std::string& noun, const std::string& verb);
@@ -195,13 +191,12 @@
   parse(const std::vector<std::string>& tokens, size_t start = 0) const;
 
 private:
-  boost::any
+  ndn::any
   parseValue(ArgValueType valueType, const std::string& token) const;
 
 private:
   std::string m_noun;
   std::string m_verb;
-
   std::string m_title;
 
   struct Arg
@@ -211,8 +206,7 @@
     bool isRequired;
     std::string metavar;
   };
-  typedef std::map<std::string, Arg> ArgMap;
-  ArgMap m_args;
+  std::map<std::string, Arg> m_args;
   std::set<std::string> m_requiredArgs;
   std::vector<std::string> m_positionalArgs;
 };
diff --git a/tools/nfdc/face-module.cpp b/tools/nfdc/face-module.cpp
index ae6ba16..7bde8bf 100644
--- a/tools/nfdc/face-module.cpp
+++ b/tools/nfdc/face-module.cpp
@@ -310,10 +310,8 @@
 void
 FaceModule::destroy(ExecuteContext& ctx)
 {
-  const boost::any& faceIdOrUri = ctx.args.at("face");
-
   FindFace findFace(ctx);
-  FindFace::Code res = findFace.execute(faceIdOrUri);
+  FindFace::Code res = findFace.execute(ctx.args.at("face"));
 
   ctx.exitCode = static_cast<int>(res);
   switch (res) {
diff --git a/tools/nfdc/find-face.cpp b/tools/nfdc/find-face.cpp
index 918693f..bb6183d 100644
--- a/tools/nfdc/find-face.cpp
+++ b/tools/nfdc/find-face.cpp
@@ -56,14 +56,14 @@
 }
 
 FindFace::Code
-FindFace::execute(const boost::any& faceIdOrUri, bool allowMulti)
+FindFace::execute(const ndn::any& faceIdOrUri, bool allowMulti)
 {
-  const uint64_t* faceId = boost::any_cast<uint64_t>(&faceIdOrUri);
+  const uint64_t* faceId = ndn::any_cast<uint64_t>(&faceIdOrUri);
   if (faceId != nullptr) {
     return this->execute(*faceId);
   }
   else {
-    return this->execute(boost::any_cast<FaceUri>(faceIdOrUri), allowMulti);
+    return this->execute(ndn::any_cast<FaceUri>(faceIdOrUri), allowMulti);
   }
 }
 
diff --git a/tools/nfdc/find-face.hpp b/tools/nfdc/find-face.hpp
index 68e5f7b..ea1245b 100644
--- a/tools/nfdc/find-face.hpp
+++ b/tools/nfdc/find-face.hpp
@@ -71,12 +71,12 @@
   execute(uint64_t faceId);
 
   /** \brief find face by FaceId or FaceUri
-   *  \param faceIdOrUri a boost::any that contains uint64_t or FaceUri
+   *  \param faceIdOrUri a ndn::any that contains uint64_t or FaceUri
    *  \param allowMulti effective only if \p faceIdOrUri contains a FaceUri
-   *  \throw boost::bad_any_cast faceIdOrUri is neither uint64_t nor FaceUri
+   *  \throw ndn::bad_any_cast faceIdOrUri is neither uint64_t nor FaceUri
    */
   Code
-  execute(const boost::any& faceIdOrUri, bool allowMulti = false);
+  execute(const ndn::any& faceIdOrUri, bool allowMulti = false);
 
   /** \brief find face by FaceQueryFilter
    *  \pre execute has not been invoked
diff --git a/tools/nfdc/rib-module.cpp b/tools/nfdc/rib-module.cpp
index 47acd0c..b41d33a 100644
--- a/tools/nfdc/rib-module.cpp
+++ b/tools/nfdc/rib-module.cpp
@@ -144,7 +144,7 @@
 RibModule::add(ExecuteContext& ctx)
 {
   auto prefix = ctx.args.get<Name>("prefix");
-  const boost::any& nexthop = ctx.args.at("nexthop");
+  auto nexthop = ctx.args.at("nexthop");
   auto origin = ctx.args.get<RouteOrigin>("origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
   auto cost = ctx.args.get<uint64_t>("cost", 0);
   bool wantChildInherit = !ctx.args.get<bool>("no-inherit", false);
@@ -212,7 +212,7 @@
 RibModule::remove(ExecuteContext& ctx)
 {
   auto prefix = ctx.args.get<Name>("prefix");
-  const boost::any& nexthop = ctx.args.at("nexthop");
+  auto nexthop = ctx.args.at("nexthop");
   auto origin = ctx.args.get<RouteOrigin>("origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
 
   FindFace findFace(ctx);