Program listing for file kernel/src/modelingTools/SubPluggedObject.hpp

Program listing for file kernel/src/modelingTools/SubPluggedObject.hpp#

 1#ifndef SubPluggedObject_H
 2#define SubPluggedObject_H
 3
 4#include "PluggedObject.hpp"
 5
 6
 7
 8typedef void (*matrixPlugin)(double, unsigned int, unsigned int, double*, unsigned int, double*);
 9
10class SubPluggedObject : public PluggedObject
11{
12private:
13
14  ACCEPT_SERIALIZATION(SubPluggedObject);
15
16  void * _parentfPtr;
17
18  SP::SiconosMatrix _tmpMat;
19
20  unsigned int _indx;
21
22  unsigned int _p;
23
24public:
25
26
27  SubPluggedObject(): PluggedObject(), _parentfPtr(nullptr), _indx(0), _p(0)  { };
28
29
30  SubPluggedObject(const PluggedObject& PO, const unsigned int n, const unsigned int p, const unsigned int indx = 0):  _indx(indx), _p(p)
31  {
32    _pluginName = "Sub" + PO.pluginName();
33    _tmpMat.reset(new SimpleMatrix(n, p));
34#if (__GNUG__ && !( __clang__ || __INTEL_COMPILER || __APPLE__ ) && (((__GNUC__ > 5) && (__GNUC_MINOR__ > 0))))
35#pragma GCC diagnostic ignored "-Wpmf-conversions"
36    fPtr = (void *)&SubPluggedObject::computeAndExtract;
37    _parentfPtr = PO.fPtr;
38#else
39    THROW_EXCEPTION("SubPluggedObject must be compiled with GCC !");
40#endif
41  };
42
43
44  SubPluggedObject(const SubPluggedObject& SPO): PluggedObject(SPO), _indx(SPO.getIndex()), _p(SPO.getp())
45  {
46    _parentfPtr = SPO.getParentfPtr();
47    _tmpMat.reset(new SimpleMatrix(SPO.getTmpMat()));
48  }
49
50
51  ~SubPluggedObject() {};
52
53
54  void computeAndExtract(double time, unsigned int n, double* M, unsigned int sizez, double* z)
55  {
56    ((matrixPlugin)_parentfPtr)(time, n, _p, &(*_tmpMat)(0, 0), sizez, z);
57    for (unsigned int i = 0; i < n; i++)
58    {
59      M[i] = (*_tmpMat)(i, _indx);
60    }
61  };
62
63
64  inline void setIndex(unsigned int newIndx)
65  {
66    _indx = newIndx;
67  };
68
69
70  inline unsigned int getIndex() const
71  {
72    return _indx;
73  };
74
75
76  inline unsigned int getp() const
77  {
78    return _p;
79  };
80
81
82  inline void * getParentfPtr() const
83  {
84    return _parentfPtr;
85  };
86
87
88  inline const SiconosMatrix& getTmpMat() const
89  {
90    return *_tmpMat;
91  };
92
93};
94#endif