Loading...
Searching...
No Matches
Program.h
1/*
2
3MIT License
4
5Copyright (c) 2017 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/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31
32// New design (2020)
33
34#ifndef PROGRAM_H_
35#define PROGRAM_H_
36
37#include <iostream>
38
39#include <drain/Sprinter.h>
40
41#include "Command.h"
42
43
44namespace drain {
45
47template <class T>
48class CommandSequence : public std::list<T> {
49
50public:
51
52 typedef T entry_t;
53
54 typedef std::list<T> list_t;
55
56 // virtual consider
57 // typename list_t::value_type & add(key, cmd) = 0;
58
60 inline
61 operator bool(){ return !this->empty(); };
62
63};
64
65template <class T>
66inline
67std::ostream & operator<<(std::ostream & ostr, const CommandSequence<T> & commands){
68
76 static const SprinterLayout layout("\n", "{,}", "=", "");
77
78 Sprinter::sequenceToStream(ostr, commands, layout);
79 return ostr;
80}
81
82
83
84
85class Script : public CommandSequence<std::pair<std::string,std::string> > {
86
87public:
88
89 typename list_t::value_type & add(const std::string & key, const std::string & params="");
90
91};
92
93
94
96
100//class Program : public CommandSequence<std::pair<std::string,Command *> > {
101class Program : public CommandSequence<std::pair<std::string,Command *> >, public Contextual {
102
103public:
104
105 inline
106 Program(){};
107
108 inline
109 Program(const Program &prog){
110 std::cerr << "Program copy ctor: ctx?\n";
111 };
112
113 inline
114 Program(Context & ctx){
116 };
117
118
119 Command & add(const std::string & key, Command & cmd);
120
122 void run() const;
123
124};
125
127//class ProgramVector : public std::vector<Program> {
128class ProgramVector : public std::map<int,Program> {
129
130public:
131
133 Program & add(Context & ctx);
134
135 void debug();
136
137};
138
139
140
141} /* namespace drain */
142
143#endif /* DRAINLET_H_ */
144
145// Rack
A base class for Script and Program.
Definition Program.h:48
Base class for commands: typically actions taking parameters but also plain variable assignments and ...
Definition Command.h:55
Definition Context.h:57
Definition Context.h:246
void setExternalContext(Context &ctx)
Sets internal contextPtr to outside target.
Definition Context.h:275
Structure for implementing threads in parallelized OpenMP for loop.
Definition Program.h:128
Program & add(Context &ctx)
Adds a new, empty program to thread vector.
Definition Program.cpp:86
Sequence consisting of Command:s retrieved from a CommandBank.
Definition Program.h:101
void run() const
Main.
Definition Program.cpp:61
Definition Program.h:85
static std::ostream & sequenceToStream(std::ostream &ostr, const T &x, const SprinterLayout &layout)
Convenience: if sequence type (array, list, set, map) not given, assume array.
Definition Sprinter.h:321
Definition DataSelector.cpp:1277
Definition Sprinter.h:137