1 /*
2  * Simulator of microcontrollers (pobjcl.h)
3  *
4  * Copyright (C) 1997,16 Drotos Daniel, Talker Bt.
5  *
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9 
10 /* This file is part of microcontroller simulator: ucsim.
11 
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16 
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27 
28 #ifndef POBJ_HEADER
29 #define POBJ_HEADER
30 
31 #include "ddconfig.h"
32 
33 #include "pobjt.h"
34 
35 #include "eventcl.h"
36 #include "charscl.h"
37 
38 
39 /*									    #
40   ==========================================================================#
41 								    cl_base #
42   ==========================================================================#
43 									    #
44 */
45 
46 class cl_abs_base
47 {
48 };
49 
50 class cl_list;
51 class cl_event;
52 
53 class cl_base: public cl_abs_base
54 {
55 private:
56   /*const char * */chars name;
57   class cl_base *parent;
58   class cl_list *children;
59 public:
60   cl_base(void);
61   virtual ~cl_base(void);
62 
63   virtual int init(void);
get_name(void)64   virtual const char *get_name(void) { return(name); }
65   virtual const char *get_name(const char *def);
have_name(void)66   virtual bool have_name(void) { return/*(name != 0)*/ !name.is_null(); }
have_real_name(void)67   virtual bool have_real_name(void) { return/*(name != 0 && *name != '\0')*/ !name.empty(); }
68   const char *set_name(const char *new_name);
69   const char *set_name(const char *new_name, const char *def_name);
70   bool is_named(const char *the_name);
71   bool is_inamed(const char *the_name);
72 
get_parent(void)73   class cl_base *get_parent(void) { return(parent); }
74   int nuof_children(void);
75 
76   virtual void add_child(class cl_base *child);
77   virtual void remove_child(class cl_base *child);
78   virtual void remove_from_chain(void);
79   virtual void unlink(void);
80   virtual class cl_base *first_child(void);
81   virtual class cl_base *next_child(class cl_base *child);
82 
83   virtual bool handle_event(class cl_event &event);
84   virtual bool pass_event_down(class cl_event &event);
85 };
86 
87 
88 /*
89  * Event
90  */
91 
92 class cl_event: public cl_base
93 {
94 protected:
95   bool handled;
96 public:
97   enum event what;
98 public:
99   cl_event(enum event what_event);
100   virtual ~cl_event(void);
101 
is_handled(void)102   bool is_handled(void) { return(handled); }
handle(void)103   virtual void handle(void) { handled= true; }
104 };
105 
106 
107 /*									    #
108   ==========================================================================#
109 								    cl_list #
110   ==========================================================================#
111 									    #
112 */
113 
114 class cl_list: public cl_base
115 {
116 public:
117   t_index	   count;
118 protected:
119   void		   **Items;
120   t_index	   Limit;
121   t_index	   Delta;
122 
123 public:
124   cl_list(t_index alimit, t_index adelta, char *aname);
125   cl_list(t_index alimit, t_index adelta, const char *aname);
126   virtual ~cl_list(void);
127 
at(t_index index)128   inline  void	   *at(t_index index)
129   {
130     if (index < 0 || index >= count)
131       error(1, index);
132     return (Items[index]);
133   }
134   class cl_base *object_at(t_index index);
135   virtual t_index  index_of(void *item);
136   virtual bool     index_of(void *item, t_index *idx);
137   virtual void     *next(void *item);
138   	  int	   get_count(void);
139   virtual void     *pop(void);
140   virtual void     *top(void);
141 
142   //void	   pack(void);
143   virtual void	   set_limit(t_index alimit);
144 
145 	  void	   free_at(t_index index);
146           void     free_all(void);
147 	  void	   disconn_at(t_index index);
148 	  void	   disconn(void *item);
149 	  void	   disconn_all(void);
150 
151 	  void	   add_at(t_index index, void *item);
152 	  void	   put_at(t_index index, void *item);
153   virtual t_index  add(void *item);
154   virtual t_index  add(class cl_base *item, class cl_base *parent);
155   virtual void     push(void *item);
156 
157 	  void	   *first_that(match_func test, void *arg);
158 	  void	   *last_that(match_func test, void *arg);
159 	  void	   for_each(iterator_func action, void *arg);
160 
161 	  void	   error(t_index code, t_index info);
162 private:
163   virtual void	   free_item(void *item);
164 };
165 
166 
167 /*									    #
168   ==========================================================================#
169 							     cl_sorted_list #
170   ==========================================================================#
171 									    #
172 */
173 
174 class cl_sorted_list: public cl_list
175 {
176 public:
177   bool		   Duplicates;
178 public:
179   cl_sorted_list(t_index alimit, t_index adelta, char *aname);
180   cl_sorted_list(t_index alimit, t_index adelta, const char *aname);
181   virtual ~cl_sorted_list(void);
182 
183   virtual bool	   search(void *key, t_index& index);
184   virtual t_index  index_of(void *item);
185   virtual t_index  add(void *item);
186   virtual void	   *key_of(void *item);
187 private:
188   virtual int	   compare(void *key1, void *key2)= 0;
189 };
190 
191 
192 /*									    #
193   ==========================================================================#
194 							         cl_strings #
195   ==========================================================================#
196 									    #
197 */
198 
199 class cl_strings: public cl_sorted_list
200 {
201 public:
202   cl_strings(t_index alimit, t_index adelta, char *aname);
203   cl_strings(t_index alimit, t_index adelta, const char *aname);
204   virtual ~cl_strings(void);
205 
206 private:
207   virtual int	   compare(void *key1, void *key2);
208   virtual void	   free_item(void *item);
209 };
210 
211 
212 /*									    #
213   ==========================================================================#
214 							        cl_ustrings #
215   ==========================================================================#
216 									    #
217 */
218 
219 class cl_ustrings: public cl_strings
220 {
221 public:
222   cl_ustrings(t_index alimit, t_index adelta, char *aname);
223   cl_ustrings(t_index alimit, t_index adelta, const char *aname);
224   virtual ~cl_ustrings(void);
225 
226 private:
227   virtual int	   compare(void *key1, void *key2);
228   virtual bool	   search(void *key, t_index &index);
229 };
230 
231 
232 #endif
233 
234 /* End of pobj.h */
235