SST  12.0.0
StructuralSimulationToolkit
component.h
1 // Copyright 2009-2022 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-2022, 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_COMPONENT_H
13 #define SST_CORE_COMPONENT_H
14 
15 #include "sst/core/baseComponent.h"
16 #include "sst/core/eli/elementinfo.h"
17 #include "sst/core/sst_types.h"
18 
19 #include <map>
20 
21 using namespace SST::Statistics;
22 
23 namespace SST {
24 class SubComponent;
25 
26 /**
27  * Main component object for the simulation.
28  * All models inherit from this.
29  */
30 class Component : public BaseComponent
31 {
32 public:
33  SST_ELI_DECLARE_BASE(Component)
34  // declare extern to limit compile times
35  SST_ELI_DECLARE_CTOR_EXTERN(ComponentId_t,SST::Params&)
36  SST_ELI_DECLARE_INFO_EXTERN(
42 
43  /** Constructor. Generally only called by the factory class.
44  @param id Unique component ID
45  */
46  Component(ComponentId_t id);
47  virtual ~Component();
48 
49  /** Register as a primary component, which allows the component to
50  specify when it is and is not OK to end simulation. The
51  simulator will not end simulation naturally (through use of
52  the Exit object) while any primary component has specified
53  primaryComponentDoNotEndSim(). However, it is still possible
54  for Actions other than Exit to end simulation. Once all
55  primary components have specified
56  primaryComponentOKToEndSim(), the Exit object will trigger and
57  end simulation.
58 
59  This must be called during simulation wireup (i.e during the
60  constructor for the component). By default, the state of the
61  primary component is set to OKToEndSim.
62 
63  If no component registers as a primary component, then the
64  Exit object will not be used for that simulation and
65  simulation termination must be accomplished through some other
66  mechanism (e.g. --stopAt flag, or some other Action object).
67 
68  @sa Component::primaryComponentDoNotEndSim()
69  @sa Component::primaryComponentOKToEndSim()
70  */
71  void registerAsPrimaryComponent();
72 
73  /** Tells the simulation that it should not exit. The component
74  will remain in this state until a call to
75  primaryComponentOKToEndSim().
76 
77  @sa Component::registerAsPrimaryComponent()
78  @sa Component::primaryComponentOKToEndSim()
79  */
80  void primaryComponentDoNotEndSim();
81 
82  /** Tells the simulation that it is now OK to end simulation.
83  Simulation will not end until all primary components have
84  called this function.
85 
86  @sa Component::registerAsPrimaryComponent()
87  @sa Component::primaryComponentDoNotEndSim()
88  */
89  void primaryComponentOKToEndSim();
90 
91 protected:
92  friend class SubComponent;
93 };
94 
95 } // namespace SST
96 
97 // These macros allow you to register a base class for a set of
98 // components that have the same (or substantially the same) ELI
99 // information. ELI information can be defined in the base class, and
100 // will be inherited by the child classes.
101 #define SST_ELI_REGISTER_COMPONENT_BASE(cls) \
102  SST_ELI_DECLARE_NEW_BASE(SST::Component,::cls) \
103  SST_ELI_NEW_BASE_CTOR(SST::ComponentId_t,SST::Params&)
104 
105 #define SST_ELI_REGISTER_COMPONENT_DERIVED_BASE(cls, base) \
106  SST_ELI_DECLARE_NEW_BASE(::base,::cls) \
107  SST_ELI_NEW_BASE_CTOR(SST::ComponentId_t,SST::Params&)
108 
109 // 'x' is needed because you can't pass ##__VAR_ARGS__ as the first
110 // item to the macro or you end up with a leading comma that won't
111 // compile.
112 #define ELI_GET_COMPONENT_DEFAULT(x, arg1, ...) arg1
113 
114 #define SST_ELI_REGISTER_COMPONENT(cls, lib, name, version, desc, cat, ...) \
115  SST_ELI_REGISTER_DERIVED(ELI_GET_COMPONENT_DEFAULT(,##__VA_ARGS__,SST::Component),cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
116  SST_ELI_CATEGORY_INFO(cat)
117 
118 #endif // SST_CORE_COMPONENT_H
Definition: portsInfo.h:39
Main component object for the simulation.
Definition: component.h:30
Definition: statsInfo.h:39
Definition: paramsInfo.h:40
Main component object for the simulation.
Definition: baseComponent.h:49
Definition: subcompSlotInfo.h:39
Parameter store.
Definition: params.h:55
Definition: categoryInfo.h:25
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:28