Encapsulate OS-specific functions to manipulate file and directory paths. More...
Files | |
file | system-path-examples.cc |
Example program illustrating use of ns3::SystemPath. | |
file | system-path.cc |
ns3::SystemPath implementation. | |
file | system-path.h |
ns3::SystemPath declarations. | |
Functions | |
std::string | ns3::SystemPath::Append (std::string left, std::string right) |
Join two file system path elements. More... | |
std::string | ns3::SystemPath::CreateValidSystemPath (const std::string path) |
Replace incompatible characters in a path, to get a path compatible with different file systems. More... | |
std::string | ns3::SystemPath::Dirname (std::string path) |
Get the directory path for a file. More... | |
bool | ns3::SystemPath::Exists (const std::string path) |
Check if a path exists. More... | |
std::string | ns3::SystemPath::FindSelfDirectory () |
Get the file system path to the current executable. More... | |
std::string | ns3::SystemPath::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. More... | |
void | ns3::SystemPath::MakeDirectories (std::string path) |
Create all the directories leading to path. More... | |
std::string | ns3::SystemPath::MakeTemporaryDirectoryName () |
Get the name of a temporary directory. More... | |
std::list< std::string > | ns3::SystemPath::ReadFiles (std::string path) |
Get the list of files located in a file system directory. More... | |
std::tuple< std::list< std::string >, bool > | ns3::anonymous_namespace{system-path.cc}::ReadFilesNoThrow (std::string path) |
Get the list of files located in a file system directory with error. More... | |
std::list< std::string > | ns3::SystemPath::Split (std::string path) |
Split a file system path into directories according to the local path separator. More... | |
Encapsulate OS-specific functions to manipulate file and directory paths.
The functions provided here are used mostly to implement the ns-3 test framework.
std::string ns3::SystemPath::Append | ( | std::string | left, |
std::string | right | ||
) |
Join two file system path elements.
[in] | left | A path element |
[in] | right | A path element |
Definition at line 240 of file system-path.cc.
References NS_LOG_FUNCTION, and SYSTEM_PATH_SEP.
Referenced by ns3::TestCase::CreateDataDirFilename(), ns3::TestCase::CreateTempDirFilename(), ns3::DesMetrics::Initialize(), and ns3::CommandLine::PrintDoxygenUsage().
std::string ns3::SystemPath::CreateValidSystemPath | ( | const std::string | path | ) |
Replace incompatible characters in a path, to get a path compatible with different file systems.
[in] | path | The path to check. |
Definition at line 412 of file system-path.cc.
Referenced by ns3::TestCase::CreateTempDirFilename().
std::string ns3::SystemPath::Dirname | ( | std::string | path | ) |
Get the directory path for a file.
This is an internal function (by virtue of not being declared in a .h file); the public API is FindSelfDirectory().
[in] | path | The full path to a file. |
Definition at line 140 of file system-path.cc.
References ns3::SystemPath::Join(), NS_LOG_FUNCTION, and ns3::SystemPath::Split().
Referenced by ns3::SystemPath::Exists(), and ns3::SystemPath::FindSelfDirectory().
bool ns3::SystemPath::Exists | ( | const std::string | path | ) |
Check if a path exists.
Path can be a file or directory.
[in] | path | The path to check. |
true
if the path exists. Definition at line 367 of file system-path.cc.
References ns3::SystemPath::Dirname(), create-module::file, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::SystemPath::ReadFiles(), ns3::anonymous_namespace{system-path.cc}::ReadFilesNoThrow(), and ns3::SystemPath::Split().
std::string ns3::SystemPath::FindSelfDirectory | ( | ) |
Get the file system path to the current executable.
This path is only equivalent to the current working directory when the executable is executed in its parent directory.
This function returns the path to the running $PREFIX. Mac OS X: _NSGetExecutablePath() (man 3 dyld) Linux: readlink /proc/self/exe Solaris: getexecname() FreeBSD: sysctl CTL_KERN KERN_PROC KERN_PROC_PATHNAME -1 BSD with procfs: readlink /proc/curproc/file Windows: GetModuleFileName() with hModule = NULL
Definition at line 150 of file system-path.cc.
References ns3::SystemPath::Dirname(), NS_ASSERT, NS_FATAL_ERROR, and NS_LOG_FUNCTION_NOARGS.
Referenced by ns3::TestRunnerImpl::GetTopLevelSourceDir().
std::string ns3::SystemPath::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.
This is the inverse of Split.
[in] | begin | Iterator to first element to join |
[in] | end | Iterator to one past the last element to join |
Definition at line 267 of file system-path.cc.
References NS_LOG_FUNCTION, and SYSTEM_PATH_SEP.
Referenced by ns3::TestCase::CreateTempDirFilename(), ns3::SystemPath::Dirname(), and ns3::TestRunnerImpl::GetTopLevelSourceDir().
void ns3::SystemPath::MakeDirectories | ( | std::string | path | ) |
Create all the directories leading to path.
[in] | path | A path to a directory |
Definition at line 350 of file system-path.cc.
References NS_FATAL_ERROR, and NS_LOG_FUNCTION.
Referenced by ns3::TestCase::CreateTempDirFilename().
std::string ns3::SystemPath::MakeTemporaryDirectoryName | ( | ) |
Get the name of a temporary directory.
The returned path identifies a directory which does not exist yet. Call ns3::SystemPath::MakeDirectories to create it. Yes, there is a well-known security race in this API but we don't care in ns-3.
The final path to the directory is going to look something like
/tmp/ns3.14.30.29.32767
The first part, "/tmp/" is the absolute path found by inspecting the environment variables TMP
and TEMP
, in order. If neither exists the hard-coded root path /tmp/
is used.
The directory name itself starts with the "ns3" identifier telling folks who is making all of the temp directories.
The next three numbers give the hour, minute and second, separated by periods.
The final number is randomly generated, to avoid name collisions.
Definition at line 305 of file system-path.cc.
References ns3::EnvironmentVariable::Get(), NS_LOG_FUNCTION_NOARGS, and SYSTEM_PATH_SEP.
Referenced by ns3::TestRunnerImpl::Run().
std::list< std::string > ns3::SystemPath::ReadFiles | ( | std::string | path | ) |
Get the list of files located in a file system directory.
[in] | path | A path which identifies a directory |
Definition at line 291 of file system-path.cc.
References NS_FATAL_ERROR, NS_LOG_FUNCTION, and ns3::anonymous_namespace{system-path.cc}::ReadFilesNoThrow().
Referenced by ns3::SystemPath::Exists(), and ns3::TestRunnerImpl::IsTopLevelSourceDir().
std::tuple<std::list<std::string>, bool> ns3::anonymous_namespace{system-path.cc}::ReadFilesNoThrow | ( | std::string | path | ) |
Get the list of files located in a file system directory with error.
[in] | path | A path which identifies a directory |
true
if directory doesn't exist. Definition at line 106 of file system-path.cc.
References NS_LOG_FUNCTION.
Referenced by ns3::SystemPath::Exists(), and ns3::SystemPath::ReadFiles().
std::list< std::string > ns3::SystemPath::Split | ( | std::string | path | ) |
Split a file system path into directories according to the local path separator.
This is the inverse of Join.
[in] | path | A path |
Definition at line 258 of file system-path.cc.
References NS_LOG_FUNCTION, ns3::SplitString(), and SYSTEM_PATH_SEP.
Referenced by ns3::CommandLine::CommandLine(), ns3::SystemPath::Dirname(), ns3::SystemPath::Exists(), ns3::TestRunnerImpl::GetTopLevelSourceDir(), and ns3::DesMetrics::Initialize().