SST  7.0.0
StructuralSimulationToolkit
subcomponent.h
1 // Copyright 2009-2017 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2017, Sandia Corporation
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 
13 #ifndef SST_CORE_SUBCOMPONENT_H
14 #define SST_CORE_SUBCOMPONENT_H
15 
16 #include <sst/core/warnmacros.h>
17 #include <sst/core/baseComponent.h>
18 #include <sst/core/component.h>
19 #include <sst/core/module.h>
20 
21 namespace SST {
22 
23 /**
24  SubComponent is a class loadable through the factory which allows
25  dynamic functionality to be added to a Component. The
26  SubComponent API is nearly identical to the Component API and all
27  the calls are proxied to the parent Compoent.
28 */
29 class SubComponent : public Module, public BaseComponent {
30 
31 public:
32  SubComponent(Component* parent) : BaseComponent(), parent(parent) {
33  my_info = parent->currentlyLoadingSubComponent;
34  };
35  virtual ~SubComponent() {};
36 
37  /** Used during the init phase. The method will be called each phase of initialization.
38  Initialization ends when no components have sent any data. */
39  virtual void init(unsigned int UNUSED(phase)) override {}
40  /** Called after all components have been constructed and inialization has
41  completed, but before simulation time has begun. */
42  virtual void setup( ) override { }
43  /** Called after simulation completes, but before objects are
44  destroyed. A good place to print out statistics. */
45  virtual void finish( ) override { }
46 
47 protected:
48  Component* const parent;
49 
50  Component* getTrueComponent() const final override { return parent; }
51  BaseComponent* getStatisticOwner() const final override {
52  /* If our ID == parent ID, then we're a legacy subcomponent that doesn't own stats. */
53  if ( this->getId() == parent->getId() )
54  return parent;
55  return const_cast<SubComponent*>(this);
56  }
57 
58  /* Deprecate? Old ELI style*/
59  SubComponent* loadSubComponent(std::string type, Params& params) {
60  return parent->loadSubComponent(type, parent, params);
61  }
62 
63  // Does the statisticName exist in the ElementInfoStatistic
64  virtual bool doesComponentInfoStatisticExist(const std::string &statisticName) const final override;
65 
66 private:
67  /** Component's type, set by the factory when the object is created.
68  It is identical to the configuration string used to create the
69  component. I.e. the XML "<component id="aFoo"><foo>..." would
70  set component::type to "foo" */
71  friend class Component;
72 
73 };
74 
75 } //namespace SST
76 
77 
78 #endif // SST_CORE_SUBCOMPONENT_H
SubComponent * loadSubComponent(std::string type, Component *comp, Params &params)
Loads a SubComponent from an element Library.
Definition: baseComponent.cc:328
virtual void finish() override
Called after simulation completes, but before objects are destroyed.
Definition: subcomponent.h:45
ComponentId_t getId() const
Returns unique component ID.
Definition: baseComponent.h:114
Main component object for the simulation.
Definition: component.h:32
Definition: action.cc:17
Module is a tag class used with the loadModule function.
Definition: module.h:20
virtual void setup() override
Called after all components have been constructed and inialization has completed, but before simulati...
Definition: subcomponent.h:42
Main component object for the simulation.
Definition: baseComponent.h:104
BaseComponent * getStatisticOwner() const final override
Returns self if Component If sub-component, returns self if a "modern" subcomponent otherwise...
Definition: subcomponent.h:51
Parameter store.
Definition: params.h:45
virtual void init(unsigned int UNUSED(phase)) override
Used during the init phase.
Definition: subcomponent.h:39
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29