src/core/model/command-line.cc
author Vedran Miletić <rivanvx@gmail.com>
Sat, 01 Sep 2012 20:57:21 +0200
changeset 9063 32755d0516f4
parent 7393 8c3dfe0be54d
child 9134 7a750f032acd
permissions -rw-r--r--
Bug 1237 - code cleanups related to includes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2581
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
     2
/*
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
     3
 * Copyright (c) 2008 INRIA
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
     4
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
     7
 * published by the Free Software Foundation;
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
     8
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    12
 * GNU General Public License for more details.
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    13
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    14
 * You should have received a copy of the GNU General Public License
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    15
 * along with this program; if not, write to the Free Software
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    17
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    18
 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    19
 */
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
    20
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
    21
#include <cstdlib> // for exit
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
    22
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    23
#include "command-line.h"
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    24
#include "log.h"
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    25
#include "config.h"
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    26
#include "global-value.h"
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
    27
#include "type-id.h"
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    28
#include "string.h"
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
    29
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    30
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    31
NS_LOG_COMPONENT_DEFINE ("CommandLine");
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    32
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    33
namespace ns3 {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    34
5844
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    35
CommandLine::CommandLine ()
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    36
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    37
}
5844
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    38
CommandLine::CommandLine (const CommandLine &cmd)
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    39
{
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    40
  Copy (cmd);
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    41
}
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    42
CommandLine &
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    43
CommandLine::operator = (const CommandLine &cmd)
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    44
{
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    45
  Clear ();
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    46
  Copy (cmd);
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    47
  return *this;
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    48
}
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    49
CommandLine::~CommandLine ()
1703
3f808ee49c2f Fix CommandLine::AddArgCommand memory leak.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1702
diff changeset
    50
{
5844
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    51
  Clear ();
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    52
}
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    53
void
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    54
CommandLine::Copy (const CommandLine &cmd)
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    55
{
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    56
  for (Items::const_iterator i = cmd.m_items.begin (); 
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    57
       i != cmd.m_items.end (); ++i)
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    58
    {
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    59
      m_items.push_back (*i);
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    60
    }
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    61
}
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    62
void
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    63
CommandLine::Clear (void)
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5255
diff changeset
    64
{
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    65
  for (Items::const_iterator i = m_items.begin (); i != m_items.end (); ++i)
1703
3f808ee49c2f Fix CommandLine::AddArgCommand memory leak.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1702
diff changeset
    66
    {
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    67
      delete *i;
1703
3f808ee49c2f Fix CommandLine::AddArgCommand memory leak.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1702
diff changeset
    68
    }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    69
  m_items.clear ();
1703
3f808ee49c2f Fix CommandLine::AddArgCommand memory leak.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1702
diff changeset
    70
}
3f808ee49c2f Fix CommandLine::AddArgCommand memory leak.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1702
diff changeset
    71
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    72
CommandLine::Item::~Item ()
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    73
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    74
}
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    75
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    76
void
2915
3573d91994cc bug 150: CommandLine::Parse argc parameter should not be a reference
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
    77
