lanelet2_map_server v1.2.3
Loading...
Searching...
No Matches
lanelet2_map_interface.cpp File Reference
#include <cctype>
#include <cstdlib>
#include <filesystem>
#include <utility>
#include "lanelet2_map_interface/lanelet2_map_interface.hpp"

Go to the source code of this file.

Functions

std::filesystem::path resolveFilepath (const std::string &path_string)
 Resolves a relative string filepath.
 

Function Documentation

◆ resolveFilepath()

std::filesystem::path resolveFilepath ( const std::string & path_string)

Resolves a relative string filepath.

Interprets paths relative to $ROS_HOME, $HOME/.ros, or current working directory. If the path is absolute, it is returned as-is.

Parameters
[in]path_string(relative) path
Returns
resolved path

Definition at line 20 of file lanelet2_map_interface.cpp.

20 {
21 std::filesystem::path path(path_string);
22 if (path_string.empty()) return path;
23 if (!path.has_root_path()) {
24 const char* ros_home_ptr = std::getenv("ROS_HOME");
25 if (ros_home_ptr != nullptr && !std::string(ros_home_ptr).empty()) {
26 path = std::filesystem::path(std::string(ros_home_ptr));
27 } else {
28 const char* home_dir = std::getenv("HOME");
29 if (home_dir != nullptr && !std::string(home_dir).empty()) {
30 path = std::filesystem::path(std::string(home_dir) + "/.ros");
31 } else {
32 path = std::filesystem::current_path();
33 }
34 }
35 path.append(path_string);
36 }
37 path = path.lexically_normal();
38 return path;
39}