diff --git a/documentation/config.rst b/documentation/config.rst index c92f636c..e344b9b0 100644 --- a/documentation/config.rst +++ b/documentation/config.rst @@ -78,6 +78,18 @@ Config file directives: +* ``python_builtin``, specify if particular class/struct should be considered a python builtin and assume existing bindings for it already exist. + The purpose of this directive is to allow developer to allow developers to toggle if bindings for types like ``std::optional`` or ``pybind11::dict`` should be + generated, or if binder should assume such bindings already exist somewhere else. Alternatively, a developer could declare a type as not-builtin if they + would prefer to force binder to generate bindings for it. Note that ``-python_builtin ab`c` always overrides ``+python_builtin abc``. + +.. code-block:: bash + + -python_builtin std::less + +python_builtin std::vector + + + * ``function``, specify if particular function should be bound. This could be used for both template and normal function. .. code-block:: bash diff --git a/source/config.cpp b/source/config.cpp index c8669282..ae0a2757 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -57,6 +57,8 @@ void Config::read(string const &file_name) string const _function_{"function"}; string const _class_{"class"}; + string const _python_builtin_{"python_builtin"}; + string const _include_{"include"}; string const _include_for_class_{"include_for_class"}; string const _include_for_namespace_{"include_for_namespace"}; @@ -116,6 +118,11 @@ void Config::read(string const &file_name) if( bind ) classes_to_bind.push_back(name_without_spaces); else classes_to_skip.push_back(name_without_spaces); } + else if( token == _python_builtin_ ) { + + if (bind) python_builtins.insert(name_without_spaces); + else not_python_builtins.insert(name_without_spaces); + } else if( token == _function_ ) { if( bind ) functions_to_bind.push_back(name_without_spaces); diff --git a/source/config.hpp b/source/config.hpp index 04f33c66..54e278a5 100644 --- a/source/config.hpp +++ b/source/config.hpp @@ -14,6 +14,7 @@ #ifndef _INCLUDED_config_hpp_ #define _INCLUDED_config_hpp_ +#include #include #include #include @@ -68,6 +69,8 @@ class Config std::map const &binder_for_namespaces() const { return binder_for_namespaces_; } std::map const &add_on_binder_for_namespaces() const { return add_on_binder_for_namespaces_; } + std::set python_builtins, not_python_builtins; + std::map > const &class_includes() const { return class_includes_; } std::map > const &namespace_includes() const { return namespace_includes_; } diff --git a/source/type.cpp b/source/type.cpp index e19efe46..b780145f 100644 --- a/source/type.cpp +++ b/source/type.cpp @@ -725,8 +725,15 @@ bool is_python_builtin(NamedDecl const *C) "pybind11::array_t", }; - for( auto &k : known_builtin ) { - // if( begins_with(name, k) ) return true; + // Not builtin's + for ( const auto &k : Config::get().not_python_builtins ) { + if ( name == k ) return false; + } + // Builtins + for( const auto &k : known_builtin ) { + if( name == k ) return true; + } + for( const auto &k : Config::get().python_builtins ) { if( name == k ) return true; }