Blender V5.3
blender::bke::path_templates::VariableMap Class Reference

#include <BKE_path_templates.hh>

Public Member Functions

bool contains (StringRef name) const
bool remove (StringRef name)
bool add_string (StringRef name, StringRef value)
bool add_filepath (StringRef name, StringRef value)
bool add_integer (StringRef name, int64_t value)
bool add_float (StringRef name, double value)
std::optional< StringRefNull > get_string (StringRef name) const
std::optional< StringRefNull > get_filepath (StringRef name) const
std::optional< int64_t > get_integer (StringRef name) const
std::optional< double > get_float (StringRef name) const
bool add_filename_only (StringRef var_name, StringRefNull full_path, StringRef fallback)
bool add_path_up_to_file (StringRef var_name, StringRefNull full_path, StringRef fallback)

Detailed Description

Variables (names and associated values) for use in template substitution.

Note that this is not intended to be persistent storage, but rather is transient for collecting data that is relevant/available in a given templating context.

There are currently four supported variable types:

  • String
  • Filepath
  • Integer
  • Float

Names must be unique across all variable types: you can't have a string and integer both with the name "bob".

A filepath variable can contain either a full or partial filepath. The distinction between string and filepath variables exists because non-path strings may include phrases like and/or or A:Left, which shouldn't be interpreted with path semantics. When used in path templating, the contents of string variables are therefore sanitized (replacing /, etc.), but the contents of filepath variables are left as-is.

Definition at line 117 of file BKE_path_templates.hh.

Member Function Documentation

◆ add_filename_only()

bool blender::bke::path_templates::VariableMap::add_filename_only ( StringRef var_name,
StringRefNull full_path,
StringRef fallback )

Add the filename (sans file extension) from the given path as a variable.

For example, if the full path is /home/bob/project_joe/scene_3.blend, then scene_3 is the value of the added variable.

If the path doesn't contain a filename, then fallback is used for the variable value.

If there is already a variable with that name, regardless of type, the new variable is not added (no overwriting).

Returns
True if the variable was successfully added, false if there was already a variable with that name.

Definition at line 141 of file path_templates.cc.

References add_filepath(), blender::BLI_path_basename(), blender::BLI_path_extension_or_end(), blender::StringRefNull::c_str(), and blender::StringRef::StringRef().

Referenced by blender::BKE_add_template_variables_general(), blender::bke::tests::TEST_F(), and blender::bke::tests::TEST_F().

◆ add_filepath()

bool blender::bke::path_templates::VariableMap::add_filepath ( StringRef name,
StringRef value )

Add a filepath variable with the given name and value.

If there is already a variable with that name, regardless of type, the new variable is not added (no overwriting).

Returns
True if the variable was successfully added, false if there was already a variable with that name.

Definition at line 78 of file path_templates.cc.

References contains().

Referenced by add_filename_only(), add_path_up_to_file(), blender::BKE_add_template_variables_for_project(), blender::bke::tests::TEST_F(), and blender::bke::tests::TEST_F().

◆ add_float()

bool blender::bke::path_templates::VariableMap::add_float ( StringRef name,
double value )

Add a float variable with the given name and value.

If there is already a variable with that name, regardless of type, the new variable is not added (no overwriting).

Returns
True if the variable was successfully added, false if there was already a variable with that name.

Definition at line 96 of file path_templates.cc.

References contains().

Referenced by blender::BKE_add_template_variables_for_project(), blender::BKE_add_template_variables_for_render_path(), blender::bke::tests::TEST_F(), and blender::bke::tests::TEST_F().

◆ add_integer()

bool blender::bke::path_templates::VariableMap::add_integer ( StringRef name,
int64_t value )

Add an integer variable with the given name and value.

If there is already a variable with that name, regardless of type, the new variable is not added (no overwriting).

Returns
True if the variable was successfully added, false if there was already a variable with that name.

Definition at line 87 of file path_templates.cc.

References contains().

