GEGELATI
Loading...
Searching...
No Matches
program.h
1
38#ifndef PROGRAM_H
39#define PROGRAM_H
40
41#include <algorithm>
42#include <vector>
43
44#include "data/constantHandler.h"
45#include "environment.h"
46#include "program/line.h"
47
48struct CounterReset;
49
50namespace Program {
56 class Program
57 {
58 protected:
61
71
83 std::vector<std::pair<Line*, bool>> lines;
84
92
96 uint64_t programID;
97
101 static uint64_t incrementeCounter();
102
109 static void resetProgramIDCounter();
110 friend struct ::CounterReset;
111
113 Program() = delete;
114
115 public:
123 Program(const Environment& e, bool actProgram)
124 : environment{e}, programID{incrementeCounter()},
125 constants{e.getParams().nbProgramConstant},
126 actionProgram{actProgram}
127 {
128 constants.resetData(); // force all constant to 0 at first.
129 };
130
139 Program(const Program& other)
140 : environment{other.environment}, lines{other.lines},
141 programID{other.programID}, constants{other.constants},
142 actionProgram{other.actionProgram}
143 {
144 // Replace lines with their copy
145 // Keep intron info
146 std::transform(lines.begin(), lines.end(), lines.begin(),
147 [](std::pair<Line*, bool>& otherLine)
148 -> std::pair<Line*, bool> {
149 return {new Line(*(otherLine.first)),
150 otherLine.second};
151 });
152 };
153
164 Program(const Program& other, bool actProgram)
165 : environment{other.environment}, programID{incrementeCounter()},
166 lines{other.lines}, constants{other.constants},
167 actionProgram{actProgram}
168 {
169 // Replace lines with their copy
170 // Keep intro info
171 std::transform(lines.begin(), lines.end(), lines.begin(),
172 [](std::pair<Line*, bool>& otherLine)
173 -> std::pair<Line*, bool> {
174 return {new Line(*(otherLine.first)),
175 otherLine.second};
176 });
177 };
178
185 Program& operator=(const Program& other) = delete;
186
193 ~Program();
194
202 Line& addNewLine();
203
214 Line& addNewLine(const uint64_t idx);
215
221 void addNewLine(Line newLine);
222
233 void clearIntrons();
234
244 void removeLine(const uint64_t idx);
245
253 void swapLines(const uint64_t idx0, const uint64_t idx1);
254
262 const Environment& getEnvironment() const;
263
269 size_t getNbLines() const;
270
278 const Line& getLine(uint64_t index) const;
279
287 Line& getLine(uint64_t index);
288
297 bool isIntron(uint64_t index) const;
298
304 bool isActionProgram() const;
305
314 uint64_t identifyIntrons();
315
324 Data::ConstantHandler& getConstantHandler();
325
335 const Data::ConstantHandler& cGetConstantHandler() const;
336
346 const Data::Constant getConstantAt(size_t index) const;
347
357 bool hasIdenticalBehavior(const Program& other) const;
358
364 uint64_t getProgramID() const;
365
371 virtual void setProgramID(uint64_t newID);
372
381 static uint64_t getProgramIDCounter();
382 };
383} // namespace Program
384#endif
Data::DataHandler used by Program::Program to handle their set of Constant values.
Definition constantHandler.h:56
void resetData() override
Sets all elements of the Array to 0 (or its equivalent for the given template param....
Definition primitiveTypeArray.h:189
The Environment class contains all information needed to execute a Program.
Definition environment.h:86
Definition line.h:49
const Environment & environment
Environment within which the Program will be executed.
Definition program.h:60
Program(const Environment &e, bool actProgram)
Main constructor of the Program.
Definition program.h:123
Program()=delete
Delete the default constructor.
Program & operator=(const Program &other)=delete
Data::ConstantHandler constants
Constants of the Program.
Definition program.h:91
Program(const Program &other)
Copy constructor of the Program.
Definition program.h:139
Program(const Program &other, bool actProgram)
Copy constructor of the Program.
Definition program.h:164
std::vector< std::pair< Line *, bool > > lines
Lines of the program and intron property.
Definition program.h:83
bool actionProgram
Boolean indicating if true that the program is an action program, if false that it is a context progr...
Definition program.h:70
uint64_t programID
Unique identifier of the Program.
Definition program.h:96
Definition line.h:44
Struct to reset static counters in classes.
Definition counterReset.h:47
Data type used in Program::Program to define constant values, accessible to Instructions,...
Definition constant.h:49