29 #include <ndn-cxx/util/logger.hpp> 37 static_assert(std::is_same<std::underlying_type<AvailableIn>::type,
38 std::underlying_type<ParseMode>::type>::value,
39 "AvailableIn and ParseMode must be declared with same underlying type");
46 os << sep <<
"one-shot";
52 os << sep <<
"hidden";
66 return os <<
"one-shot";
70 return os << static_cast<int>(mode);
75 std::underlying_type<AvailableIn>::type modes)
80 new Command{def, execute,
static_cast<AvailableIn>(modes)});
83 m_commandOrder.push_back(m_commands.find({def.getNoun(), def.getVerb()}));
92 m_commands[{noun, verb2}] = m_commands.at({noun, verb});
96 std::vector<const CommandDefinition*>
99 std::vector<const CommandDefinition*> results;
100 for (
auto i : m_commandOrder) {
101 const Command& command = *i->second;
102 if ((command.modes & static_cast<AvailableIn>(mode)) != 0 &&
103 (noun.empty() || noun == command.def.getNoun())) {
104 results.push_back(&command.def);
110 std::tuple<std::string, std::string, CommandArguments, ExecuteCommand>
115 const std::string& noun = tokens.size() > 0 ? tokens[0] :
"";
116 const std::string& verb = tokens.size() > 1 ? tokens[1] :
"";
118 NDN_LOG_TRACE(
"parse mode=" << mode <<
" noun=" << noun <<
" verb=" << verb);
120 auto i = m_commands.find({noun, verb});
121 if (i == m_commands.end() || (i->second->modes &
static_cast<AvailableIn>(mode)) == 0) {
126 NDN_LOG_TRACE(
"found command noun=" << def.
getNoun() <<
" verb=" << def.
getVerb());
128 size_t nConsumed = std::min<size_t>(2, tokens.size());
129 return std::make_tuple(def.
getNoun(), def.
getVerb(), def.
parse(tokens, nConsumed), 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