mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 22:03:43 +01:00
af084f5d59
- new parameter class : parameters are viewed as form, built in C++, and filled in C++/python. Each field of the form as a precise C++ type (erased using standard techniques). First tests ok, to be reread/checked. TODO : serialization is commented. Lead to long compilation time & large code due to boost::serialization. Use h5 when possible. - wrapper : - separated the converters of the wrapped type in the TRIQS library - necessary for parameters (it used outside an .so) and potentially other codes, outside an .so module
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from wrap_generator import *
|
|
|
|
# The module
|
|
module = module_(full_name = "pytriqs.parameters.parameters.my_module", doc = " Doc of my_module ")
|
|
module.add_include("<triqs/parameters/parameters.hpp>")
|
|
module.add_include("<triqs/utility/formatted_output.hpp>")
|
|
module.add_using("namespace triqs::params")
|
|
|
|
# one class
|
|
g = class_(
|
|
py_type = "Parameters",
|
|
c_type = "parameters",
|
|
#serializable= "tuple",
|
|
is_printable= True,
|
|
hdf5 = True,
|
|
# Add + for merging
|
|
arithmetic = ("only_add")
|
|
)
|
|
|
|
#add a constructor
|
|
#g.add_constructor(doc = "DOC of constructor", args = [])
|
|
|
|
g.add_method(py_name = "help", calling_pattern = "auto result = triqs::utility::print_formatted(self_c.generate_help())", signature = "std::string()", doc = "help")
|
|
|
|
# add getitem/setitem ...
|
|
g.add_getitem(signature = "PyObject *(const char * key)",
|
|
calling_pattern = "PyObject * result = self_c[key].to_python()",
|
|
doc = "")
|
|
g.add_setitem(signature = "void(const char * key, PyObject * ob)",
|
|
calling_pattern = """
|
|
if (!self_c[key].from_python_convertible(ob)) return NULL; // early exit, the error is set by the converter
|
|
self_c[key].set_from_python(ob);
|
|
""",
|
|
doc = "")
|
|
|
|
module.add_class(g)
|
|
|
|
if __name__ == '__main__' :
|
|
module.generate_code(mako_template = sys.argv[1], wrap_file = sys.argv[2])
|
|
module.generate_py_converter_header(mako_template = sys.argv[3], wrap_file = sys.argv[4])
|
|
|