OpenShot Audio Library | OpenShotAudio: juce_ValueTree.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_ValueTree.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
71 class JUCE_API ValueTree final
72{
73 JUCE_PUBLIC_IN_DLL_BUILD (class SharedObject)
74
75public:
76 //==============================================================================
83 ValueTree() noexcept;
84
90 explicit ValueTree (const Identifier& type);
91
131 ValueTree (const Identifier& type,
132 std::initializer_list<NamedValueSet::NamedValue> properties,
133 std::initializer_list<ValueTree> subTrees = {});
134
136 ValueTree (const ValueTree&) noexcept;
137
139 ValueTree (ValueTree&&) noexcept;
140
147 ValueTree& operator= (const ValueTree&);
148
150 ~ValueTree();
151
156 bool operator== (const ValueTree&) const noexcept;
157
162 bool operator!= (const ValueTree&) const noexcept;
163
170 bool isEquivalentTo (const ValueTree&) const;
171
172 //==============================================================================
176 bool isValid() const noexcept { return object != nullptr; }
177
179 ValueTree createCopy() const;
180
186 void copyPropertiesFrom (const ValueTree& source, UndoManager* undoManager);
187
192 void copyPropertiesAndChildrenFrom (const ValueTree& source, UndoManager* undoManager);
193
194 //==============================================================================
199 Identifier getType() const noexcept;
200
205 bool hasType (const Identifier& typeName) const noexcept;
206
207 //==============================================================================
213 const var& getProperty (const Identifier& name) const noexcept;
214
220 var getProperty (const Identifier& name, const var& defaultReturnValue) const;
221
226 const var* getPropertyPointer (const Identifier& name) const noexcept;
227
233 const var& operator[] (const Identifier& name) const noexcept;
234
242 ValueTree& setProperty (const Identifier& name, const var& newValue, UndoManager* undoManager);
243
245 bool hasProperty (const Identifier& name) const noexcept;
246
251 void removeProperty (const Identifier& name, UndoManager* undoManager);
252
257 void removeAllProperties (UndoManager* undoManager);
258
262 int getNumProperties() const noexcept;
263
270 Identifier getPropertyName (int index) const noexcept;
271
280 Value getPropertyAsValue (const Identifier& name, UndoManager* undoManager,
281 bool shouldUpdateSynchronously = false);
282
283 //==============================================================================
287 int getNumChildren() const noexcept;
288
293 ValueTree getChild (int index) const;
294
300 ValueTree getChildWithName (const Identifier& type) const;
301
308 ValueTree getOrCreateChildWithName (const Identifier& type, UndoManager* undoManager);
309
316 ValueTree getChildWithProperty (const Identifier& propertyName, const var& propertyValue) const;
317
327 void addChild (const ValueTree& child, int index, UndoManager* undoManager);
328
333 void appendChild (const ValueTree& child, UndoManager* undoManager);
334
339 void removeChild (const ValueTree& child, UndoManager* undoManager);
340
346 void removeChild (int childIndex, UndoManager* undoManager);
347
352 void removeAllChildren (UndoManager* undoManager);
353
366 void moveChild (int currentIndex, int newIndex, UndoManager* undoManager);
367
371 bool isAChildOf (const ValueTree& possibleParent) const noexcept;
372
376 int indexOf (const ValueTree& child) const noexcept;
377
382 ValueTree getParent() const noexcept;
383
387 ValueTree getRoot() const noexcept;
388
395 ValueTree getSibling (int delta) const noexcept;
396
397 //==============================================================================
402 struct Iterator
403 {
404 Iterator (const ValueTree&, bool isEnd);
405 Iterator& operator++();
406
407 bool operator== (const Iterator&) const;
408 bool operator!= (const Iterator&) const;
409 ValueTree operator*() const;
410
411 using difference_type = std::ptrdiff_t;
412 using value_type = ValueTree;
413 using reference = ValueTree&;
414 using pointer = ValueTree*;
415 using iterator_category = std::forward_iterator_tag;
416
417 private:
418 SharedObject** internal = nullptr;
419 };
420
422 Iterator begin() const noexcept;
423
425 Iterator end() const noexcept;
426
427 //==============================================================================
433 std::unique_ptr<XmlElement> createXml() const;
434
439 static ValueTree fromXml (const XmlElement& xml);
440
445 static ValueTree fromXml (const String& xmlText);
446
451 String toXmlString (const XmlElement::TextFormat& format = {}) const;
452
453 //==============================================================================
461 void writeToStream (OutputStream& output) const;
462
464 static ValueTree readFromStream (InputStream& input);
465
467 static ValueTree readFromData (const void* data, size_t numBytes);
468
472 static ValueTree readFromGZIPData (const void* data, size_t numBytes);
473
474 //==============================================================================
480 class JUCE_API Listener
481 {
482 public:
484 virtual ~Listener() = default;
485
492 virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
493 const Identifier& property);
494
501 virtual void valueTreeChildAdded (ValueTree& parentTree,
502 ValueTree& childWhichHasBeenAdded);
503
511 virtual void valueTreeChildRemoved (ValueTree& parentTree,
512 ValueTree& childWhichHasBeenRemoved,
513 int indexFromWhichChildWasRemoved);
514
522 virtual void valueTreeChildOrderChanged (ValueTree& parentTreeWhoseChildrenHaveMoved,
523 int oldIndex, int newIndex);
524
531 virtual void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged);
532
537 virtual void valueTreeRedirected (ValueTree& treeWhichHasBeenChanged);
538 };
539
554 void addListener (Listener* listener);
555
557 void removeListener (Listener* listener);
558
562 ValueTree& setPropertyExcludingListener (Listener* listenerToExclude,
563 const Identifier& name, const var& newValue,
564 UndoManager* undoManager);
565
569 void sendPropertyChangeMessage (const Identifier& property);
570
571 //==============================================================================
593 template <typename ElementComparator>
594 void sort (ElementComparator& comparator, UndoManager* undoManager, bool retainOrderOfEquivalentItems)
595 {
596 if (object != nullptr)
597 {
598 OwnedArray<ValueTree> sortedList;
599 createListOfChildren (sortedList);
600 ComparatorAdapter<ElementComparator> adapter (comparator);
601 sortedList.sort (adapter, retainOrderOfEquivalentItems);
602 reorderChildren (sortedList, undoManager);
603 }
604 }
605
609 int getReferenceCount() const noexcept;
610
611 #if JUCE_ALLOW_STATIC_NULL_VARIABLES && ! defined (DOXYGEN)
612 /* An invalid ValueTree that can be used if you need to return one as an error condition, etc. */
613 [[deprecated ("If you need an empty ValueTree object, just use ValueTree() or {}.")]]
614 static const ValueTree invalid;
615 #endif
616
617private:
618 //==============================================================================
619 friend class SharedObject;
620
621 ReferenceCountedObjectPtr<SharedObject> object;
622 ListenerList<Listener> listeners;
623
624 template <typename ElementComparator>
625 struct ComparatorAdapter
626 {
627 ComparatorAdapter (ElementComparator& comp) noexcept : comparator (comp) {}
628
629 int compareElements (const ValueTree* const first, const ValueTree* const second)
630 {
631 return comparator.compareElements (*first, *second);
632 }
633
634 private:
635 ElementComparator& comparator;
636 JUCE_DECLARE_NON_COPYABLE (ComparatorAdapter)
637 };
638
639 void createListOfChildren (OwnedArray<ValueTree>&) const;
640 void reorderChildren (const OwnedArray<ValueTree>&, UndoManager*);
641
642 explicit ValueTree (ReferenceCountedObjectPtr<SharedObject>) noexcept;
643 explicit ValueTree (SharedObject&) noexcept;
644};
645
646} // namespace juce
juce::Identifier
Definition juce_Identifier.h:39
juce::InputStream
Definition juce_InputStream.h:37
juce::ListenerList
Definition juce_ListenerList.h:81
juce::OutputStream
Definition juce_OutputStream.h:38
juce::OwnedArray
Definition juce_OwnedArray.h:50
juce::OwnedArray::sort
void sort(ElementComparator &comparator, bool retainOrderOfEquivalentItems=false) noexcept
Definition juce_OwnedArray.h:868
juce::ReferenceCountedObjectPtr
Definition juce_ReferenceCountedObject.h:247
juce::String
Definition juce_String.h:53
juce::UndoManager
Definition juce_UndoManager.h:52
juce::ValueTree::Listener
Definition juce_ValueTree.h:481
juce::ValueTree::Listener::~Listener
virtual ~Listener()=default
juce::ValueTree
Definition juce_ValueTree.h:72
juce::ValueTree::isValid
bool isValid() const noexcept
Definition juce_ValueTree.h:176
juce::ValueTree::sort
void sort(ElementComparator &comparator, UndoManager *undoManager, bool retainOrderOfEquivalentItems)
Definition juce_ValueTree.h:594
juce::Value
Definition juce_Value.h:51
juce::XmlElement
Definition juce_XmlElement.h:83
juce::var
Definition juce_Variant.h:42
juce::ValueTree::Iterator
Definition juce_ValueTree.h:403