CommandLine::Parse (int iargc, char *argv[]) const
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    78
{
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    79
  int argc = iargc;
1533
1e8249c58fda Fix infinite loop in CommandLine::Parse when trying to ignore a badly formed parameter.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 599
diff changeset
    80
  for (argc--, argv++; argc > 0; argc--, argv++)
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    81
    {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    82
      // remove "--" or "-" heading.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    83
      std::string param = *argv;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    84
      std::string::size_type cur = param.find ("--");
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    85
      if (cur == 0)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    86
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    87
          param = param.substr (2, param.size () - 2);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    88
        }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
    89
      else
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    90
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    91
          cur = param.find ("-");
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    92
          if (cur == 0)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    93
            {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    94
              param = param.substr (1, param.size () - 1);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    95
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    96
          else
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    97
            {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    98
              // invalid argument. ignore.
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    99
              continue;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   100
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   101
        }
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   102
      cur = param.find ("=");
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   103
      std::string name, value;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   104
      if (cur == std::string::npos)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   105
        {
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   106
          name = param;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   107
          value = "";
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   108
        }
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   109
      else
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   110
        {
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   111
          name = param.substr (0, cur);
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   112
          value = param.substr (cur + 1, param.size () - (cur+1));
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   113
        }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   114
      HandleArgument (name, value);
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   115
    }
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   116
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   117
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   118
void
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   119
CommandLine::PrintHelp (void) const
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   120
{
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   121
  std::cout << "--PrintHelp: Print this help message." << std::endl;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   122
  std::cout << "--PrintGroups: Print the list of groups." << std::endl;
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   123
  std::cout << "--PrintTypeIds: Print all TypeIds." << std::endl;
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   124
  std::cout << "--PrintGroup=[group]: Print all TypeIds of group." << std::endl;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   125
  std::cout << "--PrintAttributes=[typeid]: Print all attributes of typeid." << std::endl;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   126
  std::cout << "--PrintGlobals: Print the list of globals." << std::endl;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   127
  if (!m_items.empty ())
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   128
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   129
      std::cout << "User Arguments:" << std::endl;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   130
      for (Items::const_iterator i = m_items.begin (); i != m_items.end (); ++i)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   131
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   132
          std::cout << "    --" << (*i)->m_name << ": " << (*i)->m_help << std::endl;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   133
        }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   134
    }
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   135
}
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   136
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   137
void
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   138
CommandLine::PrintGlobals (void) const
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   139
{
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   140
  for (GlobalValue::Iterator i = GlobalValue::Begin (); i != GlobalValue::End (); ++i)
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   141
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   142
      std::cout << "    --" << (*i)->GetName () << "=[";
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   143
      Ptr<const AttributeChecker> checker = (*i)->GetChecker ();
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   144
      StringValue v;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   145
      (*i)->GetValue (v);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   146
      std::cout << v.Get () << "]:  "
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   147
                << (*i)->GetHelp () << std::endl;
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   148
    }
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   149
}
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   150
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   151
void
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   152
CommandLine::PrintAttributes (std::string type) const
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   153
{
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   154
  TypeId tid;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   155
  if (!TypeId::LookupByNameFailSafe (type, &tid))
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   156
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   157
      NS_FATAL_ERROR ("Unknown type="<<type<<" in --PrintAttributes");
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   158
    }
2693
56e28e34e109 TypeId::GetAttributeListN -> TypeId::GetAttributeN
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2629
diff changeset
   159
  for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   160
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   161
      std::cout << "    --"<<tid.GetAttributeFullName (i)<<"=[";
7393
8c3dfe0be54d use new API. kill old one.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   162
      struct TypeId::AttributeInformation info = tid.GetAttribute (i);
8c3dfe0be54d use new API. kill old one.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   163
      std::cout << info.initialValue->SerializeToString (info.checker) << "]:  "
8c3dfe0be54d use new API. kill old one.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   164
                << info.help << std::endl;
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   165
    }
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   166
}
1702
0fbe74581141 Bug 81 (CommandLine::AddArgValue not working correctly)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1533
diff changeset
   167
0fbe74581141 Bug 81 (CommandLine::AddArgValue not working correctly)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1533
diff changeset
   168
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   169
void
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   170
CommandLine::PrintGroup (std::string group) const
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   171
{
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   172
  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i)
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   173
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   174
      TypeId tid = TypeId::GetRegistered (i);
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   175
      if (tid.GetGroupName () == group)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   176
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   177
          std::cout << "    --PrintAttributes=" <<tid.GetName ()<<std::endl;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   178
        }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   179
    }
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   180
}
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   181
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   182
void
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   183
CommandLine::PrintTypeIds (void) const
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   184
{
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   185
  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i)
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   186
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   187
      TypeId tid = TypeId::GetRegistered (i);
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   188
      std::cout << "    --PrintAttributes=" <<tid.GetName ()<<std::endl;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   189
    }
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   190
}
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   191
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   192
void
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   193
CommandLine::PrintGroups (void) const
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   194
{
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   195
  std::list<std::string> groups;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   196
  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i)
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   197
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   198
      TypeId tid = TypeId::GetRegistered (i);
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   199
      std::string group = tid.GetGroupName ();
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   200
      if (group == "")
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   201
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   202
          continue;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   203
        }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   204
      bool found = false;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   205
      for (std::list<std::string>::const_iterator j = groups.begin (); j != groups.end (); ++j)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   206
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   207
          if (*j == group)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   208
            {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   209
              found = true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   210
              break;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   211
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   212
        }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   213
      if (!found)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   214
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   215
          groups.push_back (group);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   216
        }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   217
    }
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   218
  for (std::list<std::string>::const_iterator k = groups.begin (); k != groups.end (); ++k)
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   219
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   220
      std::cout << "    --PrintGroup="<<*k<<std::endl;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   221
    }
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   222
}
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   223
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   224
void
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   225
CommandLine::HandleArgument (std::string name, std::string value) const
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   226
{
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   227
  NS_LOG_DEBUG ("Handle arg name="<<name<<" value="<<value);
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   228
  if (name == "PrintHelp")
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   229
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   230
      // method below never returns.
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   231
      PrintHelp ();
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
   232
      std::exit (0);
4490
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   233
    } 
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   234
  else if (name == "PrintGroups")
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   235
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   236
      // method below never returns.
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   237
      PrintGroups ();
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
   238
      std::exit (0);
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   239
    }
