@@ -1,48 +1,64 | |||
|
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 |
|
|
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 | |
|
21 | 37 | struct UnknownOperation : public IFuzzingOperation { |
|
22 | 38 | bool canExecute(std::shared_ptr<Variable> variable) const override { |
|
23 | 39 | Q_UNUSED(variable); |
|
24 | 40 | return false; |
|
25 | 41 | } |
|
26 | 42 | |
|
27 | 43 | void execute(std::shared_ptr<Variable>& variable, VariableController &variableController, const Properties &properties) const override{ |
|
28 | 44 | Q_UNUSED(variable); |
|
29 | 45 | Q_UNUSED(variableController); |
|
30 | 46 | Q_UNUSED(properties); |
|
31 | 47 | // Does nothing |
|
32 | 48 | } |
|
33 | 49 | }; |
|
34 | 50 | |
|
35 | 51 | } // namespace |
|
36 | 52 | |
|
37 | 53 | std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type) |
|
38 | 54 | { |
|
39 | 55 | switch (type) { |
|
40 | 56 | case FuzzingOperationType::CREATE: |
|
41 | 57 | return std::make_unique<CreateOperation>(); |
|
42 | 58 | default: |
|
43 | 59 | // Default case returns unknown operation |
|
44 | 60 | break; |
|
45 | 61 | } |
|
46 | 62 | |
|
47 | 63 | return std::make_unique<UnknownOperation>(); |
|
48 | 64 | } |
General Comments 0
You need to be logged in to leave comments.
Login now