13 std::map<std::string, std::string> result;
17 if (entry && entry->save) text = entry->
save(ctx, component);
18 if (text.empty() && !component.config_path.empty()) {
19 auto path =
io::utf8_path(component.resolved_config_path.empty()
20 ? component.config_path : component.resolved_config_path);
22 std::ifstream file(path, std::ios::binary);
23 if (!file)
throw std::runtime_error(
"Cannot preserve component configuration: " +
io::path_utf8(path));
24 text.assign(std::istreambuf_iterator<char>(file), {});
25 if (file.bad())
throw std::runtime_error(
"Cannot finish reading component configuration");
27 if (!text.empty()) result[component.id] = std::move(text);
33 const std::map<std::string, std::string>& content) {
34 if (content.empty())
return;
36 folder +=
".resources";
37 folder /=
"components";
38 std::filesystem::create_directories(folder);
41 const auto found = content.find(component.id);
42 if (found == content.end())
continue;
43 const auto path = std::filesystem::absolute(folder / (std::to_string(index++) +
".cfg"));
45 if (!file.
stream() || std::fwrite(found->second.data(), 1, found->second.size(), file.
stream()) != found->second.size()
46 || !file.
commit())
throw std::runtime_error(
"Cannot restore component configuration: " + file.
error());
47 component.config_path = component.resolved_config_path =
io::path_utf8(path);
Checked serialization and publication of a single output file.
Opening files by UTF-8 path on every platform.
Registry + config-file delivery for [PROCESS_COMPONENTS] (Unified Transport suite D-UT8; phases IO1–I...
The central, reentrant simulation context for the new engine.
static ProcessComponentRegistry & instance()
Access the process-global lazily constructed builtin hook registry.
Definition ProcessComponentRegistry.cpp:180
const ProcessComponentEntry * find(const std::string &id) const
Borrow one exact component registry entry.
Definition ProcessComponentRegistry.cpp:192
Own a staging stream and publish it by a checked single-file rename.
Definition AtomicOutputFile.hpp:36
FILE * stream() const
Borrow the writable staging stream.
Definition AtomicOutputFile.hpp:139
const std::string & error() const
Borrow the latest stored file-operation diagnostic.
Definition AtomicOutputFile.hpp:145
bool commit()
Flush, sync, close and attempt to rename staging over the destination.
Definition AtomicOutputFile.hpp:157
std::filesystem::path utf8_path(const std::string &utf8)
Convert borrowed path bytes into an owned native filesystem path.
Definition FileIO.hpp:55
std::string path_utf8(const std::filesystem::path &p, bool generic=false)
Copy a native path into the engine byte-string representation.
Definition FileIO.hpp:99
Definition NativeModelBundle.hpp:11
std::map< std::string, std::string > configurations(const SimulationContext &ctx)
Definition NativeModelBundle.hpp:12
void restoreConfigurations(SimulationContext &ctx, const std::map< std::string, std::string > &content)
Definition NativeModelBundle.hpp:32
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
std::string inp_file_path
Path to the input .inp file (empty if not opened from a file).
Definition SimulationContext.hpp:2039
std::vector< ProcessComponentSpec > process_component_specs
Process-component registrations parsed from [PROCESS_COMPONENTS].
Definition SimulationContext.hpp:955
ComponentConfigSave save
Definition ProcessComponentRegistry.hpp:144