A Discrete-Event Network Simulator
API
command-line.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 
22 #include "command-line.h"
23 #include "des-metrics.h"
24 #include "log.h"
25 #include "config.h"
26 #include "global-value.h"
27 #include "system-path.h"
28 #include "type-id.h"
29 #include "string.h"
30 
31 #include <algorithm> // transform
32 #include <cctype> // tolower
33 #include <cstdlib> // exit, getenv
34 #include <cstring> // strlen
35 #include <iomanip> // setw, boolalpha
36 #include <set>
37 #include <sstream>
38 
39 
46 namespace ns3 {
47 
48 NS_LOG_COMPONENT_DEFINE ("CommandLine");
49 
51  : m_NNonOptions (0),
52  m_nonOptionCount (0),
53  m_usage (),
54  m_shortName ()
55 {
56  NS_LOG_FUNCTION (this);
57 }
58 CommandLine::CommandLine (const std::string filename)
59  : m_NNonOptions (0),
60  m_nonOptionCount (0),
61  m_usage ()
62 {
63  NS_LOG_FUNCTION (this << filename);
64  std::string basename = SystemPath::Split (filename).back ();
65  m_shortName = basename.substr (0, basename.rfind (".cc"));
66 }
67 
69 {
70  Copy (cmd);
71 }
74 {
75  Clear ();
76  Copy (cmd);
77  return *this;
78 }
80 {
81  NS_LOG_FUNCTION (this);
82  Clear ();
83 }
84 void
86 {
88 
89  std::copy (cmd.m_options.begin (), cmd.m_options.end (), m_options.end ());
90  std::copy (cmd.m_nonOptions.begin (), cmd.m_nonOptions.end (), m_nonOptions.end ());
91 
92  m_NNonOptions = cmd.m_NNonOptions;
93  m_nonOptionCount = 0;
94  m_usage = cmd.m_usage;
95  m_shortName = cmd.m_shortName;
96 }
97 void
99 {
100  NS_LOG_FUNCTION (this);
101 
102  for (auto i : m_options)
103  {
104  delete i;
105  }
106  for (auto i : m_nonOptions)
107  {
108  delete i;
109  }
110  m_options.clear ();
111  m_nonOptions.clear ();
112  m_NNonOptions = 0;
113  m_usage = "";
114  m_shortName = "";
115 }
116 
117 void
118 CommandLine::Usage (const std::string usage)
119 {
120  m_usage = usage;
121 }
122 
123 std::string
125 {
126  return m_shortName;
127 }
128 
130 {
131  NS_LOG_FUNCTION (this);
132 }
133 
134 void
135 CommandLine::Parse (std::vector<std::string> args)
136 {
137  NS_LOG_FUNCTION (this << args.size () << args);
138 
140 
141  m_nonOptionCount = 0;
142 
143  if (args.size () > 0)
144  {
145  args.erase (args.begin ()); // discard the program name
146 
147  for (auto param : args)
148  {
149  if (HandleOption (param))
150  {
151  continue;
152  }
153  if (HandleNonOption (param))
154  {
155  continue;
156  }
157 
158  // is this possible?
159  NS_ASSERT_MSG (false,
160  "unexpected error parsing command line parameter: '"
161  << param << "'");
162 
163  }
164  }
165 
166 #ifdef ENABLE_DES_METRICS
167  DesMetrics::Get ()->Initialize (args);
168 #endif
169 
170 }
171 
172 bool
173 CommandLine::HandleOption (const std::string & param) const
174 {
175  // remove leading "--" or "-"
176  std::string arg = param;
177  std::string::size_type cur = arg.find ("--");
178  if (cur == 0)
179  {
180  arg = arg.substr (2, arg.size () - 2);
181  }
182  else
183  {
184  cur = arg.find ("-");
185  if (cur == 0)
186  {
187  arg = arg.substr (1, arg.size () - 1);
188  }
189  else
190  {
191  // non-option argument?
192  return false;
193  }
194  }
195  // find any value following '='
196  cur = arg.find ("=");
197  std::string name, value;
198  if (cur == std::string::npos)
199  {
200  name = arg;
201  value = "";
202  }
203  else
204  {
205  name = arg.substr (0, cur);
206  value = arg.substr (cur + 1, arg.size () - (cur + 1));
207  }
208  HandleArgument (name, value);
209 
210  return true;
211 }
212 
213 bool
214 CommandLine::HandleNonOption (const std::string &value)
215 {
216  NS_LOG_FUNCTION (this << value);
217 
218  if (m_nonOptionCount == m_nonOptions.size ())
219  {
220  // Add an unspecified non-option as a string
221  NS_LOG_LOGIC ("adding StringItem, NOCount:" << m_nonOptionCount
222  << ", NOSize:" << m_nonOptions.size ());
223  StringItem * item = new StringItem;
224  item->m_name = "extra-non-option-argument";
225  item->m_help = "Extra non-option argument encountered.";
226  item->m_value = value;
227  m_nonOptions.push_back (item);
228  }
229 
230  auto i = m_nonOptions[m_nonOptionCount];
231  if (!i->Parse (value))
232  {
233  std::cerr << "Invalid non-option argument value "
234  << value << " for " << i->m_name
235  << std::endl;
236  PrintHelp (std::cerr);
237  std::exit (1);
238  }
240  return true;
241 }
242 
243 
244 
245 void
246 CommandLine::Parse (int argc, char *argv[])
247 {
248  NS_LOG_FUNCTION (this << argc);
249  std::vector<std::string> args (argv, argv + argc);
250  Parse (args);
251 }
252 
253 void
254 CommandLine::PrintHelp (std::ostream &os) const
255 {
256  NS_LOG_FUNCTION (this);
257 
258  // Hack to show just the declared non-options
259  Items nonOptions (m_nonOptions.begin (),
260  m_nonOptions.begin () + m_NNonOptions);
261  os << m_shortName
262  << (m_options.size () ? " [Program Options]" : "")
263  << (nonOptions.size () ? " [Program Arguments]" : "")
264  << " [General Arguments]"
265  << std::endl;
266 
267  if (m_usage.length ())
268  {
269  os << std::endl;
270  os << m_usage << std::endl;
271  }
272 
273  std::size_t width = 0;
274  for (auto it : m_options)
275  {
276  width = std::max (width, it->m_name.size ());
277  }
278  for (auto it : nonOptions)
279  {
280  width = std::max (width, it->m_name.size ());
281  }
282  width += 3; // room for ": " between option and help
283 
284  if (!m_options.empty ())
285  {
286  os << std::endl;
287  os << "Program Options:" << std::endl;
288  for (auto i : m_options)
289  {
290  os << " --"
291  << std::left << std::setw (width) << ( i->m_name + ":")
292  << std::right
293  << i->m_help;
294 
295  if ( i->HasDefault ())
296  {
297  os << " [" << i->GetDefault () << "]";
298  }
299  os << std::endl;
300  }
301  }
302 
303  if (!nonOptions.empty ())
304  {
305  width += 2; // account for "--" added above
306  os << std::endl;
307  os << "Program Arguments:" << std::endl;
308  for (auto i : nonOptions)
309  {
310  os << " "
311  << std::left << std::setw (width) << ( i->m_name + ":")
312  << std::right
313  << i->m_help;
314 
315  if ( i->HasDefault ())
316  {
317  os << " [" << i->GetDefault () << "]";
318  }
319  os << std::endl;
320  }
321  }
322 
323  os << std::endl;
324  os
325  << "General Arguments:\n"
326  << " --PrintGlobals: Print the list of globals.\n"
327  << " --PrintGroups: Print the list of groups.\n"
328  << " --PrintGroup=[group]: Print all TypeIds of group.\n"
329  << " --PrintTypeIds: Print all TypeIds.\n"
330  << " --PrintAttributes=[typeid]: Print all attributes of typeid.\n"
331  << " --PrintHelp: Print this help message.\n"
332  << std::endl;
333 }
334 
335 #include <unistd.h> // getcwd
336 
337 void
339 {
340  NS_LOG_FUNCTION (this);
341 
342  const char * envVar = std::getenv ("NS_COMMANDLINE_INTROSPECTION");
343  if (envVar == 0 || std::strlen (envVar) == 0)
344  {
345  return;
346  }
347 
348  if (m_shortName.size () == 0)
349  {
350  NS_FATAL_ERROR ("No file name on example-to-run; forgot to use CommandLine var (__FILE__)?");
351  return;
352  }
353 
354  // Hack to show just the declared non-options
355  Items nonOptions (m_nonOptions.begin (),
356  m_nonOptions.begin () + m_NNonOptions);
357 
358  std::string outf = SystemPath::Append (std::string (envVar), m_shortName + ".command-line");
359 
360  NS_LOG_INFO ("Writing CommandLine doxy to " << outf);
361 
362  std::fstream os (outf, std::fstream::out);
363 
364 
365  os << "/**\n \\file " << m_shortName << ".cc\n"
366  << "<h3>Usage</h3>\n"
367  << "<code>$ ./waf --run \"" << m_shortName
368  << (m_options.size () ? " [Program Options]" : "")
369  << (nonOptions.size () ? " [Program Arguments]" : "")
370  << "\"</code>\n";
371 
372  if (m_usage.length ())
373  {
374  os << m_usage << std::endl;
375  }
376 
377  if (!m_options.empty ())
378  {
379  os << std::endl;
380  os << "<h3>Program Options</h3>\n"
381  << "<dl>\n";
382  for (auto i : m_options)
383  {
384  os << " <dt>\\c --" << i->m_name << " </dt>\n"
385  << " <dd>" << i->m_help;
386 
387  if ( i->HasDefault ())
388  {
389  os << " [" << i->GetDefault () << "]";
390  }
391  os << " </dd>\n";
392  }
393  os << "</dl>\n";
394  }
395 
396  if (!nonOptions.empty ())
397  {
398  os << std::endl;
399  os << "<h3>Program Arguments</h3>\n"
400  << "<dl>\n";
401  for (auto i : nonOptions)
402  {
403  os << " <dt> \\c " << i->m_name << " </dt>\n"
404  << " <dd>" << i->m_help;
405 
406  if ( i->HasDefault ())
407  {
408  os << " [" << i->GetDefault () << "]";
409  }
410  os << " </dd>\n";
411  }
412  os << "</dl>\n";
413  }
414 
415  os << "*/" << std::endl;
416 
417  // All done, don't need to actually run the example
418  os.close ();
419  std::exit (0);
420 }
421 
422 void
423 CommandLine::PrintGlobals (std::ostream &os) const
424 {
425  NS_LOG_FUNCTION (this);
426 
427  os << "Global values:" << std::endl;
428 
429  // Sort output
430  std::vector<std::string> globals;
431 
433  i != GlobalValue::End ();
434  ++i)
435  {
436  std::stringstream ss;
437  ss << " --" << (*i)->GetName () << "=[";
438  Ptr<const AttributeChecker> checker = (*i)->GetChecker ();
439  StringValue v;
440  (*i)->GetValue (v);
441  ss << v.Get () << "]" << std::endl;
442  ss << " " << (*i)->GetHelp () << std::endl;
443  globals.push_back (ss.str ());
444  }
445  std::sort (globals.begin (), globals.end ());
446  for (std::vector<std::string>::const_iterator it = globals.begin ();
447  it < globals.end ();
448  ++it)
449  {
450  os << *it;
451  }
452 }
453 
454 void
455 CommandLine::PrintAttributes (std::ostream &os, const std::string &type) const
456 {
457  NS_LOG_FUNCTION (this);
458 
459  TypeId tid;
460  if (!TypeId::LookupByNameFailSafe (type, &tid))
461  {
462  NS_FATAL_ERROR ("Unknown type=" << type << " in --PrintAttributes");
463  }
464 
465  os << "Attributes for TypeId " << tid.GetName () << std::endl;
466 
467  // Sort output
468  std::vector<std::string> attributes;
469 
470  for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
471  {
472  std::stringstream ss;
473  ss << " --" << tid.GetAttributeFullName (i) << "=[";
474  struct TypeId::AttributeInformation info = tid.GetAttribute (i);
475  ss << info.initialValue->SerializeToString (info.checker) << "]"
476  << std::endl;
477  ss << " " << info.help << std::endl;
478  attributes.push_back (ss.str ());
479  }
480  std::sort (attributes.begin (), attributes.end ());
481  for (std::vector<std::string>::const_iterator it = attributes.begin ();
482  it < attributes.end ();
483  ++it)
484  {
485  os << *it;
486  }
487 }
488 
489 
490 void
491 CommandLine::PrintGroup (std::ostream &os, const std::string &group) const
492 {
493  NS_LOG_FUNCTION (this);
494 
495  os << "TypeIds in group " << group << ":" << std::endl;
496 
497  // Sort output
498  std::vector<std::string> groupTypes;
499 
500  for (uint16_t i = 0; i < TypeId::GetRegisteredN (); ++i)
501  {
502  std::stringstream ss;
503  TypeId tid = TypeId::GetRegistered (i);
504  if (tid.GetGroupName () == group)
505  {
506  ss << " " << tid.GetName () << std::endl;
507  }
508  groupTypes.push_back (ss.str ());
509  }
510  std::sort (groupTypes.begin (), groupTypes.end ());
511  for (std::vector<std::string>::const_iterator it = groupTypes.begin ();
512  it < groupTypes.end ();
513  ++it)
514  {
515  os << *it;
516  }
517 }
518 
519 void
520 CommandLine::PrintTypeIds (std::ostream &os) const
521 {
522  NS_LOG_FUNCTION (this);
523  os << "Registered TypeIds:" << std::endl;
524 
525  // Sort output
526  std::vector<std::string> types;
527 
528  for (uint16_t i = 0; i < TypeId::GetRegisteredN (); ++i)
529  {
530  std::stringstream ss;
531  TypeId tid = TypeId::GetRegistered (i);
532  ss << " " << tid.GetName () << std::endl;
533  types.push_back (ss.str ());
534  }
535  std::sort (types.begin (), types.end ());
536  for (std::vector<std::string>::const_iterator it = types.begin ();
537  it < types.end ();
538  ++it)
539  {
540  os << *it;
541  }
542 }
543 
544 void
545 CommandLine::PrintGroups (std::ostream &os) const
546 {
547  NS_LOG_FUNCTION (this);
548 
549  std::set<std::string> groups;
550  for (uint16_t i = 0; i < TypeId::GetRegisteredN (); ++i)
551  {
552  TypeId tid = TypeId::GetRegistered (i);
553  groups.insert (tid.GetGroupName ());
554  }
555 
556  os << "Registered TypeId groups:" << std::endl;
557  // Sets are already sorted
558  for (std::set<std::string>::const_iterator k = groups.begin ();
559  k != groups.end ();
560  ++k)
561  {
562  os << " " << *k << std::endl;
563  }
564 }
565 
566 void
567 CommandLine::HandleArgument (const std::string &name, const std::string &value) const
568 {
569  NS_LOG_FUNCTION (this << name << value);
570 
571  NS_LOG_DEBUG ("Handle arg name=" << name << " value=" << value);
572 
573  // Hard-coded options
574  if (name == "PrintHelp" || name == "help")
575  {
576  // method below never returns.
577  PrintHelp (std::cout);
578  std::exit (0);
579  }
580  else if (name == "PrintGroups")
581  {
582  // method below never returns.
583  PrintGroups (std::cout);
584  std::exit (0);
585  }
586  else if (name == "PrintTypeIds")
587  {
588  // method below never returns.
589  PrintTypeIds (std::cout);
590  std::exit (0);
591  }
592  else if (name == "PrintGlobals")
593  {
594  // method below never returns.
595  PrintGlobals (std::cout);
596  std::exit (0);
597  }
598  else if (name == "PrintGroup")
599  {
600  // method below never returns.
601  PrintGroup (std::cout, value);
602  std::exit (0);
603  }
604  else if (name == "PrintAttributes")
605  {
606  // method below never returns.
607  PrintAttributes (std::cout, value);
608  std::exit (0);
609  }
610  else
611  {
612  for (auto i : m_options)
613  {
614  if (i->m_name == name)
615  {
616  if (!i->Parse (value))
617  {
618  std::cerr << "Invalid argument value: "
619  << name << "=" << value << std::endl;
620  PrintHelp (std::cerr);
621  std::exit (1);
622  }
623  else
624  {
625  return;
626  }
627  }
628  }
629  }
630  // Global or ConfigPath options
631  if (!Config::SetGlobalFailSafe (name, StringValue (value))
632  && !Config::SetDefaultFailSafe (name, StringValue (value)))
633  {
634  std::cerr << "Invalid command-line arguments: --"
635  << name << "=" << value << std::endl;
636  PrintHelp (std::cerr);
637  std::exit (1);
638  }
639 }
640 
641 bool
643 {
644  return m_default != "";
645 }
646 
647 std::string
649 {
650  return m_default;
651 }
652 
653 bool
654 CommandLine::CallbackItem::Parse (const std::string value)
655 {
656  NS_LOG_FUNCTION (this);
657  NS_LOG_DEBUG ("CommandLine::CallbackItem::Parse \"" << value << "\"");
658  return m_callback (value);
659 }
660 
661 void
662 CommandLine::AddValue (const std::string &name,
663  const std::string &help,
665  std::string defaultValue /* = "" */)
666 
667 {
668  NS_LOG_FUNCTION (this << &name << &help << &callback);
669  CallbackItem *item = new CallbackItem ();
670  item->m_name = name;
671  item->m_help = help;
672  item->m_callback = callback;
673  item->m_default = defaultValue;
674  m_options.push_back (item);
675 }
676 
677 void
678 CommandLine::AddValue (const std::string &name,
679  const std::string &attributePath)
680 {
681  NS_LOG_FUNCTION (this << name << attributePath);
682  // Attribute name is last token
683  std::size_t colon = attributePath.rfind ("::");
684  const std::string typeName = attributePath.substr (0, colon);
685  NS_LOG_DEBUG ("typeName: '" << typeName << "', colon: " << colon);
686 
687  TypeId tid;
688  if (!TypeId::LookupByNameFailSafe (typeName, &tid))
689  {
690  NS_FATAL_ERROR ("Unknown type=" << typeName);
691  }
692 
693  const std::string attrName = attributePath.substr (colon + 2);
694  struct TypeId::AttributeInformation info;
695  if (!tid.LookupAttributeByName (attrName, &info))
696  {
697  NS_FATAL_ERROR ("Attribute not found: " << attributePath);
698  }
699 
700  std::stringstream ss;
701  ss << info.help
702  << " (" << attributePath << ") ["
703  << info.initialValue->SerializeToString (info.checker) << "]";
704 
705  AddValue (name, ss.str (),
707 }
708 
709 std::string
710 CommandLine::GetExtraNonOption (std::size_t i) const
711 {
712  std::string value;
713 
714  if (m_nonOptions.size () >= i + m_NNonOptions)
715  {
716  auto ip = dynamic_cast<StringItem *> (m_nonOptions[i + m_NNonOptions]);
717  if (ip != NULL)
718  {
719  value = ip->m_value;
720  }
721  }
722  return value;
723 }
724 
725 std::size_t
727 {
728  if (m_nonOptions.size () > m_NNonOptions)
729  {
730  return m_nonOptions.size () - m_NNonOptions;
731  }
732  else
733  {
734  return 0;
735  }
736 }
737 
738 
739 /* static */
740 bool
741 CommandLine::HandleAttribute (const std::string name,
742  const std::string value)
743 {
744  bool success = true;
745  if (!Config::SetGlobalFailSafe (name, StringValue (value))
746  && !Config::SetDefaultFailSafe (name, StringValue (value)))
747  {
748  success = false;
749  }
750  return success;
751 }
752 
753 
754 bool
756 {
757  return false;
758 }
759 
760 std::string
762 {
763  return "";
764 }
765 
766 bool
767 CommandLine::StringItem::Parse (const std::string value)
768 {
769  m_value = value;
770  return true;
771 }
772 
773 bool
775 {
776  return false;
777 }
778 
779 std::string
781 {
782  return "";
783 }
784 
785 template <>
786 std::string
788 {
789  std::ostringstream oss;
790  oss << std::boolalpha << val;
791  return oss.str ();
792 }
793 
794 template <>
795 bool
796 CommandLineHelper::UserItemParse<bool> (const std::string value, bool & val)
797 {
798  std::string src = value;
799  std::transform (src.begin (), src.end (), src.begin (),
800  [](char c) {return static_cast<char> (std::tolower (c)); });
801  if (src.length () == 0)
802  {
803  val = !val;
804  return true;
805  }
806  else if ( (src == "true") || (src == "t") )
807  {
808  val = true;
809  return true;
810  }
811  else if ( (src == "false") || (src == "f") )
812  {
813  val = false;
814  return true;
815  }
816  else
817  {
818  std::istringstream iss;
819  iss.str (src);
820  iss >> val;
821  return !iss.bad () && !iss.fail ();
822  }
823 }
824 
825 template <>
826 bool
827 CommandLineHelper::UserItemParse<uint8_t> (const std::string value, uint8_t & val)
828 {
829  uint8_t oldVal = val;
830  long newVal;
831 
832  try
833  {
834  newVal = std::stoi (value);
835  }
836  catch (std::invalid_argument & ia)
837  {
838  NS_LOG_WARN ("invalid argument: " << ia.what ());
839  val = oldVal;
840  return false;
841  }
842  catch (std::out_of_range & oor)
843  {
844  NS_LOG_WARN ("out of range: " << oor.what ());
845  val = oldVal;
846  return false;
847  }
848  if (newVal < 0 || newVal > 255)
849  {
850  return false;
851  }
852  val = newVal;
853  return true;
854 }
855 
856 
857 std::ostream &
858 operator << (std::ostream & os, const CommandLine & cmd)
859 {
860  cmd.PrintHelp (os);
861  return os;
862 }
863 
864 } // namespace ns3
~CommandLine()
Destructor.
Definition: command-line.cc:79
void PrintHelp(std::ostream &os) const
Print program usage to the desired output stream.
bool UserItemParse< bool >(const std::string value, bool &val)
Specialization of CommandLine::UserItem to bool.
std::string GetName(void) const
Get the name.
Definition: type-id.cc:977
void PrintGroups(std::ostream &os) const
Handler for --PrintGroups: print all TypeId group names.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool SetDefaultFailSafe(std::string fullName, const AttributeValue &value)
Definition: config.cc:857
void PrintDoxygenUsage(void) const
Append usage message in Doxygen format to the file indicated by the NS_COMMANDLINE_INTROSPECTION envi...
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Hold variables of type string.
Definition: string.h:41
std::vector< Item * > Items
Argument list container.
Definition: command-line.h:558
ns3::StringValue attribute value declarations.
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:894
std::string m_value
The argument value.
Definition: command-line.h:454
std::string GetName() const
Get the program name.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1703
Items m_nonOptions
The list of non-option arguments.
Definition: command-line.h:560
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Vector::const_iterator Iterator
Iterator type for the list of all global values.
Definition: global-value.h:80
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:876
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
cmd
Definition: second.py:35
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:838
std::string GetDefault< bool >(const bool &val)
Helper to specialize CommandLine::UserItem::GetDefault() on bool.
void PrintGlobals(std::ostream &os) const
Handler for --PrintGlobals: print all global variables and values.
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Definition: type-id.cc:883
Declaration of the various ns3::Config functions and classes.
static DesMetrics * Get(void)
Get a pointer to the singleton instance.
Definition: singleton.h:89
ns3::DesMetrics declaration.
void PrintAttributes(std::ostream &os, const std::string &type) const
Handler for --PrintAttributes: print the attributes for a given type.
std::list< std::string > Split(std::string path)
Split a file system path into directories according to the local path separator.
Definition: system-path.cc:258
void Usage(const std::string usage)
Supply the program usage and documentation.
bool HandleNonOption(const std::string &value)
Handle a non-option.
ns3::SystemPath declarations.
void Clear(void)
Remove all arguments, Usage(), name.
Definition: command-line.cc:98
An argument Item using a Callback to parse the input.
Definition: command-line.h:461
void Initialize(std::vector< std::string > args, std::string outDir="")
Open the DesMetrics trace file and print the header.
Definition: des-metrics.cc:42
bool UserItemParse< uint8_t >(const std::string value, uint8_t &val)
Specialization of CommandLine::UserItem to uint8_t to distinguish from char.
static bool HandleAttribute(const std::string name, const std::string value)
Callback function to handle attributes.
virtual std::string GetDefault() const
Items m_options
The list of option arguments.
Definition: command-line.h:559
bool HandleOption(const std::string &param) const
Handle an option in the form param=value.
std::string Get(void) const
Definition: string.cc:31
std::string m_shortName
The source file name (without .cc), as would be given to waf --run
Definition: command-line.h:564
std::string m_usage
The Usage string.
Definition: command-line.h:563
#define max(a, b)
Definition: 80211b.c:43
std::string GetDefault(void) const
static Iterator Begin(void)
The Begin iterator.
ns3::Callback< bool, std::string > m_callback
The Callback.
Definition: command-line.h:475
Ptr< const AttributeValue > initialValue
Configured initial value.
Definition: type-id.h:88
std::string m_default
The default value, as a string, if it exists.
Definition: command-line.h:476
std::size_t GetNExtraNonOptions(void) const
Get the total number of non-option arguments found, including those configured with AddNonOption() an...
bool Parse(const std::string value)
Parse from a string.
std::string GetDefault(void) const
std::string GetExtraNonOption(std::size_t i) const
Get extra non-option arguments by index.
Attribute implementation.
Definition: type-id.h:77
Parse command-line arguments.
Definition: command-line.h:221
void HandleArgument(const std::string &name, const std::string &value) const
Match name against the program or general arguments, and dispatch to the appropriate handler...
std::size_t m_nonOptionCount
The number of actual non-option arguments seen so far.
Definition: command-line.h:562
virtual bool Parse(const std::string value)
Parse from a string.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
ns3::CommandLine declaration.
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:92
Every class exported by the ns3 library is enclosed in the ns3 namespace.
CommandLine & operator=(const CommandLine &cmd)
Assignment.
Definition: command-line.cc:73
std::string GetGroupName(void) const
Get the group name.
Definition: type-id.cc:969
ns3::TypeId declaration; inline and template implementations.
std::string GetAttributeFullName(std::size_t i) const
Get the Attribute name by index.
Definition: type-id.cc:1090
std::string m_name
Argument label: ---m_name=...
Definition: command-line.h:405
void PrintGroup(std::ostream &os, const std::string &group) const
Handler for --PrintGroup: print all types belonging to a given group.
ns3::GlobalValue declaration.
CommandLine(void)
Constructor.
Definition: command-line.cc:50
virtual ~Item()
Destructor.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
if(desigRtr==addrLocal)
std::string m_help
Argument help string.
Definition: command-line.h:406
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:637
std::size_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1077
static Iterator End(void)
The End iterator.
std::string Append(std::string left, std::string right)
Join two file system path elements.
Definition: system-path.cc:241
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1084
void Copy(const CommandLine &cmd)
Copy constructor.
Definition: command-line.cc:85
void Parse(int argc, char *argv[])
Parse the program arguments.
std::size_t m_NNonOptions
The expected number of non-option arguments.
Definition: command-line.h:561
static uint16_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:870
Debug message logging.
a unique identifier for an interface.
Definition: type-id.h:58
void PrintTypeIds(std::ostream &os) const
Handler for --PrintTypeIds: print all TypeId names.
std::string help
Attribute help string.
Definition: type-id.h:82
virtual bool HasDefault() const
Extension of Item for strings.
Definition: command-line.h:446