21#include <juce_core/juce_core.h>
22#include <juce_data_structures/juce_data_structures.h>
31 static inline const juce::Identifier
Result {
"result" };
35 using Predicate = std::function<bool (juce::ValueTree)>;
41 using Comparison = std::function<int (
const juce::ValueTree&,
const juce::ValueTree&)>;
48 Query (
const juce::Identifier& resultType =
Result);
58 Query (Predicate filter,
const juce::Identifier& resultType =
Result);
89 juce::ValueTree
search (juce::ValueTree tree,
bool deep,
bool returnFirstFound =
false)
const;
97 int remove (juce::ValueTree tree)
const;
118 juce::ValueTree
sort (juce::ValueTree tree, juce::UndoManager* undo =
nullptr,
bool stableSort =
false)
const;
128 bool filter (juce::ValueTree tree)
const;
131 friend class juce::ValueTree;
140 int compareElements (
const juce::ValueTree& left,
const juce::ValueTree& right)
const;
144 juce::Identifier type;
146 std::vector<Predicate> filters;
148 std::vector<Comparison> sorters;
Definition cello_query.h:28
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
static const juce::Identifier Result
The default identifier for the query results tree.
Definition cello_query.h:31
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