12#ifndef SST_CORE_SSTHANDLER_H
13#define SST_CORE_SSTHANDLER_H
15#include "sst/core/serialization/serializable.h"
16#include "sst/core/sst_types.h"
108template <
typename returnT,
typename argT>
121 virtual ~AttachPoint() {}
150 std::conditional_t<std::is_pointer_v<argT>,
const std::remove_pointer_t<argT>*,
const argT&> arg) = 0;
164 std::conditional_t<std::is_pointer_v<returnT>,
const std::remove_pointer_t<returnT>*,
const returnT&>
194 using ToolList = std::vector<std::pair<AttachPoint*, uintptr_t>>;
195 ToolList* attached_tools =
nullptr;
199 virtual returnT operator_impl(argT) = 0;
203 switch ( ser.mode() ) {
204 case Core::Serialization::serializer::SIZER:
205 case Core::Serialization::serializer::PACK:
208 if ( attached_tools ) {
209 for (
auto x : *attached_tools ) {
215 size_t tool_count = tools.size();
217 if ( tool_count > 0 ) {
220 for (
auto x : tools ) {
221 SST::Core::Serialization::serializable* obj =
222 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
224 x.first->serializeHandlerAttachPointKey(ser, x.second);
229 case Core::Serialization::serializer::UNPACK:
233 if ( tool_count > 0 ) {
234 attached_tools =
new ToolList();
235 for (
size_t i = 0; i < tool_count; ++i ) {
236 SST::Core::Serialization::serializable* tool;
241 attached_tools->emplace_back(ap, key);
245 attached_tools =
nullptr;
255 virtual ~SSTHandlerBase() {}
257 inline returnT operator()(argT arg)
259 if ( !attached_tools )
return operator_impl(arg);
262 for (
auto& x : *attached_tools )
263 x.first->beforeHandler(x.second, arg);
265 returnT ret = operator_impl(arg);
267 for (
auto& x : *attached_tools )
268 x.first->afterHandler(x.second, ret);
282 if ( !attached_tools ) attached_tools =
new ToolList();
284 auto key = tool->registerHandler(mdata);
285 attached_tools->push_back(std::make_pair(tool, key));
296 if ( !attached_tools )
return;
298 for (
auto x = attached_tools->begin(); x != attached_tools->end(); ++x ) {
299 if ( x->first == tool ) {
300 attached_tools->erase(x);
311 if ( handler->attached_tools ) {
312 attached_tools = handler->attached_tools;
313 handler->attached_tools =
nullptr;
328template <
typename argT>
341 virtual ~AttachPoint() {}
370 std::conditional_t<std::is_pointer_v<argT>,
const std::remove_pointer_t<argT>*,
const argT&> arg) = 0;
478 std::vector<std::pair<AttachPoint*, uintptr_t>> attach_tools;
479 std::vector<std::pair<InterceptPoint*, uintptr_t>> intercept_tools;
481 ToolList* attached_tools =
nullptr;
485 virtual void operator_impl(argT) = 0;
489 switch ( ser.mode() ) {
490 case Core::Serialization::serializer::SIZER:
491 case Core::Serialization::serializer::PACK:
494 if ( attached_tools ) {
495 for (
auto x : attached_tools->attach_tools ) {
497 tools.attach_tools.push_back(x);
500 for (
auto x : attached_tools->intercept_tools ) {
501 if (
dynamic_cast<SST::Core::Serialization::serializable*
>(x.first) ) {
502 tools.intercept_tools.push_back(x);
508 size_t tool_count = tools.attach_tools.size();
510 if ( tool_count > 0 ) {
513 for (
auto x : tools.attach_tools ) {
514 SST::Core::Serialization::serializable* obj =
515 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
517 x.first->serializeHandlerAttachPointKey(ser, x.second);
521 tool_count = tools.intercept_tools.size();
523 if ( tool_count > 0 ) {
526 for (
auto x : tools.intercept_tools ) {
527 SST::Core::Serialization::serializable* obj =
528 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
530 x.first->serializeHandlerInterceptPointKey(ser, x.second);
535 case Core::Serialization::serializer::UNPACK:
540 if ( tool_count > 0 ) {
541 attached_tools =
new ToolList();
542 for (
size_t i = 0; i < tool_count; ++i ) {
543 SST::Core::Serialization::serializable* tool;
548 attached_tools->attach_tools.emplace_back(ap, key);
552 attached_tools =
nullptr;
557 if ( tool_count > 0 ) {
558 if (
nullptr == attached_tools ) attached_tools =
new ToolList();
559 for (
size_t i = 0; i < tool_count; ++i ) {
560 SST::Core::Serialization::serializable* tool;
563 InterceptPoint* ip =
dynamic_cast<InterceptPoint*
>(tool);
564 ip->serializeHandlerInterceptPointKey(ser, key);
565 attached_tools->intercept_tools.emplace_back(ip, key);
576 virtual ~SSTHandlerBase() {}
578 inline void operator()(argT arg)
580 if ( !attached_tools )
return operator_impl(arg);
583 for (
auto& x : attached_tools->attach_tools )
584 x.first->beforeHandler(x.second, arg);
589 for (
auto& x : attached_tools->intercept_tools ) {
590 x.first->interceptHandler(x.second, arg, cancel);
601 for (
auto& x : attached_tools->attach_tools )
602 x.first->afterHandler(x.second);
615 if ( !attached_tools ) attached_tools =
new ToolList();
618 attached_tools->attach_tools.push_back(std::make_pair(tool, key));
629 if ( !attached_tools )
return;
631 for (
auto x = attached_tools->attach_tools.begin(); x != attached_tools->attach_tools.end(); ++x ) {
632 if ( x->first == tool ) {
633 attached_tools->attach_tools.erase(x);
648 if ( !attached_tools ) attached_tools =
new ToolList();
651 attached_tools->intercept_tools.push_back(std::make_pair(tool, key));
662 if ( !attached_tools )
return;
664 for (
auto x = attached_tools->intercept_tools.begin(); x != attached_tools->intercept_tools.end(); ++x ) {
665 if ( x->first == tool ) {
666 attached_tools->intercept_tools.erase(x);
677 if ( handler->attached_tools ) {
678 attached_tools = handler->attached_tools;
679 handler->attached_tools =
nullptr;
695template <
typename returnT>
708 virtual ~AttachPoint() {}
746 std::conditional_t<std::is_pointer_v<returnT>,
const std::remove_pointer_t<returnT>*,
const returnT&>
776 using ToolList = std::vector<std::pair<AttachPoint*, uintptr_t>>;
777 ToolList* attached_tools =
nullptr;
781 virtual returnT operator_impl() = 0;
785 switch ( ser.mode() ) {
786 case Core::Serialization::serializer::SIZER:
787 case Core::Serialization::serializer::PACK:
790 if ( attached_tools ) {
791 for (
auto x : *attached_tools ) {
797 size_t tool_count = tools.size();
799 if ( tool_count > 0 ) {
802 for (
auto x : tools ) {
803 SST::Core::Serialization::serializable* obj =
804 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
806 x.first->serializeHandlerAttachPointKey(ser, x.second);
811 case Core::Serialization::serializer::UNPACK:
815 if ( tool_count > 0 ) {
816 attached_tools =
new ToolList();
817 for (
size_t i = 0; i < tool_count; ++i ) {
818 SST::Core::Serialization::serializable* tool;
823 attached_tools->emplace_back(ap, key);
827 attached_tools =
nullptr;
838 virtual ~SSTHandlerBase() {}
840 inline returnT operator()()
842 if ( attached_tools ) {
843 for (
auto& x : *attached_tools )
844 x.first->beforeHandler(x.second);
846 returnT ret = operator_impl();
848 for (
auto& x : *attached_tools )
849 x.first->afterHandler(x.second, ret);
853 return operator_impl();
865 if ( !attached_tools ) attached_tools =
new ToolList();
868 attached_tools->push_back(std::make_pair(tool, key));
879 if ( !attached_tools )
return;
881 for (
auto x = attached_tools->begin(); x != attached_tools->end(); ++x ) {
882 if ( x->first == tool ) {
883 attached_tools->erase(x);
894 if ( handler->attached_tools ) {
895 attached_tools = handler->attached_tools;
896 handler->attached_tools =
nullptr;
925 virtual ~AttachPoint() {}
987 using ToolList = std::vector<std::pair<AttachPoint*, uintptr_t>>;
988 ToolList* attached_tools =
nullptr;
992 virtual void operator_impl() = 0;
996 switch ( ser.mode() ) {
997 case Core::Serialization::serializer::SIZER:
998 case Core::Serialization::serializer::PACK:
1001 if ( attached_tools ) {
1002 for (
auto x : *attached_tools ) {
1008 size_t tool_count = tools.size();
1009 SST_SER(tool_count);
1010 if ( tool_count > 0 ) {
1013 for (
auto x : tools ) {
1014 SST::Core::Serialization::serializable* obj =
1015 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
1017 x.first->serializeHandlerAttachPointKey(ser, x.second);
1022 case Core::Serialization::serializer::UNPACK:
1025 SST_SER(tool_count);
1026 if ( tool_count > 0 ) {
1027 attached_tools =
new ToolList();
1028 for (
size_t i = 0; i < tool_count; ++i ) {
1029 SST::Core::Serialization::serializable* tool;
1034 attached_tools->emplace_back(ap, key);
1038 attached_tools =
nullptr;
1048 virtual ~SSTHandlerBase() {}
1050 inline void operator()()
1052 if ( attached_tools ) {
1053 for (
auto& x : *attached_tools )
1054 x.first->beforeHandler(x.second);
1058 for (
auto& x : *attached_tools )
1059 x.first->afterHandler(x.second);
1063 return operator_impl();
1075 if ( !attached_tools ) attached_tools =
new ToolList();
1078 attached_tools->push_back(std::make_pair(tool, key));
1089 if ( !attached_tools )
return;
1091 for (
auto x = attached_tools->begin(); x != attached_tools->end(); ++x ) {
1092 if ( x->first == tool ) {
1093 attached_tools->erase(x);
1104 if ( handler->attached_tools ) {
1105 attached_tools = handler->attached_tools;
1106 handler->attached_tools =
nullptr;
1125template <
typename returnT,
typename argT,
typename classT,
typename dataT,
auto funcT,
1126 typename parentT = SSTHandlerBase<returnT, argT>>
1130 static_assert((funcT,
false),
"Mismatched handler templates.");
1137template <
typename returnT,
typename argT,
typename classT,
typename dataT, returnT (classT::*funcT)(argT, dataT),
1141 static_assert(std::is_base_of_v<SSTHandlerBase<returnT, argT>, parentT>,
1142 "Base class of SSTHandler must inherit from SSTBaseHandler<returnT,argT>");
1145 classT*
object =
nullptr;
1161 SSTHandler(
const SSTHandler&) =
delete;
1162 SSTHandler& operator=(
const SSTHandler&) =
delete;
1164 returnT operator_impl(argT arg)
override {
return (object->*funcT)(arg, data); }
1166 void serialize_order(SST::Core::Serialization::serializer& ser)
override
1168 parentT::serialize_order(ser);
1180template <
typename returnT,
typename argT,
typename classT, returnT (
classT::*funcT)(argT),
typename parentT>
1181class SSTHandler<returnT, argT, classT, void, funcT, parentT> :
public parentT
1183 static_assert(std::is_base_of_v<SSTHandlerBase<returnT, argT>, parentT>,
1184 "Base class of SSTHandler must inherit from SSTBaseHandler<returnT,argT>");
1187 classT*
object =
nullptr;
1200 SSTHandler(
const SSTHandler&) =
delete;
1201 SSTHandler& operator=(
const SSTHandler&) =
delete;
1203 returnT operator_impl(argT arg)
override {
return (object->*funcT)(arg); }
1205 void serialize_order(SST::Core::Serialization::serializer& ser)
override
1207 parentT::serialize_order(ser);
1211 ImplementSerializable(SSTHandler)
1218template <
typename returnT,
typename classT,
typename dataT, returnT (
classT::*funcT)(dataT),
typename parentT>
1219class SSTHandler<returnT, void, classT, dataT, funcT, parentT> :
public parentT
1221 static_assert(std::is_base_of_v<SSTHandlerBase<returnT, void>, parentT>,
1222 "Base class of SSTHandler must inherit from SSTBaseHandler<returnT,argT>");
1225 classT*
object =
nullptr;
1240 SSTHandler(
const SSTHandler&) =
delete;
1241 SSTHandler& operator=(
const SSTHandler&) =
delete;
1243 returnT operator_impl()
override {
return (object->*funcT)(data); }
1245 void serialize_order(SST::Core::Serialization::serializer& ser)
override
1247 parentT::serialize_order(ser);
1252 ImplementSerializable(SSTHandler)
1259template <
typename returnT,
typename classT, returnT (
classT::*funcT)(),
typename parentT>
1260class SSTHandler<returnT, void, classT, void, funcT, parentT> :
public parentT
1262 static_assert(std::is_base_of_v<SSTHandlerBase<returnT, void>, parentT>,
1263 "Base class of SSTHandler must inherit from SSTBaseHandler<returnT,argT>");
1266 classT*
object =
nullptr;
1279 SSTHandler(
const SSTHandler&) =
delete;
1280 SSTHandler& operator=(
const SSTHandler&) =
delete;
1282 returnT operator_impl()
override {
return (object->*funcT)(); }
1284 void serialize_order(SST::Core::Serialization::serializer& ser)
override
1286 parentT::serialize_order(ser);
1290 ImplementSerializable(SSTHandler)
Definition serializable.h:25
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Parameter store.
Definition params.h:65
Attach Point to get notified when a handler starts and stops.
Definition ssthandler.h:118
virtual void serializeHandlerAttachPointKey(SST::Core::Serialization::serializer &UNUSED(ser), uintptr_t &UNUSED(key))
Function that will be called to handle the key returned from registerHandler, if the AttachPoint tool...
Definition ssthandler.h:188
virtual uintptr_t registerHandler(const AttachPointMetaData &mdata)=0
Function that will be called when a handler is registered with the tool implementing the attach point...
virtual void afterHandler(uintptr_t key, std::conditional_t< std::is_pointer_v< returnT >, const std::remove_pointer_t< returnT > *, const returnT & > ret_value)=0
Function to be called after the handler is called.
virtual void beforeHandler(uintptr_t key, std::conditional_t< std::is_pointer_v< argT >, const std::remove_pointer_t< argT > *, const argT & > arg)=0
Function to be called before the handler is called.
Attach Point to get notified when a handler starts and stops.
Definition ssthandler.h:705
virtual void afterHandler(uintptr_t key, std::conditional_t< std::is_pointer_v< returnT >, const std::remove_pointer_t< returnT > *, const returnT & > ret_value)=0
Function to be called after the handler is called.
virtual void beforeHandler(uintptr_t key)=0
Function to be called before the handler is called.
virtual uintptr_t registerHandler(const AttachPointMetaData &mdata)=0
Function that will be called when a handler is registered with the tool implementing the attach point...
virtual void serializeHandlerAttachPointKey(SST::Core::Serialization::serializer &UNUSED(ser), uintptr_t &UNUSED(key))
Function that will be called to handle the key returned from registerHandler, if the AttachPoint tool...
Definition ssthandler.h:770
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:863
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:877
void transferAttachedToolInfo(SSTHandlerBase *handler)
Transfers attached tools from existing handler.
Definition ssthandler.h:892
Attach Point to get notified when a handler starts and stops.
Definition ssthandler.h:338
virtual void beforeHandler(uintptr_t key, std::conditional_t< std::is_pointer_v< argT >, const std::remove_pointer_t< argT > *, const argT & > arg)=0
Function to be called before the handler is called.
virtual void serializeHandlerAttachPointKey(SST::Core::Serialization::serializer &UNUSED(ser), uintptr_t &UNUSED(key))
Function that will be called to handle the key returned from registerHandler, if the AttachPoint tool...
Definition ssthandler.h:402
virtual void afterHandler(uintptr_t key)=0
Function to be called after the handler is called.
virtual uintptr_t registerHandler(const AttachPointMetaData &mdata)=0
Function that will be called when a handler is registered with the tool implementing the attach point...
Attach Point to intercept the data being delivered by a Handler.
Definition ssthandler.h:414
virtual uintptr_t registerHandlerIntercept(const AttachPointMetaData &mdata)=0
Function that will be called when a handler is registered with the tool implementing the intercept at...
virtual void serializeHandlerInterceptPointKey(SST::Core::Serialization::serializer &UNUSED(ser), uintptr_t &UNUSED(key))
Function that will be called to handle the key returned from registerHandlerIntercept,...
Definition ssthandler.h:468
virtual void interceptHandler(uintptr_t key, argT &data, bool &cancel)=0
Function that will be called before the event handler to let the attach point intercept the data.
void detachInterceptTool(InterceptPoint *tool)
Remove an attached tool.
Definition ssthandler.h:660
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:613
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:627
void transferAttachedToolInfo(SSTHandlerBase *handler)
Transfers attached tools from existing handler.
Definition ssthandler.h:675
void attachInterceptTool(InterceptPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:646
Attach Point to get notified when a handler starts and stops.
Definition ssthandler.h:922
virtual void beforeHandler(uintptr_t key)=0
Function to be called before the handler is called.
virtual void serializeHandlerAttachPointKey(SST::Core::Serialization::serializer &UNUSED(ser), uintptr_t &UNUSED(key))
Function that will be called to handle the key returned from registerHandler, if the AttachPoint tool...
Definition ssthandler.h:981
virtual void afterHandler(uintptr_t key)=0
Function to be called after the handler is called.
virtual uintptr_t registerHandler(const AttachPointMetaData &mdata)=0
Function that will be called when a handler is registered with the tool implementing the attach point...
void transferAttachedToolInfo(SSTHandlerBase *handler)
Transfers attached tools from existing handler.
Definition ssthandler.h:1102
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:1073
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:1087
Base template for handlers which take a class defined argument.
Definition ssthandler.h:110
void transferAttachedToolInfo(SSTHandlerBase *handler)
Transfers attached tools from existing handler.
Definition ssthandler.h:309
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:294
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:280
SSTHandler(classT *const object, dataT data)
Constructor.
Definition ssthandler.h:1153
SSTHandler(classT *const object)
Constructor.
Definition ssthandler.h:1194
SSTHandler(classT *const object, dataT data)
Constructor.
Definition ssthandler.h:1233
SSTHandler(classT *const object)
Constructor.
Definition ssthandler.h:1273
Base template for the class.
Definition ssthandler.h:1128