23 #include "command-line.h"
26 #include "global-value.h"
35 CommandLine::CommandLine ()
39 CommandLine::CommandLine (
const CommandLine &cmd)
44 CommandLine::operator = (
const CommandLine &cmd)
50 CommandLine::~CommandLine ()
56 CommandLine::Copy (
const CommandLine &cmd)
60 for (Items::const_iterator i = cmd.m_items.begin ();
61 i != cmd.m_items.end (); ++i)
63 m_items.push_back (*i);
67 CommandLine::Clear (
void)
71 for (Items::const_iterator i = m_items.begin (); i != m_items.end (); ++i)
78 CommandLine::Item::~Item ()
89 for (argc--, argv++; argc > 0; argc--, argv++)
92 std::string param = *argv;
93 std::string::size_type cur = param.find (
"--");
96 param = param.substr (2, param.size () - 2);
100 cur = param.find (
"-");
103 param = param.substr (1, param.size () - 1);
111 cur = param.find (
"=");
112 std::string name, value;
113 if (cur == std::string::npos)
120 name = param.substr (0, cur);
121 value = param.substr (cur + 1, param.size () - (cur+1));
123 HandleArgument (name, value);
128 CommandLine::PrintHelp (
void)
const
132 std::cout <<
"--PrintHelp: Print this help message." << std::endl;
133 std::cout <<
"--PrintGroups: Print the list of groups." << std::endl;
134 std::cout <<
"--PrintTypeIds: Print all TypeIds." << std::endl;
135 std::cout <<
"--PrintGroup=[group]: Print all TypeIds of group." << std::endl;
136 std::cout <<
"--PrintAttributes=[typeid]: Print all attributes of typeid." << std::endl;
137 std::cout <<
"--PrintGlobals: Print the list of globals." << std::endl;
138 if (!m_items.empty ())
140 std::cout <<
"User Arguments:" << std::endl;
141 for (Items::const_iterator i = m_items.begin (); i != m_items.end (); ++i)
143 std::cout <<
" --" << (*i)->m_name <<
": " << (*i)->m_help << std::endl;
149 CommandLine::PrintGlobals (
void)
const
155 std::cout <<
" --" << (*i)->GetName () <<
"=[";
156 Ptr<const AttributeChecker> checker = (*i)->GetChecker ();
159 std::cout << v.Get () <<
"]: "
160 << (*i)->GetHelp () << std::endl;
165 CommandLine::PrintAttributes (std::string type)
const
174 for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
176 std::cout <<
" --"<<tid.GetAttributeFullName (i)<<
"=[";
177 struct TypeId::AttributeInformation info = tid.GetAttribute (i);
178 std::cout << info.initialValue->SerializeToString (info.checker) <<
"]: "
179 << info.help << std::endl;
185 CommandLine::PrintGroup (std::string group)
const
192 if (tid.GetGroupName () == group)
194 std::cout <<
" --PrintAttributes=" <<tid.GetName ()<<std::endl;
200 CommandLine::PrintTypeIds (
void)
const
207 std::cout <<
" --PrintAttributes=" <<tid.GetName ()<<std::endl;
212 CommandLine::PrintGroups (
void)
const
216 std::list<std::string> groups;
220 std::string group = tid.GetGroupName ();
226 for (std::list<std::string>::const_iterator j = groups.begin (); j != groups.end (); ++j)
236 groups.push_back (group);
239 for (std::list<std::string>::const_iterator k = groups.begin (); k != groups.end (); ++k)
241 std::cout <<
" --PrintGroup="<<*k<<std::endl;
246 CommandLine::HandleArgument (std::string name, std::string value)
const
250 NS_LOG_DEBUG (
"Handle arg name="<<name<<
" value="<<value);
251 if (name ==
"PrintHelp")
257 else if (name ==
"PrintGroups")
263 else if (name ==
"PrintTypeIds")
269 else if (name ==
"PrintGlobals")
275 else if (name ==
"PrintGroup")
281 else if (name ==
"PrintAttributes")
284 PrintAttributes (value);
289 for (Items::const_iterator i = m_items.begin (); i != m_items.end (); ++i)
291 if ((*i)->m_name == name)
293 if (!(*i)->Parse (value))
295 std::cerr <<
"Invalid argument value: "<<name<<
"="<<value << std::endl;
308 std::cerr <<
"Invalid command-line arguments: --"<<name<<
"="<<value<<std::endl;
315 CommandLine::CallbackItem::Parse (std::string value)
318 NS_LOG_DEBUG (
"CommandLine::CallbackItem::Parse \"" << value <<
"\"");
319 return m_callback (value);
324 const std::string &help,
331 item->m_callback = callback;
332 m_items.push_back (item);
#define NS_LOG_FUNCTION(parameters)
bool SetDefaultFailSafe(std::string fullName, const AttributeValue &value)
#define NS_LOG_COMPONENT_DEFINE(name)
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
#define NS_FATAL_ERROR(msg)
fatal error handling
static uint32_t GetRegisteredN(void)
static Iterator Begin(void)
static TypeId GetRegistered(uint32_t i)
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
void AddValue(const std::string &name, const std::string &help, T &value)
static Iterator End(void)
#define NS_LOG_DEBUG(msg)
void Parse(int argc, char *argv[]) const