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.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#ifndef COMMAND_LINE_H
21
#define COMMAND_LINE_H
22
23
#include <string>
24
#include <sstream>
25
#include <list>
26
27
#include "
callback.h
"
28
29
namespace
ns3 {
30
152
class
CommandLine
153
{
154
public
:
156
CommandLine
();
162
CommandLine
(
const
CommandLine
&cmd);
169
CommandLine
&
operator =
(
const
CommandLine
&cmd);
171
~CommandLine
();
172
178
void
Usage
(
const
std::string usage);
179
189
template
<
typename
T>
190
void
AddValue
(
const
std::string &name,
191
const
std::string &help,
192
T &value);
193
194
206
void
AddValue
(
const
std::string &name,
207
const
std::string &help,
208
Callback<bool, std::string>
callback);
209
224
void
Parse
(
int
argc,
char
*argv[]);
225
231
std::string
GetName
()
const
;
232
247
void
PrintHelp
(std::ostream &os)
const
;
248
249
private
:
250
255
class
Item
256
{
257
public
:
258
std::string
m_name
;
259
std::string
m_help
;
260
virtual
~Item
();
267
virtual
bool
Parse
(
const
std::string value) = 0;
271
virtual
bool
HasDefault
()
const
;
275
virtual
std::string
GetDefault
()
const
;
276
};
277
282
template
<
typename
T>
283
class
UserItem
:
public
Item
284
{
285
public
:
292
virtual
bool
Parse
(
const
std::string value);
293
294
bool
HasDefault
()
const
;
295
std::string
GetDefault
()
const
;
296
297
T *
m_valuePtr
;
298
std::string
m_default
;
299
};
300
305
class
CallbackItem
:
public
Item
306
{
307
public
:
314
virtual
bool
Parse
(
const
std::string value);
315
Callback<bool, std::string>
m_callback
;
316
};
317
325
void
HandleArgument
(
const
std::string &name,
const
std::string &value)
const
;
327
void
PrintGlobals
(std::ostream &os)
const
;
333
void
PrintAttributes
(std::ostream &os,
const
std::string &type)
const
;
339
void
PrintGroup
(std::ostream &os,
const
std::string &
group
)
const
;
341
void
PrintTypeIds
(std::ostream &os)
const
;
343
void
PrintGroups
(std::ostream &os)
const
;
349
void
Copy
(
const
CommandLine
&cmd);
351
void
Clear
(
void
);
352
353
typedef
std::list<Item *>
Items
;
354
Items
m_items
;
355
std::string
m_usage
;
356
std::string
m_name
;
357
};
// class CommandLine
358
359
367
namespace
CommandLineHelper {
368
378
template
<
typename
T>
379
bool
UserItemParse
(
const
std::string value, T & val);
380
template
<>
381
bool
UserItemParse<bool>
(
const
std::string value,
bool
& val);
392
template
<
typename
T>
393
std::string
GetDefault
(
const
T & val);
394
template
<>
395
std::string
GetDefault<bool>
(
const
bool
& val);
398
}
// namespace CommandLineHelper
399
400
401
402
}
// namespace ns3
403
404
namespace
ns3 {
405
406
template
<
typename
T>
407
void
408
CommandLine::AddValue
(
const
std::string &name,
409
const
std::string &help,
410
T &value)
411
{
412
UserItem<T>
*item =
new
UserItem<T>
();
413
item->
m_name
= name;
414
item->
m_help
= help;
415
item->
m_valuePtr
= &value;
416
417
std::stringstream ss;
418
ss << value;
419
ss >> item->
m_default
;
420
421
m_items
.push_back (item);
422
}
423
424
425
template
<
typename
T>
426
bool
427
CommandLine::UserItem<T>::HasDefault
()
const
428
{
429
return
true
;
430
}
431
432
template
<
typename
T>
433
std::string
434
CommandLine::UserItem<T>::GetDefault
()
const
435
{
436
return
CommandLineHelper::GetDefault<T> (*m_valuePtr);
437
}
438
439
template
<
typename
T>
440
std::string
441
CommandLineHelper::GetDefault
(
const
T & val)
442
{
443
std::ostringstream oss;
444
oss << val;
445
return
oss.str ();
446
}
447
448
449
template
<
typename
T>
450
bool
451
CommandLine::UserItem<T>::Parse
(
const
std::string value)
452
{
453
return
CommandLineHelper::UserItemParse<T> (value, *m_valuePtr);
454
}
455
456
template
<
typename
T>
457
bool
458
CommandLineHelper::UserItemParse
(
const
std::string value, T & val)
459
{
460
std::istringstream iss;
461
iss.str (value);
462
iss >> val;
463
return
!iss.bad () && !iss.fail ();
464
}
465
466
}
// namespace ns3
467
468
#endif
/* COMMAND_LINE_H */
src
core
model
command-line.h
Generated on Fri Aug 30 2013 01:42:46 for ns-3 by
1.8.1.2