Blender V5.0
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
10
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
43
48 bool write_to_disk() const;
56 bool write_to_disk(const CatalogFilePath &dest_file_path) const;
57
61 bool exists_on_disk() const;
62
63 bool contains(CatalogID catalog_id) const;
65 void add_overwrite(AssetCatalog *catalog);
67 void add_new(AssetCatalog *catalog);
68
70 void forget(CatalogID catalog_id);
71
72 using AssetCatalogParsedFn = FunctionRef<bool(std::unique_ptr<AssetCatalog>)>;
73 void parse_catalog_file(const CatalogFilePath &catalog_definition_file_path,
74 AssetCatalogParsedFn catalog_loaded_callback);
75
76 std::unique_ptr<AssetCatalogDefinitionFile> copy_and_remap(
77 const OwningAssetCatalogMap &catalogs, const OwningAssetCatalogMap &deleted_catalogs) const;
78
79 protected:
81 std::unique_ptr<AssetCatalog> parse_catalog_line(StringRef line);
82
87 bool write_to_disk_unsafe(const CatalogFilePath &dest_file_path) const;
88 bool ensure_directory_exists(const CatalogFilePath &directory_path) const;
89};
90
91} // 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)
FunctionRef< bool(std::unique_ptr< AssetCatalog >)> AssetCatalogParsedFn
Map< CatalogID, std::unique_ptr< AssetCatalog > > OwningAssetCatalogMap