3
0
mirror of https://github.com/triqs/dft_tools synced 2025-01-12 14:08:24 +01:00

wrapper : correct namespace in enum in converters

- the absolute path was missing for the value of the enum.
This commit is contained in:
Olivier Parcollet 2014-05-30 13:36:47 +02:00
parent ad45adbadd
commit 3036fe6529
3 changed files with 10 additions and 8 deletions

View File

@ -95,11 +95,11 @@ module.add_class(t)
########################
module.add_enum(c_name = "statistic_enum",
c_name_absolute = "triqs::gfs::statistic_enum",
c_namespace = "triqs::gfs",
values = ["Fermion","Boson"])
module.add_enum(c_name = "mesh_kind",
c_name_absolute = "triqs::gfs::mesh_kind",
c_namespace = "triqs::gfs",
values = ["half_bins","full_bins","without_last"])
########################

View File

@ -74,16 +74,16 @@ template<> struct py_converter<${c.c_type_absolute}> {
template <> struct py_converter<${en.c_name_absolute}> {
static PyObject * c2py(${en.c_name_absolute} x) {
%for n,val in enumerate(en.values[:-1]) :
if (x == ${val}) return PyString_FromString("${val}");
if (x == ${en.c_namespace}${val}) return PyString_FromString("${val}");
%endfor
return PyString_FromString("${en.values[-1]}"); // last case separate to avoid no return warning of compiler
}
static ${en.c_name_absolute} py2c(PyObject * ob){
std::string s=PyString_AsString(ob);
%for n,val in enumerate(en.values[:-1]) :
if (s == "${val}") return ${val};
if (s == "${val}") return ${en.c_namespace}${val};
%endfor
return ${en.values[-1]};
return ${en.c_namespace}${en.values[-1]};
}
static bool is_convertible(PyObject *ob, bool raise_exception) {
if (!PyString_Check(ob)) {

View File

@ -277,6 +277,7 @@ class class_ :
# expect a tuple : "algebra", "scalar1", "scalar2", etc...
self.number_protocol = {}
if arithmetic :
if not isinstance(arithmetic, tuple) : arithmetic = (arithmetic,)
add = arithmetic[0] in ("algebra", "abelian_group", "vector_space", "only_add")
abelian_group = arithmetic[0] in ("algebra", "abelian_group", "vector_space")
vector_space = arithmetic[0] in ("algebra", "vector_space")
@ -435,8 +436,9 @@ class enum_ :
- values : list of string representing the enumerated
- doc : the doc string.
"""
def __init__(self, c_name, values, c_name_absolute = None, doc = '') :
self.c_name, self.c_name_absolute, self.values, self.doc = c_name, c_name_absolute or c_name, values, doc
def __init__(self, c_name, values, c_namespace ="", doc = '') :
self.c_name, self.c_namespace, self.values, self.doc = c_name, c_namespace + "::", values, doc
self.c_name_absolute = self.c_namespace + self.c_name
class module_ :
"""