Gin
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
ValueTreeObject Class Reference

Maintains an object hierarchy that mirrors a ValueTree structure. More...

#include <gin_valuetreeobject.h>

Inherits juce::ValueTree::Listener.

Public Member Functions

 ValueTreeObject (const juce::ValueTree &state)
 Creates a ValueTreeObject wrapping the given ValueTree.
 
juce::ValueTree & getState ()
 Returns the ValueTree that this object represents.
 
const juce::OwnedArray< ValueTreeObject > & getChildren () const
 Returns all child objects.
 
template<class TargetClass >
TargetClassfindParentOfType () const
 Searches up the parent chain for an object of the specified type.
 
template<class TargetClass >
juce::Array< TargetClass * > findChildrenOfClass () const
 Finds all direct children of a specific class type.
 
template<class TargetClass >
int countChildrenOfClass () const
 Counts the number of direct children of a specific class type.
 
template<class TargetClass >
TargetClassfindChildOfClass (int idx) const
 Finds a specific child of a class type by index.
 

Static Public Attributes

static std::function< ValueTreeObject *(const juce::Identifier &, const juce::ValueTree &)> factory
 Factory function for creating ValueTreeObject instances.
 

Detailed Description

Maintains an object hierarchy that mirrors a ValueTree structure.

This base class allows you to create an object-oriented wrapper around a ValueTree, where each ValueTree node is represented by a corresponding object. The object hierarchy automatically stays in sync with the ValueTree structure.

To use this class:

  1. Derive your own classes from ValueTreeObject
  2. Implement a factory function to create appropriate objects for each ValueTree type
  3. Changes to the ValueTree will automatically create/destroy matching objects
See also
getState, getChildren, findParentOfType, findChildrenOfClass

Constructor & Destructor Documentation

◆ ValueTreeObject()

ValueTreeObject::ValueTreeObject ( const juce::ValueTree &  state)

Creates a ValueTreeObject wrapping the given ValueTree.

Parameters
stateThe ValueTree this object represents

Member Function Documentation

◆ getState()

juce::ValueTree & ValueTreeObject::getState ( )

Returns the ValueTree that this object represents.

Returns
Reference to the wrapped ValueTree

◆ getChildren()

const juce::OwnedArray< ValueTreeObject > & ValueTreeObject::getChildren ( ) const

Returns all child objects.

Returns
Array of child ValueTreeObject instances

◆ findParentOfType()

template<class TargetClass >
TargetClass * ValueTreeObject::findParentOfType ( ) const

Searches up the parent chain for an object of the specified type.

Template Parameters
TargetClassThe class type to search for
Returns
Pointer to the first parent of the specified type, or nullptr if not found

◆ findChildrenOfClass()

template<class TargetClass >
juce::Array< TargetClass * > ValueTreeObject::findChildrenOfClass ( ) const

Finds all direct children of a specific class type.

Template Parameters
TargetClassThe class type to search for
Returns
Array of pointers to children of the specified type

◆ countChildrenOfClass()

template<class TargetClass >
int ValueTreeObject::countChildrenOfClass ( ) const

Counts the number of direct children of a specific class type.

Template Parameters
TargetClassThe class type to count
Returns
The number of children of the specified type

◆ findChildOfClass()

template<class TargetClass >
TargetClass * ValueTreeObject::findChildOfClass ( int  idx) const

Finds a specific child of a class type by index.

Returns the nth child of the specified type (where n is the idx parameter).

Template Parameters
TargetClassThe class type to search for
Parameters
idxThe index of the child to return (0-based, among children of this type)
Returns
Pointer to the child at the specified index, or nullptr if not found

Member Data Documentation

◆ factory

std::function<ValueTreeObject* (const juce::Identifier&, const juce::ValueTree&)> ValueTreeObject::factory
static

Factory function for creating ValueTreeObject instances.

Set this to a function that creates the appropriate ValueTreeObject-derived class based on the ValueTree's type identifier.


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