SST  12.0.0
StructuralSimulationToolkit
pymodel_comp.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2022 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-2022, 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 REENABLE_WARNING
23 
24 #include <string>
25 
26 namespace SST {
27 class ConfigComponent;
28 } // namespace SST
29 
30 extern "C" {
31 
32 struct ComponentPy_t;
33 struct PyComponent;
34 
36 {
37  ComponentPy_t* pobj;
38  SST::ComponentId_t id;
39 
40  ComponentHolder(ComponentPy_t* pobj, SST::ComponentId_t id) : pobj(pobj), id(id) {}
41  virtual ~ComponentHolder() {}
42  virtual SST::ConfigComponent* getComp();
43  virtual int compare(ComponentHolder* other);
44  virtual std::string getName();
45  SST::ComponentId_t getID();
46  SST::ConfigComponent* getSubComp(const std::string& name, int slot_num);
47 };
48 
50 {
51  uint16_t subCompId;
52 
53  PyComponent(ComponentPy_t* pobj, SST::ComponentId_t id) : ComponentHolder(pobj, id), subCompId(0) {}
54  ~PyComponent() {}
55 };
56 
58 {
59  PySubComponent(ComponentPy_t* pobj, SST::ComponentId_t id) : ComponentHolder(pobj, id) {}
60  ~PySubComponent() {}
61  int getSlot();
62 };
63 
65 {
66  PyObject_HEAD ComponentHolder* obj;
67 };
68 
69 extern PyTypeObject PyModel_ComponentType;
70 extern PyTypeObject PyModel_SubComponentType;
71 
72 static inline SST::ConfigComponent*
73 getComp(PyObject* pobj)
74 {
75  SST::ConfigComponent* c = ((ComponentPy_t*)pobj)->obj->getComp();
76  if ( c == nullptr ) { PyErr_SetString(PyExc_RuntimeError, "Failed to find ConfigComponent"); }
77  return c;
78 }
79 
80 } /* extern C */
81 
82 #endif // SST_CORE_MODEL_PYTHON_PYMODEL_COMP_H
Definition: pymodel_comp.h:64
Definition: pymodel_comp.h:49
Definition: pymodel_comp.h:57
Represents the configuration of a generic component.
Definition: configGraph.h:217
Definition: pymodel_comp.h:35