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

API: builder children interface #102

Merged
merged 14 commits into from
Nov 5, 2023
Merged

Conversation

mcmikecreations
Copy link
Collaborator

Added children interface. It can take any combination of lvalues and rvalues, universal, copy, and move references. This allows for complex tree hierarchies to be created.
parent_get() points to the immediate last child in the hierarchy.
The only downside is that the hierarchy needs to be created bottom-up:

auto classes = b::children(m.heap_type("Rectangle"), m.heap_type("Circle"));
auto ns_empty = m.scope("Empty") << m.none(); // to allow an empty namespace instead of a global one.
auto ns_shapes = m.scope("Shapes") << classes; // root points to "Shapes", parent points to "Circle".
auto factory = m.source_root("Main.cs") << b::children(ns_shapes, ns_empty); // root points to "Main.cs", parent points to "Empty".

// Main.cs
// namespace Shapes {
//     class Rectangle {}
//     class Circle {}
// }
// namespace Empty {}

@mcmikecreations mcmikecreations added enhancement New feature or request input Input library for Crosslight output Output library for Crosslight labels Nov 5, 2023
@mcmikecreations mcmikecreations self-assigned this Nov 5, 2023
@@ -37,18 +37,25 @@ cl_node_term(struct cl_node* root, size_t term_children, void(*term)(void*)) {
size_t child_count = root->child_count;

if (term_children != 0 && child_count > 0 && root->children != 0) {
for (size_t i = 0; i < child_count; ++i) {
if (cl_node_term((struct cl_node*)(root->children + i), term_children, term) == 0) {
for (size_t i = child_count - 1; i != (size_t)-1; --i) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why backwards?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All children need to be observed before the memory is freed. The memory needs to be freed through the pointer to the first element in the array aka the pointer to the array in general. Thus, iterating backwards is simpler.

Copy link
Collaborator

@SergiyIvan SergiyIvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@mcmikecreations mcmikecreations merged commit f5e34f5 into master Nov 5, 2023
1 check passed
@mcmikecreations mcmikecreations deleted the feature/101-builder_children branch November 5, 2023 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request input Input library for Crosslight output Output library for Crosslight
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants