MCPcopy Create free account
hub / github.com/RevoSucks/BM64Recomp / add_resource_impl

Method add_resource_impl

src/ui/core/ui_context.cpp:496–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494}
495
496recompui::Style* recompui::ContextId::add_resource_impl(std::unique_ptr<Style>&& resource) {
497 // Ensure a context is currently opened by this thread.
498 if (opened_context_id == ContextId::null()) {
499 context_error(*this, ContextErrorType::AddResourceWithoutOpen);
500 }
501
502 // Check that the context that was specified is the same one that's currently open.
503 if (*this != opened_context_id) {
504 context_error(*this, ContextErrorType::AddResourceToWrongContext);
505 }
506
507 bool is_element = resource->is_element();
508 Style* resource_ptr = resource.get();
509 auto key = opened_context->resources.emplace(std::move(resource));
510
511 if (is_element) {
512 Element* element_ptr = static_cast<Element*>(resource_ptr);
513 element_ptr->set_id(std::string{element_ptr->get_type_name()} + "-" + std::to_string(key.raw));
514 key.set_tag(static_cast<uint8_t>(SlotTag::Element));
515 // Send one update to the element.
516 opened_context->to_update.emplace(ResourceId{ key.raw });
517 }
518 else {
519 key.set_tag(static_cast<uint8_t>(SlotTag::Style));
520 }
521
522 resource_ptr->resource_id = { key.raw };
523 return resource_ptr;
524}
525
526void recompui::ContextId::add_loose_element(Element* element) {
527 // Ensure a context is currently opened by this thread.

Callers

nothing calls this directly

Calls 7

context_errorFunction · 0.85
emplaceMethod · 0.80
set_idMethod · 0.80
is_elementMethod · 0.45
getMethod · 0.45
get_type_nameMethod · 0.45
set_tagMethod · 0.45

Tested by

no test coverage detected