MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ load_config_from_file()

MAYAFLUX_API bool MayaFlux::Config::load_config_from_file ( const std::string &  path)

Load engine configuration from a JSON file, applying any present fields to the pre-Init config structs.

Parameters
pathPath to a mayaflux.json file.
Returns
True if the file was read and at least partially applied. False if the file could not be opened or parsed; last_error() will be set.
Note
Must be called before Init(). Fields absent from the file retain defaults.

Definition at line 189 of file Config.cpp.

190{
192 auto result = ser.read<EngineConfig>(path);
193 if (!result) {
194 MF_ERROR(Journal::Component::API, Journal::Context::Configuration,
195 "Failed to load config from {}: {}", path, ser.last_error());
196 return false;
197 }
198 get_global_stream_info() = result->stream;
199 get_global_graphics_config() = result->graphics;
200 get_global_input_config() = result->input;
201 get_global_network_config() = result->network;
202
203 const auto& j = result->journal;
204
205 if (!j.severity.empty()) {
206 auto sev = Reflect::string_to_enum_case_insensitive<Journal::Severity>(j.severity);
207 if (sev) {
208 Config::set_journal_severity(*sev);
209 } else {
210 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
211 "Unknown journal severity: {}", j.severity);
212 }
213 }
214 if (j.sink_to_console)
215 Config::sink_journal_to_console();
216 if (!j.log_file.empty())
217 Config::store_journal_entries(j.log_file);
218 for (const auto& name : j.disable_components) {
219 auto comp = Reflect::string_to_enum_case_insensitive<Journal::Component>(name);
220 if (comp) {
221 Config::set_journal_component_filter({ *comp }, false);
222 } else {
223 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
224 "Unknown journal component: {}", name);
225 }
226 }
227
228 for (const auto& name : j.disable_contexts) {
229 auto ctx = Reflect::string_to_enum_case_insensitive<Journal::Context>(name);
230 if (ctx) {
231 Config::set_journal_context_filter({ *ctx }, false);
232 } else {
233 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
234 "Unknown journal context: {}", name);
235 }
236 }
237
238 std::vector<Journal::Component> included_components;
239 for (const auto& name : j.include_components) {
240 auto comp = Reflect::string_to_enum_case_insensitive<Journal::Component>(name);
241 if (comp) {
242 included_components.push_back(*comp);
243 } else {
244 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
245 "Unknown journal component: {}", name);
246 }
247 }
248 Config::set_journal_component_includes(included_components);
249
250 std::vector<Journal::Context> included_contexts;
251 for (const auto& name : j.include_contexts) {
252 auto ctx = Reflect::string_to_enum_case_insensitive<Journal::Context>(name);
253 if (ctx) {
254 included_contexts.push_back(*ctx);
255 } else {
256 MF_WARN(Journal::Component::API, Journal::Context::Configuration,
257 "Unknown journal context: {}", name);
258 }
259 }
260 Config::set_journal_context_includes(included_contexts);
261
262 return true;
263}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::vector< std::string > include_contexts
Definition Config.cpp:24
std::vector< std::string > disable_contexts
Definition Config.cpp:22
std::vector< std::string > disable_components
Definition Config.cpp:21
std::vector< std::string > include_components
Definition Config.cpp:23
std::string name
Definition VKDevice.cpp:123
std::optional< T > read(const std::string &path)
Read path and deserialize into T.
const std::string & last_error() const
Last error message, empty if no error.
Converts arbitrary C++ types to/from JSON strings and disk files.

References MayaFlux::Journal::API, MayaFlux::Journal::Configuration, get_global_graphics_config(), get_global_input_config(), get_global_network_config(), get_global_stream_info(), MayaFlux::IO::JSONSerializer::last_error(), MF_ERROR, MF_WARN, name, MayaFlux::IO::JSONSerializer::read(), set_journal_component_filter(), set_journal_component_includes(), set_journal_context_filter(), set_journal_context_includes(), set_journal_severity(), sink_journal_to_console(), and store_journal_entries().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: