feat(reflection): Bring in new libconfig
This version of fourdst (v0.9.14) brings in the version libconfig which includes reflection based config filed (v2.0.2). This is a breaking change as any code which used versions of libconfig < v2.0.0 will no longer function when linked against this version of fourdst
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -78,6 +78,8 @@ subprojects/libplugin/
|
||||
subprojects/minizip-ng-*
|
||||
subprojects/.wraplock
|
||||
subprojects/openssl-*
|
||||
subprojects/glaze/
|
||||
subprojects/tomlplusplus-*/
|
||||
|
||||
*.csv
|
||||
*.dot
|
||||
@@ -87,6 +89,8 @@ quill.wrap
|
||||
yaml-cpp.wrap
|
||||
minizip-ng.wrap
|
||||
openssl.wrap
|
||||
glaze.wrap
|
||||
tomlplusplus.wrap
|
||||
|
||||
.vscode/
|
||||
|
||||
|
||||
@@ -5,6 +5,3 @@ config_p = subproject('libconfig',
|
||||
'build_examples=false'
|
||||
])
|
||||
config_dep = config_p.get_variable('config_dep')
|
||||
libconfig = config_p.get_variable('libconfig')
|
||||
|
||||
alias_target('build-libconfig', libconfig)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# --- Python Extension Setup ---
|
||||
py_installation = import('python').find_installation('python3', pure: false)
|
||||
|
||||
py_mod = py_installation.extension_module(
|
||||
'_phys', # Name of the generated .so/.pyd file (without extension)
|
||||
'_phys',
|
||||
sources: [
|
||||
meson.project_source_root() + '/src-pybind/bindings.cpp',
|
||||
meson.project_source_root() + '/src-pybind/composition/bindings.cpp',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
project('fourdst', 'cpp', version: 'v0.9.13', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0')
|
||||
project('fourdst', 'cpp', version: 'v0.9.14', default_options: ['cpp_std=c++23'], meson_version: '>=1.5.0')
|
||||
|
||||
add_project_arguments('-fvisibility=default', language: 'cpp')
|
||||
|
||||
@@ -9,7 +9,5 @@ subdir('build-config')
|
||||
# Configure python bindings
|
||||
if get_option('build_python')
|
||||
subdir('build-python')
|
||||
|
||||
subdir('src-pybind')
|
||||
endif
|
||||
|
||||
|
||||
@@ -21,6 +21,6 @@ PYBIND11_MODULE(_phys, m) {
|
||||
auto constMod = m.def_submodule("constants", "Constants-module bindings");
|
||||
register_const_bindings(constMod);
|
||||
|
||||
auto configMod = m.def_submodule("config", "Configuration-module bindings");
|
||||
register_config_bindings(configMod);
|
||||
const auto configMod = m.def_submodule("config", "Configuration-module bindings");
|
||||
register_config_enums(configMod);
|
||||
}
|
||||
@@ -1,55 +1,17 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h> // Needed for vectors, maps, sets, strings
|
||||
#include <pybind11/stl_bind.h> // Needed for binding std::vector, std::map etc if needed directly
|
||||
|
||||
#include <string>
|
||||
#include "bindings.h"
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include "fourdst/config/config.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
void register_config_enums(const pybind11::module_& m) {
|
||||
using namespace fourdst::config;
|
||||
pybind11::enum_<ConfigState>(m, "ConfigState")
|
||||
.value("DEFAULT", ConfigState::DEFAULT)
|
||||
.value("LOADED_FROM_FILE", ConfigState::LOADED_FROM_FILE)
|
||||
.export_values();
|
||||
|
||||
// Helper function template for binding Config::get
|
||||
template <typename T>
|
||||
void def_config_get(py::module &m) {
|
||||
m.def("get",
|
||||
[](const std::string &key, T defaultValue) {
|
||||
return fourdst::config::Config::getInstance().get<T>(key, defaultValue);
|
||||
},
|
||||
py::arg("key"), py::arg("defaultValue"),
|
||||
"Get configuration value (type inferred from default)");
|
||||
}
|
||||
|
||||
void register_config_bindings(pybind11::module &config_submodule) {
|
||||
def_config_get<int>(config_submodule);
|
||||
def_config_get<double>(config_submodule);
|
||||
def_config_get<std::string>(config_submodule);
|
||||
def_config_get<bool>(config_submodule);
|
||||
|
||||
config_submodule.def("loadConfig",
|
||||
[](const std::string& configFilePath) {
|
||||
return fourdst::config::Config::getInstance().loadConfig(configFilePath);
|
||||
},
|
||||
py::arg("configFilePath"),
|
||||
"Load configuration from a YAML file.");
|
||||
|
||||
config_submodule.def("has",
|
||||
[](const std::string &key) {
|
||||
return fourdst::config::Config::getInstance().has(key);
|
||||
},
|
||||
py::arg("key"),
|
||||
"Check if a key exists in the configuration.");
|
||||
|
||||
config_submodule.def("keys",
|
||||
[]() {
|
||||
return py::cast(fourdst::config::Config::getInstance().keys());
|
||||
},
|
||||
"Get a list of all configuration keys.");
|
||||
|
||||
config_submodule.def("__repr__",
|
||||
[]() {
|
||||
std::ostringstream oss;
|
||||
oss << fourdst::config::Config::getInstance(); // Use the existing operator<<
|
||||
return std::string("<fourdsse_bindings.config module accessing C++ Singleton>\n") + oss.str();
|
||||
});
|
||||
pybind11::enum_<RootNameLoadPolicy>(m, "RootNameLoadPolicy")
|
||||
.value("FROM_FILE", RootNameLoadPolicy::FROM_FILE)
|
||||
.value("KEEP_CURRENT", RootNameLoadPolicy::KEEP_CURRENT)
|
||||
.export_values();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include "fourdst/config/config.h"
|
||||
|
||||
void register_config_bindings(pybind11::module &config_submodule);
|
||||
#include <string>
|
||||
#include <format>
|
||||
|
||||
void register_config_enums(const pybind11::module_& m);
|
||||
|
||||
template <typename ConfigType>
|
||||
pybind11::class_<ConfigType> bind_config_specialization(pybind11::module_& m , const std::string& name) {
|
||||
return pybind11::class_<ConfigType>(m, name.c_str())
|
||||
.def(pybind11::init<>())
|
||||
.def("load", &ConfigType::load, pybind11::arg("file_path"), "Load configuration from a file.")
|
||||
.def("save", &ConfigType::save, pybind11::arg("file_path") = "config_output.toml", "Save configuration to a file.")
|
||||
.def("save_schema", &ConfigType::save_schema, pybind11::arg("directory") = ".", "Save the configuration schema to a directory.")
|
||||
.def("get_state", &ConfigType::get_state, "Get the current state of the configuration.")
|
||||
.def("describe_state", &ConfigType::describe_state, "Get the current state of the configuration.")
|
||||
.def("__repr__",
|
||||
[](const ConfigType &cfg) -> std::string {
|
||||
return std::format("{}", cfg);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
subdir('composition')
|
||||
subdir('constants')
|
||||
subdir('config')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/4D-STAR/libconfig.git
|
||||
revision = v1.1.4
|
||||
revision = v2.0.2
|
||||
depth = 1
|
||||
|
||||
Reference in New Issue
Block a user