A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
system-path-examples.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2020 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
34
using namespace
ns3
;
35
using namespace
ns3::SystemPath
;
36
37
int
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? "
55
<< (
Exists
(path) ?
"yes"
:
"no"
) << std::endl;
56
57
auto
foo =
Append
(path,
"foo"
);
58
std::cout <<
"Append 'foo': "
<< foo << std::endl;
59
std::cout <<
"Exists? "
60
<< (
Exists
(foo) ?
"yes"
:
"no"
) << std::endl;
61
62
std::cout <<
"Split path:\n"
;
63
auto
items =
Split
(path);
64
for
(
auto
item : items)
65
{
66
std::cout <<
" '"
<< item <<
"'\n"
;
67
}
68
std::cout << std::endl;
69
70
std::cout <<
"Successive Joins: \n"
;
71
for
(
auto
it = items.begin (); it != items.end (); ++it)
72
{
73
auto
partial =
Join
(items.begin (), it);
74
std::cout <<
" '"
<< partial <<
"'\n"
;
75
}
76
77
std::cout <<
"Files in the directory: \n"
;
78
auto
files =
ReadFiles
(path);
79
for
(
auto
item : files)
80
{
81
std::cout <<
" '"
<< item <<
"'\n"
;
82
}
83
84
85
return
0;
86
}
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:229
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:300
ns3::SystemPath::Exists
bool Exists(const std::string path)
Check if a path exists.
Definition:
system-path.cc:393
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:241
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:276
ns3::SystemPath::FindSelfDirectory
std::string FindSelfDirectory(void)
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:129
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition:
second.py:35
src
core
examples
system-path-examples.cc
Generated on Tue Feb 6 2024 19:21:16 for ns-3 by
1.9.1