Commit ac351e4f authored by John Parent's avatar John Parent
Browse files

Updates for pure opaque stl types

parent 4d346c86
......@@ -18,4 +18,6 @@ files:
stl_container.h:
classes:
simple:
simpleT:
inst: [int]
......@@ -3,18 +3,38 @@
#include <vector>
#include <map>
#include <string>
class simple
{
public:
simple() {}
simple(std::map<int,std::vector<int>> &i_map) :i_map_(i_map) {}
void append(int i, int val) {this->i_map_.at(i).push_back(val);}
void add_pair(int i, std::vector<int> v) {this->i_map_[i]=v;}
// simple(std::map<int,std::vector<int>> &i_map) :i_map_(i_map) {}
// void append(int i, int val) {this->i_map_.at(i).push_back(val);}
// void add_pair(int i, std::vector<int> v) {this->i_map_[i]=v;}
// private:
// std::map<int,std::vector<int>> i_map_;
};
private:
template <typename T>
class simpleT
{
public:
simpleT() {}
};
std::map<int,std::vector<int>> i_map_;
class simple2
{
public:
simple2() {}
};
template <typename T>
class simple2T
{
public:
simple2T() {}
};
// template class std::vector<double>;
#endif // STL_CONTAINER
......@@ -802,8 +802,14 @@ class BindingsGenerator:
# and by querying constructor location if templ
return extra_includes
def strip_std(self, decl_string):
return decl_string.replace("std::", "")
def is_stl(self, x):
return self.check_decl("std", x.decl_string)
if type(x) is str:
return self.check_decl("std", x)
else:
return self.check_decl("std", x.decl_string)
def depends_on_eigen(self, x, member=None):
return self.check_decl("Eigen", x.decl_string)
......@@ -828,7 +834,19 @@ class BindingsGenerator:
return decl
def derive_stl_deps(self, decl_string, incs=set()):
pass
if self.is_templated(decl_string):
rec_gen = dec.templates.split_recursive(decl_string)
for split in rec_gen:
decl_type = split[0]
decl_insts = split[1]
if self.is_stl(decl_type):
incs.add(decl_type)
for decl_inst in decl_insts:
self.derive_stl_deps(decl_inst, incs)
else:
if self.is_stl(decl_string):
incs.add(decl_string)
return incs
def aquire_stl_pygccxml_data(self, pygccxml_data):
"""
......@@ -931,6 +949,15 @@ class BindingsGenerator:
)
if fmt_str not in include_str:
include_str.append(fmt_str)
extra_includes = self.derive_stl_deps(
container.cpp_name, set()
)
for inc in extra_includes:
inc_str = self.opts.generic_include.format(
"<{}>".format(self.strip_std(inc))
)
if inc_str not in include_str:
include_str.append(inc_str)
return "\n".join(include_str)
def create_stl_binder_header(self, containers):
......@@ -949,7 +976,7 @@ class BindingsGenerator:
:return: the header file name and a string representing the opaque
declarations
"""
header_str = "#ifndef STL_OPAQUE\n#define STL_OPAQUE\n#include <pybind11/pybind11.h>\n{}\n{}\n#endif\n"
header_str = "#ifndef STL_OPAQUE\n#define STL_OPAQUE\n#include <pybind11/pybind11.h>\n#include <pybind11/stl_bind.h>\n{}\n{}\n#endif\n"
binder_str = ""
file_ = "stl_opaque_dec.h"
self.universal_includes += '#include "{}"\n'.format(file_)
......@@ -2655,7 +2682,12 @@ class BindingsGenerator:
for x in stl_binders_:
if x.stl_bind:
res_dict["to_include"].add("<{}>".format(x.type))
res_dict["class_insts"].append(x.cpp_name)
addl_incs = self.derive_stl_deps(x.cpp_name, set())
for inc in addl_incs:
inc_str = "<{}>".format(self.strip_std(inc))
if inc_str not in res_dict["to_include"]:
res_dict["to_include"].add(inc_str)
res_dict["stl_insts"].add(x.cpp_name)
self.stl_binders.extend(stl_binders_)
return mod_tree
......@@ -3106,6 +3138,7 @@ class BindingsGenerator:
includes_fmt = "#include %s\n"
class_decs_fmt = "template class %s;\n"
func_ptr_assign_fmt = "auto %s = &%s;\n"
stl_insts_fmt = "template class %s;\n"
includes_str = "".join(
[includes_fmt % fname for fname in module_info["to_include"]]
)
......@@ -3122,6 +3155,9 @@ class BindingsGenerator:
self.template_args_to_underscores(func_name)
for func_name in func_list
]
stl_decs = "".join(
[stl_insts_fmt % inst for inst in module_info["stl_insts"]]
)
func_ptr_assigns = ""
for var_name, func_name in zip(var_names, func_list):
......@@ -3134,7 +3170,7 @@ class BindingsGenerator:
)
wrapper_cpp_text = self.opts.wrap_header_fmt.format(
includes=includes_str,
class_decs=class_decs,
class_decs=class_decs + "\n" + stl_decs,
func_ptr_assigns=func_ptr_assigns,
)
self.write_data_to_file(wrapper_cpp_file, wrapper_cpp_text, ".cpp")
......@@ -3197,6 +3233,7 @@ class BindingsGenerator:
"all_auto_bind": list(),
"all_auto_bind_defs": set(),
"non_template_classes": list(),
"stl_insts": set(),
}
wrapper_yaml = yaml.safe_load(open(self.opts.yaml_path, "r"))
# Generate a summary of the module
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment