[734] | 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 |
|
---|
[723] | 5 | #ifndef _PARAMTREE_H_
|
---|
| 6 | #define _PARAMTREE_H_
|
---|
| 7 |
|
---|
| 8 | #include <frams/param/param.h>
|
---|
| 9 | #include <vector>
|
---|
| 10 | #include <memory>
|
---|
| 11 |
|
---|
[728] | 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.
|
---|
[723] | 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:
|
---|
[755] | 37 | class ParamTreeNode;
|
---|
| 38 | typedef std::shared_ptr<ParamTreeNode> NodePtr;
|
---|
| 39 | class ParamTreeNode
|
---|
[723] | 40 | {
|
---|
| 41 | public:
|
---|
| 42 | ParamTree *tree;
|
---|
[755] | 43 | ParamTreeNode *parent;
|
---|
[734] | 44 | string name; //path component name
|
---|
[723] | 45 | int group_index; //original group index or -1 for dummy nodes
|
---|
| 46 | NodePtr first_child;
|
---|
| 47 | NodePtr next_sibling;
|
---|
| 48 |
|
---|
[755] | 49 | ParamTreeNode(ParamTree *_tree = NULL, ParamTreeNode *_parent = NULL, const string &_name = "", int _group_index = -1)
|
---|
[723] | 50 | :tree(_tree), parent(_parent), name(_name), group_index(_group_index) {}
|
---|
| 51 | };
|
---|
[755] | 52 | ParamTreeNode root;
|
---|
[723] | 53 | ParamInterface π
|
---|
| 54 |
|
---|
[755] | 55 | ParamTreeNode *addNode(ParamTreeNode* parent, const string &name, int group);
|
---|
| 56 | ParamTreeNode *findNode(ParamTreeNode *parent, const string& name);
|
---|
[723] | 57 |
|
---|
[744] | 58 | ParamTree(ParamInterface *_pi);
|
---|
[723] | 59 | };
|
---|
| 60 |
|
---|
| 61 | #endif
|
---|