Loading...
Searching...
No Matches
Loop.h
1/*
2
3MIT License
4
5Copyright (c) 2026 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27 * Loop.h
28 *
29 * Created on: Jun 6, 2026
30 * Author: mpeura
31 */
32
33#ifndef DRAIN_PROG_LOOP
34#define DRAIN_PROG_LOOP
35
36#include <iostream>
37#include <string>
38#include <list>
39
40#include <drain/StringTools.h>
41
42namespace drain {
43
44
45class Loop {
46public:
47
48 Loop(const std::string & key="", const std::string & values=""){
49 set(key, values);
50 }
51
52 //typedef std::list<drain::Variable> valueList;
53 typedef std::list<std::string> valueList;
54
55 std::string key;
56
57 Loop & set(const std::string & key, const std::string & values){
58 this->key = key;
59 drain::StringTools::split(values, this->values, ",");
60 return *this;
61 }
62
63 // template <class C>
64 // void set(const std::string & key, const std::string & values); //, const C & separator){
65
66 inline
67 const valueList & getValueList() const {
68 return values;
69 }
70
71 typedef std::list<Loop> loopStack;
72
73 /*
74 static inline
75 void traverse(const loopStack & stack){
76 traverse(stack.begin(), stack.end());
77 }
78 */
79
80protected:
81
82
83 //static inline
84 //void traverse(loopStack::const_iterator it, loopStack::const_iterator itEnd);
85
86 valueList values;
87
88};
89
90/*
91void Loop::traverse(loopStack::const_iterator it, loopStack::const_iterator itEnd){
92
93 std::cout << it->key << '\n';
94
95 loopStack::const_iterator it2 = it;
96 ++it2;
97
98 for (const auto & item: it->values){
99 //std::cout << '\t' << it->key << ' ' << item << '\n';
100 std::cout << '\t' << item << '\n';
101 if (it2 != itEnd){
102 Loop::traverse(it2, itEnd);
103 }
104 }
105
106}
107*/
108
109
110
111} // drain::
112
113#endif // DRAIN_PROG_LOOP
Definition Loop.h:45
static void split(const std::string &s, T &sequence, const C &separators, const std::string &trimChars=" \t\n")
Splits and trims a given std::string to a std Sequence.
Definition StringTools.h:487
Definition DataSelector.cpp:1277