SST  10.0.0
StructuralSimulationToolkit
pymodel_comp.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2020 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-2020, 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_PYMODEL_COMP_H
15 #define SST_CORE_MODEL_PYMODEL_COMP_H
16 
17 #include "sst/core/sst_types.h"
18 
19 extern "C" {
20 
21 
22 struct ComponentPy_t;
23 struct PyComponent;
24 
25 struct ComponentHolder {
26  ComponentPy_t *pobj;
27  ComponentId_t id;
28 
29  ComponentHolder(ComponentPy_t *pobj, ComponentId_t id) : pobj(pobj), id(id) { }
30  virtual ~ComponentHolder() { }
31  virtual ConfigComponent* getComp();
32  virtual int compare(ComponentHolder *other);
33  virtual std::string getName();
34  ComponentId_t getID();
35  ConfigComponent* getSubComp(const std::string& name, int slot_num);
36 };
37 
39  uint16_t subCompId;
40 
41  PyComponent(ComponentPy_t *pobj, ComponentId_t id) : ComponentHolder(pobj,id), subCompId(0) { }
42  ~PyComponent() {}
43 };
44 
46  PySubComponent(ComponentPy_t *pobj, ComponentId_t id) : ComponentHolder(pobj,id) { }
47  ~PySubComponent() {}
48  int getSlot();
49 };
50 
51 
52 struct ComponentPy_t {
53  PyObject_HEAD
54  ComponentHolder *obj;
55 };
56 
57 extern PyTypeObject PyModel_ComponentType;
58 extern PyTypeObject PyModel_SubComponentType;
59 
60 static inline ConfigComponent* getComp(PyObject *pobj) {
61  ConfigComponent *c = ((ComponentPy_t*)pobj)->obj->getComp();
62  if ( c == nullptr ) {
63  PyErr_SetString(PyExc_RuntimeError, "Failed to find ConfigComponent");
64  }
65  return c;
66 }
67 
68 } /* extern C */
69 
70 
71 #endif
Definition: pymodel_comp.h:53
Definition: pymodel_comp.h:39
Definition: pymodel_comp.h:46
Definition: pymodel_comp.h:25