feisty meow concerns codebase
2.140
menu_base.cpp
Go to the documentation of this file.
1
2
3
4
//note: in progress.
5
6
/*****************************************************************************\
7
* *
8
* Name : menu_base *
9
* Author : Chris Koeritz *
10
* *
11
*******************************************************************************
12
* Copyright (c) 2003-$now By Author. This program is free software; you can *
13
* redistribute it and/or modify it under the terms of the GNU General Public *
14
* License as published by the Free Software Foundation; either version 2 of *
15
* the License or (at your option) any later version. This is online at: *
16
* http://www.fsf.org/copyleft/gpl.html *
17
* Please send any updates to: fred@gruntose.com *
18
\*****************************************************************************/
19
20
#include "
menu_base.h
"
21
22
#include <
structures/string_array.h
>
23
#include <
structures/amorph.h
>
24
25
class
menu_common_amorph :
public
amorph<menu_common_base> {};
26
28
29
menu_common_base::~menu_common_base
() {}
30
32
33
menu_item::menu_item
(
const
string_array
&trigs,
34
const
astring &text,
const
astring &description)
35
: _triggers(new
string_array
(trigs)),
36
_text(new astring(text)),
37
_description(new astring(description))
38
{}
39
40
menu_item::menu_item
(
const
menu_item
&to_copy)
41
: root_object(),
42
menu_common_base
(),
43
_triggers(new
string_array
),
44
_text(new astring),
45
_description(new astring)
46
{ *
this
= to_copy; }
47
48
menu_item::~menu_item
()
49
{
50
WHACK(_text);
51
WHACK(_description);
52
}
53
54
menu_item
&
menu_item::operator =
(
const
menu_item
&to_copy)
55
{
56
if
(
this
== &to_copy)
return
*
this
;
57
*_triggers = *to_copy._triggers;
58
*_text = *to_copy._text;
59
*_description = *to_copy._description;
60
return
*
this
;
61
}
62
63
void
menu_item::menu_activation
(
char
formal
(trigger)) {}
64
65
const
string_array
&
menu_item::triggers
()
const
{
return
*_triggers; }
66
67
const
astring &
menu_item::text
()
const
{
return
*_text; }
68
69
const
astring &
menu_item::description
()
const
{
return
*_description; }
70
72
73
//call this when menu invoked.
75
76
menu_base::menu_base
(
const
astring &title,
const
menu_item
¶meters)
77
: _title(new astring(title)),
78
_parameters(new
menu_item
(parameters)),
79
_items(new menu_common_amorph),
80
_menus(new menu_common_amorph)
81
{
82
}
83
84
menu_base::~menu_base
()
85
{
86
WHACK(_title);
87
WHACK(_menus);
88
WHACK(_items);
89
}
90
91
bool
menu_base::validate
(
bool
recursive)
92
{
93
if
(recursive){}
94
//hmmm: implement this too....
95
return
false
;
96
}
97
98
astring
menu_base::text_form
()
const
99
{
100
//hmmm: implement this too....
101
return
""
;
102
}
103
104
astring
menu_base::recursive_text_form
()
const
105
{
106
//hmmm: implement this too....
107
return
""
;
108
}
109
110
int
menu_base::items
()
const
{
return
_items->elements(); }
111
112
void
menu_base::add_item
(
menu_item
*to_invoke)
113
{
114
if
(!to_invoke)
return
;
115
*_items += to_invoke;
116
}
117
118
menu_item
*
menu_base::get_item
(
int
index)
119
{
120
bounds_return
(index, 0, _items->elements(),
NULL_POINTER
);
121
return
dynamic_cast<
menu_item
*
>
(_items->borrow(index));
122
}
123
124
bool
menu_base::zap_item
(
int
index)
125
{
126
bounds_return
(index, 0, _items->elements(),
false
);
127
_items->zap(index, index);
128
return
true
;
129
}
130
131
bool
menu_base::enable_item
(
int
index,
bool
enable)
132
{
133
bounds_return
(index, 0, _items->elements(),
false
);
134
_items->borrow(index)->enable(
enable
);
135
return
true
;
136
}
137
138
int
menu_base::submenus
()
const
{
return
_menus->elements(); }
139
140
void
menu_base::add_submenu
(
menu_base
*sub)
141
{
142
if
(!sub)
return
;
143
_menus->append(sub);
144
}
145
146
menu_base
*
menu_base::get_submenu
(
int
index)
147
{
148
bounds_return
(index, 0, _menus->elements(),
NULL_POINTER
);
149
return
dynamic_cast<
menu_base
*
>
(_menus->borrow(index));
150
}
151
152
bool
menu_base::zap_submenu
(
int
index)
153
{
154
bounds_return
(index, 0, _menus->elements(),
false
);
155
_menus->zap(index, index);
156
return
true
;
157
}
158
159
bool
menu_base::enable_submenu
(
int
index,
bool
enable)
160
{
161
bounds_return
(index, 0, _menus->elements(),
false
);
162
_menus->borrow(index)->enable(
enable
);
163
return
true
;
164
}
165
166
menu_common_base
*
menu_base::evaluate_trigger
(
char
trigger)
167
{
168
//hmmm: implement this too....
169
if
(!trigger){}
170
return
NULL_POINTER
;
171
}
172
173
void
menu_base::activate
()
174
{
175
//hmmm: implement this too....
176
}
177
178
179
180
amorph.h
menu_base
A base class for a menu-driven interface model.
Definition
menu_base.h:87
menu_base::submenus
int submenus() const
number of submenus total.
Definition
menu_base.cpp:138
menu_base::enable_item
bool enable_item(int index, bool enable=true)
enables or disabled the item at "index".
Definition
menu_base.cpp:131
menu_base::recursive_text_form
astring recursive_text_form() const
does a text_form on all menus and submenus rooted here.
Definition
menu_base.cpp:104
menu_base::zap_item
bool zap_item(int index)
removes the item at "index" if possible.
Definition
menu_base.cpp:124
menu_base::get_submenu
menu_base * get_submenu(int index)
returns the submenu stored at "index".
Definition
menu_base.cpp:146
menu_base::validate
bool validate(bool recursive=true)
checks that all of the menu_items
Definition
menu_base.cpp:91
menu_base::add_submenu
void add_submenu(menu_base *sub)
add a new submenu into "sub".
Definition
menu_base.cpp:140
menu_base::get_item
menu_item * get_item(int index)
gets the item at position "index". NULL_POINTER is returned if out of range.
Definition
menu_base.cpp:118
menu_base::zap_submenu
bool zap_submenu(int index)
removes the submenu at the "index".
Definition
menu_base.cpp:152
menu_base::menu_base
menu_base(const astring &title, const menu_item ¶meters)
virtual bool menu_item_activity() = 0;
Definition
menu_base.cpp:76
menu_base::~menu_base
virtual ~menu_base()
Definition
menu_base.cpp:84
menu_base::evaluate_trigger
menu_common_base * evaluate_trigger(char trigger)
returns the item or menu associated with the "trigger" value.
Definition
menu_base.cpp:166
menu_base::activate
virtual void activate()
runs the menu structure by requesting input from the user.
Definition
menu_base.cpp:173
menu_base::add_item
void add_item(menu_item *to_invoke)
adds a new menu_item onto this menu.
Definition
menu_base.cpp:112
menu_base::items
int items() const
returns the number of menu items stored.
Definition
menu_base.cpp:110
menu_base::enable_submenu
bool enable_submenu(int index, bool enable=true)
enables or disables the submenu at the "index".
Definition
menu_base.cpp:159
menu_base::text_form
astring text_form() const
returns a string version of all the information here.
Definition
menu_base.cpp:98
menu_common_base
a common base class for referring to menu_items or menus polymorphically.
Definition
menu_base.h:32
menu_common_base::~menu_common_base
virtual ~menu_common_base()
Definition
menu_base.cpp:29
menu_common_base::enable
void enable(bool enable=true)
Definition
menu_base.h:37
menu_item
A base class for the active items that can be stored inside a menu.
Definition
menu_base.h:49
menu_item::~menu_item
virtual ~menu_item()
Definition
menu_base.cpp:48
menu_item::text
const astring & text() const
Definition
menu_base.cpp:67
menu_item::description
const astring & description() const
Definition
menu_base.cpp:69
menu_item::triggers
const string_array & triggers() const
Definition
menu_base.cpp:65
menu_item::operator=
menu_item & operator=(const menu_item &to_copy)
Definition
menu_base.cpp:54
menu_item::menu_activation
virtual void menu_activation(char trigger)
invoked when the user chooses the menu item in question.
Definition
menu_base.cpp:63
menu_item::menu_item
menu_item(const string_array &triggers, const astring &text, const astring &description)
constructs a menu item that shows the "text" and "description".
Definition
menu_base.cpp:33
formal
#define formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
Definition
definitions.h:48
NULL_POINTER
#define NULL_POINTER
The value representing a pointer to nothing.
Definition
definitions.h:32
bounds_return
#define bounds_return(value, low, high, to_return)
Verifies that "value" is between "low" and "high", inclusive.
Definition
guards.h:48
menu_base.h
string_array.h
string_array
string_array(1, math_list))) const char *addr_list[]
graphiq
library
user_interface
menu_base.cpp
Generated by
1.9.8