##// END OF EJS Templates
Implements "Variable creation" operation (2)
Alexandre Leroux -
r1208:94f6e8c9cecc
parent child
Show More
@@ -1,48 +1,64
1 #include "FuzzingOperations.h"
1 #include "FuzzingOperations.h"
2 #include "FuzzingUtils.h"
3
4 #include <Data/IDataProvider.h>
2
5
3 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
4 #include <Variable/VariableController.h>
7 #include <Variable/VariableController.h>
5
8
9 #include <QUuid>
10
6 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
11 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
7
12
8 namespace {
13 namespace {
9
14
10 struct CreateOperation : public IFuzzingOperation {
15 struct CreateOperation : public IFuzzingOperation {
11 bool canExecute(std::shared_ptr<Variable> variable) const override {
16 bool canExecute(std::shared_ptr<Variable> variable) const override {
12 /// @todo: complete
17 // A variable can be created only if it doesn't exist yet
13 return false;
18 return variable == nullptr;
14 }
19 }
15
20
16 void execute(std::shared_ptr<Variable>& variable, VariableController &variableController, const Properties &properties) const override{
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
21 struct UnknownOperation : public IFuzzingOperation {
37 struct UnknownOperation : public IFuzzingOperation {
22 bool canExecute(std::shared_ptr<Variable> variable) const override {
38 bool canExecute(std::shared_ptr<Variable> variable) const override {
23 Q_UNUSED(variable);
39 Q_UNUSED(variable);
24 return false;
40 return false;
25 }
41 }
26
42
27 void execute(std::shared_ptr<Variable>& variable, VariableController &variableController, const Properties &properties) const override{
43 void execute(std::shared_ptr<Variable>& variable, VariableController &variableController, const Properties &properties) const override{
28 Q_UNUSED(variable);
44 Q_UNUSED(variable);
29 Q_UNUSED(variableController);
45 Q_UNUSED(variableController);
30 Q_UNUSED(properties);
46 Q_UNUSED(properties);
31 // Does nothing
47 // Does nothing
32 }
48 }
33 };
49 };
34
50
35 } // namespace
51 } // namespace
36
52
37 std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type)
53 std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type)
38 {
54 {
39 switch (type) {
55 switch (type) {
40 case FuzzingOperationType::CREATE:
56 case FuzzingOperationType::CREATE:
41 return std::make_unique<CreateOperation>();
57 return std::make_unique<CreateOperation>();
42 default:
58 default:
43 // Default case returns unknown operation
59 // Default case returns unknown operation
44 break;
60 break;
45 }
61 }
46
62
47 return std::make_unique<UnknownOperation>();
63 return std::make_unique<UnknownOperation>();
48 }
64 }
General Comments 0
You need to be logged in to leave comments. Login now