A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
system-path-examples.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Lawrence Livermore National Laboratory
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
7
*/
8
9
#include "ns3/command-line.h"
10
#include "ns3/system-path.h"
11
12
#include <iostream>
13
#include <string>
14
15
/**
16
* @file
17
* @ingroup core-examples
18
* @ingroup systempath
19
* Example program illustrating use of ns3::SystemPath
20
*/
21
22
using namespace
ns3
;
23
using namespace
ns3::SystemPath
;
24
25
int
26
main(
int
argc,
char
* argv[])
27
{
28
std::string path =
FindSelfDirectory
();
29
30
CommandLine
cmd
(__FILE__);
31
cmd
.Usage(
"SystemPath examples.\n"
);
32
33
cmd
.AddValue(
"path"
,
"Path to demonstrate SystemPath functions."
, path);
34
cmd
.Parse(argc, argv);
35
36
// Print system path information
37
std::cout <<
"Example name : "
<<
cmd
.GetName() <<
"\n"
;
38
std::cout <<
"FindSelf : "
<<
FindSelf
() <<
"\n"
;
39
std::cout <<
"FindSelfDirectory : "
<<
FindSelfDirectory
() <<
"\n"
;
40
std::cout <<
"Temporary directory name : "
<<
MakeTemporaryDirectoryName
() <<
"\n"
;
41
std::cout <<
"\n"
;
42
43
std::cout <<
"Path : "
<< path <<
"\n"
;
44
std::cout <<
"Exists : "
<< std::boolalpha <<
Exists
(path) <<
"\n"
;
45
std::cout <<
"Valid system path : "
<<
CreateValidSystemPath
(path) <<
"\n"
;
46
std::cout <<
"\n"
;
47
48
auto
pathFoo =
Append
(path,
"foo"
);
49
std::cout <<
"Append 'foo' to path : "
<< pathFoo <<
"\n"
;
50
std::cout <<
"Exists : "
<< std::boolalpha <<
Exists
(pathFoo) <<
"\n"
;
51
std::cout <<
"\n"
;
52
53
std::cout <<
"Split path:\n"
;
54
auto
items =
Split
(path);
55
for
(
const
auto
& item : items)
56
{
57
std::cout <<
" '"
<< item <<
"'\n"
;
58
}
59
std::cout <<
"\n"
;
60
61
std::cout <<
"Successive joins of the split path:\n"
;
62
for
(
auto
it = items.begin(); it != items.end(); ++it)
63
{
64
auto
partial =
Join
(items.begin(), it);
65
std::cout <<
" '"
<< partial <<
"'\n"
;
66
}
67
std::cout <<
"\n"
;
68
69
std::cout <<
"Files in the path directory:\n"
;
70
auto
files =
ReadFiles
(path);
71
for
(
const
auto
& item : files)
72
{
73
std::cout <<
" '"
<< item <<
"'\n"
;
74
}
75
76
return
0;
77
}
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::SystemPath::ReadFiles
std::list< std::string > ReadFiles(std::string path)
Get the list of files located in a file system directory.
Definition
system-path.cc:266
ns3::SystemPath::Exists
bool Exists(const std::string path)
Check if a path exists.
Definition
system-path.cc:342
ns3::SystemPath::Split
std::list< std::string > Split(std::string path)
Split a file system path into directories according to the local path separator.
Definition
system-path.cc:233
ns3::SystemPath::FindSelf
std::string FindSelf()
Get the file system path to the current executable.
Definition
system-path.cc:119
ns3::SystemPath::MakeTemporaryDirectoryName
std::string MakeTemporaryDirectoryName()
Get the name of a temporary directory.
Definition
system-path.cc:280
ns3::SystemPath::Append
std::string Append(std::string left, std::string right)
Join two file system path elements.
Definition
system-path.cc:215
ns3::SystemPath::Join
std::string Join(std::list< std::string >::const_iterator begin, std::list< std::string >::const_iterator end)
Join a list of file system path directories into a single file system path.
Definition
system-path.cc:242
ns3::SystemPath::CreateValidSystemPath
std::string CreateValidSystemPath(const std::string path)
Replace incompatible characters in a path, to get a path compatible with different file systems.
Definition
system-path.cc:386
ns3::SystemPath::FindSelfDirectory
std::string FindSelfDirectory()
Get the file system path to the current executable.
Definition
system-path.cc:209
ns3::SystemPath
Namespace for various file and directory path functions.
Definition
system-path.cc:96
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition
second.py:29
src
core
examples
system-path-examples.cc
Generated on
for ns-3 by
1.15.0