6std::vector<std::string> Path::split_path(
const fs::path& path) {
7 std::vector<std::string> parts;
8 for (
const auto& part : path) {
9 std::string s = part.string();
17size_t Path::find_position_start_relative_path()
const {
18 size_t sz = tokens.size();
20 for (
size_t i = 1; i < sz - 1; i++) {
21 if (tokens[i - 1] == BASE_INIT_STRING && tokens[i + 1] == SOURCE_STRING) {
25 assert(ret != sz &&
"PATH NOT VALID FOR THE TOOL");
30 return tokens.empty();
34 tokens = split_path(path);
35 position_start_relative_path = find_position_start_relative_path();
38std::string Path::build_string_path(
const std::vector<std::string>& path_tokens) {
40 for (
const auto& token : path_tokens) {
46std::string Path::build_base_path(
const std::string& base)
const {
50 std::vector<std::string> path = tokens;
51 size_t pos_change = position_start_relative_path - 1;
52 path[pos_change] = base;
53 std::string string_path = build_string_path(path);
58 return build_base_path(SOURCE_STRING);
62 return build_base_path(HEADER_STRING);
66 std::string ret = build_base_path(INFO_STRING);
70 ret = remove_extension(ret);
74 ret += JSON_EXTENSION;
78std::vector<std::string> Path::get_tokens_from_relative_path()
const {
79 std::vector<std::string> token_relative_path = tokens;
80 token_relative_path.pop_back();
81 size_t to_remove = position_start_relative_path;
82 reverse(token_relative_path.begin(), token_relative_path.end());
83 for (
size_t i = 0; i < to_remove; i++) {
84 token_relative_path.pop_back();
86 reverse(token_relative_path.begin(), token_relative_path.end());
87 return token_relative_path;
90std::string Path::remove_extension(std::string& token) {
91 while (!token.empty()) {
92 auto c = token.back();
105 std::vector<std::string> token_relative_path = get_tokens_from_relative_path();
106 std::string string_path = build_string_path(token_relative_path);
114 std::string function_name = tokens.back();
115 function_name = remove_extension(function_name);
116 return function_name;
120 std::vector<std::string> tokens_relative_1 = get_tokens_from_relative_path();
121 std::vector<std::string> tokens_relative_2 = path.get_tokens_from_relative_path();
122 size_t minimum_size_tokens = std::min(tokens_relative_1.size(), tokens_relative_2.size());
123 std::vector<std::string> common_folders;
124 for (
size_t i = 0; i < minimum_size_tokens; i++) {
125 auto token_1 = tokens_relative_1[i];
126 auto token_2 = tokens_relative_2[i];
127 if (token_1 == token_2) {
128 common_folders.push_back(token_1);
133 return common_folders;
137 return tokens < path.tokens;
142 return relative_path_plus_function_name.find(pattern) != std::string::npos;
Path manipulation class for tool-specific directory structure.
std::string format_path_message_in_pair() const
Formats path for display.
std::string build_relative_path() const
Builds relative path portion.
std::string build_info_path() const
Builds metadata file path.
std::vector< std::string > get_common_folders(const Path &path) const
Finds common folders with another path.
std::string build_function_name() const
Extracts function name from path.
bool contains_given_pattern(const std::string &pattern) const
Checks for pattern in path.
Path()=default
Default constructor.
bool operator<(const Path &path) const
Path comparison operator.
std::string build_header_path() const
Builds header file path.
std::string build_source_path() const
Builds source file path.
bool is_empty() const
Checks if path is empty.
Path abstraction for temporary codebase.