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"
77template <
typename returnT,
typename argT>
90 virtual ~AttachPoint() {}
119 std::conditional_t<std::is_pointer_v<argT>,
const std::remove_pointer_t<argT>*,
const argT&> arg) = 0;
133 std::conditional_t<std::is_pointer_v<returnT>,
const std::remove_pointer_t<returnT>*,
const returnT&>
163 using ToolList = std::vector<std::pair<AttachPoint*, uintptr_t>>;
164 ToolList* attached_tools =
nullptr;
168 virtual returnT operator_impl(argT) = 0;
172 switch ( ser.mode() ) {
173 case Core::Serialization::serializer::SIZER:
174 case Core::Serialization::serializer::PACK:
177 if ( attached_tools ) {
178 for (
auto x : *attached_tools ) {
184 size_t tool_count = tools.size();
186 if ( tool_count > 0 ) {
190 for (
auto x : tools ) {
191 SST::Core::Serialization::serializable* obj =
192 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
194 x.first->serializeHandlerAttachPointKey(ser, x.second);
199 case Core::Serialization::serializer::UNPACK:
203 if ( tool_count > 0 ) {
204 attached_tools =
new ToolList();
205 for (
size_t i = 0; i < tool_count; ++i ) {
206 SST::Core::Serialization::serializable* tool;
211 attached_tools->emplace_back(ap, key);
215 attached_tools =
nullptr;
225 virtual ~SSTHandlerBase() {}
227 inline returnT operator()(argT arg)
229 if ( !attached_tools )
return operator_impl(arg);
232 for (
auto& x : *attached_tools )
233 x.first->beforeHandler(x.second, arg);
235 returnT ret = operator_impl(arg);
237 for (
auto& x : *attached_tools )
238 x.first->afterHandler(x.second, ret);
252 if ( !attached_tools ) attached_tools =
new ToolList();
254 auto key = tool->registerHandler(mdata);
255 attached_tools->push_back(std::make_pair(tool, key));
266 if ( !attached_tools )
return;
268 for (
auto x = attached_tools->begin(); x != attached_tools->end(); ++x ) {
269 if ( x->first == tool ) {
270 attached_tools->erase(x);
281 if ( handler->attached_tools ) {
282 attached_tools = handler->attached_tools;
283 handler->attached_tools =
nullptr;
298template <
typename argT>
311 virtual ~AttachPoint() {}
340 std::conditional_t<std::is_pointer_v<argT>,
const std::remove_pointer_t<argT>*,
const argT&> arg) = 0;
448 std::vector<std::pair<AttachPoint*, uintptr_t>> attach_tools;
449 std::vector<std::pair<InterceptPoint*, uintptr_t>> intercept_tools;
451 ToolList* attached_tools =
nullptr;
455 virtual void operator_impl(argT) = 0;
459 switch ( ser.mode() ) {
460 case Core::Serialization::serializer::SIZER:
461 case Core::Serialization::serializer::PACK:
464 if ( attached_tools ) {
465 for (
auto x : attached_tools->attach_tools ) {
467 tools.attach_tools.push_back(x);
470 for (
auto x : attached_tools->intercept_tools ) {
471 if (
dynamic_cast<SST::Core::Serialization::serializable*
>(x.first) ) {
472 tools.intercept_tools.push_back(x);
478 size_t tool_count = tools.attach_tools.size();
480 if ( tool_count > 0 ) {
484 for (
auto x : tools.attach_tools ) {
485 SST::Core::Serialization::serializable* obj =
486 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
488 x.first->serializeHandlerAttachPointKey(ser, x.second);
492 tool_count = tools.intercept_tools.size();
494 if ( tool_count > 0 ) {
498 for (
auto x : tools.intercept_tools ) {
499 SST::Core::Serialization::serializable* obj =
500 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
502 x.first->serializeHandlerInterceptPointKey(ser, x.second);
507 case Core::Serialization::serializer::UNPACK:
512 if ( tool_count > 0 ) {
513 attached_tools =
new ToolList();
514 for (
size_t i = 0; i < tool_count; ++i ) {
515 SST::Core::Serialization::serializable* tool;
520 attached_tools->attach_tools.emplace_back(ap, key);
524 attached_tools =
nullptr;
529 if ( tool_count > 0 ) {
530 if (
nullptr == attached_tools ) attached_tools =
new ToolList();
531 for (
size_t i = 0; i < tool_count; ++i ) {
532 SST::Core::Serialization::serializable* tool;
535 InterceptPoint* ip =
dynamic_cast<InterceptPoint*
>(tool);
536 ip->serializeHandlerInterceptPointKey(ser, key);
537 attached_tools->intercept_tools.emplace_back(ip, key);
548 virtual ~SSTHandlerBase() {}
550 inline void operator()(argT arg)
552 if ( !attached_tools )
return operator_impl(arg);
555 for (
auto& x : attached_tools->attach_tools )
556 x.first->beforeHandler(x.second, arg);
561 for (
auto& x : attached_tools->intercept_tools ) {
562 x.first->interceptHandler(x.second, arg, cancel);
574 for (
auto& x : attached_tools->attach_tools )
575 x.first->afterHandler(x.second);
588 if ( !attached_tools ) attached_tools =
new ToolList();
591 attached_tools->attach_tools.push_back(std::make_pair(tool, key));
602 if ( !attached_tools )
return;
604 for (
auto x = attached_tools->attach_tools.begin(); x != attached_tools->attach_tools.end(); ++x ) {
605 if ( x->first == tool ) {
606 attached_tools->attach_tools.erase(x);
621 if ( !attached_tools ) attached_tools =
new ToolList();
624 attached_tools->intercept_tools.push_back(std::make_pair(tool, key));
635 if ( !attached_tools )
return;
637 for (
auto x = attached_tools->intercept_tools.begin(); x != attached_tools->intercept_tools.end(); ++x ) {
638 if ( x->first == tool ) {
639 attached_tools->intercept_tools.erase(x);
650 if ( handler->attached_tools ) {
651 attached_tools = handler->attached_tools;
652 handler->attached_tools =
nullptr;
668template <
typename returnT>
681 virtual ~AttachPoint() {}
719 std::conditional_t<std::is_pointer_v<returnT>,
const std::remove_pointer_t<returnT>*,
const returnT&>
749 using ToolList = std::vector<std::pair<AttachPoint*, uintptr_t>>;
750 ToolList* attached_tools =
nullptr;
754 virtual returnT operator_impl() = 0;
758 switch ( ser.mode() ) {
759 case Core::Serialization::serializer::SIZER:
760 case Core::Serialization::serializer::PACK:
763 if ( attached_tools ) {
764 for (
auto x : *attached_tools ) {
770 size_t tool_count = tools.size();
772 if ( tool_count > 0 ) {
776 for (
auto x : tools ) {
777 SST::Core::Serialization::serializable* obj =
778 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
780 x.first->serializeHandlerAttachPointKey(ser, x.second);
785 case Core::Serialization::serializer::UNPACK:
789 if ( tool_count > 0 ) {
790 attached_tools =
new ToolList();
791 for (
size_t i = 0; i < tool_count; ++i ) {
792 SST::Core::Serialization::serializable* tool;
797 attached_tools->emplace_back(ap, key);
801 attached_tools =
nullptr;
812 virtual ~SSTHandlerBase() {}
814 inline returnT operator()()
816 if ( attached_tools ) {
817 for (
auto& x : *attached_tools )
818 x.first->beforeHandler(x.second);
820 returnT ret = operator_impl();
822 for (
auto& x : *attached_tools )
823 x.first->afterHandler(x.second, ret);
827 return operator_impl();
839 if ( !attached_tools ) attached_tools =
new ToolList();
842 attached_tools->push_back(std::make_pair(tool, key));
853 if ( !attached_tools )
return;
855 for (
auto x = attached_tools->begin(); x != attached_tools->end(); ++x ) {
856 if ( x->first == tool ) {
857 attached_tools->erase(x);
868 if ( handler->attached_tools ) {
869 attached_tools = handler->attached_tools;
870 handler->attached_tools =
nullptr;
899 virtual ~AttachPoint() {}
961 using ToolList = std::vector<std::pair<AttachPoint*, uintptr_t>>;
962 ToolList* attached_tools =
nullptr;
966 virtual void operator_impl() = 0;
970 switch ( ser.mode() ) {
971 case Core::Serialization::serializer::SIZER:
972 case Core::Serialization::serializer::PACK:
975 if ( attached_tools ) {
976 for (
auto x : *attached_tools ) {
982 size_t tool_count = tools.size();
984 if ( tool_count > 0 ) {
988 for (
auto x : tools ) {
989 SST::Core::Serialization::serializable* obj =
990 dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
992 x.first->serializeHandlerAttachPointKey(ser, x.second);
997 case Core::Serialization::serializer::UNPACK:
1000 SST_SER(tool_count);
1001 if ( tool_count > 0 ) {
1002 attached_tools =
new ToolList();
1003 for (
size_t i = 0; i < tool_count; ++i ) {
1004 SST::Core::Serialization::serializable* tool;
1009 attached_tools->emplace_back(ap, key);
1013 attached_tools =
nullptr;
1023 virtual ~SSTHandlerBase() {}
1025 inline void operator()()
1027 if ( attached_tools ) {
1028 for (
auto& x : *attached_tools )
1029 x.first->beforeHandler(x.second);
1033 for (
auto& x : *attached_tools )
1034 x.first->afterHandler(x.second);
1038 return operator_impl();
1050 if ( !attached_tools ) attached_tools =
new ToolList();
1053 attached_tools->push_back(std::make_pair(tool, key));
1064 if ( !attached_tools )
return;
1066 for (
auto x = attached_tools->begin(); x != attached_tools->end(); ++x ) {
1067 if ( x->first == tool ) {
1068 attached_tools->erase(x);
1079 if ( handler->attached_tools ) {
1080 attached_tools = handler->attached_tools;
1081 handler->attached_tools =
nullptr;
1100template <
typename returnT,
typename argT,
typename classT,
typename dataT, auto funcT>
1104 static_assert((funcT,
false),
"Mismatched handler templates.");
1111template <
typename returnT,
typename argT,
typename classT,
typename dataT, returnT (
classT::*funcT)(argT, dataT)>
1115 classT*
object =
nullptr;
1131 SSTHandler(
const SSTHandler&) =
delete;
1132 SSTHandler& operator=(
const SSTHandler&) =
delete;
1134 returnT operator_impl(argT arg)
override {
return (object->*funcT)(arg, data); }
1136 void serialize_order(SST::Core::Serialization::serializer& ser)
override
1138 SSTHandlerBase<returnT, argT>::serialize_order(ser);
1143 ImplementSerializable(SSTHandler)
1150template <
typename returnT,
typename argT,
typename classT, returnT (
classT::*funcT)(argT)>
1154 classT*
object =
nullptr;
1167 SSTHandler(
const SSTHandler&) =
delete;
1168 SSTHandler& operator=(
const SSTHandler&) =
delete;
1170 returnT operator_impl(argT arg)
override {
return (object->*funcT)(arg); }
1172 void serialize_order(SST::Core::Serialization::serializer& ser)
override
1174 SSTHandlerBase<returnT, argT>::serialize_order(ser);
1178 ImplementSerializable(SSTHandler)
1185template <
typename returnT,
typename classT,
typename dataT, returnT (
classT::*funcT)(dataT)>
1189 classT*
object =
nullptr;
1204 SSTHandler(
const SSTHandler&) =
delete;
1205 SSTHandler& operator=(
const SSTHandler&) =
delete;
1207 returnT operator_impl()
override {
return (object->*funcT)(data); }
1209 void serialize_order(SST::Core::Serialization::serializer& ser)
override
1211 SSTHandlerBase<returnT, void>::serialize_order(ser);
1216 ImplementSerializable(SSTHandler)
1223template <
typename returnT,
typename classT, returnT (
classT::*funcT)()>
1227 classT*
object =
nullptr;
1240 SSTHandler(
const SSTHandler&) =
delete;
1241 SSTHandler& operator=(
const SSTHandler&) =
delete;
1243 returnT operator_impl()
override {
return (object->*funcT)(); }
1245 void serialize_order(SST::Core::Serialization::serializer& ser)
override
1247 SSTHandlerBase<returnT, void>::serialize_order(ser);
1251 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:87
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:157
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:678
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:743
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:837
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:851
void transferAttachedToolInfo(SSTHandlerBase *handler)
Transfers attached tools from existing handler.
Definition ssthandler.h:866
Attach Point to get notified when a handler starts and stops.
Definition ssthandler.h:308
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:372
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:384
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:438
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:633
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:586
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:600
void transferAttachedToolInfo(SSTHandlerBase *handler)
Transfers attached tools from existing handler.
Definition ssthandler.h:648
void attachInterceptTool(InterceptPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:619
Attach Point to get notified when a handler starts and stops.
Definition ssthandler.h:896
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:955
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:1077
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:1048
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:1062
Base template for handlers which take a class defined argument.
Definition ssthandler.h:79
void transferAttachedToolInfo(SSTHandlerBase *handler)
Transfers attached tools from existing handler.
Definition ssthandler.h:279
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:264
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:250
SSTHandler(classT *const object, dataT data)
Constructor.
Definition ssthandler.h:1123
SSTHandler(classT *const object)
Constructor.
Definition ssthandler.h:1161
SSTHandler(classT *const object, dataT data)
Constructor.
Definition ssthandler.h:1197
SSTHandler(classT *const object)
Constructor.
Definition ssthandler.h:1234
Base template for the class.
Definition ssthandler.h:1102