1 /*$Id: e_cardlist.h,v 26.138 2013/04/24 02:32:27 al Exp $ -*- C++ -*-
2  * Copyright (C) 2001 Albert Davis
3  * Author: Albert Davis <aldavis@gnu.org>
4  *
5  * This file is part of "Gnucap", the Gnu Circuit Analysis Package
6  *
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)
10  * any later version.
11  *
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.
16  *
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
20  * 02110-1301, USA.
21  *------------------------------------------------------------------
22  * "card" container -- list of circuit elements
23  */
24 //testing=script,complete 2006.07.11
25 #ifndef E_CARDLIST_H
26 #define E_CARDLIST_H
27 #include "md.h"
28 /*--------------------------------------------------------------------------*/
29 // defined here
30 class CARD_LIST;
31 /*--------------------------------------------------------------------------*/
32 // external
33 class CARD;
34 class PARAM_LIST;
35 class NODE_MAP;
36 class LANGUAGE;
37 class TIME_PAIR;
38 /*--------------------------------------------------------------------------*/
39 class INTERFACE CARD_LIST {
40 private:
41   const CARD_LIST* _parent;
42   mutable NODE_MAP* _nm;
43   mutable PARAM_LIST* _params;
44   std::list<CARD*> _cl;
45 public:
46   // internal types
47   typedef std::list<CARD*>::iterator iterator;
48   typedef std::list<CARD*>::const_iterator const_iterator;
49   class fat_iterator {
50   private:
51     CARD_LIST* _list;
52     iterator   _iter;
53   private:
fat_iterator()54     explicit	  fat_iterator()	{unreachable();}
55   public:
fat_iterator(const fat_iterator & p)56 		  fat_iterator(const fat_iterator& p)
57 			: _list(p._list), _iter(p._iter) {}
fat_iterator(CARD_LIST * l,iterator i)58     explicit	  fat_iterator(CARD_LIST* l, iterator i)
59 			: _list(l), _iter(i) {}
is_end()60     bool	  is_end()const		{return _iter == _list->end();}
61     CARD*	  operator*()		{return (is_end()) ? NULL : *_iter;}
62     fat_iterator& operator++()	{assert(!is_end()); ++_iter; return *this;}
63     fat_iterator  operator++(int)
64 		{assert(!is_end()); fat_iterator t(*this); ++_iter; return t;}
65     bool	  operator==(const fat_iterator& x)const
66     	     {unreachable(); assert(_list==x._list); return (_iter==x._iter);}
67     bool	  operator!=(const fat_iterator& x)const
68 			{assert(_list==x._list); return (_iter!=x._iter);}
iter()69     iterator	  iter()const		{return _iter;}
list()70     CARD_LIST*	  list()const		{return _list;}
end()71     fat_iterator  end()const	{return fat_iterator(_list, _list->end());}
72 
insert(CARD * c)73     void	  insert(CARD* c)	{list()->insert(iter(),c);}
74   };
75 
76   // status queries
is_empty()77   bool is_empty()const			{return _cl.empty();}
parent()78   const CARD_LIST* parent()const	{return _parent;}
79 
80   // return an iterator
begin()81   iterator begin()			{return _cl.begin();}
end()82   iterator end()			{return _cl.end();}
83   iterator find_again(const std::string& short_name, iterator);
find_(const std::string & short_name)84   iterator find_(const std::string& short_name)
85 					{return find_again(short_name, begin());}
86 
87   // return a const_iterator
begin()88   const_iterator begin()const		{return _cl.begin();}
end()89   const_iterator end()const		{return _cl.end();}
90   const_iterator find_again(const std::string& short_name, const_iterator)const;
find_(const std::string & short_name)91   const_iterator find_(const std::string& short_name)const
92 					{return find_again(short_name, begin());}
93 
94   // add to it
push_front(CARD * c)95   CARD_LIST& push_front(CARD* c)	{_cl.push_front(c); return *this;}
push_back(CARD * c)96   CARD_LIST& push_back(CARD* c)		{_cl.push_back(c);  return *this;}
insert(CARD_LIST::iterator i,CARD * c)97   CARD_LIST& insert(CARD_LIST::iterator i, CARD* c)
98 					{_cl.insert(i, c);  return *this;}
99 
100   // take things out
101   CARD_LIST& erase(iterator i);
102   CARD_LIST& erase(CARD* c);
103   CARD_LIST& erase_all();
104 
105   // operations on the whole list
106   CARD_LIST& set_owner(CARD* owner);
107   CARD_LIST& set_slave();
108   CARD_LIST& precalc_first();
109   CARD_LIST& expand();
110   CARD_LIST& precalc_last();
111   CARD_LIST& map_nodes();
112   CARD_LIST& tr_iwant_matrix();
113   CARD_LIST& tr_begin();
114   CARD_LIST& tr_restore();
115   CARD_LIST& dc_advance();
116   CARD_LIST& tr_advance();
117   CARD_LIST& tr_regress();
118   bool	     tr_needs_eval()const;
119   CARD_LIST& tr_queue_eval();
120   bool	     do_tr();
121   CARD_LIST& tr_load();
122   TIME_PAIR  tr_review();
123   CARD_LIST& tr_accept();
124   CARD_LIST& tr_unload();
125   CARD_LIST& ac_iwant_matrix();
126   CARD_LIST& ac_begin();
127   CARD_LIST& do_ac();
128   CARD_LIST& ac_load();
129 
nodes()130   NODE_MAP*   nodes()const {assert(_nm); return _nm;}
131   PARAM_LIST* params();
132   PARAM_LIST* params()const;
133 
134   // more complex stuff
135   void attach_params(PARAM_LIST* p, const CARD_LIST* scope);
136   void shallow_copy(const CARD_LIST*);
137   void map_subckt_nodes(const CARD* model, const CARD* owner);
138 
139   explicit CARD_LIST();
140   CARD_LIST(const CARD* model, CARD* owner, const CARD_LIST* scope,
141   	    PARAM_LIST* p);
142   ~CARD_LIST();
143 private:
CARD_LIST(const CARD_LIST &)144   explicit CARD_LIST(const CARD_LIST&) {unreachable(); incomplete();}
145 public:
146   static CARD_LIST card_list; // in globals.cc
147 };
148 /*--------------------------------------------------------------------------*/
149 INTERFACE CARD_LIST::fat_iterator findbranch(CS&,CARD_LIST::fat_iterator);
150 /*--------------------------------------------------------------------------*/
findbranch(CS & cmd,CARD_LIST * cl)151 inline CARD_LIST::fat_iterator findbranch(CS& cmd, CARD_LIST* cl)
152 {
153   assert(cl);
154   return findbranch(cmd, CARD_LIST::fat_iterator(cl, cl->begin()));
155 }
156 /*--------------------------------------------------------------------------*/
157 /*--------------------------------------------------------------------------*/
158 #endif
159