in src/esp/bindings/AttributesManagersBindings.cpp [47:244]
void declareBaseAttributesManager(py::module& m,
const std::string& attrType,
const std::string& classStrPrefix) {
using MgrClass = AttributesManager<T, Access>;
using AttribsPtr = std::shared_ptr<T>;
// Most, but not all, of these methods are from ManagedContainer class
// template. However, we use AttributesManager as the base class because we
// wish to have appropriate (attributes-related) argument nomenclature and
// documentation.
std::string pyclass_name = classStrPrefix + std::string("AttributesManager");
py::class_<MgrClass, std::shared_ptr<MgrClass>>(m, pyclass_name.c_str())
.def("get_template_handle_by_id", &MgrClass::getObjectHandleByID,
("Returns string handle for the " + attrType +
" template corresponding to passed ID.")
.c_str(),
"template_id"_a)
.def(
"get_template_id_by_handle",
py::overload_cast<const std::string&>(&MgrClass::getObjectIDByHandle),
("Returns integer ID for the " + attrType +
" template with the passed handle.")
.c_str(),
"handle"_a)
.def("get_template_handles",
static_cast<std::vector<std::string> (MgrClass::*)(
const std::string&, bool, bool) const>(
&MgrClass::getObjectHandlesBySubstring),
("Returns a potentially sorted list of " + attrType +
" template handles that either contain or "
"explicitly do not contain the passed search_str, based on the "
"value of boolean contains.")
.c_str(),
"search_str"_a = "", "contains"_a = true, "sorted"_a = true)
.def("get_templates_info", &MgrClass::getObjectInfoStrings,
("Returns a list of CSV strings describing each " + attrType +
" template whose handles either contain or explicitly do not "
"contain the passed search_str, based on the value of boolean "
"contains.")
.c_str(),
"search_str"_a = "", "contains"_a = true)
.def("get_templates_CSV_info", &MgrClass::getObjectInfoCSVString,
("Returns a comma-separated string describing each " + attrType +
" template whose handles either contain or explicitly do not "
"contain the passed search_str, based on the value of boolean "
"contains. Each template's info is separated by a newline.")
.c_str(),
"search_str"_a = "", "contains"_a = true)
.def(
"load_configs",
static_cast<std::vector<int> (MgrClass::*)(const std::string&, bool)>(
&MgrClass::loadAllJSONConfigsFromPath),
("Build " + attrType +
" templates for all JSON files with appropriate extension "
"that exist in the provided file or directory path. If "
"save_as_defaults is true, then these " +
attrType + " templates will be unable to be deleted")
.c_str(),
"path"_a, "save_as_defaults"_a = false)
.def("create_template",
static_cast<AttribsPtr (MgrClass::*)(const std::string&, bool)>(
&MgrClass::createObject),
("Creates a " + attrType +
" template based on passed handle, and registers it "
"in the library if register_template is True.")
.c_str(),
"handle"_a, "register_template"_a = true)
.def("create_new_template",
static_cast<AttribsPtr (MgrClass::*)(const std::string&, bool)>(
&MgrClass::createDefaultObject),
("Creates a " + attrType +
" template built with default values, and registers "
"it in the library if register_template is True.")
.c_str(),
"handle"_a, "register_template"_a = false)
.def(
"is_valid_filename",
[](CORRADE_UNUSED MgrClass& self, const std::string& filename) {
return Corrade::Utility::Directory::exists(filename);
},
R"(Returns whether the passed handle is a valid, existing file.)",
"handle"_a)
.def("get_num_templates", &MgrClass::getNumObjects,
("Returns the number of existing " + attrType +
" templates being managed.")
.c_str())
.def("get_random_template_handle", &MgrClass::getRandomObjectHandle,
("Returns the handle for a random " + attrType +
" template chosen"
" from the existing " +
attrType + " templates being managed.")
.c_str())
.def("get_undeletable_handles", &MgrClass::getUndeletableObjectHandles,
("Returns a list of " + attrType + " template handles for " +
attrType +
" templates that have been marked undeletable by the system. "
"These " +
attrType + " templates can still be edited.")
.c_str())
.def(
"get_user_locked_handles", &MgrClass::getUserLockedObjectHandles,
("Returns a list of " + attrType + " template handles for " +
attrType +
" templates that have been marked locked by the user. These will be "
"undeletable until unlocked by the user. These " +
attrType + " templates can still be edited.")
.c_str())
.def("get_library_has_handle", &MgrClass::getObjectLibHasHandle,
("Returns whether the passed handle describes an existing " +
attrType + " template in the library.")
.c_str(),
"handle"_a)
.def("get_library_has_id", &MgrClass::getObjectLibHasID,
("Returns whether the passed template ID describes an existing " +
attrType + " template in the library.")
.c_str(),
"template_id"_a)
.def("set_template_lock", &MgrClass::setLock,
("This sets the lock state for the " + attrType +
" template that has the passed name. Lock == True makes the " +
attrType + " template unable to be deleted. Note : Locked " +
attrType + " templates can still be edited.")
.c_str(),
"handle"_a, "lock"_a)
.def("set_lock_by_substring", &MgrClass::setLockBySubstring,
("This sets the lock state for all " + attrType +
" templates whose handles either contain or explicitly do not "
"contain the passed search_str. Returns a list of handles for " +
attrType +
" templates locked by this function call. Lock == True makes the " +
attrType + " template unable to be deleted. Note : Locked " +
attrType + " templates can still be edited.")
.c_str(),
"lock"_a, "search_str"_a = "", "contains"_a = true)
.def("set_template_list_lock", &MgrClass::setLockByHandles,
("This sets the lock state for all " + attrType +
" templates whose handles are passed "
"in list. Returns a list of handles for templates locked by this "
"function call. Lock == True makes the " +
attrType + " template unable to be deleted. Note : Locked " +
attrType + " templates can still be edited.")
.c_str(),
"handles"_a, "lock"_a)
.def("remove_all_templates", &MgrClass::removeAllObjects,
("This removes, and returns, a list of all the " + attrType +
" templates referenced in the library that have not been marked "
"undeletable by the system or read-only by the user.")
.c_str())
.def("remove_templates_by_str", &MgrClass::removeObjectsBySubstring,
("This removes, and returns, a list of all the " + attrType +
" templates referenced in the library that have not been marked "
"undeletable by the system or read-only by the user and whose "
"handles either contain or explicitly do not contain the passed "
"search_str.")
.c_str(),
"search_str"_a = "", "contains"_a = true)
.def("remove_template_by_id", &MgrClass::removeObjectByID,
("This removes, and returns the " + attrType +
" template referenced by the passed ID from the library.")
.c_str(),
"template_id"_a)
.def("remove_template_by_handle", &MgrClass::removeObjectByHandle,
("This removes, and returns the " + attrType +
" template referenced by the passed handle from the library.")
.c_str(),
"handle"_a)
.def("register_template", &MgrClass::registerObject,
("This registers a copy of the passed " + attrType +
" template in the library, and returns the template's integer ID.")
.c_str(),
"template"_a, "specified_handle"_a = "",
"force_registration"_a = false)
.def("get_template_by_id",
static_cast<AttribsPtr (MgrClass::*)(int)>(
&MgrClass::getObjectOrCopyByID),
("This returns a copy of the " + attrType +
" template specified by the passed ID if it exists, and NULL if it "
"does not.")
.c_str(),
"template_id"_a)
.def("get_template_by_handle",
static_cast<AttribsPtr (MgrClass::*)(const std::string&)>(
&MgrClass::getObjectOrCopyByHandle),
("This returns a copy of the " + attrType +
" template specified by the passed handle if it exists, and NULL "
"if it does not.")
.c_str(),
"handle"_a)
.def("get_templates_by_handle_substring",
static_cast<std::unordered_map<std::string, AttribsPtr> (
MgrClass::*)(const std::string&, bool)>(
&MgrClass::getObjectsByHandleSubstring),
("Returns a dictionary of " + attrType +
" templates, keyed by their handles, for all handles that either "
"contain or explicitly do not contain the passed search_str, based "
"on the value of boolean contains.")
.c_str(),
"search_str"_a = "", "contains"_a = true);
} // declareBaseAttributesManager