source: cpp/frams/_demos/paramtree_stdin_test.cpp @ 920

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

ParamTree? constructor changed (to make it easier for javascript) to accept ParamInterface?* instead of ParamInterface?&

File size: 2.2 KB
RevLine 
[724]1#include <frams/util/sstringutils.h>
2#include <common/virtfile/stdiofile.h>
3#include <frams/param/paramtree.h>
4#include "paramtree_print.h"
5
6class EmptyParamWithGroupsForTesting : public Param
7{
8        std::vector<ParamEntry> entries;
9        std::vector<std::shared_ptr<std::string>> strings; //could be a simple vector of strings, but then char* pointers can change when adding new strings and so ParamEntry structures would need updating. Therefore using "vector of string pointers" instead of "vector of strings".
10public:
11        EmptyParamWithGroupsForTesting()
12        {
13                ParamEntry zero_ending = { 0, 0, 0, 0 };
14                entries.push_back(zero_ending);
[725]15                setParamTab(getParamTab());
[724]16        }
17        void addGroup(const char* name)
18        {
19                std::shared_ptr<string> str(new std::string(name));
20                strings.push_back(str);
21                ParamEntry tmp = { str.get()->c_str(), 0, 0, 0 };
22                entries.insert(entries.begin() + (entries.size() - 1), tmp);
23                entries[0].group = entries.size() - 1;
24                setParamTab(getParamTab());
25        }
26        ParamEntry *getParamTab()
27        {
28                return &entries[0];
29        }
30};
31
[730]32// This program tests parameter tree construction for paramtab names read from stdin.
33// app_group_names.txt can be used as a sample input, because it contains a large set of paramtab objects from Framsticks GUI.
34// See paramtree_paramlist_test.cpp for a demonstration of parameter tree construction for all paramtab's that are available in SDK.
35// See mutableparam_test.cpp for a demonstration on how to detect (and possibly respond to) changing parameter definitions.
[724]36int main()
37{
38        SString group_names;
[725]39        StdioFILE::setStdio(); //setup VirtFILE::Vstdin/out/err
40        puts("(loading group names from stdin)");
[724]41        loadSString(VirtFILE::Vstdin, group_names);
42        int pos = 0;
43        SString line;
44        EmptyParamWithGroupsForTesting param;
45        while (group_names.getNextToken(pos, line, '\n'))
46        {
47                if ((line.len() > 0) && (line[line.len() - 1] == '\r')) //support for reading \r\n files...
48                        line = line.substr(0, line.len() - 1);
[725]49                if (line.len() > 0 && line[0] != '#') //skip empty lines and #commment lines
[724]50                        param.addGroup(line.c_str());
51        }
52        printf("%d groups\n\n", param.getGroupCount());
53
[744]54        ParamTree tree(&param);
[724]55
56        printTree(&tree.root);
57}
Note: See TracBrowser for help on using the repository browser.