SST  15.1.0
StructuralSimulationToolkit
pymodel_comp.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2025 NTESS. Under the terms
4 // of Contract DE-NA0003525 with NTESS, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2025, NTESS
8 // All rights reserved.
9 //
10 // This file is part of the SST software package. For license
11 // information, see the LICENSE file in the top level directory of the
12 // distribution.
13 
14 #ifndef SST_CORE_MODEL_PYTHON_PYMODEL_COMP_H
15 #define SST_CORE_MODEL_PYTHON_PYMODEL_COMP_H
16 
17 #include "sst/core/sst_types.h"
18 #include "sst/core/warnmacros.h"
19 
20 DISABLE_WARN_DEPRECATED_REGISTER
21 #include <Python.h>
22 #include <cstdint>
23 REENABLE_WARNING
24 
25 #include <string>
26 
27 namespace SST {
28 class ConfigComponent;
29 }
30 
31 extern "C" {
32 
33 struct ComponentPy_t;
34 struct PyComponent;
35 
37 {
38  ComponentPy_t* pobj;
39  SST::ComponentId_t id;
40 
41  ComponentHolder(ComponentPy_t* pobj, SST::ComponentId_t id) :
42  pobj(pobj),
43  id(id)
44  {}
45  virtual ~ComponentHolder() {}
46  virtual SST::ConfigComponent* getComp();
47  virtual int compare(ComponentHolder* other);
48  virtual std::string getName();
49  SST::ComponentId_t getID();
50  SST::ConfigComponent* getSubComp(const std::string& name, int slot_num);
51 
52  ComponentHolder(const ComponentHolder&) = delete;
53  ComponentHolder& operator=(const ComponentHolder&) = delete;
54 };
55 
57 {
58  uint16_t subCompId;
59 
60  PyComponent(ComponentPy_t* pobj, SST::ComponentId_t id) :
61  ComponentHolder(pobj, id),
62  subCompId(0)
63  {}
64  ~PyComponent() override = default;
65 };
66 
68 {
69  PySubComponent(ComponentPy_t* pobj, SST::ComponentId_t id) :
70  ComponentHolder(pobj, id)
71  {}
72  ~PySubComponent() override = default;
73  int getSlot();
74 };
75 
77 {
78  PyObject_HEAD ComponentHolder* obj;
79 };
80 
81 extern PyTypeObject PyModel_ComponentType;
82 extern PyTypeObject PyModel_SubComponentType;
83 
84 static inline SST::ConfigComponent*
85 getComp(PyObject* pobj)
86 {
87  SST::ConfigComponent* c = ((ComponentPy_t*)pobj)->obj->getComp();
88  if ( c == nullptr ) {
89  PyErr_SetString(PyExc_RuntimeError, "Failed to find ConfigComponent");
90  }
91  return c;
92 }
93 
94 } /* extern C */
95 
96 #endif // SST_CORE_MODEL_PYTHON_PYMODEL_COMP_H
Definition: pymodel_comp.h:76
Definition: pymodel_comp.h:56
Definition: pymodel_comp.h:67
Represents the configuration of a generic component.
Definition: configGraph.h:381
Definition: action.cc:18
Definition: pymodel_comp.h:36