diff --git a/build-python/meson.build b/build-python/meson.build index b7adeae..7141c6e 100644 --- a/build-python/meson.build +++ b/build-python/meson.build @@ -7,10 +7,12 @@ py_mod = py_installation.extension_module( meson.project_source_root() + '/src/python/bindings.cpp', meson.project_source_root() + '/src/python/composition/bindings.cpp', meson.project_source_root() + '/src/python/const/bindings.cpp', + meson.project_source_root() + '/src/python/config/bindings.cpp', ], dependencies : [ pybind11_dep, const_dep, + config_dep, composition_dep, species_weight_dep ], diff --git a/meson_options.txt b/meson_options.txt index cc87109..6c51e48 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,11 @@ +# Build options for the project + +# Usage: +# -Doption_name=value + +# -Dbuild_tests=true (default) build tests +# -Duser_mode=false (default) enable user mode (set mode = 0) If user mode is enabled then the optimization level is set to 3 and the build type is set to release +# -Dbuild_python=true (default) build Python bindings option('build_tests', type: 'boolean', value: true, description: 'Build tests') option('user_mode', type: 'boolean', value: false, description: 'Enable user mode (set mode = 0)') option('build_python', type: 'boolean', value: true, description: 'Build Python bindings') diff --git a/src/config/public/config.h b/src/config/public/config.h index 33a901c..3f0c8fe 100644 --- a/src/config/public/config.h +++ b/src/config/public/config.h @@ -18,8 +18,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // *********************************************************************** */ -#ifndef CONFIG_H -#define CONFIG_H +#pragma once #include #include @@ -134,12 +133,6 @@ public: */ bool loadConfig(const std::string& configFilePath); - /** - * @brief Get the input table from the configuration. - * @return Input table as a string. - */ - std::string getInputTable() const; - /** * @brief Get a configuration value by key. * @tparam T Type of the value to retrieve. @@ -234,8 +227,6 @@ public: // Setup gTest class as a friend friend class configTestPrivateAccessor; - // -- Resource Manager is a friend of config so it can create a seperate instance + // --- Resource Manager is a friend of config so it can create a separate instance friend class ResourceManager; }; - -#endif \ No newline at end of file diff --git a/src/python/bindings.cpp b/src/python/bindings.cpp index 4b56e17..1eb5d01 100644 --- a/src/python/bindings.cpp +++ b/src/python/bindings.cpp @@ -4,6 +4,7 @@ #include "const/bindings.h" #include "composition/bindings.h" +#include "config/bindings.h" PYBIND11_MODULE(fourdsse_bindings, m) { m.doc() = "Python bindings for the 4DSSE project"; @@ -13,4 +14,7 @@ PYBIND11_MODULE(fourdsse_bindings, 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); } \ No newline at end of file diff --git a/src/python/config/bindings.cpp b/src/python/config/bindings.cpp new file mode 100644 index 0000000..69e04ca --- /dev/null +++ b/src/python/config/bindings.cpp @@ -0,0 +1,55 @@ +#include +#include // Needed for vectors, maps, sets, strings +#include // Needed for binding std::vector, std::map etc if needed directly + +#include +#include "bindings.h" + +#include "config.h" + +namespace py = pybind11; + +// Helper function template for binding Config::get +template +void def_config_get(py::module &m) { + m.def("get", + [](const std::string &key, T defaultValue) { + return Config::getInstance().get(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(config_submodule); + def_config_get(config_submodule); + def_config_get(config_submodule); + def_config_get(config_submodule); + + config_submodule.def("loadConfig", + [](const std::string& configFilePath) { + return Config::getInstance().loadConfig(configFilePath); + }, + py::arg("configFilePath"), + "Load configuration from a YAML file."); + + config_submodule.def("has", + [](const std::string &key) { + return Config::getInstance().has(key); + }, + py::arg("key"), + "Check if a key exists in the configuration."); + + config_submodule.def("keys", + []() { + return py::cast(Config::getInstance().keys()); + }, + "Get a list of all configuration keys."); + + config_submodule.def("__repr__", + []() { + std::ostringstream oss; + oss << Config::getInstance(); // Use the existing operator<< + return std::string("\n") + oss.str(); + }); +} diff --git a/src/python/config/bindings.h b/src/python/config/bindings.h new file mode 100644 index 0000000..30fcae7 --- /dev/null +++ b/src/python/config/bindings.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void register_config_bindings(pybind11::module &config_submodule); diff --git a/src/python/config/meson.build b/src/python/config/meson.build new file mode 100644 index 0000000..cfc749c --- /dev/null +++ b/src/python/config/meson.build @@ -0,0 +1,17 @@ +# Define the library +bindings_sources = files('bindings.cpp') +bindings_headers = files('bindings.h') + +dependencies = [ + config_dep, + python3_dep, + pybind11_dep, +] + +shared_module('py_config', + bindings_sources, + include_directories: include_directories('.'), + cpp_args: ['-fvisibility=default'], + install : true, + dependencies: dependencies, +) \ No newline at end of file diff --git a/src/python/meson.build b/src/python/meson.build index be2d427..4d21619 100644 --- a/src/python/meson.build +++ b/src/python/meson.build @@ -1,2 +1,3 @@ subdir('composition') -subdir('const') \ No newline at end of file +subdir('const') +subdir('config') \ No newline at end of file