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

bonded<> recursive usage question #38

Closed
codespare opened this issue Feb 21, 2015 · 2 comments
Closed

bonded<> recursive usage question #38

codespare opened this issue Feb 21, 2015 · 2 comments
Labels

Comments

@codespare
Copy link

Hello, I am trying to get a combination of the generic_tree and polymorphic_container samples to obtain a polymorphic tree. But I cannot figure out how to serialize nested bonded<> fields, and I was wondering if that is supported?

@sapek
Copy link
Contributor

sapek commented Feb 22, 2015

You could define polymorphic tree like this:

struct Data
{}

struct Node;
struct Node
{
    0: nullable<Node> left;
    1: nullable<Node> right;
    2: bonded<Base> data;
}

You will need to serialize each node data to initialize the data field, like in the polymorphic_container example. You can also use generic Node<T>, either defining the data field as 2: bonded<T> data; or as 2: T data;. In the latter case you would use Node<bonded<Data>> instance.

@codespare
Copy link
Author

Thank you, that got me unstuck. Ironically, that is much closer to the structure I am experimenting with(GumboParser) as opposed to the inheritance based model I was trying initially (conventional OO bias probably).
I have also tried the approach briefly mentioned in the 'Why Bond' article to emulate union with nullable<> and that works too. I still need to dig further to figure out the trade-offs in each approach.
Also, I am curious to understand when a mapping between a C and Bond model such as this one mandates the use of bonded<> and an interim serialization, versus when it can be made blittable, possibly using transforms, but no intermediate copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants