ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
path_parser.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7#include <optional>
8#include <stdexcept>
9#include <string>
10#include <string_view>
11#include <vector>
12
13namespace rux::database {
14
18class PathError : public std::runtime_error {
19public:
20 explicit PathError(const std::string &message)
21 : std::runtime_error(message) {}
22};
23
27enum class ComponentType {
28 Collection, // e.g., "clouds", "meshes", "frames"
29 Item, // e.g., "mycloud", "123"
30 Property, // e.g., "metadata", "point_count"
31 Index // e.g., "[0]", "[5]"
32};
33
45 std::string value;
46 std::optional<int> index;
47
48 PathComponent(ComponentType t, std::string v)
49 : type(t), value(std::move(v)), index(std::nullopt) {}
50
51 PathComponent(ComponentType t, std::string v, int idx)
52 : type(t), value(std::move(v)), index(idx) {}
53
54 bool is_collection() const { return type == ComponentType::Collection; }
55 bool is_item() const { return type == ComponentType::Item; }
56 bool is_property() const { return type == ComponentType::Property; }
57 bool is_index() const { return type == ComponentType::Index; }
58 bool has_wildcard() const { return value.find('*') != std::string::npos; }
59};
60
89std::vector<PathComponent> parse_path(std::string_view path);
90
99bool is_valid_collection(std::string_view name);
100
108std::vector<std::string>
109expand_wildcard(std::string_view pattern,
110 const std::vector<std::string> &items);
111
119bool matches_wildcard(std::string_view str, std::string_view pattern);
120
121} // namespace rux::database
PathError(const std::string &message)
std::vector< std::string > expand_wildcard(std::string_view pattern, const std::vector< std::string > &items)
Expand wildcard patterns in item names.
bool is_valid_collection(std::string_view name)
Check if a collection name is valid.
std::vector< PathComponent > parse_path(std::string_view path)
Parse a resource path into components.
ComponentType
Type of path component.
bool matches_wildcard(std::string_view str, std::string_view pattern)
Check if a string matches a wildcard pattern.
std::optional< int > index
PathComponent(ComponentType t, std::string v)
PathComponent(ComponentType t, std::string v, int idx)