##// END OF EJS Templates
Implements canExecute() method of syn/desync operations
Alexandre Leroux -
r1239:4bcf5995377c
parent child
Show More
@@ -36,3 +36,15 VariableState &FuzzingState::variableState(VariableId id)
36 return m_VariablesPool.at(id);
36 return m_VariablesPool.at(id);
37 }
37 }
38
38
39 SyncGroupId FuzzingState::syncGroupId(VariableId variableId) const
40 {
41 auto end = m_SyncGroupsPool.cend();
42 auto it
43 = std::find_if(m_SyncGroupsPool.cbegin(), end, [&variableId](const auto &syncGroupEntry) {
44 const auto &syncGroup = syncGroupEntry.second;
45 return syncGroup.m_Variables.find(variableId) != syncGroup.m_Variables.end();
46 });
47
48 return it != end ? it->first : SyncGroupId{};
49 }
50
@@ -93,6 +93,10 struct FuzzingState {
93 const VariableState &variableState(VariableId id) const;
93 const VariableState &variableState(VariableId id) const;
94 VariableState &variableState(VariableId id);
94 VariableState &variableState(VariableId id);
95
95
96 /// @return the identifier of the synchronization group in which the variable passed in
97 /// parameter is located. If the variable is not in any group, returns an invalid identifier
98 SyncGroupId syncGroupId(VariableId variableId) const;
99
96
100
97 VariablesPool m_VariablesPool;
101 VariablesPool m_VariablesPool;
98 SyncGroupsPool m_SyncGroupsPool;
102 SyncGroupsPool m_SyncGroupsPool;
@@ -152,6 +152,9 struct MoveOperation : public IFuzzingOperation {
152 struct SynchronizeOperation : public IFuzzingOperation {
152 struct SynchronizeOperation : public IFuzzingOperation {
153 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
153 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
154 {
154 {
155 auto variable = fuzzingState.variableState(variableId).m_Variable;
156 return variable != nullptr && !fuzzingState.m_SyncGroupsPool.empty()
157 && fuzzingState.syncGroupId(variableId).isNull();
155 }
158 }
156
159
157 void execute(VariableId variableId, FuzzingState &fuzzingState,
160 void execute(VariableId variableId, FuzzingState &fuzzingState,
@@ -163,6 +166,8 struct SynchronizeOperation : public IFuzzingOperation {
163 struct DesynchronizeOperation : public IFuzzingOperation {
166 struct DesynchronizeOperation : public IFuzzingOperation {
164 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
167 bool canExecute(VariableId variableId, const FuzzingState &fuzzingState) const override
165 {
168 {
169 auto variable = fuzzingState.variableState(variableId).m_Variable;
170 return variable != nullptr && !fuzzingState.syncGroupId(variableId).isNull();
166 }
171 }
167
172
168 void execute(VariableId variableId, FuzzingState &fuzzingState,
173 void execute(VariableId variableId, FuzzingState &fuzzingState,
General Comments 0
You need to be logged in to leave comments. Login now