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