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