Blender V5.0
AS_asset_catalog_path.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_function_ref.hh"
12#include "BLI_string_ref.hh"
13
14#include <string>
15
16namespace blender::asset_system {
17
36 friend std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append);
37
41 std::string path_;
42
43 public:
44 static const char SEPARATOR;
45
46 AssetCatalogPath() = default;
48 AssetCatalogPath(std::string path);
49 AssetCatalogPath(const char *path);
50 AssetCatalogPath(const AssetCatalogPath &other_path) = default;
51 AssetCatalogPath(AssetCatalogPath &&other_path) noexcept;
52 ~AssetCatalogPath() = default;
53
54 uint64_t hash() const;
55 uint64_t length() const; /* Length of the path in bytes. */
56
58 const char *c_str() const;
59 const std::string &str() const;
60
61 /* The last path component, used as label in the tree view. */
62 StringRefNull name() const;
63
64 /* In-class operators, because of the implicit `AssetCatalogPath(StringRef)` constructor.
65 * Otherwise `string == string` could cast both sides to `AssetCatalogPath`. */
66 bool operator==(const AssetCatalogPath &other_path) const;
67 bool operator!=(const AssetCatalogPath &other_path) const;
68 bool operator<(const AssetCatalogPath &other_path) const;
69 AssetCatalogPath &operator=(const AssetCatalogPath &other_path) = default;
71
73 AssetCatalogPath operator/(const AssetCatalogPath &path_to_append) const;
74
75 /* False when the path is empty, true otherwise. */
76 operator bool() const;
77
84 [[nodiscard]] AssetCatalogPath cleanup() const;
85
97 bool is_contained_in(const AssetCatalogPath &other_path) const;
98
102 AssetCatalogPath parent() const;
103
114 const AssetCatalogPath &to_path) const;
115
117 using ComponentIteratorFn = FunctionRef<void(StringRef component_name, bool is_last_component)>;
118 void iterate_components(ComponentIteratorFn callback) const;
119
120 protected:
122 static std::string cleanup_component(StringRef component_name);
123};
124
126std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append);
127
128} // namespace blender::asset_system
unsigned long long int uint64_t
AssetCatalogPath & operator=(const AssetCatalogPath &other_path)=default
AssetCatalogPath rebase(const AssetCatalogPath &from_path, const AssetCatalogPath &to_path) const
AssetCatalogPath operator/(const AssetCatalogPath &path_to_append) const
bool operator==(const AssetCatalogPath &other_path) const
bool operator!=(const AssetCatalogPath &other_path) const
AssetCatalogPath & operator=(AssetCatalogPath &&other_path)=default
FunctionRef< void(StringRef component_name, bool is_last_component)> ComponentIteratorFn
bool is_contained_in(const AssetCatalogPath &other_path) const
AssetCatalogPath(const AssetCatalogPath &other_path)=default
void iterate_components(ComponentIteratorFn callback) const
friend std::ostream & operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append)
bool operator<(const AssetCatalogPath &other_path) const
static std::string cleanup_component(StringRef component_name)
std::ostream & operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append)