cello
JUCE ValueTrees for Humans
Loading...
Searching...
No Matches
cello::Query Class Reference

Public Types

using Predicate = std::function<bool (juce::ValueTree)>
 
using Comparison = std::function<int (const juce::ValueTree&, const juce::ValueTree&)>
 

Public Member Functions

 Query (const juce::Identifier &resultType=Result)
 Construct a new Query object.
 
 Query (Predicate filter, const juce::Identifier &resultType=Result)
 Construct a new Query object that has a single filter predicate ready to run.
 
 Query (const Query &)=default
 
Queryoperator= (const Query &)=default
 
 Query (Query &&)=default
 
Queryoperator= (Query &&)=default
 
QueryaddFilter (Predicate filter)
 Append a filter predicate to the end of our list; these are executed in the sequence they're added, and we stop testing at the first filter that returns false.
 
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 of type resultType that contains a copy (either shallow or deep) of each child that fulfills the query, sorted according to the sort criteria we've been given.
 
QueryaddComparison (Comparison sorter)
 Add a comparison function to the list we use to sort a list of children.
 
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.
 

Static Public Attributes

static const juce::Identifier Result { "result" }
 The default identifier for the query results tree.
 

Friends

class juce::ValueTree
 

Constructor & Destructor Documentation

◆ Query() [1/2]

cello::Query::Query ( const juce::Identifier & resultType = Result)

Construct a new Query object.

Parameters
resultTypetype id of the ValueTree that we should return.

◆ Query() [2/2]

cello::Query::Query ( Predicate filter,
const juce::Identifier & resultType = Result )

Construct a new Query object that has a single filter predicate ready to run.

Parameters
filterPredicate function to run. You can add additional predicates (that will be logically ANDed) with the addFilter method.
resultType

Member Function Documentation

◆ addComparison()

Query & cello::Query::addComparison ( Comparison sorter)

Add a comparison function to the list we use to sort a list of children.

Parameters
sorter
Returns
Query& so we can chain these calls together.

◆ addFilter()

Query & cello::Query::addFilter ( Predicate filter)

Append a filter predicate to the end of our list; these are executed in the sequence they're added, and we stop testing at the first filter that returns false.

Parameters
filter
Returns
Query& reference to this so we can use the builder pattern.

◆ search()

juce::ValueTree cello::Query::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 of type resultType that contains a copy (either shallow or deep) of each child that fulfills the query, sorted according to the sort criteria we've been given.

Parameters
treeValueTree to search.
deepIf true, the result tree will contain a deep copy of each child found.
returnFirstFoundIf true, will return a copy of the first matching child found, or an invalid tree if none was found.
Returns
juce::ValueTree with query results.

◆ sort()

juce::ValueTree cello::Query::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.

Parameters
treeTree to sort.
undooptional undo manager.
stableSortif true, retain the current order of elements that compare as equal. This is slower, so only use it if needed.
Returns
juce::ValueTree

The documentation for this class was generated from the following files: