SST 15.0
Structural Simulation Toolkit
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
20DISABLE_WARN_DEPRECATED_REGISTER
21#include <Python.h>
22REENABLE_WARNING
23
24#include <string>
25
26namespace SST {
27class ConfigComponent;
28}
29
30extern "C" {
31
32struct ComponentPy_t;
33struct PyComponent;
34
35struct ComponentHolder
36{
37 ComponentPy_t* pobj;
38 SST::ComponentId_t id;
39
40 ComponentHolder(ComponentPy_t* pobj, SST::ComponentId_t id) :
41 pobj(pobj),
42 id(id)
43 {}
44 virtual ~ComponentHolder() {}
45 virtual SST::ConfigComponent* getComp();
46 virtual int compare(ComponentHolder* other);
47 virtual std::string getName();
48 SST::ComponentId_t getID();
49 SST::ConfigComponent* getSubComp(const std::string& name, int slot_num);
50
51 ComponentHolder(const ComponentHolder&) = delete;
52 ComponentHolder& operator=(const ComponentHolder&) = delete;
53};
54
55struct PyComponent : ComponentHolder
56{
57 uint16_t subCompId;
58
59 PyComponent(ComponentPy_t* pobj, SST::ComponentId_t id) :
60 ComponentHolder(pobj, id),
61 subCompId(0)
62 {}
63 ~PyComponent() override = default;
64};
65
66struct PySubComponent : ComponentHolder
67{
68 PySubComponent(ComponentPy_t* pobj, SST::ComponentId_t id) :
69 ComponentHolder(pobj, id)
70 {}
71 ~PySubComponent() override = default;
72 int getSlot();
73};
74
76{
77 PyObject_HEAD ComponentHolder* obj;
78};
79
80extern PyTypeObject PyModel_ComponentType;
81extern PyTypeObject PyModel_SubComponentType;
82
83static inline SST::ConfigComponent*
84getComp(PyObject* pobj)
85{
86 SST::ConfigComponent* c = ((ComponentPy_t*)pobj)->obj->getComp();
87 if ( c == nullptr ) {
88 PyErr_SetString(PyExc_RuntimeError, "Failed to find ConfigComponent");
89 }
90 return c;
91}
92
93} /* extern C */
94
95#endif // SST_CORE_MODEL_PYTHON_PYMODEL_COMP_H
Represents the configuration of a generic component.
Definition configGraph.h:263
Definition pymodel_comp.h:36
Definition pymodel_comp.h:76
Definition pymodel_comp.h:56