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

Last change on this file since 1237 was 973, checked in by Maciej Komosinski, 4 years ago

Increased SString and std::string compatibility: introduced length(), size(), and capacity(), and removed legacy methods that have std::string equivalents

File size: 2.2 KB
Line 
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);
15                setParamTab(getParamTab());
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
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.
36int main()
37{
38        SString group_names;
39        StdioFILE::setStdio(); //setup VirtFILE::Vstdin/out/err
40        puts("(loading group names from stdin)");
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.length() > 0) && (line[line.length() - 1] == '\r')) //support for reading \r\n files...
48                        line = line.substr(0, line.length() - 1);
49                if (line.length() > 0 && line[0] != '#') //skip empty lines and #commment lines
50                        param.addGroup(line.c_str());
51        }
52        printf("%d groups\n\n", param.getGroupCount());
53
54        ParamTree tree(&param);
55
56        printTree(&tree.root);
57}
Note: See TracBrowser for help on using the repository browser.