interactive testing
[gnucap-felix.git] / src / u_probe.h
blob6a92007a54712d46b2ddeeb8f18ff683ba9123c2
1 /*$Id: u_probe.h,v 1.6 2010-09-22 13:19:51 felix Exp $ -*- C++ -*-
2 * vim:ts=8:sw=2:et:
3 * Copyright (C) 2001 Albert Davis
4 * Author: Albert Davis <aldavis@gnu.org>
6 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3, or (at your option)
11 * any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
22 *------------------------------------------------------------------
23 * single probe item
25 //testing=script,complete 2006.07.14
26 #ifndef U_PROBE_H
27 #define U_PROBE_H
28 #include "e_base.h"
29 #include "l_compar.h" // inorder
30 #include "e_cardlist.h" // inorder
31 #include "m_expression.h"
32 #include "u_function.h"
33 /*--------------------------------------------------------------------------*/
34 class CKT_BASE;
35 /*--------------------------------------------------------------------------*/
36 #define MATH_OP_CONST 0
37 #define MATH_OP_UNARY 1 * 32
38 #define MATH_OP_BINARY 2 * 32
39 #define MATH_OP_OTHER 3 * 32
40 #define MATH_OP_SET 4 * 32
42 #define MATH_OP_MASK 7 * 32
45 // this is c-ish. fixme
46 // use parameter expressions and a list of probes instead.
47 typedef enum{
48 op_null = MATH_OP_CONST, // constant value.
49 op_pi,
50 op_sum = MATH_OP_SET, // argument is a set
51 op_prod,
52 op_exp = MATH_OP_UNARY,
53 op_neg,
54 op_abs,
55 op_inv,
56 op_square,
57 op_cos,
58 op_sin,
59 op_tan,
60 op_artan,
61 op_diff = MATH_OP_BINARY,
62 op_quot
63 } MATH_OP;
65 MATH_OP strtotype( std::string );
66 char typetochar(MATH_OP );
68 inline bool is_const(MATH_OP x){
69 return x<32;
72 inline bool is_unary(MATH_OP x){
73 return x>=MATH_OP_UNARY && x<MATH_OP_BINARY ;
76 /*--------------------------------------------------------------------------*/
77 /*--------------------------------------------------------------------------*/
78 class INTERFACE PROBE : public CKT_BASE {
79 protected:
80 std::string _what;
81 std::string _override_label;
82 public:
83 explicit PROBE(): _brh(0),_next(0) {unreachable(); incomplete();}
84 explicit PROBE(const std::string& what, const CKT_BASE *brh);
85 PROBE(const PROBE& p);
86 virtual ~PROBE();
88 virtual double value()const;
90 void set_override_label(const std::string _override) { _override_label=_override; } // ???
92 PROBE* arg() const {return _arg;}
93 std::string override_label() const {return _override_label;}
94 virtual PROBE* clone()const { return (new PROBE(*this));}
95 virtual void expand(){}
96 virtual void precalc_last(){}
97 private:
98 private:
99 const CKT_BASE* _brh;
100 double _lo,_hi;
101 public:
103 void set_limit(double Lo,double Hi) {_lo = Lo; _hi = Hi;}
104 void set_next( PROBE* n ) { assert(this); _next=n;}
105 void detach();
106 PROBE& operator=(const PROBE& p);
108 virtual const std::string label()const;
109 const CKT_BASE* object()const {return _brh;}
110 double lo()const {return _lo;}
111 double hi()const {return _hi;}
112 double range()const {return hi()-lo();}
113 bool in_range()const{return in_order(lo(),value(),hi());}
114 PROBE* next()const {return _next;}
115 private:
116 double probe_node()const;
117 protected:
118 PROBE* _next;
119 PROBE* _arg; // ->MATH_PROBE
121 public: // compare probes.
122 bool operator==(const PROBE& p)const
123 { return ( ( _what == p._what )
124 // &&( _override_label == p._override_label ) ???
125 &&( _brh == p._brh ));
129 public: // compare (for STL)
130 bool operator==(const CKT_BASE& brh)const;
131 bool operator!=(const CKT_BASE& brh)const
132 { untested(); return (object() != &brh); }
133 bool operator==(const std::string& par)const
134 { return wmatch(label(), par); }
135 bool operator!=(const std::string& par)const
136 { untested(); return !( *this == par); }
140 /*--------------------------------------------------------------------------*/
141 class MATH_PROBE : public PROBE {
142 public:
143 MATH_PROBE(): PROBE() {_next=0;untested(); _arg=0;};
144 MATH_PROBE(const MATH_OP type) { _type=type; _next=NULL; _arg=0; }
145 MATH_PROBE(const MATH_PROBE& p);
146 virtual PROBE* clone()const { return new MATH_PROBE(*this);}
147 MATH_OP type()const{return(_type);}
148 MATH_PROBE& operator=(const MATH_PROBE& p);
149 void set_arg( PROBE* );// { assert(this); _arg=n;}
150 ~MATH_PROBE();
151 private:
152 MATH_OP _type;
153 unsigned _arity;
154 public:
155 double value()const;
156 const std::string label()const;
157 void push( PROBE* );
159 /*--------------------------------------------------------------------------*/
160 class EVAL_PROBE: public PROBE {
161 public:
162 EVAL_PROBE(): PROBE() {_cmd="none";untested();};
163 EVAL_PROBE(const EVAL_PROBE& p);
164 explicit EVAL_PROBE(const std::string& what, const CARD_LIST* scope);
165 virtual PROBE* clone()const { return new EVAL_PROBE(*this);}
166 EVAL_PROBE& operator=(const EVAL_PROBE& p);
167 private:
168 // FIXME carry expression. not _cmd and _scope
169 std::string _cmd;
170 Expression _exp;
171 const CARD_LIST* _scope;
172 public:
173 double value()const;
174 const std::string label()const { return _cmd; }
176 /*--------------------------------------------------------------------------*/
177 class MEAS_PROBE: public PROBE {
178 public:
179 MEAS_PROBE(): PROBE() {_cmd="none";untested();};
180 MEAS_PROBE(const MEAS_PROBE& p);
181 explicit MEAS_PROBE(const std::string& what);
182 explicit MEAS_PROBE(const std::string& what, const CARD_LIST* scope);
183 virtual PROBE* clone()const { return new MEAS_PROBE(*this);}
184 MEAS_PROBE& operator=(const MEAS_PROBE& p);
185 private:
186 std::string _cmd;
187 const CARD_LIST* _scope;
188 WAVE_FUNCTION* _f;
189 WAVE* _w;
190 public:
191 string probe_name;
192 void precalc_first();
193 void expand();
194 double value()const;
195 const std::string label()const;
196 void precalc_last();
198 /*--------------------------------------------------------------------------*/
199 #endif