From: William S F. <ws...@fu...> - 2009-07-28 18:44:17
|
Guillaume Yziquel wrote: > Guillaume Yziquel a écrit : >> Guillaume Yziquel a écrit : >>> Hello. > > Hi. I really need help on this one... > >>> For the OCaml Swig module that I am writing, I am now in the process of >>> defining typemaps to map, say, std::list<int> to Ocaml's 'int list'. >> I'd like to ask for advice on this one: >> >> What I want is to create a tmap:ocamlout typemap converting >> 'std::list<int>' to 'int list'. >> >> So, in ocaml/std_list.i, I'd like to do things like: >> >> namespace std { >> template<class T> >> class list { >> %typemap(ocamlout, noblock=1) std::list< T > {OCAML_OUT_FOR_T list} >> }; >> } >> >> I'm concerned with how to deal with OCAML_OUT_FOR_T. There are two >> problems I stumble upon: >> >> -1- My understand of swig macro magic is somewhat limited: I understand that >> >> OCAML_OUT ##T yields stuff like OCAML_OUT "int" >> OCAML_OUT_#T yields OCAML_OUT_#int >> OCAML_OUT_##T yields OCAML_OUT_#"int" >> >> But this is still kind of black magic to me. I also understand that >> noblock=1 enables swig macro expansion, so here goes my other, and main >> question: Is OCAML_OUT a macro parameter or what? >> >> -2- Is it possible to make a swig macro, say %my_ocaml_out(this_type) >> and that yields back the tmap:ocamlout typemap attached to this_type? >> >> If not, then it is a pain: The only solution I see is to make code in >> ocaml.cxx to recursively expand OCAML_OUT_#"this_type" strings. I'm not >> sure if it is a sensible way to go about this... >> >> The point is that Marcello's stuff >> >> http://thread.gmane.org/gmane.comp.programming.swig.devel/13615/focus=13665 >> >> does not work out since I really need to write, in the OCaml code, 'int' >> and 'list' on the same line, and not in a %fragment. (Well, perhaps not, >> but things in OCaml would get very quickly very ugly, I guess) >> Guillaume I'm not entirely clear what you are asking given I don't know Ocaml, nor do I know what your new typemaps do. If ocamlout, is like javaout or csout, then it should contain Ocaml code to marshal from the C/C++ type to the Ocaml type. But I don't think you have followed this convention. I guess ocamlout is like the jstype or cstype typemap so it contains the Ocaml type for the given C/C++ type. Correct? If so, you are asking how to obtain the Ocaml type when wrapping std::vector<int>? Ignoring templates for now, how have you solved getting the Ocaml type for a non-templated class, eg class X {}; ? What would the Ocaml type be here and how do you declare this in your Ocaml type typemap, which I think is ocamlout? You might also want to give an example of the desired output for the complete Ocaml proxy class for std::vector<int> to aid what you are trying to achieve. Also, can the C type always be used in the Ocaml code as is including namespaces etc or is there some mapping from C types to Ocaml types? William |