SST  11.1.0
StructuralSimulationToolkit
component.h
1 // Copyright 2009-2021 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-2021, 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  Component() {} // Unused, but previously available
94 };
95 
96 } // namespace SST
97 
98 // These macros allow you to register a base class for a set of
99 // components that have the same (or substantially the same) ELI
100 // information. ELI information can be defined in the base class, and
101 // will be inherited by the child classes.
102 #define SST_ELI_REGISTER_COMPONENT_BASE(cls) \
103  SST_ELI_DECLARE_NEW_BASE(SST::Component,::cls) \
104  SST_ELI_NEW_BASE_CTOR(SST::ComponentId_t,SST::Params&)
105 
106 #define SST_ELI_REGISTER_COMPONENT_DERIVED_BASE(cls, base) \
107  SST_ELI_DECLARE_NEW_BASE(::base,::cls) \
108  SST_ELI_NEW_BASE_CTOR(SST::ComponentId_t,SST::Params&)
109 
110 // 'x' is needed because you can't pass ##__VAR_ARGS__ as the first
111 // item to the macro or you end up with a leading comma that won't
112 // compile.
113 #define ELI_GET_COMPONENT_DEFAULT(x, arg1, ...) arg1
114 
115 #define SST_ELI_REGISTER_COMPONENT(cls, lib, name, version, desc, cat, ...) \
116  SST_ELI_REGISTER_DERIVED(ELI_GET_COMPONENT_DEFAULT(,##__VA_ARGS__,SST::Component),cls,lib,name,ELI_FORWARD_AS_ONE(version),desc) \
117  SST_ELI_CATEGORY_INFO(cat)
118 
119 #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:51
Definition: subcompSlotInfo.h:39
Parameter store.
Definition: params.h:43
Definition: categoryInfo.h:25
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:28