FuzzingDefs.cpp
118 lines
| 3.9 KiB
| text/x-c
|
CppLexer
|
r1169 | #include "FuzzingDefs.h" | ||
|
r1215 | const QString ACQUISITION_TIMEOUT_PROPERTY = QStringLiteral("acquisitionTimeout"); | ||
|
r1170 | const QString NB_MAX_OPERATIONS_PROPERTY = QStringLiteral("component"); | ||
|
r1204 | const QString NB_MAX_SYNC_GROUPS_PROPERTY = QStringLiteral("nbSyncGroups"); | ||
|
r1170 | const QString NB_MAX_VARIABLES_PROPERTY = QStringLiteral("nbMaxVariables"); | ||
|
r1173 | const QString AVAILABLE_OPERATIONS_PROPERTY = QStringLiteral("availableOperations"); | ||
|
r1191 | const QString CACHE_TOLERANCE_PROPERTY = QStringLiteral("cacheTolerance"); | ||
|
r1190 | const QString INITIAL_RANGE_PROPERTY = QStringLiteral("initialRange"); | ||
|
r1178 | const QString MAX_RANGE_PROPERTY = QStringLiteral("maxRange"); | ||
|
r1176 | const QString METADATA_POOL_PROPERTY = QStringLiteral("metadataPool"); | ||
const QString PROVIDER_PROPERTY = QStringLiteral("provider"); | ||||
|
r1210 | const QString OPERATION_DELAY_BOUNDS_PROPERTY = QStringLiteral("operationDelays"); | ||
|
r1195 | const QString VALIDATORS_PROPERTY = QStringLiteral("validators"); | ||
|
r1211 | const QString VALIDATION_FREQUENCY_BOUNDS_PROPERTY = QStringLiteral("validationFrequencyBounds"); | ||
|
r1202 | |||
// //////////// // | ||||
// FuzzingState // | ||||
// //////////// // | ||||
const SyncGroup &FuzzingState::syncGroup(SyncGroupId id) const | ||||
{ | ||||
return m_SyncGroupsPool.at(id); | ||||
} | ||||
SyncGroup &FuzzingState::syncGroup(SyncGroupId id) | ||||
{ | ||||
return m_SyncGroupsPool.at(id); | ||||
} | ||||
const VariableState &FuzzingState::variableState(VariableId id) const | ||||
{ | ||||
return m_VariablesPool.at(id); | ||||
} | ||||
VariableState &FuzzingState::variableState(VariableId id) | ||||
{ | ||||
return m_VariablesPool.at(id); | ||||
} | ||||
|
r1206 | SyncGroupId FuzzingState::syncGroupId(VariableId variableId) const | ||
{ | ||||
auto end = m_SyncGroupsPool.cend(); | ||||
auto it | ||||
= std::find_if(m_SyncGroupsPool.cbegin(), end, [&variableId](const auto &syncGroupEntry) { | ||||
const auto &syncGroup = syncGroupEntry.second; | ||||
return syncGroup.m_Variables.find(variableId) != syncGroup.m_Variables.end(); | ||||
}); | ||||
return it != end ? it->first : SyncGroupId{}; | ||||
} | ||||
|
r1207 | std::vector<SyncGroupId> FuzzingState::syncGroupsIds() const | ||
{ | ||||
std::vector<SyncGroupId> result{}; | ||||
for (const auto &entry : m_SyncGroupsPool) { | ||||
result.push_back(entry.first); | ||||
} | ||||
return result; | ||||
} | ||||
void FuzzingState::synchronizeVariable(VariableId variableId, SyncGroupId syncGroupId) | ||||
{ | ||||
if (syncGroupId.isNull()) { | ||||
return; | ||||
} | ||||
|
r1274 | // Registers variable into sync group | ||
|
r1207 | auto &syncGroup = m_SyncGroupsPool.at(syncGroupId); | ||
|
r1274 | auto &variableState = m_VariablesPool.at(variableId); | ||
|
r1207 | syncGroup.m_Variables.insert(variableId); | ||
if (syncGroup.m_Variables.size() == 1) { | ||||
|
r1274 | // If it's the first variable, sets the variable range as the sync group range | ||
|
r1207 | syncGroup.m_Range = variableState.m_Range; | ||
} | ||||
|
r1274 | else { | ||
// If a variable is added to an existing group, sets its range to the group's range | ||||
variableState.m_Range = syncGroup.m_Range; | ||||
} | ||||
|
r1207 | } | ||
|
r1208 | void FuzzingState::desynchronizeVariable(VariableId variableId, SyncGroupId syncGroupId) | ||
{ | ||||
if (syncGroupId.isNull()) { | ||||
return; | ||||
} | ||||
|
r1209 | // Unregisters variable from sync group: if there is no more variable in the group, resets the | ||
// range | ||||
|
r1208 | auto &syncGroup = m_SyncGroupsPool.at(syncGroupId); | ||
syncGroup.m_Variables.erase(variableId); | ||||
if (syncGroup.m_Variables.empty()) { | ||||
syncGroup.m_Range = INVALID_RANGE; | ||||
} | ||||
} | ||||
r1346 | void FuzzingState::updateRanges(VariableId variableId, const DateTimeRange &newRange) | |||
|
r1209 | { | ||
auto syncGroupId = this->syncGroupId(variableId); | ||||
// Retrieves the variables to update: | ||||
|
r1274 | // - if the variable is synchronized to others, updates the range of the group and of all | ||
// synchronized variables | ||||
|
r1209 | // - otherwise, updates only the variable | ||
|
r1274 | if (syncGroupId.isNull()) { | ||
|
r1209 | m_VariablesPool.at(variableId).m_Range = newRange; | ||
} | ||||
|
r1274 | else { | ||
auto &syncGroup = m_SyncGroupsPool.at(syncGroupId); | ||||
syncGroup.m_Range = newRange; | ||||
for (const auto &variableId : syncGroup.m_Variables) { | ||||
m_VariablesPool.at(variableId).m_Range = newRange; | ||||
} | ||||
} | ||||
|
r1209 | } | ||