diff --git a/source/class.cpp b/source/class.cpp index 79073f7d..32b42194 100644 --- a/source/class.cpp +++ b/source/class.cpp @@ -1229,7 +1229,7 @@ void ClassBinder::bind(Context &context) if( named_class ) { if (Config::get().is_smart_holder_requested(qualified_name_without_template)) { c += '\t' + - R"(PYBIND11_TYPE_CASTER_BASE_HOLDER({}, {})"_format(qualified_name, maybe_holder_type) + + R"(PYBIND11_TYPE_CASTER_BASE_HOLDER({} {}))"_format(qualified_name, maybe_holder_type) + '\n'; } c += '\t' + diff --git a/test/T61.smart_holder.config b/test/T61.smart_holder.config new file mode 100644 index 00000000..3dfc4c24 --- /dev/null +++ b/test/T61.smart_holder.config @@ -0,0 +1,2 @@ ++custom_shared my_shared_ptr ++smart_holder A \ No newline at end of file diff --git a/test/T61.smart_holder.hpp b/test/T61.smart_holder.hpp new file mode 100644 index 00000000..737420cf --- /dev/null +++ b/test/T61.smart_holder.hpp @@ -0,0 +1,54 @@ +// -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*- +// vi: set ts=2 noet: +// +// Copyright (c) 2016 Sergey Lyskov +// +// All rights reserved. Use of this source code is governed by a +// MIT license that can be found in the LICENSE file. + +/// @file binder/test/T01.enum.hpp +/// @brief Binder self-test file. Bindings of enum's functionality. +/// @author Sergey Lyskov + +#ifndef _INCLUDED_T60_hpp_ +#define _INCLUDED_T60_hpp_ + +#include + +template +using my_shared_ptr = std::shared_ptr; + +enum E1 { E1_V0, E1_V1 }; + +enum struct E2_struct { V0, V1 }; +enum class E3_class { V0, V1 }; + + +template +class A +{ +public: + enum AE1 { AE1_V0, AE1_V1 }; + enum struct AE2_struct { AE3_V0, AE3_V1 }; + enum class AE3_class { AE2_V0, AE2_V1 }; + +protected: + enum AE3_not_binded { AE3_V0_not_binded, AE3_V1_not_binded }; + enum class AE4_not_binded { AE4_V0_not_binded, AE4_V1_not_binded }; + +private: + enum AE5_not_binded { AE5_V0_not_binded, AE5_V1_not_binded }; + enum class AE6_not_binded { AE6_V0_not_binded, AE6_V1_not_binded }; +}; + +void fi_instantiated_by_use_in_function(A) +{ +} +void fi(A &) +{ +} +void fi(A *) +{ +} + +#endif // _INCLUDED_T01_enum_hpp_ diff --git a/test/T61.smart_holder.ref b/test/T61.smart_holder.ref new file mode 100644 index 00000000..9bc19f86 --- /dev/null +++ b/test/T61.smart_holder.ref @@ -0,0 +1,126 @@ +// File: T61_smart_holder.cpp +#include // A +#include // E1 +#include // E2_struct +#include // E3_class +#include // fi +#include // fi_instantiated_by_use_in_function +#include // __str__ + +#include +#include +#include + +#ifndef BINDER_PYBIND11_TYPE_CASTER + #define BINDER_PYBIND11_TYPE_CASTER + PYBIND11_DECLARE_HOLDER_TYPE(T, my_shared_ptr) + PYBIND11_DECLARE_HOLDER_TYPE(T, T*) + PYBIND11_MAKE_OPAQUE(my_shared_ptr) +#endif + +void bind_T61_smart_holder(std::function< pybind11::module &(std::string const &namespace_) > &M) +{ + // E1 file:T61.smart_holder.hpp line:21 + pybind11::enum_(M(""), "E1", pybind11::arithmetic(), "") + .value("E1_V0", E1_V0) + .value("E1_V1", E1_V1) + .export_values(); + +; + + // E2_struct file:T61.smart_holder.hpp line:23 + pybind11::enum_(M(""), "E2_struct", "") + .value("V0", E2_struct::V0) + .value("V1", E2_struct::V1) + .export_values(); + +; + + // E3_class file:T61.smart_holder.hpp line:24 + pybind11::enum_(M(""), "E3_class", "") + .value("V0", E3_class::V0) + .value("V1", E3_class::V1); + +; + + { // A file:T61.smart_holder.hpp line:28 + PYBIND11_TYPE_CASTER_BASE_HOLDER(A , my_shared_ptr>) + pybind11::class_, my_shared_ptr>> cl(M(""), "A_int_t", ""); + cl.def( pybind11::init( [](){ return new A(); } ) ); + + pybind11::enum_::AE1>(cl, "AE1", pybind11::arithmetic(), "") + .value("AE1_V0", A::AE1_V0) + .value("AE1_V1", A::AE1_V1) + .export_values(); + + + pybind11::enum_::AE2_struct>(cl, "AE2_struct", "") + .export_values(); + + + pybind11::enum_::AE3_class>(cl, "AE3_class", ""); + + } + // fi_instantiated_by_use_in_function(class A) file:T61.smart_holder.hpp line:44 + M("").def("fi_instantiated_by_use_in_function", (void (*)(class A)) &fi_instantiated_by_use_in_function, "C++: fi_instantiated_by_use_in_function(class A) --> void", pybind11::arg("")); + + // fi(class A &) file:T61.smart_holder.hpp line:47 + M("").def("fi", (void (*)(class A &)) &fi, "C++: fi(class A &) --> void", pybind11::arg("")); + + // fi(class A *) file:T61.smart_holder.hpp line:50 + M("").def("fi", (void (*)(class A *)) &fi, "C++: fi(class A *) --> void", pybind11::arg("")); + +} + + +#include +#include +#include +#include +#include +#include + +#include + +typedef std::function< pybind11::module & (std::string const &) > ModuleGetter; + +void bind_T61_smart_holder(std::function< pybind11::module &(std::string const &namespace_) > &M); + + +PYBIND11_MODULE(T61_smart_holder, root_module) { + root_module.doc() = "T61_smart_holder module"; + + std::map modules; + ModuleGetter M = [&](std::string const &namespace_) -> pybind11::module & { + auto it = modules.find(namespace_); + if( it == modules.end() ) throw std::runtime_error("Attempt to access pybind11::module for namespace " + namespace_ + " before it was created!!!"); + return it->second; + }; + + modules[""] = root_module; + + static std::vector const reserved_python_words {"nonlocal", "global", }; + + auto mangle_namespace_name( + [](std::string const &ns) -> std::string { + if ( std::find(reserved_python_words.begin(), reserved_python_words.end(), ns) == reserved_python_words.end() ) return ns; + else return ns+'_'; + } + ); + + std::vector< std::pair > sub_modules { + }; + for(auto &p : sub_modules ) modules[p.first.size() ? p.first+"::"+p.second : p.second] = modules[p.first].def_submodule( mangle_namespace_name(p.second).c_str(), ("Bindings for " + p.first + "::" + p.second + " namespace").c_str() ); + + //pybind11::class_>(M(""), "_encapsulated_data_"); + + bind_T61_smart_holder(M); + +} + +// Source list file: TEST/T61_smart_holder.sources +// T61_smart_holder.cpp +// T61_smart_holder.cpp + +// Modules list file: TEST/T61_smart_holder.modules +//