cello
JUCE ValueTrees for Humans
Loading...
Searching...
No Matches
cello_path.h
1/*
2 Copyright (c) 2023 Brett g Porter
3 Permission is hereby granted, free of charge, to any person obtaining a copy
4 of this software and associated documentation files (the "Software"), to deal
5 in the Software without restriction, including without limitation the rights
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 copies of the Software, and to permit persons to whom the Software is
8 furnished to do so, subject to the following conditions:
9 The above copyright notice and this permission notice shall be included in all
10 copies or substantial portions of the Software.
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17 SOFTWARE.
18*/
19
20#pragma once
21
22#include <juce_core/juce_core.h>
23#include <juce_data_structures/juce_data_structures.h>
24
25namespace cello
26{
27
49class Path
50{
51public:
53 static const inline juce::String sep { "/" };
54 static const inline juce::String ancestor { "^" };
55 static const inline juce::String parent { ".." };
56 static const inline juce::String current { "." };
57
58 Path (const juce::String& pathString)
59 : pathSegments { parsePathSegments (pathString) }
60 {
61 }
62
69
76
85 juce::ValueTree findValueTree (juce::ValueTree& origin, SearchType searchType, juce::UndoManager* undo = nullptr);
86
93 SearchResult getSearchResult () const { return searchResult; }
94
95private:
102 juce::StringArray parsePathSegments (const juce::String& pathString);
103
104 const juce::StringArray pathSegments;
105
106 SearchResult searchResult { SearchResult::notFound };
107};
108
109} // namespace cello
SearchType
Definition cello_path.h:64
@ query
only search, do not create anything.
Definition cello_path.h:65
@ createAll
create final tree and all intermediate trees needed to reach it.
Definition cello_path.h:67
@ createTarget
create final tree in specification, but no intermediate trees
Definition cello_path.h:66
SearchResult getSearchResult() const
Find out whether performing a search succeeded, and if so, needed to create a new tree.
Definition cello_path.h:93
juce::ValueTree findValueTree(juce::ValueTree &origin, SearchType searchType, juce::UndoManager *undo=nullptr)
Navigate the path from origin to a tree that is expected at the end of the current path specification...
Definition cello_path.cpp:59
SearchResult
Definition cello_path.h:71
@ created
performing a search created a new tree
Definition cello_path.h:74
@ notFound
unable to find the requested tree
Definition cello_path.h:72
@ found
the sought tree existed already and was found
Definition cello_path.h:73
static const juce::String sep
Path separator.
Definition cello_path.h:53