File: cmdargs.h

package info (click to toggle)
kcemu 0.5.2%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 13,004 kB
  • sloc: cpp: 48,526; ansic: 27,053; makefile: 1,731; sh: 1,340; asm: 376; yacc: 291; xml: 64; sed: 16
file content (169 lines) | stat: -rw-r--r-- 4,331 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 *  KCemu -- The emulator for the KC85 homecomputer series and much more.
 *  Copyright (C) 1997-2010 Torsten Paul
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __cmd_cmdargs_h
#define __cmd_cmdargs_h

#include <list>

class CMD_Change_Listener
{
 public:
  CMD_Change_Listener(void) {}
  virtual ~CMD_Change_Listener(void) {}

  virtual void cmd_args_changed(void) = 0;
};

typedef unsigned int CMD_Context;

typedef enum {
  CMD_ARG_LONG, CMD_ARG_STRING,
} CMD_Arg_Type;

class CMD;
class CMD_Args;

class CMD_ListEntry
{
 private:
  CMD *_cmd;
  CMD_Context _context;
  char *_name;

 public:
  CMD_ListEntry(CMD *cmd, CMD_Context context, const char *name = 0);
  virtual ~CMD_ListEntry(void);
  
  CMD * get_cmd(void);
  CMD_Context get_context(void);
  const char * get_name(void);
};

class CMD_List
{
 private:
  typedef std::list<CMD_ListEntry *>cmd_list_t;
  
 public:
  typedef cmd_list_t::iterator iterator;

 private:
  char *_name;
  cmd_list_t *_cmd_list;

 public:
  CMD_List(const char *name);
  virtual ~CMD_List(void);
  
  virtual const char * get_name();
  virtual void add_cmd(CMD *cmd, CMD_Context context);
  virtual void remove_cmd(CMD *cmd, CMD_Context context);
  virtual void execute(CMD_Args *args = 0);

  virtual void dump(void);
};

class CMD_Arg
{
 protected:
  char *_name;
  CMD_Arg_Type _type;
  union {
    long  v_long;
    char *v_string;
  } _val;
  bool _value_set;

 public:
  CMD_Arg(const char *name, CMD_Arg_Type type);
  virtual ~CMD_Arg(void);

  CMD_Arg_Type get_type(void);
  const char * get_name(void);
  virtual void set_long_arg(long value);
  virtual void set_string_arg(const char *value);
  virtual void set_pointer_arg(void *ptr);
  virtual long get_long_arg(void);
  virtual const char * get_string_arg(void);
  virtual void * get_pointer_arg(void);
};

class CMD_Args {
 private:
  typedef std::list<CMD_Arg *> arg_list_t;
  typedef std::list<CMD_Change_Listener *> cl_list_t;
  typedef std::list<CMD_ListEntry *> cb_list_t;
  
 public:
  typedef cl_list_t::iterator cl_iterator;
  typedef cb_list_t::iterator cb_iterator;
  typedef arg_list_t::iterator arg_iterator;

 private:
  void *_user_data;
  cl_list_t _cl_list;
  cb_list_t _cb_list;
  arg_list_t _arg_list;

 public:
  CMD_Args(void);
  virtual ~CMD_Args(void);

 protected:
  virtual void notify_change_listeners(void);

 public:
  CMD_Arg * lookup(const char *name);
  virtual CMD_Args * set_long_arg(const char *name, long value);
  virtual CMD_Args * set_string_arg(const char *name, const char *value);
  virtual CMD_Args * set_pointer_arg(const char *name, void *value);
  virtual CMD_Args * add_change_listener(CMD_Change_Listener *listener);
  virtual long get_long_arg(const char *name);
  virtual const char * get_string_arg(const char *name);
  virtual void * get_pointer_arg(const char *name);
  virtual bool has_arg(const char *name);
  virtual void add_callback(const char *name,
                            CMD *cmd,
                            CMD_Context context);
  virtual void remove_callback(const char *name,
                               CMD *cmd,
                               CMD_Context context);
  virtual void call_callbacks(const char *name);

  virtual void set_user_data(void *data);
  virtual void * get_user_data(void);

  virtual void dump(const char *text);
};

class CMD_Caller
{
 private:
  CMD_Args *_args;
  
 public:
  CMD_Caller(CMD_Args *args = 0) { _args = args; }
  virtual ~CMD_Caller(void) {}
  
  virtual CMD_Args * cmd_caller_get_args(void) { return _args; }
  virtual void cmd_caller_set_args(CMD_Args *args) { _args = args; }
};

#endif /* __cmd_cmdargs_h */