##// END OF EJS Templates
Implements "Variable creation" operation (2)
Alexandre Leroux -
r1208:94f6e8c9cecc
parent child
Show More
@@ -1,20 +1,36
1 1 #include "FuzzingOperations.h"
2 #include "FuzzingUtils.h"
3
4 #include <Data/IDataProvider.h>
2 5
3 6 #include <Variable/Variable.h>
4 7 #include <Variable/VariableController.h>
5 8
9 #include <QUuid>
10
6 11 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
7 12
8 13 namespace {
9 14
10 15 struct CreateOperation : public IFuzzingOperation {
11 16 bool canExecute(std::shared_ptr<Variable> variable) const override {
12 /// @todo: complete
13 return false;
17 // A variable can be created only if it doesn't exist yet
18 return variable == nullptr;
14 19 }
15 20
16 21 void execute(std::shared_ptr<Variable>& variable, VariableController &variableController, const Properties &properties) const override{
17 /// @todo: complete
22 // Retrieves metadata pool from properties, and choose one of the metadata entries to associate it with the variable
23 auto metaDataPool = properties.value(METADATA_POOL_PROPERTY).value<MetadataPool>();
24 auto variableMetadata = RandomGenerator::instance().randomChoice(metaDataPool);
25
26 // Retrieves provider
27 auto variableProvider = properties.value(PROVIDER_PROPERTY).value<std::shared_ptr<IDataProvider>>();
28
29 auto variableName = QString{"Var_%1"}.arg(QUuid::createUuid().toString());
30 qCInfo(LOG_FuzzingOperations()) << "Creating variable" << variableName << "(metadata:" << variableMetadata << ")";
31
32 auto newVariable = variableController.createVariable(variableName, variableMetadata, variableProvider);
33 std::swap(variable, newVariable);
18 34 }
19 35 };
20 36
General Comments 0
You need to be logged in to leave comments. Login now