bump to -rc12
[gnucap-felix.git] / src / e_cardlist.h
blob06fc224530cd2a1fd1cfe84c74586f321e6e6f8f
1 /*$Id: e_cardlist.h,v 1.10 2010-08-26 09:07:17 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 * "card" container -- list of circuit elements
25 //testing=script,complete 2006.07.11
26 #ifndef E_CARDLIST_H
27 #define E_CARDLIST_H
28 #include "md.h"
29 #include "ap.h"
31 /*--------------------------------------------------------------------------*/
32 // defined here
33 class CARD_LIST;
34 /*--------------------------------------------------------------------------*/
35 // external
36 class CARD;
37 #define PARAM_LIST PARAM_LIST_MAP
38 class PARAM_LIST;
39 class PARAM_LIST_BASE;
40 class NODE_MAP;
41 class NODE;
42 class NODE_BASE;
43 class LANGUAGE;
44 struct TIME_PAIR;
45 /*--------------------------------------------------------------------------*/
46 class INTERFACE CARD_LIST {
47 private:
48 const CARD_LIST* _parent;
49 mutable NODE_MAP* _nm;
50 mutable int *_mnm; // map node user number to matrix number.
51 mutable PARAM_LIST* _params;
52 LANGUAGE* _language;
53 std::list<CARD*> _cl;
54 std::list<CARD*> _eq; // eval queue
55 const CARD* _owner; // stupid hack
56 const CARD_LIST* _origin; // even more stupid hack
57 public:
58 static void q_hack(CARD* x);
59 // internal types
60 typedef std::list<CARD*>::iterator iterator;
61 typedef std::list<CARD*>::const_iterator const_iterator;
62 class fat_iterator {
63 private:
64 CARD_LIST* _list;
65 iterator _iter;
66 private:
67 explicit fat_iterator() {unreachable();}
68 public:
69 fat_iterator(const fat_iterator& p)
70 : _list(p._list), _iter(p._iter) {}
71 explicit fat_iterator(CARD_LIST* l, iterator i)
72 : _list(l), _iter(i) {}
73 bool is_end()const {return _iter == _list->end();}
74 CARD* operator*() {return (is_end()) ? NULL : *_iter;}
75 fat_iterator& operator++() {assert(!is_end()); ++_iter; return *this;}
76 fat_iterator operator++(int)
77 {assert(!is_end()); fat_iterator t(*this); ++_iter; return t;}
78 bool operator==(const fat_iterator& x)const
79 {unreachable(); assert(_list==x._list); return (_iter==x._iter);}
80 bool operator!=(const fat_iterator& x)const
81 {assert(_list==x._list); return (_iter!=x._iter);}
82 iterator iter()const {return _iter;}
83 CARD_LIST* list()const {return _list;}
84 fat_iterator end()const {return fat_iterator(_list, _list->end());}
86 void insert(CARD* c) {list()->insert(iter(),c);}
89 // status queries
90 bool is_empty()const {return _cl.empty();}
91 size_t size()const {return _cl.size();}
92 const CARD_LIST* parent()const {return _parent;}
93 const LANGUAGE* language()const {untested(); return _language;}
95 // return an iterator
96 iterator begin() {return _cl.begin();}
97 iterator end() {return _cl.end();}
98 iterator find_again(const std::string& short_name, iterator);
99 iterator find_(const std::string& short_name)
100 {return find_again(short_name, begin());}
102 // return a const_iterator
103 const_iterator begin()const {return _cl.begin();}
104 const_iterator end()const {return _cl.end();}
105 const_iterator find_again(const std::string& short_name, const_iterator)const;
106 const_iterator find_(const std::string& short_name)const
107 {return find_again(short_name, begin());}
109 // add to it
110 CARD_LIST& push_front(CARD* c) {_cl.push_front(c); return *this;}
111 CARD_LIST& push_back(CARD* c) {_cl.push_back(c); return *this;}
112 CARD_LIST& insert(CARD_LIST::iterator i, CARD* c)
113 {_cl.insert(i, c); return *this;}
115 // take things out
116 CARD_LIST& erase(iterator i);
117 CARD_LIST& erase(CARD* c);
118 CARD_LIST& erase_all();
120 // just delete...
121 CARD_LIST& remove(CARD* c);
123 // operations on the whole list
124 CARD_LIST& do_forall( void (CARD::*thing)( void ) );
125 CARD_LIST& do_forall( void (CARD::*thing)( int ), int );
126 const CARD_LIST& do_forall( void (CARD::*thing)( void ) const ) const;
127 const CARD_LIST& tr_stress_last()const;
128 CARD_LIST& stress_calc(); // calculate stress parameters
129 CARD_LIST& do_tt(); // apply stress parameters to components.
130 CARD_LIST& set_owner(CARD* owner);
131 CARD_LIST& set_origin(CARD_LIST* origin);
132 const CARD* owner()const {return _owner;}
133 CARD_LIST& set_slave();
134 CARD_LIST& precalc_first();
135 CARD_LIST& expand();
136 CARD_LIST& precalc_last();
137 CARD_LIST& map_nodes();
138 void rewire_nodenames(const CARD_LIST*); //temporary hack
139 CARD_LIST& tr_iwant_matrix();
140 CARD_LIST& tr_begin();
141 CARD_LIST& tr_restore();
142 CARD_LIST& dc_advance();
143 CARD_LIST& tr_advance();
144 CARD_LIST& tr_regress();
145 bool tr_needs_eval()const;
146 CARD_LIST& tr_queue_eval();
147 bool do_tr();
148 CARD_LIST& tr_load();
149 TIME_PAIR tr_review();
150 CARD_LIST& tr_accept();
151 CARD_LIST& tr_unload();
152 CARD_LIST& keep_ic();
153 CARD_LIST& ac_iwant_matrix();
154 CARD_LIST& ac_begin();
155 CARD_LIST& do_ac();
156 CARD_LIST& ac_load();
157 double do_noise() const;
158 CARD_LIST& do_sens();
159 CARD_LIST& tt_begin();
160 TIME_PAIR tt_review();
161 CARD_LIST& tt_accept();
162 CARD_LIST& tt_advance();
163 CARD_LIST& tt_regress();
164 CARD_LIST& tt_behaviour_commit();
166 NODE_MAP* nodes()const {assert(_nm); return _nm;}
167 NODE_BASE* node(std::string)const;
168 unsigned total_nodes()const; // recursively (for now) sum up ckt node number...
169 unsigned adp_nodes()const; // recursively (for now) sum up total adp number...
170 PARAM_LIST* params();
171 PARAM_LIST* params()const;
173 // more complex stuff
174 void attach_params(PARAM_LIST_BASE* p, const CARD_LIST* scope);
175 void shallow_copy(const CARD_LIST*);
176 void map_subckt_nodes(const CARD* model, const CARD* owner);
179 void init_node_count( unsigned* user_nodes, unsigned* subckt_nodes, unsigned*
180 _model_nodes, unsigned* _adp_nodes) const;
181 // ADP_NODE* new_adp_node(const CARD* c, string name);
183 explicit CARD_LIST(const CARD* owner=0, PARAM_LIST_MAP* p=NULL);
184 CARD_LIST(const CARD* model, CARD* owner, const CARD_LIST* scope,
185 PARAM_LIST_BASE* p);
186 ~CARD_LIST();
187 private:
188 // needed to parr to <<
189 // explicit CARD_LIST(const CARD_LIST&) {unreachable(); incomplete();}
190 public:
191 static CARD_LIST card_list; // in globals.cc
193 /*--------------------------------------------------------------------------*/
194 INTERFACE CARD_LIST::fat_iterator findbranch(CS&,CARD_LIST::fat_iterator);
195 /*--------------------------------------------------------------------------*/
196 inline CARD_LIST::fat_iterator findbranch(CS& cmd, CARD_LIST* cl)
198 assert(cl);
199 return findbranch(cmd, CARD_LIST::fat_iterator(cl, cl->begin()));
201 /*--------------------------------------------------------------------------*/
202 inline CARD_LIST::fat_iterator findbranch(const string cmd, CARD_LIST* cl = 0)
204 if (cl==0) cl = &CARD_LIST::card_list;
205 CS c(CS::_STRING,cmd);
206 return findbranch(c, CARD_LIST::fat_iterator(cl, cl->begin()));
208 /*--------------------------------------------------------------------------*/
209 /*--------------------------------------------------------------------------*/
210 #endif
211 // vim:ts=8:sw=2:noet: