Evoplex  0.2.1
attrsgenerator.h
1 /* Evoplex <https://evoplex.org>
2  * Copyright (C) 2016-present - Marcos Cardinot <marcos@cardinot.net>
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ATTRS_GENERATOR_H
18 #define ATTRS_GENERATOR_H
19 
20 #include <functional>
21 #include <memory>
22 
23 #include "attributes.h"
24 #include "attributerange.h"
25 #include "enum.h"
26 
27 namespace evoplex {
28 
29 class AGSameFuncForAll;
30 class AGDiffFunctions;
31 class AttrsGenerator;
32 using AttrsGeneratorPtr = std::unique_ptr<AttrsGenerator>;
33 
39 {
40 public:
42  virtual ~AttrsGeneratorInterface() = default;
43 
51  virtual SetOfAttributes create(int size=-1, std::function<void(int)> progress = [](int){}) = 0;
52 };
53 
59 {
60 public:
86  static AttrsGeneratorPtr parse(const AttributesScope& attrsScope,
87  const QString &cmd, QString& error);
88 
90  virtual ~AttrsGenerator() = default;
91 
95  inline AttributesScope attrsScope() const { return m_attrsScope; }
96 
100  inline const QString& command() { return m_command; }
101 
105  inline int size() const { return m_size; }
106 
113  static Value parseRandSeed(QString seedStr);
114 
115 protected:
116  const AttributesScope m_attrsScope;
117  const int m_size;
118  QString m_command;
119 
125  explicit AttrsGenerator(const AttributesScope& attrsScope, const int size);
126 
127 private:
128  // auxiliar parser for commands starting with '*'
129  static std::unique_ptr<AGSameFuncForAll> parseStarCmd(
130  const AttributesScope& attrsScope, const int size,
131  const QStringList& cmds, QString& error);
132 
133  // auxiliar parser for commands starting with '#'
134  static std::unique_ptr<AGDiffFunctions> parseHashCmd(
135  const AttributesScope& attrsScope, const int size,
136  const QStringList& cmds, QString& error);
137 };
138 
145 {
146 public:
155  explicit AGSameFuncForAll(const AttributesScope& attrsScope, const int size,
156  const Function& func, const Value& funcInput);
157  ~AGSameFuncForAll() override;
158 
159  SetOfAttributes create(int size=-1,
160  std::function<void(int)> progress = [](int){}) override;
161 
165  inline Function function() const { return m_function; }
169  inline const Value& functionInput() const { return m_functionInput; }
170 
171 private:
172  const Function m_function;
173  const Value m_functionInput;
174 
175  std::function<Value(AttributeRangePtr)> f_value;
176  PRG* m_prg;
177 };
178 
185 {
186 public:
190  struct AttrCmd {
191  int attrId;
192  QString attrName;
193  Function func;
195  };
196 
204  explicit AGDiffFunctions(const AttributesScope& attrsScope, const int size,
205  const std::vector<AttrCmd>& attrCmds);
206  ~AGDiffFunctions() override = default;
207 
208  SetOfAttributes create(int size=-1,
209  std::function<void(int)> progress = [](int){}) override;
210 
214  inline const std::vector<AttrCmd>& attrCmds() const { return m_attrCmds; }
215 
216 private:
217  const std::vector<AttrCmd> m_attrCmds;
218 };
219 
220 } // evoplex
221 #endif // ATTRS_GENERATOR_H
SetOfAttributes create(int size=-1, std::function< void(int)> progress=[](int){}) override
Creates a set of attributes.
A class for variant data types (tagged union).
Definition: value.h:56
This class is used to generate a set of Attributes using different functions for each attribute...
Definition: attrsgenerator.h:184
QString attrName
attribute&#39;s name
Definition: attrsgenerator.h:192
AGDiffFunctions(const AttributesScope &attrsScope, const int size, const std::vector< AttrCmd > &attrCmds)
Constructor.
The attribute&#39;s command struct.
Definition: attrsgenerator.h:190
SetOfAttributes create(int size=-1, std::function< void(int)> progress=[](int){}) override
Creates a set of attributes.
const QString & command()
Gets the source command for the AttrsGenerator object.
Definition: attrsgenerator.h:100
static AttrsGeneratorPtr parse(const AttributesScope &attrsScope, const QString &cmd, QString &error)
Creates a AttrsGenerator object from a command.
AttrsGenerator(const AttributesScope &attrsScope, const int size)
Constructor.
Function func
attribute&#39;s function
Definition: attrsgenerator.h:193
int size() const
Gets the size of the set of attributes.
Definition: attrsgenerator.h:105
AttributesScope attrsScope() const
Gets the attribute&#39;s scope.
Definition: attrsgenerator.h:95
const std::vector< AttrCmd > & attrCmds() const
Gets the attribute&#39;s commands.
Definition: attrsgenerator.h:214
virtual ~AttrsGeneratorInterface()=default
Destructor.
Generates a set of Attributes.
Definition: attrsgenerator.h:58
Value funcInput
function&#39;s input
Definition: attrsgenerator.h:194
virtual ~AttrsGenerator()=default
Destructor.
Pseudo-random number generator.
Definition: prg.h:29
A common interface for the attributes&#39; generators classes.
Definition: attrsgenerator.h:38
int attrId
attribute&#39;s id
Definition: attrsgenerator.h:191
const Value & functionInput() const
Gets the input of the function used by this attributes generator.
Definition: attrsgenerator.h:169
AGSameFuncForAll(const AttributesScope &attrsScope, const int size, const Function &func, const Value &funcInput)
Constructor.
This class is used to generate a set of Attributes using the same function for all attributes...
Definition: attrsgenerator.h:144
Definition: abstractgraph.h:29
virtual SetOfAttributes create(int size=-1, std::function< void(int)> progress=[](int){})=0
Creates a set of attributes.
static Value parseRandSeed(QString seedStr)
Parse a &#39;rand_seed&#39; command.