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

How to access public attributes on C++ class e.g. Monomial #3

Open
chrisdjscott opened this issue Apr 17, 2024 · 3 comments
Open

How to access public attributes on C++ class e.g. Monomial #3

chrisdjscott opened this issue Apr 17, 2024 · 3 comments

Comments

@chrisdjscott
Copy link
Collaborator

We could look at map_type instead of add_type

Could also add a method that takes monomial and returns the value in dace_julia.cxx

@afossa
Copy link
Collaborator

afossa commented Apr 17, 2024

For "trivial" layouts, CxxWrap assumes that the exposed class is mirrored to an already defined Julia mutable struct. See Breaking changes in v0.9 in the repository README.

If you try to add_type a simple C++ class or struct like DACE::Interval, you'll encounter this error which can be solved by adding this line at the top of dace_julia.cxx

template<> struct jlcxx::IsMirroredType<DACE::Interval> : std::false_type { };

this will let you add the class with the "limitations" of add_type, i.e. no public attributes exposed to Julia

If instead you conform to the defaults, you can map_type (aka mirror) the simple class to a predefined mutable struct in DACE.jl

mutable struct Interval
  m_lb::Float64
  m_ub::Float64
end

this will expose public attributes to Julia, but we need to check how to expose other methods of the wrapped class.
See also this discussion

@afossa
Copy link
Collaborator

afossa commented Apr 22, 2024

I implemented DACE.bounds() using map_type to map the Interval object defined in DACE.
You can check the code here ade179b and here afossa/dace@bc594ab

If you find a more suitable solution, notably for Monomial, feel free to update the implementation to reflect your.

@jackyarndley
Copy link
Collaborator

I'm not sure that more complicated classes will be possible to add, so we might need to add some get/set methods.

See JuliaInterop/CxxWrap.jl#418

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

3 participants