-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mapping std::ostream - any ideas? #221
Comments
Mapping standard containers types in the C# backend is something that I've tried to do before. You can see my previous effort in the The way I tried to do it was by consuming the APIs directly from the native library, without needing to generate C code first. The big problem is that C# generics are just not powerful enough to represent the C++ types and it's not helped by the fact that the object layouts and algorithms change between standard library implementations. Yet another complication is that the object size can change even across debug/release configurations, at least on MSVC. For the reasons above, I've mostly abandoned that approach. The approaches that I think are worth considering are:
Using the C++/CLI backend you can trivially write a type map that does marshaling for template types. The main problem with this approach is that we still do not have a proper C++/CLI compiler for Mono, so for the time being you'd be limited to Windows. There's some hope here though, we might have someone working on this in the following months via the Google Summer of Code program.
We can also generate C/C++ wrapper code for all template instantiations that we come across while generating the bindings. We then also create a managed binding class for each template that consumes the generated native code bindings. For the C# backend, this is the only general approach that is known to work in practice. Tools like SWIG do this, though it's a bit of an hassle to have to compile extra native code and potentially have to distribute additional shared libraries with your managed bindings. |
thank you for the explanation. if anyone is interested, i've gone the C++/CLI route - see a72c43f for an example mapping std::ostream to System.TextWriter. |
hi there. i wanted to ask if someone ever tried to map the std::*stream classes for the CSharp backend?
if not, what would be the prefered way to do this? is it even possible or say i'd try it what obstacles would i encounter in doing so?
basically i'm trying to wrap the c++ api of opencv and after i sorted out a couple of issues in CppSharp to get the bindings for the core classes (a pull request will probably follow soon), i'm now at the point where i need std::string/std::ostream mapped properly in the CSharp backend.
thanks for any hints and keep up the good work.
elias
The text was updated successfully, but these errors were encountered: