CTDEDataType.h
1 // -----------------------------------------------------------------//
2 // //
3 // Project : MLDesigner, CTDE Domain //
4 // Author : Gregor Beck Andreas Franck //
5 // eMail : gregor.beck@mldesigner.com //
6 // andreas.franck@mldesigner.com //
7 // Copyright : MLDesign Technologies, Inc. //
8 // Created : 04/15/2001 //
9 // //
10 // ---------------------------------------------------------------- //
11 
16 // -------------------------------------------------------------------
17 
18 #ifndef __CTDEDataType_h
19 #define __CTDEDataType_h
20 
21 // -------------------------------------------------------------------
22 // standard includes
23 #include <string.h>
24 
25 #include <valarray>
26 #include <queue>
27 #include <cfloat>
28 
29 // -------------------------------------------------------------------
30 // kernel includes
31 #include "kernel/Exception.h"
32 
33 // forward declarations
34 class GenericPort;
35 class Star;
36 
37 // -------------------------------------------------------------------
38 
39 enum BreakPointType {
40  SAMPLE = 0,
41  BREAK = 1
42 };
43 
44 typedef double Real;
45 typedef std::valarray<Real> RVector;
46 
47 #ifndef INFINITY
48 static const double INFINITY = DBL_MAX;
49 #endif
50 
51 //static const Real INFINITY = numeric_limits<Real>::infinity();
52 
59 const double state_eps = 1e-12;
60 const double time_eps = 1e-8;
61 
62 //------------------------------------------------------------------------------
63 // exceptions
64 
65 class CTDEException: public Exception
66 {
67  public:
68  CTDEException();
69  CTDEException(const Kernel::String& pMsg);
70 };
71 
72 class MissedBreakPoint : public CTDEException {};
73 
75 public:
76  InvalidPortAccess(): CTDEException("Invalid Port Access" ), mPort( 0 ) {}
77  InvalidPortAccess( const char* pMsg ): CTDEException(pMsg), mPort( 0 ) {}
78  InvalidPortAccess( const GenericPort* pPort, const char* pMsg ):
79  CTDEException( pMsg ), mPort( pPort ) {}
80 
81  const GenericPort* mPort;
82 };
83 
84 // include debug tests
85 #define TEST_POINTERS_AND_RANGES 1
86 
87 class VFunction_ {
88 public:
89  virtual ~VFunction_() {} ;
90 // virtual RVector operator() (const RVector&, Real) = 0;
91  virtual void operator() (const RVector& pArg, Real pTime,
92  RVector& pRes )
93  { operator()(&(const_cast<RVector&>(pArg)[0]), pTime, &pRes[0]); }
94 
95  virtual void operator() (const double* pArg, Real pTime,
96  double* pRes ) = 0;
97 
98  virtual void calculateJacobian(const double* x, Real t, double* pFres,
99  double* pJacRes) = 0;
100 };
101 
103 {
104  public:
105  virtual ~StateEventFunction() {}
106  virtual size_t stateEventNumber() const = 0;
107 
108  virtual bool stateEventFcn( double pTime,
109  const double* pState,
110  double* pResult ) = 0;
111 };
112 
113 namespace StateEvent
114 {
118  enum direction
119  {
120  none=0,
121  falling=1,
122  rising=2,
123  both=3
124  };
125 };
126 
127 class OutCTDEPort;
128 
130 {
131  friend std::ostream& operator<<(std::ostream& pStrm, const OutSignalDescriptor& pSignal );
132  public:
133  OutSignalDescriptor(): mPort(0), mIdx(0) {}
134  OutSignalDescriptor(const OutCTDEPort* pPort, size_t pIdx ): mPort(pPort), mIdx(pIdx) {}
135  OutSignalDescriptor( const OutSignalDescriptor& pRhs ): mPort(pRhs.mPort), mIdx(pRhs.mIdx) {}
136  const OutSignalDescriptor& operator=( const OutSignalDescriptor& pRhs )
137  { mPort = pRhs.mPort; mIdx=pRhs.mIdx; return *this; }
138 
139  const OutCTDEPort* port() const { return mPort; }
140  OutCTDEPort* port() { return const_cast<OutCTDEPort*>(mPort); }
141  size_t index() const {return mIdx; }
142 
143  void setPort( OutCTDEPort* pPort ) { mPort = pPort; }
144  void setIndex( size_t pIdx ) { mIdx = pIdx; }
145 
146  bool operator<( const OutSignalDescriptor& pRhs ) const;
147  bool operator==( const OutSignalDescriptor& pRhs ) const;
148  bool operator!=( const OutSignalDescriptor& pRhs ) const
149  { return !operator==(pRhs ); }
150  static const OutSignalDescriptor null;
151 
152  private:
153  const OutCTDEPort* mPort;
154  size_t mIdx;
155 };
156 
157 class InCTDEPort;
162 {
163  friend std::ostream& operator<<(std::ostream& pStrm, const InSignalDescriptor& pSignal );
164  public:
165  InSignalDescriptor(): mPort(0), mIdx(0) {}
166  InSignalDescriptor(const InCTDEPort* pPort, size_t pIdx ): mPort(pPort), mIdx(pIdx) {}
167  InSignalDescriptor( const InSignalDescriptor& pRhs ): mPort(pRhs.mPort), mIdx(pRhs.mIdx) {}
168  const InSignalDescriptor& operator=( const InSignalDescriptor& pRhs )
169  { mPort = pRhs.mPort; mIdx=pRhs.mIdx; return *this; }
170 
171  const InCTDEPort* port() const { return mPort; };
172  InCTDEPort* port() { return const_cast<InCTDEPort*>(mPort); }
173  size_t index() const {return mIdx; }
174 
175  void setPort( InCTDEPort* pPort ) { mPort = pPort; }
176  void setIndex( size_t pIdx ) { mIdx = pIdx; }
177 
178  bool operator<( const InSignalDescriptor& pRhs ) const;
179  bool operator==( const InSignalDescriptor& pRhs ) const;
180  bool operator!=( const InSignalDescriptor& pRhs ) const
181  { return !operator==(pRhs); }
182 
183  static const InSignalDescriptor null;
184 
185  private:
186  const InCTDEPort* mPort;
187  size_t mIdx;
188 };
189 std::ostream& operator<<(std::ostream& pStrm, const InSignalDescriptor& pSignal );
190 
194 class StrLt {
195 public:
196  bool operator()(const char* s1, const char* s2) const {
197  return strcmp(s1, s2) < 0;
198  }
199 };
200 
201 #endif
202 
203 
204 
205 
206 
207 
208 
209 
210 
Definition: CTDEDataType.h:65
Definition: CTDEDataType.h:161
Definition: CTDEPortHole.h:244
Definition: CTDEDataType.h:72
Definition: CTDEDataType.h:74
Definition: CTDEDataType.h:87
Definition: CTDEDataType.h:194
const GenericPort * mPort
Definition: CTDEDataType.h:81
Definition: CTDEDataType.h:102
Definition: CTDEDataType.h:129
Definition: CTDEPortHole.h:103