2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
22 * base class for anything in a netlist or circuit file
28 #include "u_time_pair.h"
29 /*--------------------------------------------------------------------------*/
32 /*--------------------------------------------------------------------------*/
36 class PARAM_LIST_BASE
;
40 /*--------------------------------------------------------------------------*/
41 class INTERFACE CARD
: public CKT_BASE
{
43 mutable int _evaliter
; // model eval iteration number
46 bool _constant
; // eval stays the same every iteration
51 uint_t _net_nodes
; // actual number of "nodes" in the netlist
52 //--------------------------------------------------------------------
53 public: // traversal functions
54 CARD
* find_in_my_scope(const std::string
& name
);
55 const CARD
* find_in_my_scope(const std::string
& name
)const;
56 const CARD
* find_in_parent_scope(const std::string
& name
)const;
57 const CARD
* find_looking_out(const std::string
& name
)const;
58 //--------------------------------------------------------------------
59 protected: // create and destroy.
61 explicit CARD(const CARD
&);
64 virtual CARD
* clone()const = 0;
65 virtual CARD
* clone_instance()const {return clone();}
66 //--------------------------------------------------------------------
67 public: // "elaborate"
68 virtual void precalc_first() {}
69 virtual void expand_first() {}
70 virtual void expand() {}
71 virtual void expand_last() {}
72 virtual void precalc_last() {}
73 virtual void map_nodes() {}
74 //--------------------------------------------------------------------
76 virtual void tr_iwant_matrix() {}
77 virtual void tr_begin() {}
78 virtual void tr_restore() {}
79 virtual void dc_advance() {}
80 virtual void tr_advance() {}
81 virtual void tr_regress() {}
82 virtual void keep_ic() {}
84 virtual bool tr_needs_eval()const {return false;}
85 virtual void tr_queue_eval() {} // not const, would need mutable iteration_tag
86 virtual bool do_tr() {return true;}
87 virtual bool do_tr_last() {return true;}
88 virtual void tr_load() {}
89 virtual TIME_PAIR
tr_review(); //{return TIME_PAIR(NEVER,NEVER);}
90 virtual void tr_accept() {}
91 virtual void tr_unload() {untested(); assert(false);}
92 //--------------------------------------------------------------------
94 virtual void ac_iwant_matrix() {}
95 virtual void ac_begin() {}
96 virtual void do_ac() {}
97 virtual void ac_load() {}
98 //--------------------------------------------------------------------
100 virtual double do_noise() const {return 0; incomplete(); trace1("not implemented", typeid(*this).name()); }
101 //--------------------------------------------------------------------
103 // virtual void sens_load() {} // ckt_base
104 virtual void do_sens() {}
105 //--------------------------------------------------------------------
106 public: // state, aux data
107 // not unreachable. some devices are simply not spice.
108 virtual char id_letter()const {return '\0';}
109 virtual uint_t
net_nodes()const {return 0;}
110 virtual bool is_device()const {return false;}
111 virtual void set_slave() {untested(); assert(!subckt());}
112 bool evaluated()const;
114 void set_constant(bool c
) {_constant
= c
;}
115 bool is_constant()const {return _constant
;}
116 //--------------------------------------------------------------------
117 public: // owner, scope
118 virtual CARD_LIST
* scope();
119 virtual const CARD_LIST
* scope()const;
120 virtual bool makes_own_scope()const {return false;}
121 CARD
* owner() {return _owner
;}
122 const CARD
* owner()const {return _owner
;}
123 void set_owner(CARD
* o
) {assert(!_owner
||_owner
==o
); _owner
=o
;}
124 //--------------------------------------------------------------------
126 CARD_LIST
* subckt() {return _subckt
;}
127 const CARD_LIST
* subckt()const {return _subckt
;}
128 void new_subckt(PARAM_LIST_MAP
* p
=NULL
);
129 void new_subckt(const CARD
* model
, PARAM_LIST
* p
);
130 void renew_subckt(const CARD
* model
, PARAM_LIST
* p
);
131 void new_subckt(const CARD
* model
, CARD
* Owner
, const CARD_LIST
* Scope
, PARAM_LIST
* p
){
132 USE(Scope
); assert(Scope
==scope());
133 USE(Owner
); assert(Owner
==this);
134 new_subckt(model
, p
);
136 void renew_subckt(const CARD
* model
, CARD
* Owner
, const CARD_LIST
* Scope
, PARAM_LIST
* p
){
137 USE(Scope
); assert(Scope
==scope());
138 USE(Owner
); assert(Owner
==this);
139 renew_subckt(model
, p
);
142 //--------------------------------------------------------------------
144 virtual std::string
dev_type()const {unreachable(); return "";}
145 virtual void set_dev_type(const std::string
&);
146 //--------------------------------------------------------------------
147 public: // label -- in CKT_BASE
148 // non-virtual void set_label(const std::string& s) //BASE
149 // non-virtual const std::string& short_label()const //BASE
150 /*virtual*/ const std::string
long_label()const; // no further override
151 //--------------------------------------------------------------------
152 public: // ports -- mostly defer to COMPONENT
153 node_t
& n_(unsigned i
)const;
154 int connects_to(const node_t
& node
)const;
155 //--------------------------------------------------------------------
156 public: // parameters
157 virtual void set_param_by_name(std::string
, std::string
);
158 virtual void set_param_by_index(int i
, std::string
&, int offset
)
159 {untested(); throw Exception_Too_Many(unsigned(i
), 0u, offset
);}
160 virtual int param_count_dont_print()const {return 0;}
161 virtual int param_count()const {return 0;}
162 virtual bool param_is_printable(int)const {untested(); return false;}
163 virtual std::string
param_name(int)const {return "";}
164 virtual std::string
param_name(int i
,int j
)const {return (j
==0) ? param_name(i
) : "";}
165 virtual std::string
param_value(int)const {untested(); return "";}
166 virtual std::string
value_name()const = 0;
167 //--------------------------------------------------------------------
168 public: // obsolete -- do not use in new code
169 virtual bool use_obsolete_callback_parse()const {return false;}
170 virtual bool use_obsolete_callback_print()const {return false;}
171 virtual void print_args_obsolete_callback(OMSTREAM
&,LANGUAGE
*)const {unreachable();}
172 //--------------------------------------------------------------------
174 virtual void tt_begin(){}
175 virtual void tt_restore(){}
176 virtual void tt_advance(){} // prepare for next sweep
177 virtual void tt_regress(){} // same but backwards in time
178 virtual void tt_accept(){}
179 virtual void tt_init_i(){} // save unstressed parameters
180 // virtual void tr_stress(){} // calculate stress during tr. tr_accept?
181 virtual void do_tt(){}; // called before tr_begin.
182 virtual void tr_stress_last(){} // calculate stress during tr. tt_review? do_tt_last?
183 virtual TIME_PAIR
tt_review() {return TIME_PAIR(NEVER
,NEVER
);}
184 public: /// experimental & cruft
185 std::string
comment() const {return _comment
;}
186 void set_comment(std::string s
) {_comment
= s
;}
187 virtual void tr_save_amps( int ){ } // behaviouir??
188 hp_float_t tr_behaviour_del
; // behaviour now.
189 hp_float_t tt_behaviour_del
;
190 hp_float_t tr_behaviour_rel
;
191 hp_float_t tt_behaviour_rel
;
192 void tt_behaviour_reset() { tt_behaviour_del
=0; tt_behaviour_rel
=0; }
193 void tt_behaviour_commit(){ tt_behaviour_reset(); }
195 /*--------------------------------------------------------------------------*/
198 inline S
& operator<<( S
& o
, const std::deque
<CARD
*> &d
){
199 for(std::deque
<CARD
*>::const_iterator i
=d
.begin(); i
!=d
.end(); ++i
){
200 o
<< "\n" << (*i
)->long_label() << " " << (*i
)->short_label() ;
205 /*--------------------------------------------------------------------------*/
206 /*--------------------------------------------------------------------------*/
208 // vim:ts=8:sw=2:noet: