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 ) {
 
  221                for ( 
auto x : tools ) {
 
  222                    SST::Core::Serialization::serializable* obj =
 
  223                        dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
 
  225                    x.first->serializeHandlerAttachPointKey(ser, x.second);
 
  230        case Core::Serialization::serializer::UNPACK:
 
  234            if ( tool_count > 0 ) {
 
  235                attached_tools = 
new ToolList();
 
  236                for ( 
size_t i = 0; i < tool_count; ++i ) {
 
  237                    SST::Core::Serialization::serializable* tool;
 
  242                    attached_tools->emplace_back(ap, key);
 
  246                attached_tools = 
nullptr;
 
  256    virtual ~SSTHandlerBase() {}
 
  258    inline returnT operator()(argT arg)
 
  260        if ( !attached_tools ) 
return operator_impl(arg);
 
  263        for ( 
auto& x : *attached_tools )
 
  264            x.first->beforeHandler(x.second, arg);
 
  266        returnT ret = operator_impl(arg);
 
  268        for ( 
auto& x : *attached_tools )
 
  269            x.first->afterHandler(x.second, ret);
 
  283        if ( !attached_tools ) attached_tools = 
new ToolList();
 
  285        auto key = tool->registerHandler(mdata);
 
  286        attached_tools->push_back(std::make_pair(tool, key));
 
 
  297        if ( !attached_tools ) 
return;
 
  299        for ( 
auto x = attached_tools->begin(); x != attached_tools->end(); ++x ) {
 
  300            if ( x->first == tool ) {
 
  301                attached_tools->erase(x);
 
 
  312        if ( handler->attached_tools ) {
 
  313            attached_tools          = handler->attached_tools;
 
  314            handler->attached_tools = 
nullptr;
 
 
 
  329template <
typename argT>
 
  342        virtual ~AttachPoint() {}
 
  371            std::conditional_t<std::is_pointer_v<argT>, 
const std::remove_pointer_t<argT>*, 
const argT&> arg) = 0;
 
 
  479        std::vector<std::pair<AttachPoint*, uintptr_t>>    attach_tools;
 
  480        std::vector<std::pair<InterceptPoint*, uintptr_t>> intercept_tools;
 
  482    ToolList* attached_tools = 
nullptr;
 
  486    virtual void operator_impl(argT) = 0;
 
  490        switch ( ser.mode() ) {
 
  491        case Core::Serialization::serializer::SIZER:
 
  492        case Core::Serialization::serializer::PACK:
 
  495            if ( attached_tools ) {
 
  496                for ( 
auto x : attached_tools->attach_tools ) {
 
  498                        tools.attach_tools.push_back(x);
 
  501                for ( 
auto x : attached_tools->intercept_tools ) {
 
  502                    if ( 
dynamic_cast<SST::Core::Serialization::serializable*
>(x.first) ) {
 
  503                        tools.intercept_tools.push_back(x);
 
  509            size_t tool_count = tools.attach_tools.size();
 
  511            if ( tool_count > 0 ) {
 
  515                for ( 
auto x : tools.attach_tools ) {
 
  516                    SST::Core::Serialization::serializable* obj =
 
  517                        dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
 
  519                    x.first->serializeHandlerAttachPointKey(ser, x.second);
 
  523            tool_count = tools.intercept_tools.size();
 
  525            if ( tool_count > 0 ) {
 
  529                for ( 
auto x : tools.intercept_tools ) {
 
  530                    SST::Core::Serialization::serializable* obj =
 
  531                        dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
 
  533                    x.first->serializeHandlerInterceptPointKey(ser, x.second);
 
  538        case Core::Serialization::serializer::UNPACK:
 
  543            if ( tool_count > 0 ) {
 
  544                attached_tools = 
new ToolList();
 
  545                for ( 
size_t i = 0; i < tool_count; ++i ) {
 
  546                    SST::Core::Serialization::serializable* tool;
 
  551                    attached_tools->attach_tools.emplace_back(ap, key);
 
  555                attached_tools = 
nullptr;
 
  560            if ( tool_count > 0 ) {
 
  561                if ( 
nullptr == attached_tools ) attached_tools = 
new ToolList();
 
  562                for ( 
size_t i = 0; i < tool_count; ++i ) {
 
  563                    SST::Core::Serialization::serializable* tool;
 
  566                    InterceptPoint* ip = 
dynamic_cast<InterceptPoint*
>(tool);
 
  567                    ip->serializeHandlerInterceptPointKey(ser, key);
 
  568                    attached_tools->intercept_tools.emplace_back(ip, key);
 
  579    virtual ~SSTHandlerBase() {}
 
  581    inline void operator()(argT arg)
 
  583        if ( !attached_tools ) 
return operator_impl(arg);
 
  586        for ( 
auto& x : attached_tools->attach_tools )
 
  587            x.first->beforeHandler(x.second, arg);
 
  592        for ( 
auto& x : attached_tools->intercept_tools ) {
 
  593            x.first->interceptHandler(x.second, arg, cancel);
 
  605        for ( 
auto& x : attached_tools->attach_tools )
 
  606            x.first->afterHandler(x.second);
 
  621        if ( !attached_tools ) attached_tools = 
new ToolList();
 
  624        attached_tools->attach_tools.push_back(std::make_pair(tool, key));
 
 
  635        if ( !attached_tools ) 
return;
 
  637        for ( 
auto x = attached_tools->attach_tools.begin(); x != attached_tools->attach_tools.end(); ++x ) {
 
  638            if ( x->first == tool ) {
 
  639                attached_tools->attach_tools.erase(x);
 
 
  654        if ( !attached_tools ) attached_tools = 
new ToolList();
 
  657        attached_tools->intercept_tools.push_back(std::make_pair(tool, key));
 
 
  668        if ( !attached_tools ) 
return;
 
  670        for ( 
auto x = attached_tools->intercept_tools.begin(); x != attached_tools->intercept_tools.end(); ++x ) {
 
  671            if ( x->first == tool ) {
 
  672                attached_tools->intercept_tools.erase(x);
 
 
  683        if ( handler->attached_tools ) {
 
  684            attached_tools          = handler->attached_tools;
 
  685            handler->attached_tools = 
nullptr;
 
 
 
  701template <
typename returnT>
 
  714        virtual ~AttachPoint() {}
 
  752            std::conditional_t<std::is_pointer_v<returnT>, 
const std::remove_pointer_t<returnT>*, 
const returnT&>
 
 
  782    using ToolList           = std::vector<std::pair<AttachPoint*, uintptr_t>>;
 
  783    ToolList* attached_tools = 
nullptr;
 
  787    virtual returnT operator_impl() = 0;
 
  791        switch ( ser.mode() ) {
 
  792        case Core::Serialization::serializer::SIZER:
 
  793        case Core::Serialization::serializer::PACK:
 
  796            if ( attached_tools ) {
 
  797                for ( 
auto x : *attached_tools ) {
 
  803            size_t tool_count = tools.size();
 
  805            if ( tool_count > 0 ) {
 
  809                for ( 
auto x : tools ) {
 
  810                    SST::Core::Serialization::serializable* obj =
 
  811                        dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
 
  813                    x.first->serializeHandlerAttachPointKey(ser, x.second);
 
  818        case Core::Serialization::serializer::UNPACK:
 
  822            if ( tool_count > 0 ) {
 
  823                attached_tools = 
new ToolList();
 
  824                for ( 
size_t i = 0; i < tool_count; ++i ) {
 
  825                    SST::Core::Serialization::serializable* tool;
 
  830                    attached_tools->emplace_back(ap, key);
 
  834                attached_tools = 
nullptr;
 
  845    virtual ~SSTHandlerBase() {}
 
  847    inline returnT operator()()
 
  849        if ( attached_tools ) {
 
  850            for ( 
auto& x : *attached_tools )
 
  851                x.first->beforeHandler(x.second);
 
  853            returnT ret = operator_impl();
 
  855            for ( 
auto& x : *attached_tools )
 
  856                x.first->afterHandler(x.second, ret);
 
  860        return operator_impl();
 
  872        if ( !attached_tools ) attached_tools = 
new ToolList();
 
  874        auto key = tool->registerHandler(mdata);
 
  875        attached_tools->push_back(std::make_pair(tool, key));
 
  886        if ( !attached_tools ) 
return;
 
  888        for ( 
auto x = attached_tools->begin(); x != attached_tools->end(); ++x ) {
 
  889            if ( x->first == tool ) {
 
  890                attached_tools->erase(x);
 
  901        if ( handler->attached_tools ) {
 
  902            attached_tools          = handler->attached_tools;
 
  903            handler->attached_tools = 
nullptr;
 
  908    ImplementVirtualSerializable(SSTHandlerBase)
 
  932        virtual ~AttachPoint() {}
 
 
  994    using ToolList           = std::vector<std::pair<AttachPoint*, uintptr_t>>;
 
  995    ToolList* attached_tools = 
nullptr;
 
  999    virtual void operator_impl() = 0;
 
 1003        switch ( ser.mode() ) {
 
 1004        case Core::Serialization::serializer::SIZER:
 
 1005        case Core::Serialization::serializer::PACK:
 
 1008            if ( attached_tools ) {
 
 1009                for ( 
auto x : *attached_tools ) {
 
 1015            size_t tool_count = tools.size();
 
 1016            SST_SER(tool_count);
 
 1017            if ( tool_count > 0 ) {
 
 1021                for ( 
auto x : tools ) {
 
 1022                    SST::Core::Serialization::serializable* obj =
 
 1023                        dynamic_cast<SST::Core::Serialization::serializable*
>(x.first);
 
 1025                    x.first->serializeHandlerAttachPointKey(ser, x.second);
 
 1030        case Core::Serialization::serializer::UNPACK:
 
 1033            SST_SER(tool_count);
 
 1034            if ( tool_count > 0 ) {
 
 1035                attached_tools = 
new ToolList();
 
 1036                for ( 
size_t i = 0; i < tool_count; ++i ) {
 
 1037                    SST::Core::Serialization::serializable* tool;
 
 1042                    attached_tools->emplace_back(ap, key);
 
 1046                attached_tools = 
nullptr;
 
 1056    virtual ~SSTHandlerBase() {}
 
 1058    inline void operator()()
 
 1060        if ( attached_tools ) {
 
 1061            for ( 
auto& x : *attached_tools )
 
 1062                x.first->beforeHandler(x.second);
 
 1066            for ( 
auto& x : *attached_tools )
 
 1067                x.first->afterHandler(x.second);
 
 1071        return operator_impl();
 
 1083        if ( !attached_tools ) attached_tools = 
new ToolList();
 
 1086        attached_tools->push_back(std::make_pair(tool, key));
 
 
 1097        if ( !attached_tools ) 
return;
 
 1099        for ( 
auto x = attached_tools->begin(); x != attached_tools->end(); ++x ) {
 
 1100            if ( x->first == tool ) {
 
 1101                attached_tools->erase(x);
 
 
 1112        if ( handler->attached_tools ) {
 
 1113            attached_tools          = handler->attached_tools;
 
 1114            handler->attached_tools = 
nullptr;
 
 
 
 1130template <
typename returnT>
 
 1131using SSTHandlerBaseNoArgs = SSTHandlerBase<returnT, void>;
 
 1135template <
typename returnT, 
typename argT, 
typename classT, 
typename dataT = 
void>
 
 1139    using PtrMember = returnT (classT::*)(argT, dataT);
 
 1141    const PtrMember member;
 
 1160    returnT operator_impl(argT arg)
 override { 
return (object->*member)(arg, data); }
 
 
 1169template <
typename returnT, 
typename argT, 
typename classT>
 
 1173    using PtrMember = returnT (classT::*)(argT);
 
 1174    const PtrMember member;
 
 1191    returnT operator_impl(argT arg)
 override { 
return (object->*member)(arg); }
 
 
 1200template <
typename returnT, 
typename classT, 
typename dataT = 
void>
 
 1204    using PtrMember = returnT (classT::*)(dataT);
 
 1206    const PtrMember member;
 
 1225    void operator_impl()
 override { 
return (object->*member)(data); }
 
 
 1234template <
typename returnT, 
typename classT>
 
 1238    using PtrMember = returnT (classT::*)();
 
 1239    const PtrMember member;
 
 1256    void operator_impl()
 override { 
return (object->*member)(); }
 
 
 1272template <
typename returnT, 
typename argT, 
typename classT, 
typename dataT, auto funcT>
 
 1276    static_assert((funcT, 
false), 
"Mismatched handler templates.");
 
 
 1283template <
typename returnT, 
typename argT, 
typename classT, 
typename dataT, returnT (
classT::*funcT)(argT, dataT)>
 
 1303    SSTHandler2(
const SSTHandler2&)            = 
delete;
 
 1304    SSTHandler2& operator=(
const SSTHandler2&) = 
delete;
 
 1306    returnT operator_impl(argT arg)
 override { 
return (object->*funcT)(arg, data); }
 
 1308    void serialize_order(SST::Core::Serialization::serializer& ser)
 override 
 1310        SSTHandlerBase<returnT, argT>::serialize_order(ser);
 
 1315    ImplementSerializable(SSTHandler2)
 
 
 1322template <
typename returnT, 
typename argT, 
typename classT, returnT (
classT::*funcT)(argT)>
 
 1339    SSTHandler2(
const SSTHandler2&)            = 
delete;
 
 1340    SSTHandler2& operator=(
const SSTHandler2&) = 
delete;
 
 1342    returnT operator_impl(argT arg)
 override { 
return (object->*funcT)(arg); }
 
 1344    void serialize_order(SST::Core::Serialization::serializer& ser)
 override 
 1346        SSTHandlerBase<returnT, argT>::serialize_order(ser);
 
 1350    ImplementSerializable(SSTHandler2)
 
 
 1357template <
typename returnT, 
typename classT, 
typename dataT, returnT (
classT::*funcT)(dataT)>
 
 1376    SSTHandler2(
const SSTHandler2&)            = 
delete;
 
 1377    SSTHandler2& operator=(
const SSTHandler2&) = 
delete;
 
 1379    returnT operator_impl()
 override { 
return (object->*funcT)(data); }
 
 1381    void serialize_order(SST::Core::Serialization::serializer& ser)
 override 
 1383        SSTHandlerBase<returnT, void>::serialize_order(ser);
 
 1388    ImplementSerializable(SSTHandler2)
 
 
 1395template <
typename returnT, 
typename classT, returnT (
classT::*funcT)()>
 
 1412    SSTHandler2(
const SSTHandler2&)            = 
delete;
 
 1413    SSTHandler2& operator=(
const SSTHandler2&) = 
delete;
 
 1415    returnT operator_impl()
 override { 
return (object->*funcT)(); }
 
 1417    void serialize_order(SST::Core::Serialization::serializer& ser)
 override 
 1419        SSTHandlerBase<returnT, void>::serialize_order(ser);
 
 1423    ImplementSerializable(SSTHandler2)
 
 
Definition serializable.h:24
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45
Parameter store.
Definition params.h:58
SSTHandler2(classT *const object, dataT data)
Constructor.
Definition ssthandler.h:1295
SSTHandler2(classT *const object)
Constructor.
Definition ssthandler.h:1333
SSTHandler2(classT *const object, dataT data)
Constructor.
Definition ssthandler.h:1369
SSTHandler2(classT *const object)
Constructor.
Definition ssthandler.h:1406
Base template for the class.
Definition ssthandler.h:1274
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.
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:776
Attach Point to get notified when a handler starts and stops.
Definition ssthandler.h:339
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:403
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:415
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:469
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:666
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:619
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:633
void transferAttachedToolInfo(SSTHandlerBase *handler)
Transfers attached tools from existing handler.
Definition ssthandler.h:681
void attachInterceptTool(InterceptPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:652
Attach Point to get notified when a handler starts and stops.
Definition ssthandler.h:929
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:988
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:1110
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:1081
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:1095
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:310
void detachTool(AttachPoint *tool)
Remove an attached tool.
Definition ssthandler.h:295
void attachTool(AttachPoint *tool, const AttachPointMetaData &mdata)
Attaches a tool to the AttachPoint.
Definition ssthandler.h:281
SSTHandlerNoArgs(classT *const object, PtrMember member)
Constructor.
Definition ssthandler.h:1247
Event Handler class with user-data argument.
Definition ssthandler.h:1202
SSTHandlerNoArgs(classT *const object, PtrMember member, dataT data)
Constructor.
Definition ssthandler.h:1215
SSTHandler(classT *const object, PtrMember member)
Constructor.
Definition ssthandler.h:1182
Handler class with user-data argument.
Definition ssthandler.h:1137
SSTHandler(classT *const object, PtrMember member, dataT data)
Constructor.
Definition ssthandler.h:1150