Referenced by blender::BKE_add_template_variables_for_project(), blender::BKE_add_template_variables_for_render_path(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), and blender::bke::tests::TEST_F().

◆ add_path_up_to_file()

bool blender::bke::path_templates::VariableMap::add_path_up_to_file ( StringRef var_name,
StringRefNull full_path,
StringRef fallback )

Add the path up-to-but-not-including the filename as a variable.

For example, if the full path is /home/bob/project_joe/scene_3.blend, then /home/bob/project_joe/ is the value of the added variable.

If the path lacks either a filename or a path leading up to that filename, then fallback is used for the variable value.

If there is already a variable with that name, regardless of type, the new variable is not added (no overwriting).

Returns
True if the variable was successfully added, false if there was already a variable with that name.

Definition at line 160 of file path_templates.cc.

References add_filepath(), blender::BLI_path_basename(), blender::BLI_path_parent_dir(), blender::StringRefNull::c_str(), blender::blender::StringRefBase::copy_unsafe(), blender::Vector< T, InlineBufferCapacity, Allocator >::data(), blender::blender::StringRefBase::end(), blender::blender::StringRefBase::is_empty(), and blender::blender::StringRefBase::size().

Referenced by blender::BKE_add_template_variables_general(), and blender::bke::tests::TEST_F().

◆ add_string()

bool blender::bke::path_templates::VariableMap::add_string ( StringRef name,
StringRef value )

Add a string variable with the given name and value.

If there is already a variable with that name, regardless of type, the new variable is not added (no overwriting).

Returns
True if the variable was successfully added, false if there was already a variable with that name.

Definition at line 69 of file path_templates.cc.

References contains().

Referenced by blender::BKE_add_template_variables_for_node(), blender::BKE_add_template_variables_for_project(), blender::BKE_add_template_variables_for_render_path(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), and blender::bke::tests::TEST_F().

◆ contains()

bool blender::bke::path_templates::VariableMap::contains ( StringRef name) const

Check if a variable of the given name exists.

Definition at line 35 of file path_templates.cc.

Referenced by add_filepath(), add_float(), add_integer(), add_string(), and blender::bke::tests::TEST_F().

◆ get_filepath()

std::optional< StringRefNull > blender::bke::path_templates::VariableMap::get_filepath ( StringRef name) const

Fetch the value of the filepath variable with the given name.

Returns
The value if a filepath variable with that name exists, #std::nullopt otherwise.

Definition at line 114 of file path_templates.cc.

References blender::StringRefNull::StringRefNull().

Referenced by blender::eval_template(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), and blender::bke::tests::TEST_F().

◆ get_float()

std::optional< double > blender::bke::path_templates::VariableMap::get_float ( StringRef name) const

Fetch the value of the float variable with the given name.

Returns
The value if a float variable with that name exists, #std::nullopt otherwise.

Definition at line 132 of file path_templates.cc.

Referenced by blender::eval_template(), and blender::bke::tests::TEST_F().

◆ get_integer()

std::optional< int64_t > blender::bke::path_templates::VariableMap::get_integer ( StringRef name) const

Fetch the value of the integer variable with the given name.

Returns
The value if a integer variable with that name exists, #std::nullopt otherwise.

Definition at line 123 of file path_templates.cc.

Referenced by blender::eval_template(), and blender::bke::tests::TEST_F().

◆ get_string()

std::optional< StringRefNull > blender::bke::path_templates::VariableMap::get_string ( StringRef name) const

Fetch the value of the string variable with the given name.

Returns
The value if a string variable with that name exists, #std::nullopt otherwise.

Definition at line 105 of file path_templates.cc.

References blender::StringRefNull::StringRefNull().

Referenced by blender::eval_template(), and blender::bke::tests::TEST_F().

◆ remove()

bool blender::bke::path_templates::VariableMap::remove ( StringRef name)

Remove the variable with the given name.

Returns
True if the variable existed and was removed, false if it didn't exist in the first place.

Definition at line 52 of file path_templates.cc.

Referenced by blender::bke::tests::TEST_F().


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