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