MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / initialize

Method initialize

framework/platform/platform.cpp:48–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48ExitCode Platform::initialize(const std::vector<Plugin *> &plugins_)
49{
50 plugins = plugins_;
51
52 auto sinks = get_platform_sinks();
53
54 auto logger = std::make_shared<spdlog::logger>("logger", sinks.begin(), sinks.end());
55
56#ifdef VKB_DEBUG
57 logger->set_level(spdlog::level::debug);
58#else
59 logger->set_level(spdlog::level::info);
60#endif
61
62 logger->set_pattern(LOGGER_FORMAT);
63 spdlog::set_default_logger(logger);
64
65 LOGI("Logger initialized");
66
67 // To get the error messages formatted as we like them to have, exit after initializing the logger, earliest
68 if (arguments.empty())
69 {
70 return ExitCode::NoSample;
71 }
72 else if (std::ranges::any_of(arguments, [](auto const &arg) { return arg == "-h" || arg == "--help"; }))
73 {
74 return ExitCode::Help;
75 }
76
77 for (auto const &plugin : plugins)
78 {
79 plugin->set_platform(this);
80 for (auto const &command : plugin->get_commands())
81 {
82 auto [it, inserted] = command_map.insert(std::make_pair(command.first, plugin));
83 if (!inserted)
84 {
85 LOGE("Command \"{}\" from plugin \"{}\" is already listed for plugin \"{}\"!", command.first, plugin->get_name(), it->second->get_name());
86 }
87 }
88 for (auto const &option : plugin->get_options())
89 {
90 auto [it, inserted] = option_map.insert(std::make_pair(option.first, plugin));
91 if (!inserted)
92 {
93 LOGE("Option \"{}\" from plugin \"{}\" is already listed for plugin \"{}\"!", option.first, plugin->get_name(), it->second->get_name());
94 }
95 }
96 }
97
98 std::deque<std::string> argumentDeque(arguments.begin(), arguments.end());
99
100 // the arguments have to start with a command
101 auto commandIt = command_map.find(argumentDeque[0]);
102 if (commandIt == command_map.end())
103 {
104 LOGE("Command \"{}\" is unknown!", argumentDeque[0]);
105 return ExitCode::Help;

Callers 1

CUSTOM_MAINFunction · 0.45

Calls 9

endMethod · 0.80
emptyMethod · 0.80
set_platformMethod · 0.80
get_nameMethod · 0.80
beginMethod · 0.45
insertMethod · 0.45
handle_commandMethod · 0.45
handle_optionMethod · 0.45
trigger_commandMethod · 0.45

Tested by

no test coverage detected