12#ifndef WSF_EVENT_OUTPUT_BASE
13#define WSF_EVENT_OUTPUT_BASE
15#include "wsf_export.h"
20#include "UtCallback.hpp"
21#include "UtCallbackHolder.hpp"
23#include "UtInputBlock.hpp"
54 bool PrepareExtension()
override;
61 bool OpenFile(
const std::string& aFileName);
64 const std::string&
GetFileName()
const {
return mData.mFileName; }
66 std::ostream&
StreamRef()
const {
return *mCurrentStream; }
68 bool IsEnabled(
const std::string& aEventName)
const;
70 void AddEvent(
const std::string& aEventName, std::unique_ptr<UtCallback> aCallbackPtr);
77 template<
typename RESULT,
typename... Args>
78 void AddEvent(
const std::string& aEventName, UtCallbackListN<
void(Args...)>& aObserver)
80 auto fn = UtStd::Bind(&SimulationExtension::ObserverCallback<RESULT, Args...>,
this);
81 AddEvent(aEventName, aObserver.Connect(fn));
84 void AddEventAlias(
const std::string& aAliasEventName,
const std::string& aCurrentEventName);
86 bool EnableOrDisableEvent(
const std::string& aEventName,
bool aEnable);
99 : mEventOutput(aEventOutput)
101 mEventOutput.EventEntry();
110 void AddedToSimulation()
override;
116 virtual void EnableOrDisableEventP(
const std::string& aEventName,
bool aEnable) {}
118 void SetStream(std::ostream* aStreamPtr);
119 bool StreamIsOpen()
const {
return mCurrentStream !=
nullptr; }
128 template<
typename RESULT,
typename... Args>
129 void ObserverCallback(Args&&... args)
131 EventGuard guard(*
this);
132 RESULT result(std::forward<Args>(args)..., mData.mSettings);
136 void SimulationStarting();
138 void SimulationComplete(
double aSimTime);
144 std::unique_ptr<UtCallback> mCallbackPtr{
nullptr};
145 bool mEnabled{
false};
149 using EventMap = std::map<std::string, EventData>;
151 UtCallbackHolder mCallbacks;
153 using EventAliases = std::map<std::string, std::string>;
154 EventAliases mEventAliases;
155 std::ostream* mCurrentStream{
nullptr};
156 std::ofstream mFileStream;
157 bool mIsInitialized{
false};
158 std::recursive_mutex mMutex;
169template<
typename DATA,
typename SIM_EXTENSION>
172 static_assert(std::is_base_of<Data, DATA>::value,
"Template type DATA must be subclass of wsf::event::output::Data");
173 static_assert(std::is_base_of<SimulationExtension, SIM_EXTENSION>::value,
174 "Template type SIM_EXTENSION must be subclass of wsf::event::output::SimulationExtension");
178 : mData(
ut::make_unique<DATA>())
185 std::unique_ptr<Data> mData;
188template<
typename DATA,
typename SIM_EXTENSION>
191 bool myCommand{
false};
195 UtInputBlock inputBlock(aInput);
196 inputBlock.ProcessInput(mData.get());
201template<
typename DATA,
typename SIM_EXTENSION>
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
const std::string & GetExtensionName() const
Definition WsfExtension.hpp:31
WsfScenarioExtension()
Definition WsfScenarioExtension.cpp:21
WsfSimulationExtension()
Definition WsfSimulationExtension.cpp:23
The main controller for a simulation.
Definition WsfSimulation.hpp:109
void RegisterExtension(const std::string &aName, std::unique_ptr< WsfSimulationExtension > aExtensionPtr)
Definition WsfSimulation.cpp:1554
Definition WsfEventResult.hpp:117
Definition WsfEventResult.hpp:35
std::function< void(double, const WsfMessage &)> MessagePrintFunction
Definition WsfEventResult.hpp:37
bool ProcessInput(UtInput &aInput) override
Definition WsfEventOutputBase.hpp:189
ScenarioExtension()
Definition WsfEventOutputBase.hpp:177
void SimulationCreated(WsfSimulation &aSimulation) override
Definition WsfEventOutputBase.hpp:202
EventGuard(SimulationExtension &aEventOutput)
Definition WsfEventOutputBase.hpp:98
~EventGuard()
Definition WsfEventOutputBase.hpp:103
virtual void OnSimulationComplete(double aSimTime)
Definition WsfEventOutputBase.hpp:59
Settings & GetSettings()
Definition WsfEventOutputBase.hpp:90
void AddEvent(const std::string &aEventName, std::unique_ptr< UtCallback > aCallbackPtr)
Definition WsfEventOutputBase.cpp:202
void AddEvent(const std::string &aEventName, UtCallbackListN< void(Args...)> &aObserver)
Definition WsfEventOutputBase.hpp:78
std::ostream & StreamRef() const
Definition WsfEventOutputBase.hpp:66
SimulationExtension(Data &aData)
Definition WsfEventOutputBase.hpp:50
const std::string & GetFileName() const
Returns the name of the file in which the events are output.
Definition WsfEventOutputBase.hpp:64
virtual void PrintEvent(const Result &aResult) const =0
Print an event result in the desired format. Must be implemented by derived classes.
Definition WsfSensorErrorModel.hpp:21
Definition WsfEventOutputBase.cpp:36
Definition WsfXIO_EventResults.cpp:33
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Definition WsfEventOutputBase.hpp:36
std::string mFileName
Definition WsfEventOutputBase.hpp:41
virtual bool ProcessInput(UtInput &aInput)
Definition WsfEventOutputBase.cpp:38
Settings mSettings
Definition WsfEventOutputBase.hpp:43
bool mFlushOutput
Definition WsfEventOutputBase.hpp:42
std::map< std::string, bool > mToggledEvents
Definition WsfEventOutputBase.hpp:40