A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
command-line-example.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013 Lawrence Livermore National Laboratory
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
19
*/
20
21
#include <iostream>
22
#include <iomanip>
23
#include <string>
24
25
#include "ns3/core-module.h"
26
27
28
using namespace
ns3;
29
30
31
std::string
g_cbArg
=
"cbArg default"
;
32
33
bool
SetCbArg
(std::string val)
34
{
35
g_cbArg
= val;
36
return
true
;
37
}
38
39
40
int
main
(
int
argc,
char
*argv[])
41
{
42
43
int
intArg = 1;
44
bool
boolArg =
false
;
45
std::string strArg =
"strArg default"
;
46
47
CommandLine
cmd;
48
cmd.
Usage
(
"CommandLine example program.\n"
49
"\n"
50
"This little program demonstrates how to use CommandLine."
);
51
cmd.
AddValue
(
"intArg"
,
"an int argument"
, intArg);
52
cmd.
AddValue
(
"boolArg"
,
"a bool argument"
, boolArg);
53
cmd.
AddValue
(
"strArg"
,
"a string argument"
, strArg);
54
cmd.
AddValue
(
"cbArg"
,
"a string via callback"
,
MakeCallback
(
SetCbArg
));
55
cmd.
Parse
(argc, argv);
56
57
std::cout << std::left
58
<< std::setw (10) <<
"intArg:"
<< intArg << std::endl;
59
std::cout << std::setw (10) <<
"boolArg:"
60
<< std::boolalpha << boolArg
61
<< std::noboolalpha << std::endl;
62
63
std::cout << std::setw (10) <<
"strArg:"
<<
"\""
<< strArg <<
"\""
<< std::endl;
64
std::cout << std::setw (10) <<
"cbArg:"
<<
"\""
<<
g_cbArg
<<
"\""
<< std::endl;
65
66
return
0;
67
}
main
int main(int argc, char *argv[])
Definition:
command-line-example.cc:40
ns3::CommandLine::Usage
void Usage(const std::string usage)
Supply the program usage and documentation.
Definition:
command-line.cc:87
ns3::MakeCallback
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition:
callback.h:1238
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:152
SetCbArg
bool SetCbArg(std::string val)
Definition:
command-line-example.cc:33
ns3::CommandLine::AddValue
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition:
command-line.h:408
ns3::CommandLine::Parse
void Parse(int argc, char *argv[])
Parse the program arguments.
Definition:
command-line.cc:104
g_cbArg
std::string g_cbArg
Definition:
command-line-example.cc:31
src
core
examples
command-line-example.cc
Generated on Sat Apr 19 2014 14:06:51 for ns-3 by
1.8.6