c2b30692076491cb603525c0d6ae0af0991df105
[fw/sdcc] / 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, char *aname, 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 *con) {}
83
84   virtual void get_value(bool *val);
85   virtual void get_value(char **val);
86   virtual union option_value *get_value(void) { return(&value); }
87   virtual void set_value(bool);
88   virtual void set_value(char *s);
89
90   virtual void new_reference(class cl_optref *ref);
91   virtual void del_reference(class cl_optref *ref);
92   virtual void inform_users(void);
93 };
94
95
96 class cl_options: public cl_sorted_list
97 {
98 public:
99   cl_options(void): cl_sorted_list(2, 2) { Duplicates= DD_TRUE; }
100   virtual void *key_of(void *item);
101   virtual int compare(void *key1, void *key2);
102   virtual void new_option(class cl_option *opt);
103   virtual void del_option(class cl_option *opt);
104   virtual class cl_option *get_option(char *the_name);
105   virtual class cl_option *get_option(char *the_name, class cl_base *creator);
106   virtual class cl_option *get_option(char *the_name, char *creator);
107   virtual class cl_option *get_option(int idx);
108   virtual int nuof_options(char *the_name);
109   virtual int nuof_options(char *the_name, char *creator);
110
111   virtual class cl_option *set_value(char *the_name, cl_base *creator,
112                                      bool value);
113   virtual class cl_option *set_value(char *the_name, cl_base *creator,
114                                      char *value);
115 };
116
117
118 class cl_optref: public cl_base
119 {
120 protected:
121   class cl_option *option;
122   class cl_base *owner;
123 public:
124   cl_optref(class cl_base *the_owner);
125   cl_optref(class cl_base *the_owner, class cl_option *new_option);
126   virtual ~cl_optref(void);
127
128   virtual class cl_option *create(class cl_base *creator,
129                                   enum option_type type,
130                                   char *the_name, char *help);
131   virtual void default_option(char *the_name);
132   virtual class cl_option *use(void);
133   virtual class cl_option *use(char *the_name);
134   virtual void option_changed(void) {}
135   virtual void option_removing(void);
136   virtual class cl_base *get_owner(void) { return(owner); }
137
138   virtual bool get_value(bool);
139   virtual char *get_value(char *);
140 };
141
142
143 class cl_bool_option: public cl_option
144 {
145 public:
146   cl_bool_option(class cl_base *the_creator, char *aname, char *Ihelp);
147
148   virtual void print(class cl_console *con);
149   //virtual void get_value(bool *val);
150   //virtual void set_value(bool);
151   virtual void set_value(char *s);
152 };
153
154
155 class cl_string_option: public cl_option
156 {
157 public:
158   cl_string_option(class cl_base *the_creator, char *aname, char *Ihelp);
159   virtual class cl_option &operator=(class cl_option &o);
160
161   virtual void print(class cl_console *con);
162   //virtual void get_value(char *val);
163   //virtual void set_value(char *opt);
164 };
165
166
167 class cl_cons_debug_opt: public cl_option
168 {
169 public:
170   class cl_app *app;
171 public:
172   cl_cons_debug_opt(class cl_app *the_app, char *Iid, char *Ihelp);
173
174   virtual void print(class cl_console *con);
175
176   virtual void get_value(bool *val);
177
178   virtual void set_value(bool);
179   virtual void set_value(char *s);
180 };
181
182
183 #endif
184
185 /* End of optioncl.h */