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