Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / optioncl.h
1 /*
2  * Simulator of microcontrollers (sim.src/optioncl.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 /* 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 SIM_OPTIONCL_HEADER
29 #define SIM_OPTIONCL_HEADER
30
31 #include "ddconfig.h"
32
33 #include <stdio.h>
34
35 #include "pobjcl.h"
36 #include "stypes.h"
37   
38
39 enum option_type {
40   non_opt,
41   integer_opt,
42   float_opt,
43   bool_opt,
44   string_opt,
45   pointer_opt
46 };
47
48 // forward
49 class cl_optref;
50
51 union option_value {
52   long ival;
53   double fval;
54   bool bval;
55   char *sval;
56   void *pval;
57 };
58
59 class cl_option: public cl_base
60 {
61 protected:
62   //enum opt_type type;
63   void *option;
64   union option_value value;
65   class cl_base *creator;
66 public:
67   class cl_list *users; // cl_optref
68   //char *name;
69   char *help;
70   bool hidden;
71
72 public:
73   cl_option(class cl_base *the_creator, const char *aname, const char *Ihelp);
74   virtual class cl_option &operator=(class cl_option &o);
75   virtual ~cl_option(void);
76   virtual void pre_remove(void);
77
78   virtual class cl_base *get_creator(void) { return(creator); }
79   virtual void hide(void) { hidden= DD_TRUE; }
80   virtual void show(void) { hidden= DD_FALSE; }
81
82   virtual void print(class cl_console_base *con) {}
83   virtual const char *get_type_name(void) { return("non"); }
84
85   virtual union option_value *get_value(void) { return(&value); }
86   virtual void get_value(bool *val);
87   virtual void get_value(char **val);
88   virtual void get_value(void **val);
89   virtual void get_value(long *val);
90   virtual void get_value(double *val);
91   virtual void set_value(bool opt);
92   virtual void set_value(char *opt);
93   virtual void set_value(void *opt);
94   virtual void set_value(long opt);
95   virtual void set_value(double opt);
96
97   virtual void new_reference(class cl_optref *ref);
98   virtual void del_reference(class cl_optref *ref);
99   virtual void inform_users(void);
100 };
101
102
103 class cl_options: public cl_sorted_list
104 {
105 public:
106   cl_options(void): cl_sorted_list(2, 2, "options") { Duplicates= DD_TRUE; }
107   virtual const void *key_of(void *item);
108   virtual int compare(const void *key1, const void *key2);
109   virtual void new_option(class cl_option *opt);
110   virtual void del_option(class cl_option *opt);
111   virtual class cl_option *get_option(const char *the_name);
112   virtual class cl_option *get_option(const char *the_name, class cl_base *creator);
113   virtual class cl_option *get_option(const char *the_name, char *creator);
114   virtual class cl_option *get_option(int idx);
115   virtual int nuof_options(char *the_name);
116   virtual int nuof_options(char *the_name, char *creator);
117
118   virtual class cl_option *set_value(const char *the_name, cl_base *creator,
119                                      bool value);
120   virtual class cl_option *set_value(const char *the_name, cl_base *creator,
121                                      char *value);
122   virtual class cl_option *set_value(const char *the_name, cl_base *creator,
123                                      void *value);
124   virtual class cl_option *set_value(const char *the_name, cl_base *creator,
125                                      long value);
126   virtual class cl_option *set_value(const char *the_name, cl_base *creator,
127                                      double value);
128 };
129
130
131 class cl_optref: public cl_base
132 {
133 protected:
134   class cl_option *option;
135   class cl_base *owner;
136 public:
137   cl_optref(class cl_base *the_owner);
138   cl_optref(class cl_base *the_owner, class cl_option *new_option);
139   virtual ~cl_optref(void);
140
141   virtual class cl_option *create(class cl_base *creator,
142                                   enum option_type type,
143                                   const char *the_name, const char *help);
144   virtual void default_option(const char *the_name);
145   virtual class cl_option *use(void);
146   virtual class cl_option *use(const char *the_name);
147   virtual void option_changed(void) {}
148   virtual void option_removing(void);
149   virtual class cl_base *get_owner(void) { return(owner); }
150
151   virtual bool get_value(bool);
152   virtual char *get_value(const char *);
153   virtual void *get_value(void *);
154   virtual long get_value(long);
155   virtual double get_value(double);
156 };
157
158
159 class cl_bool_option: public cl_option
160 {
161 public:
162   cl_bool_option(class cl_base *the_creator, const char *aname, const char *Ihelp);
163   virtual void print(class cl_console_base *con);
164   virtual const char *get_type_name(void) { return("boolean"); }
165   virtual void set_value(char *s);
166 };
167
168
169 class cl_string_option: public cl_option
170 {
171 public:
172   cl_string_option(class cl_base *the_creator, const char *aname, const char *Ihelp);
173   virtual class cl_option &operator=(class cl_option &o);
174   virtual void print(class cl_console_base *con);
175   virtual const char *get_type_name(void) { return("string"); }
176 };
177
178
179 class cl_pointer_option: public cl_option
180 {
181 public:
182   cl_pointer_option(class cl_base *the_creator, const char *aname, const char *Ihelp);
183   virtual class cl_option &operator=(class cl_option &o);
184   virtual void print(class cl_console_base *con);
185   virtual const char *get_type_name(void) { return("pointer"); }
186 };
187
188
189 class cl_number_option: public cl_option
190 {
191 public:
192   cl_number_option(class cl_base *the_creator, const char *aname, const char *Ihelp);
193   virtual void print(class cl_console_base *con);
194   virtual const char *get_type_name(void) { return("integer"); }
195   virtual void set_value(char *s);
196 };
197
198
199 class cl_float_option: public cl_option
200 {
201 public:
202   cl_float_option(class cl_base *the_creator, const char *aname, const char *Ihelp);
203   virtual void print(class cl_console_base *con);
204   virtual const char *get_type_name(void) { return("float"); }
205   virtual void set_value(char *s);
206 };
207
208
209 /*class cl_cons_debug_opt: public cl_option
210 {
211 public:
212   class cl_app *app;
213 public:
214   cl_cons_debug_opt(class cl_app *the_app, char *Iid, char *Ihelp);
215
216   virtual void print(class cl_console_base *con);
217
218   virtual void get_value(bool *val);
219
220   virtual void set_value(bool);
221   virtual void set_value(char *s);
222 };*/
223
224
225 #endif
226
227 /* End of optioncl.h */