WSF
WsfCyberEventManager.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2020 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFCYBEREVENTMANAGER_HPP
13#define WSFCYBEREVENTMANAGER_HPP
14
15#include "wsf_cyber_export.h"
16
17#include <memory>
18#include <unordered_map>
19
20#include "WsfCyberEvent.hpp"
21class WsfSimulation;
22
23namespace wsf
24{
25namespace cyber
26{
27
41class WSF_CYBER_EXPORT EventManager final
42{
43public:
44 EventManager(WsfSimulation& aSimulation);
45 ~EventManager() = default;
46 EventManager(const EventManager& aSrc) = delete;
47 EventManager& operator=(const EventManager& aRhs) = delete;
48 EventManager(EventManager&& aSrc) = default;
50
54 void AddEvent(std::unique_ptr<Event> aEventPtr);
55
60 void EndEvent(bool aAttack, size_t aEngagementKey);
61
67 bool CancelEvent(bool aAttack, size_t aEngagementKey);
68
71 bool EventExists(bool aAttack, size_t aEngagementKey) const;
72
74 Event::Type GetEventType(bool aAttack, size_t aEngagementKey) const;
75
76private:
77 struct EventKey
78 {
79 EventKey(bool aAttack, size_t aEngagementKey)
80 : mAttack(aAttack)
81 , mEngagementKey(aEngagementKey)
82 {
83 }
84
85 bool operator==(const EventKey& aRhs) const
86 {
87 return ((mAttack == aRhs.mAttack) && (mEngagementKey == aRhs.mEngagementKey));
88 }
89
90 bool mAttack;
91 size_t mEngagementKey;
92 };
93
94 struct EventKeyHash
95 {
96 size_t operator()(const EventKey& aKey) const
97 {
98 auto val = std::hash<size_t>{}(aKey.mEngagementKey);
99 val ^= std::hash<bool>{}(aKey.mAttack) + 0x9e3779b9 + (val << 6) + (val >> 2);
100 return val;
101 }
102 };
103
104 using EventMap = std::unordered_map<EventKey, Event*, EventKeyHash>;
105
106 WsfSimulation& mSimulation;
107 EventMap mEventMap{};
108};
109
110} // namespace cyber
111} // namespace wsf
112
113#endif
bool operator==(int aId, const WsfStringInt &aRhs)
Equal relational operator for the case of an integer on the LHS and a StringId on the RHS.
Definition WsfStringId.hpp:69
The main controller for a simulation.
Definition WsfSimulation.hpp:109
bool EventExists(bool aAttack, size_t aEngagementKey) const
Definition WsfCyberEventManager.cpp:77
EventManager & operator=(const EventManager &aRhs)=delete
void EndEvent(bool aAttack, size_t aEngagementKey)
Definition WsfCyberEventManager.cpp:48
EventManager(const EventManager &aSrc)=delete
EventManager(EventManager &&aSrc)=default
bool CancelEvent(bool aAttack, size_t aEngagementKey)
Definition WsfCyberEventManager.cpp:60
EventManager & operator=(EventManager &&aRhs)=default
Event::Type GetEventType(bool aAttack, size_t aEngagementKey) const
Retrieve the type of the event.
Definition WsfCyberEventManager.cpp:86
void AddEvent(std::unique_ptr< Event > aEventPtr)
Definition WsfCyberEventManager.cpp:34
EventManager(WsfSimulation &aSimulation)
Definition WsfCyberEventManager.cpp:28
Type
Definition WsfCyberEvent.hpp:33
Definition WsfCyberApplicationExtension.cpp:24
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Copyrights Multiple, All Rights Reserved