Blender  V3.3
BKE_asset_catalog_path.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 
9 #ifndef __cplusplus
10 # error This is a C++ header.
11 #endif
12 
13 #include "BLI_function_ref.hh"
14 #include "BLI_string_ref.hh"
15 #include "BLI_sys_types.h"
16 
17 #include <string>
18 
19 namespace blender::bke {
20 
39  friend std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append);
40 
41  private:
45  std::string path_ = "";
46 
47  public:
48  static const char SEPARATOR;
49 
50  AssetCatalogPath() = default;
52  AssetCatalogPath(const std::string &path);
53  AssetCatalogPath(const char *path);
54  AssetCatalogPath(const AssetCatalogPath &other_path) = default;
55  AssetCatalogPath(AssetCatalogPath &&other_path) noexcept;
56  ~AssetCatalogPath() = default;
57 
58  uint64_t hash() const;
59  uint64_t length() const; /* Length of the path in bytes. */
60 
62  const char *c_str() const;
63  const std::string &str() const;
64 
65  /* The last path component, used as label in the tree view. */
66  StringRefNull name() const;
67 
68  /* In-class operators, because of the implicit `AssetCatalogPath(StringRef)` constructor.
69  * Otherwise `string == string` could cast both sides to `AssetCatalogPath`. */
70  bool operator==(const AssetCatalogPath &other_path) const;
71  bool operator!=(const AssetCatalogPath &other_path) const;
72  bool operator<(const AssetCatalogPath &other_path) const;
73  AssetCatalogPath &operator=(const AssetCatalogPath &other_path) = default;
74  AssetCatalogPath &operator=(AssetCatalogPath &&other_path) = default;
75 
77  AssetCatalogPath operator/(const AssetCatalogPath &path_to_append) const;
78 
79  /* False when the path is empty, true otherwise. */
80  operator bool() const;
81 
88  [[nodiscard]] AssetCatalogPath cleanup() const;
89 
101  bool is_contained_in(const AssetCatalogPath &other_path) const;
102 
106  AssetCatalogPath parent() const;
107 
117  AssetCatalogPath rebase(const AssetCatalogPath &from_path,
118  const AssetCatalogPath &to_path) const;
119 
121  using ComponentIteratorFn = FunctionRef<void(StringRef component_name, bool is_last_component)>;
123 
124  protected:
126  static std::string cleanup_component(StringRef component_name);
127 };
128 
130 std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append);
131 
132 } // namespace blender::bke
AssetCatalogPath & operator=(AssetCatalogPath &&other_path)=default
const std::string & str() const
AssetCatalogPath operator/(const AssetCatalogPath &path_to_append) const
AssetCatalogPath cleanup() const
friend std::ostream & operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append)
bool operator<(const AssetCatalogPath &other_path) const
AssetCatalogPath(const AssetCatalogPath &other_path)=default
bool is_contained_in(const AssetCatalogPath &other_path) const
bool operator==(const AssetCatalogPath &other_path) const
static std::string cleanup_component(StringRef component_name)
void iterate_components(ComponentIteratorFn callback) const
bool operator!=(const AssetCatalogPath &other_path) const
AssetCatalogPath rebase(const AssetCatalogPath &from_path, const AssetCatalogPath &to_path) const
AssetCatalogPath & operator=(const AssetCatalogPath &other_path)=default
AssetCatalogPath parent() const
DEGForeachIDComponentCallback callback
SyclQueue void void size_t num_bytes void
std::ostream & operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append)
unsigned __int64 uint64_t
Definition: stdint.h:90