SST  13.0.0
StructuralSimulationToolkit
subcomponent.h
1 // Copyright 2009-2023 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2023, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_SUBCOMPONENT_H
13 #define SST_CORE_SUBCOMPONENT_H
14 
15 #include "sst/core/baseComponent.h"
16 #include "sst/core/eli/elementinfo.h"
17 #include "sst/core/module.h"
18 #include "sst/core/warnmacros.h"
19 
20 namespace SST {
21 
22 /**
23  SubComponent is a class loadable through the factory which allows
24  dynamic functionality to be added to a Component. The
25  SubComponent API is nearly identical to the Component API and all
26  the calls are proxied to the parent Component.
27 */
29 {
30 
31 public:
32  SST_ELI_DECLARE_BASE(SubComponent)
33  // declare extern to limit compile times
34  SST_ELI_DECLARE_CTOR_EXTERN(ComponentId_t)
35  // These categories will print in sst-info in the order they are
36  // listed here
37  SST_ELI_DECLARE_INFO_EXTERN(
45 
46  SubComponent(ComponentId_t id);
47 
48  virtual ~SubComponent() {};
49 
50  /** Used during the init phase. The method will be called each phase of initialization.
51  Initialization ends when no components have sent any data. */
52  virtual void init(unsigned int UNUSED(phase)) override {}
53  /** Called after all components have been constructed and initialization has
54  completed, but before simulation time has begun. */
55  virtual void setup() override {}
56  /** Called after simulation completes, but before objects are
57  destroyed. A good place to print out statistics. */
58  virtual void finish() override {}
59 
60 private:
61  friend class Component;
62 };
63 
64 namespace SUBCOMPONENT {
65 
66 // Very hackish way to get a deprecation warning for
67 // SST_ELI_REGISTER_SUBCOMPONENT_DERIVED, but there are no standard ways to do this
69 {
70 public:
71  [[deprecated("SST_ELI_REGISTER_SUBCOMPONENT_DERIVED is deprecated and will be removed in SST 14. Please use the "
72  "SST_ELI_REGISTER_SUBCOMPONENT macro")]] static constexpr int
73  fake_deprecated_function()
74  {
75  return 0;
76  }
77 };
78 
79 } // namespace SUBCOMPONENT
80 
81 } // namespace SST
82 
83 // New way to register subcomponents. Must register an interface
84 // (API) first, then you can register a subcomponent that implements
85 // it
86 #define SST_ELI_REGISTER_SUBCOMPONENT_API(cls, ...) \
87  SST_ELI_DECLARE_NEW_BASE(SST::SubComponent,::cls) \
88  SST_ELI_NEW_BASE_CTOR(SST::ComponentId_t,SST::Params&,##__VA_ARGS__)
89 
90 #define SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(cls, base, ...) \
91  SST_ELI_DECLARE_NEW_BASE(::base,::cls) \
92  SST_ELI_NEW_BASE_CTOR(SST::ComponentId_t,SST::Params&,##__VA_ARGS__)
93 
94 #define SST_ELI_REGISTER_SUBCOMPONENT_DERIVED(cls, lib, name, version, desc, interface) \
95  static const int SST_ELI_FAKE_VALUE = \
96  SST::SUBCOMPONENT::sst_eli_fake_deprecated_class::fake_deprecated_function(); \
97  SST_ELI_REGISTER_DERIVED(::interface,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
98  SST_ELI_INTERFACE_INFO(#interface)
99 
100 #define SST_ELI_REGISTER_SUBCOMPONENT(cls, lib, name, version, desc, interface) \
101  SST_ELI_REGISTER_DERIVED(::interface,cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
102  SST_ELI_INTERFACE_INFO(#interface)
103 
104 #endif // SST_CORE_SUBCOMPONENT_H
virtual void finish() override
Called after simulation completes, but before objects are destroyed.
Definition: subcomponent.h:58
Definition: portsInfo.h:39
Main component object for the simulation.
Definition: component.h:30
Definition: statsInfo.h:39
Definition: action.cc:18
Definition: paramsInfo.h:40
virtual void setup() override
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: subcomponent.h:55
Main component object for the simulation.
Definition: baseComponent.h:51
Definition: subcompSlotInfo.h:39
virtual void init(unsigned int UNUSED(phase)) override
Used during the init phase.
Definition: subcomponent.h:52
Definition: attributeInfo.h:40
Definition: profilePointInfo.h:39
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:28
Definition: interfaceInfo.h:18