A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
system-path.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef SYSTEM_PATH_H
9#define SYSTEM_PATH_H
10
11#include <list>
12#include <string>
13
14/**
15 * @file
16 * @ingroup systempath
17 * ns3::SystemPath declarations.
18 */
19
20namespace ns3
21{
22
23/**
24 * @ingroup system
25 * @defgroup systempath Host Filesystem
26 * @brief Encapsulate OS-specific functions to manipulate file
27 * and directory paths.
28 *
29 * The functions provided here are used mostly to implement
30 * the ns-3 test framework.
31 */
32
33/**
34 * @ingroup systempath
35 * @brief Namespace for various file and directory path functions.
36 */
37namespace SystemPath
38{
39
40/**
41 * @ingroup systempath
42 * Get the file system path to the current executable.
43 *
44 * This path contains the currently-executing binary. For its directory,
45 * use FindSelfDirectory() instead.
46 *
47 * @return The path to the currently-executing binary
48 */
49std::string FindSelf();
50
51/**
52 * @ingroup systempath
53 * Get the file system path to the current executable.
54 *
55 * This path is only equivalent to the current working directory when
56 * the executable is executed in its parent directory.
57 *
58 * @return The directory in which the currently-executing binary is located
59 */
60std::string FindSelfDirectory();
61
62/**
63 * @ingroup systempath
64 * Join two file system path elements.
65 *
66 * @param [in] left A path element
67 * @param [in] right A path element
68 * @return A concatenation of the two input paths
69 */
70std::string Append(std::string left, std::string right);
71
72/**
73 * @ingroup systempath
74 * Split a file system path into directories according to
75 * the local path separator.
76 *
77 * This is the inverse of Join.
78 *
79 * @param [in] path A path
80 * @return A list of path elements that can be joined together again with
81 * the Join function.
82 * \sa ns3::SystemPath::Join
83 */
84std::list<std::string> Split(std::string path);
85
86/**
87 * Join a list of file system path directories into a single
88 * file system path.
89 *
90 * This is the inverse of Split.
91 *
92 * @ingroup systempath
93 * @param [in] begin Iterator to first element to join
94 * @param [in] end Iterator to one past the last element to join
95 * @return A path that is a concatenation of all the input elements.
96 */
97std::string Join(std::list<std::string>::const_iterator begin,
98 std::list<std::string>::const_iterator end);
99
100/**
101 * @ingroup systempath
102 * Get the list of files located in a file system directory.
103 *
104 * @param [in] path A path which identifies a directory
105 * @return A list of the filenames which are located in the input directory
106 */
107std::list<std::string> ReadFiles(std::string path);
108
109/**
110 * @ingroup systempath
111 * Get the name of a temporary directory.
112 *
113 * The returned path identifies a directory which does not exist yet.
114 * Call ns3::SystemPath::MakeDirectories to create it. Yes, there is a
115 * well-known security race in this API but we don't care in ns-3.
116 *
117 * The final path to the directory is going to look something like
118 *
119 * /tmp/ns3.14.30.29.32767
120 *
121 * The first part, "/tmp/" is the absolute path found by inspecting
122 * the environment variables `TMP`and `TEMP`, in order. If neither
123 * exists the hard-coded root path `/tmp/` is used.
124 *
125 * The directory name itself starts with the "ns3" identifier telling folks
126 * who is making all of the temp directories.
127 *
128 * The next three numbers give the hour, minute and second, separated by
129 * periods.
130 *
131 * The final number is randomly generated, to avoid name collisions.
132 *
133 * @return A path which identifies a temporary directory.
134 */
135std::string MakeTemporaryDirectoryName();
136
137/**
138 * @ingroup systempath
139 * Create all the directories leading to path.
140 *
141 * @param [in] path A path to a directory
142 */
143void MakeDirectories(std::string path);
144
145/**
146 * @ingroup systempath
147 * Check if a path exists.
148 * Path can be a file or directory.
149 * @param [in] path The path to check.
150 * @returns \c true if the \pname{path} exists.
151 */
152bool Exists(const std::string path);
153
154/**
155 * @ingroup systempath
156 * Replace incompatible characters in a path,
157 * to get a path compatible with different
158 * file systems.
159 * @param [in] path The path to check.
160 * @returns A compatible path.
161 */
162std::string CreateValidSystemPath(const std::string path);
163
164} // namespace SystemPath
165
166} // namespace ns3
167
168#endif /* SYSTEM_PATH_H */
std::list< std::string > ReadFiles(std::string path)
Get the list of files located in a file system directory.
bool Exists(const std::string path)
Check if a path exists.
std::list< std::string > Split(std::string path)
Split a file system path into directories according to the local path separator.
std::string FindSelf()
Get the file system path to the current executable.
void MakeDirectories(std::string path)
Create all the directories leading to path.
std::string MakeTemporaryDirectoryName()
Get the name of a temporary directory.
std::string Append(std::string left, std::string right)
Join two file system path elements.
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.
std::string CreateValidSystemPath(const std::string path)
Replace incompatible characters in a path, to get a path compatible with different file systems.
std::string FindSelfDirectory()
Get the file system path to the current executable.
Namespace for various file and directory path functions.
Every class exported by the ns3 library is enclosed in the ns3 namespace.