/* * This source code is released into the public domain. */ module; #include export module liblfvm:context; namespace lfvm { /* * Our global context. */ export struct context { // The database directory where our configuration is stored. auto dbdir(this context const &self) -> std::filesystem::path { return self._dbdir; } // The directory where VM configurations are stored (usually a // subdirectory of dbdir). auto vmconfdir(this context const &self) -> std::filesystem::path { return self.dbdir() / "vm"; } // The directory where disk configurations are stored (usually a // subdirectory of dbdir). auto diskconfdir(this context const &self) -> std::filesystem::path { return self.dbdir() / "disk"; } // The path to our configuration file. auto config_file(this context const &self) -> std::filesystem::path { return self.dbdir() / "config.ucl"; } // The configuration file for a particular VM. auto vm_config_file(this context const &self, std::string_view vm_name) -> std::filesystem::path { using namespace std::literals; return self.vmconfdir() / (vm_name + ".ucl"s); } // The configuration file for a particular disk. auto disk_config_file(this context const &self, std::string_view disk_name) -> std::filesystem::path { using namespace std::literals; return self.diskconfdir() / (disk_name + ".ucl"s); } private: std::filesystem::path _dbdir = LFVM_DBDIR; }; export auto get_context() -> context & { static context ctx; return ctx; } } // namespace lfvm