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

Allow daisy-chaining when adding children to ValueTrees #1332

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ImJimmi
Copy link
Contributor

@ImJimmi ImJimmi commented Jan 23, 2024

Currently, it's possible to daisy-chain property setters on a value tree:

juce::ValueTree {"Tree"}
    .setProperty("foo", 10, nullptr)
    .setProperty("bar", 20, nullptr);

This PR adds this behaviour to the child-adders as well, allowing a whole tree to be constructed this way:

juce::ValueTree {"Root"}
    .setProperty("foo", 10, nullptr)
    .setProperty("bar", 20, nullptr)
    .appendChild (juce::ValueTree {"Branch"}
                      .setProperty ("x", y, nullptr)
                      .appendChild (juce::ValueTree {"Leaf"}, nullptr),
                  nullptr)
    .addChild (juce::ValueTree {"Branch"}, 0, nullptr);

This is useful when loading value-trees from places external to the current call site (.e.g loading state from XML) and then adding on any additional children (e.g. any state that shouldn't be persisted to a file).

It also allows for better const-ness as the tree doesn't need to be changed after initialisation:

juce::ValueTree nonConst {"Tree"};
nonConst.appendChild (juce::ValueTree {"Data"}, nullptr);

const auto isConst = juce::ValueTree {"Tree"}
                         .appendChild (juce::ValueTree {"Data"}, nullptr);

@ImJimmi
Copy link
Contributor Author

ImJimmi commented Jan 23, 2024

This would go nicely with #1333 to make constructing value trees even cleaner:

juce::ValueTree {"Root"}
    .setProperty("foo", 10)
    .setProperty("bar", 20)
    .appendChild (juce::ValueTree {"Branch"}
                      .setProperty ("x", y)
                      .appendChild (juce::ValueTree {"Leaf"}))
    .addChild (juce::ValueTree {"Branch"}, 0);

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

Successfully merging this pull request may close these issues.

1 participant