Blender  V3.3
Public Types | Public Member Functions | Static Public Attributes | Static Protected Member Functions | Friends | List of all members
blender::bke::AssetCatalogPath Class Reference

#include <BKE_asset_catalog_path.hh>

Public Types

using ComponentIteratorFn = FunctionRef< void(StringRef component_name, bool is_last_component)>
 

Public Member Functions

 AssetCatalogPath ()=default
 
 AssetCatalogPath (StringRef path)
 
 AssetCatalogPath (const std::string &path)
 
 AssetCatalogPath (const char *path)
 
 AssetCatalogPath (const AssetCatalogPath &other_path)=default
 
 AssetCatalogPath (AssetCatalogPath &&other_path) noexcept
 
 ~AssetCatalogPath ()=default
 
uint64_t hash () const
 
uint64_t length () const
 
const char * c_str () const
 
const std::string & str () const
 
StringRefNull name () const
 
bool operator== (const AssetCatalogPath &other_path) const
 
bool operator!= (const AssetCatalogPath &other_path) const
 
bool operator< (const AssetCatalogPath &other_path) const
 
AssetCatalogPathoperator= (const AssetCatalogPath &other_path)=default
 
AssetCatalogPathoperator= (AssetCatalogPath &&other_path)=default
 
AssetCatalogPath operator/ (const AssetCatalogPath &path_to_append) const
 
 operator bool () const
 
AssetCatalogPath cleanup () const
 
bool is_contained_in (const AssetCatalogPath &other_path) const
 
AssetCatalogPath parent () const
 
AssetCatalogPath rebase (const AssetCatalogPath &from_path, const AssetCatalogPath &to_path) const
 
void iterate_components (ComponentIteratorFn callback) const
 

Static Public Attributes

static const char SEPARATOR = '/'
 

Static Protected Member Functions

static std::string cleanup_component (StringRef component_name)
 

Friends

std::ostream & operator<< (std::ostream &stream, const AssetCatalogPath &path_to_append)
 

Detailed Description

Location of an Asset Catalog in the catalog tree, denoted by slash-separated path components.

Each path component is a string that is not allowed to have slashes or colons. The latter is to make things easy to save in the colon-delimited Catalog Definition File format.

The path of a catalog determines where in the catalog hierarchy the catalog is shown. Examples are "Characters/Ellie/Poses/Hand" or "Kit_bash/City/Skyscrapers". The path looks like a file-system path, with a few differences:

See https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Catalogs

Paths are stored as byte sequences, and assumed to be UTF-8.

Definition at line 38 of file BKE_asset_catalog_path.hh.

Member Typedef Documentation

◆ ComponentIteratorFn

Call the callback function for each path component, in left-to-right order.

Definition at line 121 of file BKE_asset_catalog_path.hh.

Constructor & Destructor Documentation

◆ AssetCatalogPath() [1/6]

blender::bke::AssetCatalogPath::AssetCatalogPath ( )
default

Referenced by cleanup(), operator/(), parent(), and rebase().

◆ AssetCatalogPath() [2/6]

blender::bke::AssetCatalogPath::AssetCatalogPath ( StringRef  path)

Definition at line 19 of file asset_catalog_path.cc.

◆ AssetCatalogPath() [3/6]

blender::bke::AssetCatalogPath::AssetCatalogPath ( const std::string &  path)

Definition at line 15 of file asset_catalog_path.cc.

◆ AssetCatalogPath() [4/6]

blender::bke::AssetCatalogPath::AssetCatalogPath ( const char *  path)

Definition at line 23 of file asset_catalog_path.cc.

◆ AssetCatalogPath() [5/6]

blender::bke::AssetCatalogPath::AssetCatalogPath ( const AssetCatalogPath other_path)
default

◆ AssetCatalogPath() [6/6]

blender::bke::AssetCatalogPath::AssetCatalogPath ( AssetCatalogPath &&  other_path)
noexcept

Definition at line 27 of file asset_catalog_path.cc.

◆ ~AssetCatalogPath()

blender::bke::AssetCatalogPath::~AssetCatalogPath ( )
default

Member Function Documentation

◆ c_str()

const char * blender::bke::AssetCatalogPath::c_str ( ) const

◆ cleanup()

AssetCatalogPath blender::bke::AssetCatalogPath::cleanup ( ) const

Clean up the path. This ensures:

  • Every path component is stripped of its leading/trailing spaces.
  • Empty components (caused by double slashes or leading/trailing slashes) are removed.
  • Invalid characters are replaced with valid ones.

Definition at line 104 of file asset_catalog_path.cc.

References AssetCatalogPath(), cleanup_component(), iterate_components(), and SEPARATOR.

Referenced by ED_asset_catalog_move(), ED_asset_catalog_rename(), blender::bke::AssetCatalog::from_path(), blender::bke::AssetCatalogDefinitionFile::parse_catalog_line(), and blender::bke::tests::TEST().

◆ cleanup_component()

std::string blender::bke::AssetCatalogPath::cleanup_component ( StringRef  component_name)
staticprotected

Strip leading/trailing spaces and replace disallowed characters.

Definition at line 132 of file asset_catalog_path.cc.

References component().

Referenced by cleanup().

◆ hash()

uint64_t blender::bke::AssetCatalogPath::hash ( ) const

Definition at line 32 of file asset_catalog_path.cc.

◆ is_contained_in()

bool blender::bke::AssetCatalogPath::is_contained_in ( const AssetCatalogPath other_path) const
Returns
true only if the given path is a parent of this catalog's path. When this catalog's path is equal to the given path, return true as well. In other words, this defines a weak subset.

True: "some/path/there" is contained in "some/path" and "some". False: "path/there" is not contained in "some/path/there".

Note that non-cleaned-up paths (so for example starting or ending with a slash) are not supported, and result in undefined behavior.

Definition at line 140 of file asset_catalog_path.cc.

References length(), SEPARATOR, and blender::StringRefBase::startswith().

Referenced by blender::ed::asset_browser::AssetCatalogDropController::can_drop(), blender::bke::AssetCatalogService::create_catalog_filter(), blender::bke::AssetCatalogService::prune_catalogs_by_path(), rebase(), and blender::bke::tests::TEST().

◆ iterate_components()

void blender::bke::AssetCatalogPath::iterate_components ( ComponentIteratorFn  callback) const

◆ length()

uint64_t blender::bke::AssetCatalogPath::length ( ) const

Definition at line 38 of file asset_catalog_path.cc.

Referenced by is_contained_in(), rebase(), and blender::bke::tests::TEST().

◆ name()

StringRefNull blender::bke::AssetCatalogPath::name ( ) const

◆ operator bool()

blender::bke::AssetCatalogPath::operator bool ( ) const

Definition at line 93 of file asset_catalog_path.cc.

◆ operator!=()

Definition at line 68 of file asset_catalog_path.cc.

◆ operator/()

AssetCatalogPath blender::bke::AssetCatalogPath::operator/ ( const AssetCatalogPath path_to_append) const

Concatenate two paths, returning the new path.

Definition at line 78 of file asset_catalog_path.cc.

References AssetCatalogPath(), and SEPARATOR.

◆ operator<()

bool blender::bke::AssetCatalogPath::operator< ( const AssetCatalogPath other_path) const

Definition at line 73 of file asset_catalog_path.cc.

◆ operator=() [1/2]

AssetCatalogPath& blender::bke::AssetCatalogPath::operator= ( AssetCatalogPath &&  other_path)
default

◆ operator=() [2/2]

AssetCatalogPath& blender::bke::AssetCatalogPath::operator= ( const AssetCatalogPath other_path)
default

◆ operator==()

bool blender::bke::AssetCatalogPath::operator== ( const AssetCatalogPath other_path) const

Definition at line 63 of file asset_catalog_path.cc.

◆ parent()

AssetCatalogPath blender::bke::AssetCatalogPath::parent ( ) const

◆ rebase()

AssetCatalogPath blender::bke::AssetCatalogPath::rebase ( const AssetCatalogPath from_path,
const AssetCatalogPath to_path 
) const

Change the initial part of the path from from_path to to_path. If this path does not start with from_path, return an empty path as result.

Example:

AssetCatalogPath path("some/path/to/some/catalog"); path.rebase("some/path", "new/base") -> "new/base/to/some/catalog"

Definition at line 199 of file asset_catalog_path.cc.

References AssetCatalogPath(), is_contained_in(), length(), and blender::StringRefBase::substr().

Referenced by blender::bke::tests::TEST(), and blender::bke::AssetCatalogService::update_catalog_path().

◆ str()

const std::string & blender::bke::AssetCatalogPath::str ( ) const

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const AssetCatalogPath path_to_append 
)
friend

Output the path as string.

Definition at line 98 of file asset_catalog_path.cc.

Member Data Documentation

◆ SEPARATOR

const char blender::bke::AssetCatalogPath::SEPARATOR = '/'
static

The documentation for this class was generated from the following files: