mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.14k stars 518 forks source link

How to write a typemap that can handle multple similar types? #689

Closed javagg closed 8 years ago

javagg commented 8 years ago
Brief Description

I have a header that defines a lot of struct which includes

e.g. myheader.h

typedef char XxType1[12];
typedef char XxType2[4];
typedef char XxType3[10];
....

struct XxStrunt1 {
   XxType1 f1;
   XxType2 f2
   XxType3 f3
}

struct XxStrunt2 {
   XxType4 f1;
   XxType5 f2
   XxType6 f3
}
...

for now, CppSharp Will transform XxTypes into sbyte[] property, but I need them to be string properties. How can I write a typemap that can match multiple types instread of one. I have hundreds of them, it's a pain to write a typemap for each. or Is there another way to accomplish this task?

tritao commented 8 years ago

I think we do not provide an easy way to achieve this at this time.

Me and @ddobrev have discussed a system for type map matching using AST pattern or AST name regex matching, but none of us has yet implemented it.

I think for now we could extend the Declaration class with a custom type map property, and if it's set the generator will use that particular type map. Then you could use a pass or some other piece of code to set the typemap manually.

Would that work?

javagg commented 8 years ago

I guess it could be better. Thanks!