4490
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   240
  else if (name == "PrintTypeIds")
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   241
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   242
      // method below never returns.
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   243
      PrintTypeIds ();
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
   244
      std::exit (0);
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   245
    }
4490
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   246
  else if (name == "PrintGlobals")
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   247
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   248
      // method below never returns.
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   249
      PrintGlobals ();
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
   250
      std::exit (0);
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   251
    }
4490
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   252
  else if (name == "PrintGroup")
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   253
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   254
      // method below never returns.
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   255
      PrintGroup (value);
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
   256
      std::exit (0);
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   257
    }
4490
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   258
  else if (name == "PrintAttributes")
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   259
    {
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   260
      // method below never returns.
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   261
      PrintAttributes (value);
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
   262
      std::exit (0);
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   263
    }
4490
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   264
  else
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   265
    {
4490
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   266
      for (Items::const_iterator i = m_items.begin (); i != m_items.end (); ++i)
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   267
        {
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   268
          if ((*i)->m_name == name)
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   269
            {
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   270
              if (!(*i)->Parse (value))
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   271
                {
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   272
                  std::cerr << "Invalid argument value: "<<name<<"="<<value << std::endl;
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
   273
                  std::exit (1);
4490
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   274
                }
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   275
              else
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   276
                {
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   277
                  return;
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   278
                }
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   279
            }
6aa43c812fec bug 561: CommandLine based programs should exit with non-zero return if bad parameters are given
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   280
        }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   281
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   282
  if (!Config::SetGlobalFailSafe (name, StringValue (value))
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   283
      && !Config::SetDefaultFailSafe (name, StringValue (value)))
2629
085df3e28a28 Fix parsing of GlobalValues as command line options.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2612
diff changeset
   284
    {
085df3e28a28 Fix parsing of GlobalValues as command line options.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2612
diff changeset
   285
      std::cerr << "Invalid command-line arguments: --"<<name<<"="<<value<<std::endl;
085df3e28a28 Fix parsing of GlobalValues as command line options.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2612
diff changeset
   286
      PrintHelp ();
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7393
diff changeset
   287
      std::exit (1);
2629
085df3e28a28 Fix parsing of GlobalValues as command line options.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2612
diff changeset
   288
    }
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   289
}
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2195
diff changeset
   290
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   291
bool
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   292
CommandLine::CallbackItem::Parse (std::string value)
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   293
{
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   294
  NS_LOG_DEBUG ("CommandLine::CallbackItem::Parse \"" << value << "\"");
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   295
  return m_callback (value);
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   296
}
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   297
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   298
void
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   299
CommandLine::AddValue (const std::string &name,
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   300
                       const std::string &help,
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   301
                       Callback<bool, std::string> callback)
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   302
{
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   303
  NS_LOG_FUNCTION (this << name << help << "callback");
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   304
  CallbackItem *item = new CallbackItem ();
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   305
  item->m_name = name;
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   306
  item->m_help = help;
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   307
  item->m_callback = callback;
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   308
  m_items.push_back (item);
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   309
}
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2972
diff changeset
   310
5246
0974f3a8f379 Remove and replace CommandLine BVT (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4490
diff changeset
   311
} // namespace ns3