source: cpp/frams/param/paramtree.h @ 976

Last change on this file since 976 was 755, checked in by Maciej Komosinski, 7 years ago

Renamed ParamTree::Node -> ParamTree::ParamTreeNode? to avoid name conflicts with js

File size: 2.0 KB
Line 
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
34class ParamTree
35{
36public:
37        class ParamTreeNode;
38        typedef std::shared_ptr<ParamTreeNode> NodePtr;
39        class ParamTreeNode
40        {
41        public:
42                ParamTree *tree;
43                ParamTreeNode *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                ParamTreeNode(ParamTree *_tree = NULL, ParamTreeNode *_parent = NULL, const string &_name = "", int _group_index = -1)
50                        :tree(_tree), parent(_parent), name(_name), group_index(_group_index) {}
51        };
52        ParamTreeNode root;
53        ParamInterface &pi;
54
55        ParamTreeNode *addNode(ParamTreeNode* parent, const string &name, int group);
56        ParamTreeNode *findNode(ParamTreeNode *parent, const string& name);
57
58        ParamTree(ParamInterface *_pi);
59};
60
61#endif
Note: See TracBrowser for help on using the repository browser.