diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-08-02 12:02:47 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-08-02 12:08:02 +0300 |
commit | 1f0d6f763573b22772dcdb61320a12e1c11949e0 (patch) | |
tree | 03f68b9e777d507b3aeeb21fac35a172f32b95fa /source/blender/blenkernel/BKE_asset_catalog.hh | |
parent | 3fd5c93f9ce805b1a59bb6a03a9d39767697e336 (diff) |
Asset Catalogs: loading a catalog definition file
Initial, limited implementation of loading a single asset catalog
definition file. These files are structured as follows:
CATALOG_ID virtual/path/of/catalog
SUBCATALOG_ID virtual/path/of/catalog/child
SOMETHING_ELSE some/unrelated/hierarchy
These virtual paths will be used to show the catalog in a tree
structure; the tree structure itself is not part of this commit. Each
asset will have one catalog ID that determines where in that tree the
asset shows up.
Currently only a single catalog definition file can be read; merging
data from multiple such files, and writing them out again after changes
are made, is for future commits.
This commit only contains the code to load a single file, and unittests
to check that this actually works. No UI, no user-facing functionality
yet.
Diffstat (limited to 'source/blender/blenkernel/BKE_asset_catalog.hh')
-rw-r--r-- | source/blender/blenkernel/BKE_asset_catalog.hh | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh b/source/blender/blenkernel/BKE_asset_catalog.hh new file mode 100644 index 00000000000..82449bcdbcc --- /dev/null +++ b/source/blender/blenkernel/BKE_asset_catalog.hh @@ -0,0 +1,97 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup bke + */ + +#pragma once + +#ifndef __cplusplus +# error This is a C++ header. The C interface is yet to be implemented/designed. +#endif + +#include "BLI_map.hh" +#include "BLI_set.hh" +#include "BLI_string_ref.hh" +#include "BLI_vector_set.hh" + +#include <filesystem> +#include <memory> +#include <string> + +namespace blender::bke { + +using CatalogID = std::string; +using CatalogPath = std::string; +using CatalogPathReference = StringRef; +using CatalogPathComponent = std::string; +using CatalogFilePath = std::filesystem::path; + +class AssetCatalog; +class AssetCatalogDefinitionFile; +class AssetCatalogTreeNode; + +/* Manages the asset catalogs of a single asset library (i.e. of catalogs defined in a single + * directory hierarchy). */ +class AssetCatalogService { + const char path_separator = '/'; + + /* TODO(@sybren): determine which properties should be private / get accessors. */ + + // These pointers are owned by this AssetCatalogService. + Map<CatalogID, std::unique_ptr<AssetCatalog>> catalogs; + std::unique_ptr<AssetCatalogDefinitionFile> catalog_definition_file; + + public: + AssetCatalogService(); + + // Return nullptr if not found. + AssetCatalog *find_catalog(const CatalogID &catalog_id); + + void load_from_disk(const CatalogFilePath &asset_library_root); + + protected: + void load_directory_recursive(const CatalogFilePath &directory_path); + void load_single_file(const CatalogFilePath &catalog_definition_file_path); + + std::unique_ptr<AssetCatalogDefinitionFile> parse_catalog_file( + const CatalogFilePath &catalog_definition_file_path); + + std::unique_ptr<AssetCatalog> parse_catalog_line( + StringRef line, const AssetCatalogDefinitionFile *catalog_definition_file); +}; + +class AssetCatalogDefinitionFile { + /* TODO(@sybren): determine which properties should be private / get accessors. */ + public: + CatalogFilePath file_path; + Map<CatalogID, AssetCatalog *> catalogs; + + AssetCatalogDefinitionFile(); +}; + +class AssetCatalog { + /* TODO(@sybren): determine which properties should be private / get accessors. */ + public: + AssetCatalog(); + AssetCatalog(const CatalogID &catalog_id, const CatalogPath &name); + + CatalogID catalog_id; + CatalogPath path; +}; + +} // namespace blender::bke |