28 #include <ndn-cxx/util/logger.hpp>
36 static_assert(std::is_same<std::underlying_type<AvailableIn>::type,
37 std::underlying_type<ParseMode>::type>::value,
38 "AvailableIn and ParseMode must be declared with same underlying type");
45 os << sep <<
"one-shot";
62 return os <<
"one-shot";
66 return os << static_cast<int>(mode);
71 std::underlying_type<AvailableIn>::type modes)
75 new Command{def, execute,
static_cast<AvailableIn>(modes)});
82 m_commands[{noun, verb2}] = m_commands.at({noun, verb});
86 std::tuple<std::string, std::string, CommandArguments, ExecuteCommand>
91 const std::string& noun = tokens.size() > 0 ? tokens[0] :
"";
92 const std::string& verb = tokens.size() > 1 ? tokens[1] :
"";
93 size_t nameLen = std::min<size_t>(2, tokens.size());
95 auto i = m_commands.find({noun, verb});
96 if (i == m_commands.end()) {
98 i = m_commands.find({noun,
"list"});
102 i = m_commands.find({noun,
""});
104 nameLen = std::min<size_t>(1, tokens.size());
106 if (i == m_commands.end() || (i->second->modes &
static_cast<AvailableIn>(mode)) == 0) {
107 BOOST_THROW_EXCEPTION(
Error(
"no such command: " + noun +
" " + verb));
111 NDN_LOG_TRACE(
"found command " << def.
getNoun() <<
" " << def.
getVerb());
113 return std::make_tuple(def.
getNoun(), def.
getVerb(), def.
parse(tokens, nameLen), i->second->execute);
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
print different string on first and subsequent usage