src/core/model/command-line.h
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Thu, 18 Dec 2014 15:12:35 -0800
changeset 11131 6a448ac28669
parent 11093 5ae2ca8407fc
child 11140 35c2c969d0b2
permissions -rw-r--r--
[Doxygen] Various in src/core
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
 */
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    20
#ifndef COMMAND_LINE_H
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
    21
#define COMMAND_LINE_H
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    22
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
    23
#include <string>
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
    24
#include <sstream>
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    25
#include <list>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    26
7383
c5e131450339 remove ns3/ prefix which is un-needed now that all files are in same module.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    27
#include "callback.h"
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
    28
11093
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
    29
/**
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
    30
 * \file
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
    31
 * \ingroup commandline
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
    32
 * CommandLine class declaration.
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
    33
 */
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
    34
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    35
namespace ns3 {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    36
2584
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    37
/**
3190
51fe9001a679 add some doxygen, remove a couple of XXX
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2915
diff changeset
    38
 * \ingroup core
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    39
 * \defgroup commandline Command Line Parsing
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    40
 *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    41
 * A uniform way to specify program documentation,
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    42
 * allowed command line arguments and help strings,
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    43
 * and set any attribute or global value, all from
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    44
 * the command line directly.
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    45
 *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    46
 * The main entry point is CommandLine
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    47
 */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    48
/**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    49
 * \ingroup commandline
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    50
 * \brief Parse command-line arguments
2584
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    51
 *
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    52
 * Instances of this class can be used to parse command-line 
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    53
 * arguments.  Programs can register a general usage message with
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    54
 * CommandLine::Usage, and arguments with CommandLine::AddValue.
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    55
 * POD argument variables will be set directly; more general arguments
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    56
 * can be processed via a Callback.
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    57
 *
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    58
 * CommandLine also provides handlers for these standard arguments:
10860
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    59
 * \verbatim
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    60
   --PrintGlobals:              Print the list of globals.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    61
   --PrintGroups:               Print the list of groups.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    62
   --PrintGroup=[group]:        Print all TypeIds of group.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    63
   --PrintTypeIds:              Print all TypeIds.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    64
   --PrintAttributes=[typeid]:  Print all attributes of typeid.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    65
   --PrintHelp:                 Print this help message. \endverbatim
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    66
 * 
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    67
 * The more common \c --help is a synonym for \c --PrintHelp; an example
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    68
 * is given below.
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    69
 *
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    70
 * Finally, CommandLine processes Attribute and GlobalValue arguments.
10861
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
    71
 * Default values for chosen attributes can be set using a shorthand
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
    72
 * argument name.
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
    73
 *
9971
d31b6210afc8 [Doxygen] src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9917
diff changeset
    74
 * In use, arguments are given in the form
10860
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    75
 * \verbatim
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    76
   --arg=value --toggle \endverbatim
9971
d31b6210afc8 [Doxygen] src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9917
diff changeset
    77
 * Most arguments expect a value, as in the first form, \c --arg=value.
d31b6210afc8 [Doxygen] src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9917
diff changeset
    78
 * Toggles, corresponding to boolean arguments, can be given in any of
d31b6210afc8 [Doxygen] src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9917
diff changeset
    79
 * the forms
10860
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    80
 * \verbatim
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
    81
   --toggle1 --toggle2=1 --toggle3=t --toggle4=true \endverbatim
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    82
 * The first form changes the state of toggle1 from its default; 
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    83
 * all the rest set the corresponding boolean variable to true.
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    84
 * \c 0, \c f and \c false are accepted to set the variable to false.
9971
d31b6210afc8 [Doxygen] src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9917
diff changeset
    85
 *
10953
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    86
 * Arguments can be repeated on the command line; the last value given
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    87
 * will be the final value used.  For example,
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    88
 * \verbatim
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    89
   --arg=one --toggle=f --arg=another --toggle \endverbatim
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    90
 * The variable set by \c --arg will end up with the value \c "another";
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    91
 * the boolean set by \c --toggle will end up as \c true.
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    92
 *
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    93
 * Because arguments can be repeated it can be hard to decipher what
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    94
 * value each variable ended up with, especially when using boolean toggles.
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    95
 * Suggested best practice is for scripts to report the values of all items
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    96
 * settable throught CommandLine, as done by the example below.
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    97
 * 
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
    98
 *
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
    99
 * CommandLine can set the initial value of every attribute in the system
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   100
 * with the 
9971
d31b6210afc8 [Doxygen] src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9917
diff changeset
   101
 * \c --TypeIdName::AttributeName=value syntax, for example
10860
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   102
 * \verbatim
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   103
   --Application::StartTime=3s \endverbatim
10861
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   104
 * In some cases you may want to highlight the use of a particular
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   105
 * attribute for a simulation script.  For example, you might want
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   106
 * to make it easy to set the \c Application::StartTime using
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   107
 * the argument \c --start, and have its help string show as part
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   108
 * of the help message.  This can be done using the
11093
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   109
 * \link AddValue(const std::string&, const std::string&) AddValue (name, attributePath) \endlink
10953
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
   110
 * method.
9971
d31b6210afc8 [Doxygen] src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9917
diff changeset
   111
 *
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   112
 * CommandLine can also set the value of every GlobalValue
9971
d31b6210afc8 [Doxygen] src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9917
diff changeset
   113
 * in the system with the \c --GlobalValueName=value syntax, for example
10860
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   114
 * \verbatim
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   115
   --SchedulerType=HeapScheduler \endverbatim
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   116
 *
10953
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
   117
 * A simple example is in `src/core/example/``command-line-example.cc`
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   118
 * The heart of that example is this code:
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   119
 *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   120
 * \code
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   121
 *    int         intArg  = 1;
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   122
 *    bool        boolArg = false;
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   123
 *    std::string strArg  = "strArg default";
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   124
 *  
10860
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   125
 *    CommandLine cmd;
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   126
 *    cmd.Usage ("CommandLine example program.\n"
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   127
 *               "\n"
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   128
 *               "This little program demonstrates how to use CommandLine.");
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   129
 *    cmd.AddValue ("intArg",  "an int argument",       intArg);
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   130
 *    cmd.AddValue ("boolArg", "a bool argument",       boolArg);
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   131
 *    cmd.AddValue ("strArg",  "a string argument",     strArg);
10861
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   132
 *    cmd.AddValue ("anti",    "ns3::RandomVariableStream::Antithetic");
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   133
 *    cmd.AddValue ("cbArg",   "a string via callback", MakeCallback (SetCbArg));
10860
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   134
 *    cmd.Parse (argc, argv);
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   135
 * \endcode
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   136
 * after which it prints the values of each variable.  (The \c SetCbArg function
10953
6751a4094ffd Bug 1972: documentation to clarify the behavior with repeated argument
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10861
diff changeset
   137
 * is not shown here; see `src/core/example/``command-line-example.cc`)
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   138
 *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   139
 * Here is the output from a few runs of that program:
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   140
 *
10860
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   141
 * \verbatim
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   142
   $ ./waf --run="command-line-example"
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   143
   intArg:   1
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   144
   boolArg:  false
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   145
   strArg:   "strArg default"
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   146
   cbArg:    "cbArg default"
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   147
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   148
   $ ./waf --run="command-line-example --intArg=2 --boolArg --strArg=Hello --cbArg=World"
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   149
   intArg:   2
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   150
   boolArg:  true
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   151
   strArg:   "Hello"
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   152
   cbArg:    "World"
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   153
   
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   154
   $ ./waf --run="command-line-example --help"
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   155
   ns3-dev-command-line-example-debug [Program Arguments] [General Arguments]
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   156
   
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   157
   CommandLine example program.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   158
   
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   159
   This little program demonstrates how to use CommandLine.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   160
   
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   161
   Program Arguments:
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   162
       --intArg:   an int argument [1]
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   163
       --boolArg:  a bool argument [false]
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   164
       --strArg:   a string argument [strArg default]
10861
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   165
       --anti:     Set this RNG stream to generate antithetic values (ns3::RandomVariableStream::Antithetic) [false]
10860
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   166
       --cbArg:    a string via callback
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   167
   
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   168
   General Arguments:
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   169
       --PrintGlobals:              Print the list of globals.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   170
       --PrintGroups:               Print the list of groups.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   171
       --PrintGroup=[group]:        Print all TypeIds of group.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   172
       --PrintTypeIds:              Print all TypeIds.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   173
       --PrintAttributes=[typeid]:  Print all attributes of typeid.
02edc8b606e2 [doxygen] CommandLine formatting
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10654
diff changeset
   174
       --PrintHelp:                 Print this help message. \endverbatim
10621
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   175
 *
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   176
 * Having parsed the arguments, some programs will need to perform
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   177
 * some additional validation of the received values.  A common issue at this
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   178
 * point is to discover that the supplied arguments are incomplete or
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   179
 * incompatible.  Suggested best practice is to supply an error message
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   180
 * and the complete usage message.  For example,
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   181
 *
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   182
 * \code
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   183
 *   int value1;
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   184
 *   int value2;
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   185
 *   
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   186
 *   CommandLine cmd;
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   187
 *   cmd.Usage ("...");
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   188
 *   cmd.AddValue ("value1", "first value", value1);
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   189
 *   cmd.AddValue ("value2", "second value", value1);
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   190
 *
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   191
 *   cmd.Parse (argc, argv);
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   192
 *
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   193
 *   if (value1 * value2 < 0)
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   194
 *     {
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   195
 *       std::cerr << "value1 and value2 must have the same sign!" << std::endl;
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   196
 *       std::cerr << cmd;
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   197
 *       exit (-1);
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   198
 *     }
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   199
 * \endcode
2584
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   200
 */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   201
class CommandLine
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   202
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   203
public:
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   204
  /** Constructor */
5844
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   205
  CommandLine ();
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   206
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   207
   * Copy constructor
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   208
   *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   209
   * \param cmd the CommandLine to copy from
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   210
   */
5844
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   211
  CommandLine (const CommandLine &cmd);
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   212
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   213
   * Assignment
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   214
   *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   215
   * \param cmd the CommandLine to assign from
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   216
   * \return the CommandLine
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   217
   */
5844
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   218
  CommandLine &operator = (const CommandLine &cmd);
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   219
  /** Destructor */
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   220
  ~CommandLine ();
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   221
2584
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   222
  /**
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   223
   * Supply the program usage and documentation.
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   224
   *
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   225
   * \param usage Program usage message to write with \c --help.
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   226
   */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   227
  void Usage (const std::string usage);
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   228
  
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   229
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   230
   * Add a program argument, assigning to POD
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   231
   *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   232
   * \param name the name of the program-supplied argument
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   233
   * \param help the help text used by \c \-\-PrintHelp
2584
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   234
   * \param value a reference to the variable where the
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   235
   *        value parsed will be stored (if no value
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   236
   *        is parsed, this variable is not modified).
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   237
   */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   238
  template <typename T>
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   239
  void AddValue (const std::string &name,
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   240
                 const std::string &help,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   241
                 T &value);
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   242
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
   243
  /**
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   244
   * Add a program argument, using a Callback to parse the value
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   245
   *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   246
   * \param name the name of the program-supplied argument
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   247
   * \param help the help text used by \c --help
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   248
   * \param callback a Callback function that will be invoked to parse and
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   249
   *   store the value.
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   250
   *
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   251
   * The callback should have the signature
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   252
   * <tt>bool callback (const std::string value)</tt>
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
   253
   */
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
   254
  void AddValue (const std::string &name,
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   255
                 const std::string &help,
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
   256
                 Callback<bool, std::string> callback);
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
   257
2584
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   258
  /**
10861
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   259
   * Add a program argument as a shorthand for an Attribute.
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   260
   *
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   261
   * \param name the name of the program-supplied argument.
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   262
   * \param attributePath the fully-qualified name of the Attribute
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   263
   */
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   264
  void AddValue (const std::string &name,
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   265
                 const std::string &attributePath);
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   266
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   267
  /**
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   268
   * Parse the program arguments
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   269
   *
2584
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   270
   * \param argc the 'argc' variable: number of arguments (including the
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   271
   *        main program name as first element).
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   272
   * \param argv the 'argv' variable: a null-terminated array of strings,
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   273
   *        each of which identifies a command-line argument.
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   274
   * 
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   275
   * Obviously, this method will parse the input command-line arguments and
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   276
   * will attempt to handle them all.
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   277
   *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   278
   * As a side effect, this method saves the program basename, which
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   279
   * can be retrieved by GetName().
2584
5011c132ed6c doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   280
   */
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   281
  void Parse (int argc, char *argv[]);
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   282
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   283
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   284
   * Get the program name
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   285
   *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   286
   * \return the program name.  Only valid after calling Parse()
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   287
   */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   288
  std::string GetName () const;
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   289
10143
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   290
  /**
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   291
   * \brief Print program usage to the desired output stream
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   292
   *
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   293
   * Handler for \c \-\-PrintHelp and \c \-\-help:  print Usage(), argument names, and help strings
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   294
   *
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   295
   * Alternatively, an overloaded operator << can be used:
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   296
   * @code
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   297
   *       CommandLine cmd;
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   298
   *       cmd.Parse (argc, argv);
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   299
   *     ...
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   300
   *
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   301
   *       std::cerr << cmd;
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   302
   * @endcode
11093
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   303
   *
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   304
   * \param [in,out] os The output stream to print on.
10143
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   305
   */
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   306
  void PrintHelp (std::ostream &os) const;
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   307
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   308
private:
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   309
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   310
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   311
   * \ingroup commandline
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   312
   * \brief The argument base class
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   313
   */
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   314
  class Item 
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   315
  {
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   316
  public:
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   317
    std::string m_name;       /**< Argument label:  \c \-\--m_name=... */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   318
    std::string m_help;       /**< Argument help string */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   319
    virtual ~Item ();         /**< Destructor */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   320
    /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   321
     * Parse from a string.
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   322
     *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   323
     * \param value the string representation
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   324
     * \return true if parsing the value succeeded
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   325
     */
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   326
    virtual bool Parse (const std::string value) = 0;
9917
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   327
    /**
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   328
     * \return true if this item have a default value?
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   329
     */
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   330
    virtual bool HasDefault () const;
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   331
    /**
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   332
     * \return the default value
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   333
     */
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   334
    virtual std::string GetDefault () const;
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   335
  };
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   336
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   337
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   338
   * \ingroup commandline
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   339
   *\brief An argument Item assigning to POD
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   340
   */
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   341
  template <typename T>
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   342
  class UserItem : public Item
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   343
  {
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   344
  public:
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   345
    /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   346
     * Parse from a string.
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   347
     *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   348
     * \param value the string representation
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   349
     * \return true if parsing the value succeeded
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   350
     */
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   351
    virtual bool Parse (const std::string value);
9917
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   352
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   353
    bool HasDefault () const;
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   354
    std::string GetDefault () const;
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   355
      
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   356
    T *m_valuePtr;            /**< Pointer to the POD location */
9917
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   357
    std::string m_default;    /**< String representation of default value */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   358
  };
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   359
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   360
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   361
   * \ingroup commandline
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   362
   * \brief An argument Item using a Callback to parse the input
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   363
   */
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
   364
  class CallbackItem : public Item
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
   365
  {
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   366
  public:
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   367
    /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   368
     * Parse from a string.
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   369
     *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   370
     * \param value the string representation
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   371
     * \return true if parsing the value succeeded
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   372
     */
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   373
    virtual bool Parse (const std::string value);
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   374
    Callback<bool, std::string> m_callback;  /**< The Callback */
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
   375
  };
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3190
diff changeset
   376
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   377
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   378
   * Match name against the program or general arguments,
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   379
   * and dispatch to the appropriate handler.
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   380
   *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   381
   * \param name the argument name
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   382
   * \param value the command line value
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   383
   */
10143
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   384
  void HandleArgument (const std::string &name, const std::string &value) const;
10861
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   385
  /**
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   386
   * Callback function to handle attributes.
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   387
   *
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   388
   * \param name The full name of the Attribute.
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   389
   * \param value The value to assign to \p name.
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   390
   * \return true if the value was set successfully, false otherwise.
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   391
   */  
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   392
  static bool HandleAttribute (const std::string name, const std::string value);
40a485317b1d CommandLine Attribute shorthand
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10860
diff changeset
   393
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   394
  /** Handler for \c \-\-PrintGlobals:  print all global variables and values */
10143
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   395
  void PrintGlobals (std::ostream &os) const;
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   396
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   397
   * Handler for \c \-\-PrintAttributes:  print the attributes for a given type.
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   398
   *
10654
0148f9c47331 [doxygen] Make introspected lists more visible, various other doxy
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10621
diff changeset
   399
   * \param os the output stream.
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   400
   * \param type the TypeId whose Attributes should be displayed
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   401
   */
10143
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   402
  void PrintAttributes (std::ostream &os, const std::string &type) const;
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   403
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   404
   * Handler for \c \-\-PrintGroup:  print all types belonging to a given group.
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   405
   *
10654
0148f9c47331 [doxygen] Make introspected lists more visible, various other doxy
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10621
diff changeset
   406
   * \param os the output stream.
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   407
   * \param group the name of the TypeId group to display
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   408
   */
10143
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   409
  void PrintGroup (std::ostream &os, const std::string &group) const;
11093
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   410
  /**
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   411
   * Handler for \c \-\-PrintTypeIds:  print all TypeId names.
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   412
   *
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   413
   * \param os the output stream.
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   414
   */
10143
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   415
  void PrintTypeIds (std::ostream &os) const;
11093
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   416
  /**
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   417
   * Handler for \c \-\-PrintGroups:  print all TypeId group names
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   418
   *
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   419
   * \param os the output stream.
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   420
   */
10143
48f66512ec9b [PATCH] core: Extending public interface of CommandLine class
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9971
diff changeset
   421
  void PrintGroups (std::ostream &os) const;
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   422
  /**
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   423
   * Copy constructor
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   424
   *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   425
   * \param cmd CommandLine to copy
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   426
   */
5844
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   427
  void Copy (const CommandLine &cmd);
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   428
  /** Remove all arguments, Usage(), name */
5844
0dd442f011c7 add copy constructors and assignment operators to avoid leaks.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3929
diff changeset
   429
  void Clear (void);
1703
3f808ee49c2f Fix CommandLine::AddArgCommand memory leak.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1702
diff changeset
   430
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   431
  typedef std::list<Item *> Items;      /**< Argument list container */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   432
  Items m_items;                        /**< The list of arguments */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   433
  std::string m_usage;                  /**< The Usage string */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   434
  std::string m_name;                   /**< The program name */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   435
};  // class CommandLine
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   436
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   437
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   438
/** \ingroup commandline
11131
6a448ac28669 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11093
diff changeset
   439
 *  \defgroup commandlinehelper Helpers to Specialize on \c bool
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   440
 */
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   441
/**
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   442
 * \ingroup commandlinehelper
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   443
 * \brief Helpers for CommandLine to specialize on bool
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   444
 */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   445
