Blender V4.3
asset_catalog_definition_file.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
11#pragma once
12
13#include "AS_asset_catalog.hh"
14
15#include "BLI_string_ref.hh"
16
17namespace blender::asset_system {
18
25 protected:
26 /* Catalogs stored in this file. They are mapped by ID to make it possible to query whether a
27 * catalog is already known, without having to find the corresponding `AssetCatalog*`. */
29
30 public:
31 /* For now this is the only version of the catalog definition files that is supported.
32 * Later versioning code may be added to handle older files. */
33 const static int SUPPORTED_VERSION;
34 /* String that's matched in the catalog definition file to know that the line is the version
35 * declaration. It has to start with a space to ensure it won't match any hypothetical future
36 * field that starts with "VERSION". */
37 const static std::string VERSION_MARKER;
38 const static std::string HEADER;
39
41
42 public:
44
49 bool write_to_disk() const;
57 bool write_to_disk(const CatalogFilePath &dest_file_path) const;
58
59 bool contains(CatalogID catalog_id) const;
61 void add_overwrite(AssetCatalog *catalog);
63 void add_new(AssetCatalog *catalog);
64
66 void forget(CatalogID catalog_id);
67
68 using AssetCatalogParsedFn = FunctionRef<bool(std::unique_ptr<AssetCatalog>)>;
69 void parse_catalog_file(const CatalogFilePath &catalog_definition_file_path,
70 AssetCatalogParsedFn catalog_loaded_callback);
71
72 std::unique_ptr<AssetCatalogDefinitionFile> copy_and_remap(
73 const OwningAssetCatalogMap &catalogs, const OwningAssetCatalogMap &deleted_catalogs) const;
74
75 protected:
77 std::unique_ptr<AssetCatalog> parse_catalog_line(StringRef line);
78
83 bool write_to_disk_unsafe(const CatalogFilePath &dest_file_path) const;
84 bool ensure_directory_exists(const CatalogFilePath &directory_path) const;
85};
86
87} // namespace blender::asset_system
bool ensure_directory_exists(const CatalogFilePath &directory_path) const
void parse_catalog_file(const CatalogFilePath &catalog_definition_file_path, AssetCatalogParsedFn catalog_loaded_callback)
std::unique_ptr< AssetCatalogDefinitionFile > copy_and_remap(const OwningAssetCatalogMap &catalogs, const OwningAssetCatalogMap &deleted_catalogs) const
bool write_to_disk_unsafe(const CatalogFilePath &dest_file_path) const
std::unique_ptr< AssetCatalog > parse_catalog_line(StringRef line)
Universally Unique Identifier according to RFC4122.