24#include <mach-o/dyld.h>
28#include <sys/sysctl.h>
38#define WIN32_LEAN_AND_MEAN
74std::tuple<std::list<std::string>,
bool>
78 std::list<std::string> files;
79 if (!std::filesystem::exists(path))
81 return std::make_tuple(files,
true);
83 for (
auto&
it : std::filesystem::directory_iterator(path))
85 if (!std::filesystem::is_directory(
it.path()))
87 files.push_back(
it.path().filename().string());
90 return std::make_tuple(files,
false);
112 std::list<std::string> elements =
Split(path);
113 auto last = elements.end();
115 return Join(elements.begin(),
last);
132#if defined(__linux__)
135 char* buffer = (
char*)
malloc(size);
140 status =
readlink(
"/proc/self/exe", buffer, size);
147 buffer = (
char*)
malloc(size);
157#elif defined(__WIN32__)
163 while (status == size)
174#elif defined(__APPLE__)
190#elif defined(__FreeBSD__)
226std::list<std::string>
231 std::list<std::string>
retval(items.begin(), items.end());
236Join(std::list<std::string>::const_iterator begin, std::list<std::string>::const_iterator end)
240 for (
auto i = begin;
i != end;
i++)
259std::list<std::string>
264 std::list<std::string> files;
265 std::tie(files,
err) = ReadFilesNoThrow(path);
291 time_t now = time(
nullptr);
297 srand(time(
nullptr));
311 std::ostringstream
oss;
313 <<
tm_now->tm_sec <<
"." << n;
324 if (!std::filesystem::exists(path))
326 std::filesystem::create_directories(path,
ec);
342 std::list<std::string> files;
353 auto tokens =
Split(path);
354 const std::string& file = tokens.back();
367 auto it = std::find(files.begin(), files.end(), file);
368 if (
it == files.end())
389 std::regex_replace(std::back_inserter(
valid_path),
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
static KeyFoundType Get(const std::string &envvar, const std::string &key="", const std::string &delim=";")
Get the value corresponding to a key from an environment variable.
Class Environment declaration.
NS_FATAL_x macro definitions.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
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 Dirname(std::string path)
Get the directory path for a file.
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::tuple< std::list< std::string >, bool > ReadFilesNoThrow(std::string path)
Get the list of files located in a file system directory with error.
std::string FindSelfDirectory()
Get the file system path to the current executable.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
StringVector SplitString(const std::string &str, const std::string &delim)
Split a string on a delimiter.
ns3::StringValue attribute value declarations.
constexpr auto SYSTEM_PATH_SEP
System-specific path separator used between directory names.
ns3::SystemPath declarations.