26#ifndef SCENARIO_ANALYZER_UTILITIES_HPP
27#define SCENARIO_ANALYZER_UTILITIES_HPP
29#include "wsf_scenario_analyzer_lib_export.h"
67using Messages = std::vector<ScenarioAnalyzerMessage>;
74template<
typename TFunc>
76 const std::string& aCheckName,
80 bool aWriteFlag =
true)
89 if (aFunction(aSimulation, messages, message))
92 messages.push_back(message);
97 for (
const auto& m : messages)
120 std::vector<WsfPlatform*>& visitedPlatforms,
121 std::vector<wsf::comm::Comm*>& visitedComms,
122 const std::vector<std::string>& ignoreOrFollowExternalLinks,
129 std::vector<WsfPlatform*>& visitedPlatforms,
130 std::vector<wsf::comm::Comm*>& visitedComms,
131 const std::vector<std::string>& ignoreOrFollowExternalLinks,
146 UtScriptContext& aContext,
147 UtScriptClass* aReturnClassPtr);
159 std::vector<WsfPlatformPart*> visited;
167 std::vector<T*> linkedPlatformParts;
168 visited.push_back(platformPart);
172 for (
unsigned int i = 0; i != internalLinksCount; ++i)
176 if (recipient && find(visited.begin(), visited.end(), recipient) == visited.end())
178 auto tPtr =
dynamic_cast<T*
>(recipient);
181 linkedPlatformParts.push_back(tPtr);
185 linkedPlatformParts.insert(linkedPlatformParts.end(), indirectlyLinked.begin(), indirectlyLinked.end());
188 return linkedPlatformParts;
195 std::vector<T*> results;
198 for (
unsigned i = 0; i != partCount; ++i)
203 results.push_back(part);
209 for (
unsigned j = 0; j < chainCount; ++j)
212 for (
auto s : subordinates)
217 results.insert(results.end(), subResults.begin(), subResults.end());
222 std::sort(results.begin(), results.end(), [](T * a, T * b)
224 return (a->GetPlatform()->GetNameId() < b->GetPlatform()->GetNameId()) ||
225 (a->GetPlatform()->GetNameId() == b->GetPlatform()->GetNameId() && a->GetNameId() < b->GetNameId());
227 typename std::vector<T*>::iterator
end = std::unique(results.begin(), results.end(), [](T * a, T * b) { return a->GetNameId() == b->GetNameId(); });
228 std::vector<T*> uniqueResults(results.begin(),
end);
229 return uniqueResults;
236 std::vector<T*> results;
239 for (
unsigned i = 0; i != partCount; ++i)
244 results.push_back(part);
252 std::vector<WsfPlatform*> subordinates = commandChain->
GetSubordinates();
253 for (
auto s : subordinates)
258 results.insert(results.end(), subResults.begin(), subResults.end());
268 std::vector<std::string> ignoreOrFollowExternalLinks;
276 std::vector<WsfPlatform*> visitedPlatforms;
277 std::vector<wsf::comm::Comm*> visitedComms;
285 std::vector<WsfPlatform*>& visitedPlatforms,
286 std::vector<wsf::comm::Comm*>& visitedComms,
287 const std::vector<std::string>& ignoreOrFollowExternalLinks,
291 if (std::find(visitedPlatforms.begin(), visitedPlatforms.end(), platform) == visitedPlatforms.end() &&
292 std::find(visitedComms.begin(), visitedComms.end(), origin) == visitedComms.end())
307 linkedAndReachableParts.reserve(linkedAndReachableParts.size() + results.size());
308 linkedAndReachableParts.insert(linkedAndReachableParts.end(), results.begin(), results.end());
314 linkedAndReachableParts.reserve(linkedAndReachableParts.size() + results.size());
315 linkedAndReachableParts.insert(linkedAndReachableParts.end(), results.begin(), results.end());
331 bool considerLP = !follow;
332 for (
const std::string& type : ignoreOrFollowExternalLinks)
334 if (lp->IsA_TypeOf(type))
336 considerLP = !considerLP;
344 linkedAndReachableParts.reserve(linkedAndReachableParts.size() + results.size());
345 linkedAndReachableParts.insert(linkedAndReachableParts.end(), results.begin(), results.end());
350 bool considerSP = !follow;
351 for (
const std::string& type : ignoreOrFollowExternalLinks)
353 if (sp->IsA_TypeOf(type))
355 considerSP = !considerSP;
363 linkedAndReachableParts.reserve(linkedAndReachableParts.size() + results.size());
364 linkedAndReachableParts.insert(linkedAndReachableParts.end(), results.begin(), results.end());
367 return linkedAndReachableParts;
371 return std::vector<T*>();
379 std::vector<WsfPlatform*>& visitedPlatforms,
380 std::vector<wsf::comm::Comm*>& visitedComms,
381 const std::vector<std::string>& ignoreOrFollowExternalLinks,
384 std::vector<T*> linkedAndReachablePlatformParts;
389 for (
size_t i = 0, count = links.
GetLinkCount(); i != count; ++i)
399 std::vector<wsf::comm::Address> recipientAddresses = link.
GetRecipients();
403 if (networkManager->
PathExists(xmtrAddress, rcvrAddress))
409 visitedComms.push_back(xmtr);
411 visitedComms.push_back(rcvr);
412 linkedAndReachablePlatformParts.reserve(linkedAndReachablePlatformParts.size() + results.size());
413 linkedAndReachablePlatformParts.insert(linkedAndReachablePlatformParts.end(), results.begin(), results.end());
420 return linkedAndReachablePlatformParts;
std::vector< T * > getInternallyLinkedPlatformParts(WsfPlatformPart *origin)
Definition ScenarioAnalyzerUtilities.hpp:157
std::function< bool(WsfPlatform *)> PlatformCheck
Definition ScenarioAnalyzerUtilities.hpp:66
WSF_SCENARIO_ANALYZER_LIB_EXPORT bool checkDownCommandChain(WsfPlatform *platform, PlatformCheck check)
Definition ScenarioAnalyzerUtilities.cpp:183
WSF_SCENARIO_ANALYZER_LIB_EXPORT WsfPlatform * getTopCommander(WsfStringId commandChainName, WsfPlatform *platform)
Definition ScenarioAnalyzerUtilities.cpp:58
std::vector< T * > getAllPartsDownCommandChain(WsfPlatform *platform)
Definition ScenarioAnalyzerUtilities.hpp:193
std::vector< T * > getLinkedAndReachablePlatformParts(WsfPlatformPart *origin, const std::vector< std::string > &ignoreExternalLinks, bool follow)
Definition ScenarioAnalyzerUtilities.hpp:274
WSF_SCENARIO_ANALYZER_LIB_EXPORT bool checkFullCommandChain(WsfPlatform *platform, PlatformCheck check)
Definition ScenarioAnalyzerUtilities.cpp:291
WSF_SCENARIO_ANALYZER_LIB_EXPORT void ConvertMessagesToScript(const Messages &aMessages, UtScriptData &aReturnVal, UtScriptContext &aContext, UtScriptClass *aReturnClassPtr)
Definition ScenarioAnalyzerUtilities.cpp:734
WSF_SCENARIO_ANALYZER_LIB_EXPORT Messages runSuiteCheck(const std::string &aSuiteName, const std::string &aCheckName, ScenarioAnalyzerMessage::SeverityLevel aSeverity, WsfSimulation &aSimulation, TFunc aFunction, bool aWriteFlag=true)
Definition ScenarioAnalyzerUtilities.hpp:75
WSF_SCENARIO_ANALYZER_LIB_EXPORT bool checkUpCommandChain(WsfPlatform *platform, PlatformCheck check)
Definition ScenarioAnalyzerUtilities.cpp:72
std::vector< ScenarioAnalyzerMessage > Messages
Definition ScenarioAnalyzerUtilities.hpp:67
void RegisterUtilsScriptTypes(WsfApplication &application)
Definition ScenarioAnalyzerUtilities.cpp:749
WsfComponentListT< T >::Iterator end(const WsfComponentListT< T > &aList)
Definition WsfComponentList.hpp:546
ut::script::Data UtScriptData
Definition WsfScriptContext.hpp:47
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
Class for Scenario Analyzer messages that provides simple message building and writing.
Definition ScenarioAnalyzerMessage.hpp:40
void SetSuccessful()
Set default details and type for a successful message.
Definition ScenarioAnalyzerMessage.cpp:114
void SetCheckName(const std::string &aCheckName)
Definition ScenarioAnalyzerMessage.hpp:80
SeverityLevel
Definition ScenarioAnalyzerMessage.hpp:44
void SetSuiteName(const std::string &aSuiteName)
Definition ScenarioAnalyzerMessage.hpp:79
void SetSeverity(SeverityLevel aSeverityLevel)
Definition ScenarioAnalyzerMessage.hpp:83
Definition WsfApplication.hpp:45
Definition WsfBMSensorsManager.hpp:50
Definition WsfBattleManager.hpp:61
Definition WsfCommandChain.hpp:36
PlatformList & GetSubordinates()
Definition WsfCommandChain.hpp:93
T * GetComponentEntry(unsigned int aEntry) const
Definition WsfComponentList.hpp:154
unsigned int GetComponentCount(int aRole) const
Definition WsfComponentList.cpp:71
T * GetComponent() const
Definition WsfComponentList.hpp:116
Definition WsfInternalLinks.hpp:30
unsigned int GetRecipientCount() const
Definition WsfInternalLinks.hpp:60
WsfPlatformPart * GetRecipientEntry(unsigned int aEntry) const
Definition WsfInternalLinks.hpp:84
A linked processor is a processor with both internal links (see WsfInternalLinks) and external links ...
Definition WsfLinkedProcessor.hpp:24
Definition WsfScriptProcessor.hpp:43
The main controller for a simulation.
Definition WsfSimulation.hpp:109
wsf::comm::NetworkManager * GetCommNetworkManager() const
Definition WsfSimulation.hpp:450
Definition WsfExternalLinks.hpp:98
AddressVec GetRecipients(bool aNotify=false) const
Definition WsfExternalLinks.cpp:87
comm::Comm * GetXmtr() const
Definition WsfExternalLinks.cpp:250
Definition WsfExternalLinks.hpp:62
size_t GetLinkCount() const
Definition WsfExternalLinks.hpp:208
ExternalLink & GetLink(size_t aIndex)
Definition WsfExternalLinks.hpp:209
Definition WsfCommAddress.hpp:57
Definition WsfComm.hpp:43
const Address & GetAddress() const
Definition WsfComm.hpp:184
Definition WsfCommNetworkManager.hpp:44
Comm * GetComm(const Address &aAddress) const
Provides Comm object for an Address.
Definition WsfCommNetworkManager.cpp:561
bool PathExists(const Address &aSourceAddress, const Address &aDestinationAddress) const
Simple check of pathing from source to destination.
Definition WsfCommNetworkManager.cpp:1635
Definition WsfComm.cpp:34
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32