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 
23 #include <structures/amorph.h>
24 
25 class menu_common_amorph : public amorph<menu_common_base> {};
26 
28 
30 
32 
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 
41 : root_object(),
43  _triggers(new string_array),
44  _text(new astring),
45  _description(new astring)
46 { *this = to_copy; }
47 
49 {
50  WHACK(_text);
51  WHACK(_description);
52 }
53 
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 &parameters)
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 
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 
105 {
106 //hmmm: implement this too....
107 return "";
108 }
109 
110 int menu_base::items() const { return _items->elements(); }
111 
113 {
114  if (!to_invoke) return;
115  *_items += to_invoke;
116 }
117 
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 
141 {
142  if (!sub) return;
143  _menus->append(sub);
144 }
145 
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 
167 {
168 //hmmm: implement this too....
169 if (!trigger){}
170 return NULL_POINTER;
171 }
172 
174 {
175 //hmmm: implement this too....
176 }
177 
178 
179 
180 
A base class for a menu-driven interface model.
Definition: menu_base.h:87
int submenus() const
number of submenus total.
Definition: menu_base.cpp:138
bool enable_item(int index, bool enable=true)
enables or disabled the item at "index".
Definition: menu_base.cpp:131
astring recursive_text_form() const
does a text_form on all menus and submenus rooted here.
Definition: menu_base.cpp:104
bool zap_item(int index)
removes the item at "index" if possible.
Definition: menu_base.cpp:124
menu_base * get_submenu(int index)
returns the submenu stored at "index".
Definition: menu_base.cpp:146
bool validate(bool recursive=true)
checks that all of the menu_items
Definition: menu_base.cpp:91
void add_submenu(menu_base *sub)
add a new submenu into "sub".
Definition: menu_base.cpp:140
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
bool zap_submenu(int index)
removes the submenu at the "index".
Definition: menu_base.cpp:152
menu_base(const astring &title, const menu_item &parameters)
virtual bool menu_item_activity() = 0;
Definition: menu_base.cpp:76
virtual ~menu_base()
Definition: menu_base.cpp:84
menu_common_base * evaluate_trigger(char trigger)
returns the item or menu associated with the "trigger" value.
Definition: menu_base.cpp:166
virtual void activate()
runs the menu structure by requesting input from the user.
Definition: menu_base.cpp:173
void add_item(menu_item *to_invoke)
adds a new menu_item onto this menu.
Definition: menu_base.cpp:112
int items() const
returns the number of menu items stored.
Definition: menu_base.cpp:110
bool enable_submenu(int index, bool enable=true)
enables or disables the submenu at the "index".
Definition: menu_base.cpp:159
astring text_form() const
returns a string version of all the information here.
Definition: menu_base.cpp:98
a common base class for referring to menu_items or menus polymorphically.
Definition: menu_base.h:32
virtual ~menu_common_base()
Definition: menu_base.cpp:29
void enable(bool enable=true)
Definition: menu_base.h:37
A base class for the active items that can be stored inside a menu.
Definition: menu_base.h:49
virtual ~menu_item()
Definition: menu_base.cpp:48
const astring & text() const
Definition: menu_base.cpp:67
const astring & description() const
Definition: menu_base.cpp:69
const string_array & triggers() const
Definition: menu_base.cpp:65
menu_item & operator=(const menu_item &to_copy)
Definition: menu_base.cpp:54
virtual void menu_activation(char trigger)
invoked when the user chooses the menu item in question.
Definition: menu_base.cpp:63
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
#define formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
Definition: definitions.h:48
#define NULL_POINTER
The value representing a pointer to nothing.
Definition: definitions.h:32
#define bounds_return(value, low, high, to_return)
Verifies that "value" is between "low" and "high", inclusive.
Definition: guards.h:48
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
Definition: functions.h:121
string_array(1, math_list))) const char *addr_list[]