namespace CommandLineHelper {
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   446
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   447
  /**
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   448
   * \ingroup commandlinehelper
11131
6a448ac28669 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11093
diff changeset
   449
   * \brief Helpers to specialize CommandLine::UserItem::Parse() on bool
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   450
   *
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   451
   * \param value the argument name
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   452
   * \param val the argument location
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   453
   * \return true if parsing was successful
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   454
   * @{
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   455
   */
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   456
  template <typename T>
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   457
  bool UserItemParse (const std::string value, T & val);
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   458
  template <>
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   459
  bool UserItemParse<bool> (const std::string value, bool & val);
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   460
  /**@}*/
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   461
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   462
  /**
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   463
   * \ingroup commandlinehelper
11131
6a448ac28669 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11093
diff changeset
   464
   * \brief Helper to specialize CommandLine::UserItem::GetDefault() on bool
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   465
   *
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   466
   * \param val the argument value
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   467
   * \return the string representation of value
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   468
   * @{
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   469
   */
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   470
  template <typename T>
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   471
  std::string GetDefault (const T & val);
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   472
  template <>
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   473
  std::string GetDefault<bool> (const bool & val);
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   474
  /**@}*/
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   475
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   476
}  // namespace CommandLineHelper
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   477
    
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   478
  
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   479
  
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   480
} // namespace ns3
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   481
11093
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   482
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   483
/********************************************************************
11131
6a448ac28669 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11093
diff changeset
   484
 *  Implementation of the templates declared above.
11093
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   485
 ********************************************************************/
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   486
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   487
namespace ns3 {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   488
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   489
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   490
void 
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   491
CommandLine::AddValue (const std::string &name,
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   492
                       const std::string &help,
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   493
                       T &value)
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   494
{
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   495
  UserItem<T> *item = new UserItem<T> ();
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   496
  item->m_name = name;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   497
  item->m_help = help;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   498
  item->m_valuePtr = &value;
9917
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   499
  
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   500
  std::stringstream ss;
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   501
  ss << value;
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   502
  ss >> item->m_default;
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   503
    
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   504
  m_items.push_back (item);
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   505
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   506
9917
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   507
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   508
template <typename T>
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   509
bool
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   510
CommandLine::UserItem<T>::HasDefault () const
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   511
{
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   512
  return true;
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   513
}
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   514
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   515
template <typename T>
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   516
std::string
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   517
CommandLine::UserItem<T>::GetDefault () const
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   518
{
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   519
  return CommandLineHelper::GetDefault<T> (*m_valuePtr);
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   520
}
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   521
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   522
template <typename T>
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   523
std::string
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   524
CommandLineHelper::GetDefault (const T & val)
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   525
{
9917
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   526
  std::ostringstream oss;
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   527
  oss << val;
9917
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   528
  return oss.str ();
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   529
}
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   530
b61b15f922a2 CommandLine callback example, show user defaults, code cleanup
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9830
diff changeset
   531
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   532
template <typename T>
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   533
bool
10154
5f6bab1bf0f4 Make CommandLine print boolean defaults as text.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10143
diff changeset
   534
CommandLine::UserItem<T>::Parse (const std::string value)
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   535
{
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   536
  return CommandLineHelper::UserItemParse<T> (value, *m_valuePtr);
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   537
}
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   538
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   539
template <typename T>
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   540
bool
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   541
CommandLineHelper::UserItemParse (const std::string value, T & val)
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   542
{
441
d824620eac38 Added default value sample
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   543
  std::istringstream iss;
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   544
  iss.str (value);
9829
0828b3ad8057 CommandLine: add Usage message, simplify bool args
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7600
diff changeset
   545
  iss >> val;
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   546
  return !iss.bad () && !iss.fail ();
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   547
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   548
10621
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   549
/**
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   550
 * Overloaded operator << to print program usage
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   551
 * (shortcut for CommandLine::PrintHelper)
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   552
 *
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   553
 * \see CommandLine::PrintHelper
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   554
 *
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   555
 * Example usage:
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   556
 * \code
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   557
 *    CommandLine cmd;
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   558
 *    cmd.Parse (argc, argv);
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   559
 *    ...
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   560
 *    
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   561
 *    std::cerr << cmd;
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   562
 * \endcode
11093
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   563
 *
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   564
 * \param [in,out] os The stream to print on.
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   565
 * \param [in] cmd The CommandLine describing the program.
5ae2ca8407fc [Doxygen] CommandLine
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10953
diff changeset
   566
 * \returns The stream.
10621
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   567
 */
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   568
std::ostream & operator << (std::ostream & os, const CommandLine & cmd);
c23778df1349 [Bug 1653] Extension of CommandLine interface
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10154
diff changeset
   569
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1703
diff changeset
   570
} // namespace ns3
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   571
2581
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2575
diff changeset
   572
#endif /* COMMAND_LINE_H */