Skip to content
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

Closed
azeno opened this issue Apr 9, 2014 · 2 comments
Closed

mapping std::ostream - any ideas? #221

azeno opened this issue Apr 9, 2014 · 2 comments

Comments

@azeno
Copy link
Contributor

azeno commented Apr 9, 2014

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

@tritao
Copy link
Collaborator

tritao commented Apr 9, 2014

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 CppSharp.Runtime project, mainly the StdVector.cs, StdString.cs and StdMap.cs files.

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 C++/CLI

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.

  • Generating native code bindings

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.

@azeno
Copy link
Contributor Author

azeno commented May 6, 2014

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.
i'll close this issue now - was more of a question anyway.

@azeno azeno closed this as completed May 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants