A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
system-path-examples.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Lawrence Livermore National Laboratory
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
18
*/
19
20
#include "ns3/core-module.h"
21
22
#include <iomanip>
23
#include <iostream>
24
#include <string>
25
33
using namespace
ns3
;
34
using namespace
ns3::SystemPath
;
35
36
int
37
main(
int
argc,
char
* argv[])
38
{
39
std::string path =
"/usr/share/dict/"
;
40
41
CommandLine
cmd
;
42
cmd
.Usage(
"SystemPath examples.\n"
);
43
44
cmd
.AddValue(
"path"
,
"Path to demonstrate SystemPath functions."
, path);
45
cmd
.Parse(argc, argv);
46
47
// Show initial values:
48
std::cout << std::endl;
49
std::cout <<
cmd
.GetName() <<
":"
<< std::endl;
50
51
std::cout <<
"FindSelfDirectory: "
<<
FindSelfDirectory
() << std::endl;
52
53
std::cout <<
"Demonstration path: "
<< path << std::endl;
54
std::cout <<
"Exists? "
<< (
Exists
(path) ?
"yes"
:
"no"
) << std::endl;
55
56
auto
foo =
Append
(path,
"foo"
);
57
std::cout <<
"Append 'foo': "
<< foo << std::endl;
58
std::cout <<
"Exists? "
<< (
Exists
(foo) ?
"yes"
:
"no"
) << std::endl;
59
60
std::cout <<
"Split path:\n"
;
61
auto
items =
Split
(path);
62
for
(
const
auto
& item : items)
63
{
64
std::cout <<
" '"
<< item <<
"'\n"
;
65
}
66
std::cout << std::endl;
67
68
std::cout <<
"Successive Joins: \n"
;
69
for
(
auto
it = items.begin(); it != items.end(); ++it)
70
{
71
auto
partial =
Join
(items.begin(), it);
72
std::cout <<
" '"
<< partial <<
"'\n"
;
73
}
74
75
std::cout <<
"Files in the directory: \n"
;
76
auto
files =
ReadFiles
(path);
77
for
(
const
auto
& item : files)
78
{
79
std::cout <<
" '"
<< item <<
"'\n"
;
80
}
81
82
return
0;
83
}
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:232
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:291
ns3::SystemPath::Exists
bool Exists(const std::string path)
Check if a path exists.
Definition:
system-path.cc:367
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:258
ns3::SystemPath::Append
std::string Append(std::string left, std::string right)
Join two file system path elements.
Definition:
system-path.cc:240
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:267
ns3::SystemPath::FindSelfDirectory
std::string FindSelfDirectory()
Get the file system path to the current executable.
Definition:
system-path.cc:150
ns3::SystemPath
Namespace for various file and directory path functions.
Definition:
system-path.cc:127
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition:
second.py:40
src
core
examples
system-path-examples.cc
Generated on Sun Mar 3 2024 17:10:55 for ns-3 by
1.9.1