1 | #ifndef _PARAMTREE_H_
|
---|
2 | #define _PARAMTREE_H_
|
---|
3 |
|
---|
4 | #include <frams/param/param.h>
|
---|
5 | #include <vector>
|
---|
6 | #include <memory>
|
---|
7 |
|
---|
8 | // building a tree of Param groups based on the convention used in the Framsticks GUI application:
|
---|
9 | // - group names containing colon characters ":" are hierarchical paths (like a filesystem),
|
---|
10 | // - groups referencing common subpaths connect to their common parent nodes,
|
---|
11 | // - group ordering is preserved,
|
---|
12 | // - duplicate group names are not allowed.
|
---|
13 | //
|
---|
14 | // input: ParamInterface object, only using getGroupCount() and grname()
|
---|
15 | // output: tree structure in ParamTree.root, traverse using first_child/next_sibling
|
---|
16 | //
|
---|
17 | // example input: "a" "b" "c" "a:b:c" (connects to existing "a") "b:c" (connects to existing "b") "b:d" (connects to existing "b")
|
---|
18 | // example output:
|
---|
19 | //
|
---|
20 | // +-+ a (node name="a", group name="a")
|
---|
21 | // | '-+ b (dummy node, there is no "a:b" group)
|
---|
22 | // | '-- c (node name="c", group name="a:b:c")
|
---|
23 | // +-+ b
|
---|
24 | // | +-- c
|
---|
25 | // | '-- d
|
---|
26 | // +-- c
|
---|
27 | //
|
---|
28 | // sample code: see frams/_demos/paramtree_stdin_test.cpp
|
---|
29 |
|
---|
30 | class ParamTree
|
---|
31 | {
|
---|
32 | public:
|
---|
33 | class Node;
|
---|
34 | typedef std::shared_ptr<Node> NodePtr;
|
---|
35 | class Node
|
---|
36 | {
|
---|
37 | public:
|
---|
38 | ParamTree *tree;
|
---|
39 | Node *parent;
|
---|
40 | SString name; //path component name
|
---|
41 | int group_index; //original group index or -1 for dummy nodes
|
---|
42 | NodePtr first_child;
|
---|
43 | NodePtr next_sibling;
|
---|
44 |
|
---|
45 | Node(ParamTree *_tree = NULL, Node *_parent = NULL, const SString &_name = "", int _group_index = -1)
|
---|
46 | :tree(_tree), parent(_parent), name(_name), group_index(_group_index) {}
|
---|
47 | };
|
---|
48 | Node root;
|
---|
49 | ParamInterface π
|
---|
50 |
|
---|
51 | Node *addNode(Node* parent, const SString &name, int group);
|
---|
52 | Node *findNode(Node *parent, const SString& name);
|
---|
53 |
|
---|
54 | ParamTree(ParamInterface &_pi);
|
---|
55 | };
|
---|
56 |
|
---|
57 | #endif
|
---|