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/core-module.h"
10
11
#include <iomanip>
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 =
"/usr/share/dict/"
;
29
30
CommandLine
cmd
;
31
cmd
.Usage(
"SystemPath examples.\n"
);
32
33
cmd
.AddValue(
"path"
,
"Path to demonstrate SystemPath functions."
, path);
34
cmd
.Parse(argc, argv);
35
36
// Show initial values:
37
std::cout << std::endl;
38
std::cout <<
cmd
.GetName() <<
":"
<< std::endl;
39
40
std::cout <<
"FindSelfDirectory: "
<<
FindSelfDirectory
() << std::endl;
41
42
std::cout <<
"Demonstration path: "
<< path << std::endl;
43
std::cout <<
"Exists? "
<< (
Exists
(path) ?
"yes"
:
"no"
) << std::endl;
44
45
auto
foo =
Append
(path,
"foo"
);
46
std::cout <<
"Append 'foo': "
<< foo << std::endl;
47
std::cout <<
"Exists? "
<< (
Exists
(foo) ?
"yes"
:
"no"
) << std::endl;
48
49
std::cout <<
"Split path:\n"
;
50
auto
items =
Split
(path);
51
for
(
const
auto
& item : items)
52
{
53
std::cout <<
" '"
<< item <<
"'\n"
;
54
}
55
std::cout << std::endl;
56
57
std::cout <<
"Successive Joins: \n"
;
58
for
(
auto
it = items.begin(); it != items.end(); ++it)
59
{
60
auto
partial =
Join
(items.begin(), it);
61
std::cout <<
" '"
<< partial <<
"'\n"
;
62
}
63
64
std::cout <<
"Files in the directory: \n"
;
65
auto
files =
ReadFiles
(path);
66
for
(
const
auto
& item : files)
67
{
68
std::cout <<
" '"
<< item <<
"'\n"
;
69
}
70
71
return
0;
72
}
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:260
ns3::SystemPath::Exists
bool Exists(const std::string path)
Check if a path exists.
Definition
system-path.cc:336
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:227
ns3::SystemPath::Append
std::string Append(std::string left, std::string right)
Join two file system path elements.
Definition
system-path.cc:209
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:236
ns3::SystemPath::FindSelfDirectory
std::string FindSelfDirectory()
Get the file system path to the current executable.
Definition
system-path.cc:119
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 Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0