Blender V4.3
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
9#pragma once
10
11#include "BLI_function_ref.hh"
12#include "BLI_string_ref.hh"
13#include "BLI_sys_types.h"
14
15#include <string>
16
17namespace blender::asset_system {
18
37 friend std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append);
38
42 std::string path_ = "";
43
44 public:
45 static const char SEPARATOR;
46
47 AssetCatalogPath() = default;
49 AssetCatalogPath(std::string path);
50 AssetCatalogPath(const char *path);
51 AssetCatalogPath(const AssetCatalogPath &other_path) = default;
52 AssetCatalogPath(AssetCatalogPath &&other_path) noexcept;
53 ~AssetCatalogPath() = default;
54
55 uint64_t hash() const;
56 uint64_t length() const; /* Length of the path in bytes. */
57
59 const char *c_str() const;
60 const std::string &str() const;
61
62 /* The last path component, used as label in the tree view. */
63 StringRefNull name() const;
64
65 /* In-class operators, because of the implicit `AssetCatalogPath(StringRef)` constructor.
66 * Otherwise `string == string` could cast both sides to `AssetCatalogPath`. */
67 bool operator==(const AssetCatalogPath &other_path) const;
68 bool operator!=(const AssetCatalogPath &other_path) const;
69 bool operator<(const AssetCatalogPath &other_path) const;
70 AssetCatalogPath &operator=(const AssetCatalogPath &other_path) = default;
72
74 AssetCatalogPath operator/(const AssetCatalogPath &path_to_append) const;
75
76 /* False when the path is empty, true otherwise. */
77 operator bool() const;
78
85 [[nodiscard]] AssetCatalogPath cleanup() const;
86
98 bool is_contained_in(const AssetCatalogPath &other_path) const;
99
103 AssetCatalogPath parent() const;
104
115 const AssetCatalogPath &to_path) const;
116
118 using ComponentIteratorFn = FunctionRef<void(StringRef component_name, bool is_last_component)>;
120
121 protected:
123 static std::string cleanup_component(StringRef component_name);
124};
125
127std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append);
128
129} // namespace blender::asset_system
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
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)
DEGForeachIDComponentCallback callback
std::ostream & operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append)
unsigned __int64 uint64_t
Definition stdint.h:90