##// END OF EJS Templates
Defines VariableState struct (2)...
Alexandre Leroux -
r1221:ea075ddc1542
parent child
Show More
@@ -15,13 +15,13 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
15 namespace {
15 namespace {
16
16
17 struct CreateOperation : public IFuzzingOperation {
17 struct CreateOperation : public IFuzzingOperation {
18 bool canExecute(std::shared_ptr<Variable> variable) const override
18 bool canExecute(const VariableState &variableState) const override
19 {
19 {
20 // A variable can be created only if it doesn't exist yet
20 // A variable can be created only if it doesn't exist yet
21 return variable == nullptr;
21 return variableState.m_Variable == nullptr;
22 }
22 }
23
23
24 void execute(std::shared_ptr<Variable> &variable, VariableController &variableController,
24 void execute(VariableState &variableState, VariableController &variableController,
25 const Properties &properties) const override
25 const Properties &properties) const override
26 {
26 {
27 // Retrieves metadata pool from properties, and choose one of the metadata entries to
27 // Retrieves metadata pool from properties, and choose one of the metadata entries to
@@ -39,7 +39,7 struct CreateOperation : public IFuzzingOperation {
39
39
40 auto newVariable
40 auto newVariable
41 = variableController.createVariable(variableName, variableMetadata, variableProvider);
41 = variableController.createVariable(variableName, variableMetadata, variableProvider);
42 std::swap(variable, newVariable);
42 std::swap(variableState.m_Variable, newVariable);
43 }
43 }
44 };
44 };
45
45
@@ -75,14 +75,16 struct MoveOperation : public IFuzzingOperation {
75 {
75 {
76 }
76 }
77
77
78 bool canExecute(std::shared_ptr<Variable> variable) const override
78 bool canExecute(const VariableState &variableState) const override
79 {
79 {
80 return variable != nullptr;
80 return variableState.m_Variable != nullptr;
81 }
81 }
82
82
83 void execute(std::shared_ptr<Variable> &variable, VariableController &variableController,
83 void execute(VariableState &variableState, VariableController &variableController,
84 const Properties &properties) const override
84 const Properties &properties) const override
85 {
85 {
86 auto variable = variableState.m_Variable;
87
86 // Gets the max range defined
88 // Gets the max range defined
87 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
89 auto maxRange = properties.value(MAX_RANGE_PROPERTY, QVariant::fromValue(INVALID_RANGE))
88 .value<SqpRange>();
90 .value<SqpRange>();
@@ -107,6 +109,9 struct MoveOperation : public IFuzzingOperation {
107 << "Performing" << m_Label << "on" << variable->name() << "(from" << variableRange
109 << "Performing" << m_Label << "on" << variable->name() << "(from" << variableRange
108 << "to" << newVariableRange << ")...";
110 << "to" << newVariableRange << ")...";
109 variableController.onRequestDataLoading({variable}, newVariableRange, false);
111 variableController.onRequestDataLoading({variable}, newVariableRange, false);
112
113 // Updates variable's state
114 variableState.m_Range = newVariableRange;
110 }
115 }
111
116
112 MoveFunction m_RangeStartMoveFun;
117 MoveFunction m_RangeStartMoveFun;
@@ -116,16 +121,16 struct MoveOperation : public IFuzzingOperation {
116 };
121 };
117
122
118 struct UnknownOperation : public IFuzzingOperation {
123 struct UnknownOperation : public IFuzzingOperation {
119 bool canExecute(std::shared_ptr<Variable> variable) const override
124 bool canExecute(const VariableState &variableState) const override
120 {
125 {
121 Q_UNUSED(variable);
126 Q_UNUSED(variableState);
122 return false;
127 return false;
123 }
128 }
124
129
125 void execute(std::shared_ptr<Variable> &variable, VariableController &variableController,
130 void execute(VariableState &variableState, VariableController &variableController,
126 const Properties &properties) const override
131 const Properties &properties) const override
127 {
132 {
128 Q_UNUSED(variable);
133 Q_UNUSED(variableState);
129 Q_UNUSED(variableController);
134 Q_UNUSED(variableController);
130 Q_UNUSED(properties);
135 Q_UNUSED(properties);
131 // Does nothing
136 // Does nothing
@@ -11,7 +11,6
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingOperations)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_FuzzingOperations)
13
13
14 class Variable;
15 class VariableController;
14 class VariableController;
16
15
17 /**
16 /**
@@ -23,17 +22,17 enum class FuzzingOperationType { CREATE, PAN_LEFT, PAN_RIGHT, ZOOM_IN, ZOOM_OUT
23 struct IFuzzingOperation {
22 struct IFuzzingOperation {
24 virtual ~IFuzzingOperation() noexcept = default;
23 virtual ~IFuzzingOperation() noexcept = default;
25
24
26 /// Checks if the operation can be executed according to the current state of the variable
25 /// Checks if the operation can be executed according to the current variable state passed in
27 /// passed in parameter
26 /// parameter
28 virtual bool canExecute(std::shared_ptr<Variable> variable) const = 0;
27 virtual bool canExecute(const VariableState &variableState) const = 0;
29 /// Executes the operation on the variable passed in parameter
28 /// Executes the operation on the variable state passed in parameter
30 /// @param variable the variable on which to execute the operation
29 /// @param variableState the variable state on which to execute the operation
31 /// @param variableController the controller associated to the operation
30 /// @param variableController the controller associated to the operation
32 /// @param properties properties that can be used to configure the operation
31 /// @param properties properties that can be used to configure the operation
33 /// @remarks variable is passed as a reference because, according to the operation, it can be
32 /// @remarks variableState is passed as a reference because, according to the operation, it can
33 /// be
34 /// modified (in/out parameter)
34 /// modified (in/out parameter)
35 virtual void execute(std::shared_ptr<Variable> &variable,
35 virtual void execute(VariableState &variableState, VariableController &variableController,
36 VariableController &variableController,
37 const Properties &properties = {}) const = 0;
36 const Properties &properties = {}) const = 0;
38 };
37 };
39
38
General Comments 0
You need to be logged in to leave comments. Login now