20#include "cello_query.h"
37 filters.push_back (filter);
41juce::ValueTree
Query::search (juce::ValueTree tree,
bool deep,
bool returnFirstFound)
const
43 juce::ValueTree result { type };
44 for (
auto child : tree)
48 auto childCopy { juce::ValueTree { child.getType () } };
50 childCopy.copyPropertiesAndChildrenFrom (child,
nullptr);
52 childCopy.copyPropertiesFrom (child,
nullptr);
55 result.appendChild (childCopy,
nullptr);
69 for (
int i = tree.getNumChildren () - 1; i >= 0; i--)
71 if (filter (tree.getChild (i)))
73 tree.removeChild (i,
nullptr);
81bool Query::filter (juce::ValueTree tree)
const
83 if (filters.size () > 0)
85 for (
auto fn : filters)
96 sorters.push_back (sorter);
100juce::ValueTree
Query::sort (juce::ValueTree tree, juce::UndoManager* undo,
bool stableSort)
const
102 if (sorters.size () > 0)
103 tree.
sort (*
this, undo, stableSort);
107int Query::compareElements (
const juce::ValueTree& left,
const juce::ValueTree& right)
const
109 for (
auto sorter : sorters)
111 auto sortOrder { sorter (left, right) };
120#include "test/test_cello_query.inl"
juce::ValueTree sort(juce::ValueTree tree, juce::UndoManager *undo=nullptr, bool stableSort=false) const
Use the list of comparison functions to sort the tree arg into its desired order.
Definition cello_query.cpp:100
Query & addComparison(Comparison sorter)
Add a comparison function to the list we use to sort a list of children.
Definition cello_query.cpp:94
Query & addFilter(Predicate filter)
Append a filter predicate to the end of our list; these are executed in the sequence they're added,...
Definition cello_query.cpp:35
Query(const juce::Identifier &resultType=Result)
Construct a new Query object.
Definition cello_query.cpp:24
int remove(juce::ValueTree tree) const
Remove all children from the tree that match the query.
Definition cello_query.cpp:66
juce::ValueTree search(juce::ValueTree tree, bool deep, bool returnFirstFound=false) const
Execute the query we're programmed for – iterate through the children of tree, returning a new tree o...
Definition cello_query.cpp:41