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 * 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 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef SYSTEM_PATH_H
20#define SYSTEM_PATH_H
21
22#include <list>
23#include <string>
24
25/**
26 * \file
27 * \ingroup systempath
28 * ns3::SystemPath declarations.
29 */
30
31namespace ns3
32{
33
34/**
35 * \ingroup system
36 * \defgroup systempath Host Filesystem
37 * \brief Encapsulate OS-specific functions to manipulate file
38 * and directory paths.
39 *
40 * The functions provided here are used mostly to implement
41 * the ns-3 test framework.
42 */
43
44/**
45 * \ingroup systempath
46 * \brief Namespace for various file and directory path functions.
47 */
48namespace SystemPath
49{
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.
Definition: system-path.cc:271
bool Exists(const std::string path)
Check if a path exists.
Definition: system-path.cc:347
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:238
void MakeDirectories(std::string path)
Create all the directories leading to path.
Definition: system-path.cc:330
std::string MakeTemporaryDirectoryName()
Get the name of a temporary directory.
Definition: system-path.cc:285
std::string Append(std::string left, std::string right)
Join two file system path elements.
Definition: system-path.cc:220
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:247
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:392
std::string FindSelfDirectory()
Get the file system path to the current executable.
Definition: system-path.cc:130
Every class exported by the ns3 library is enclosed in the ns3 namespace.