15 #include "buttonRegistry.h" 16 #include "config_util.h" 52 NameRegistry::iterator ri;
53 ri = _name_registry.find(name);
55 if (ri == _name_registry.end()) {
60 if (ascii_equivalent !=
'\0') {
61 if (_handle_registry[ascii_equivalent] == (RegistryNode *)NULL) {
62 index = ascii_equivalent;
65 <<
"Attempt to register multiple buttons under ASCII equivalent " 66 << ascii_equivalent <<
"\n";
73 if (util_cat->is_spam()) {
75 <<
"Registering button " << name <<
"\n";
81 index = _handle_registry.size();
82 _handle_registry.push_back(NULL);
86 new_handle._index = index;
88 RegistryNode *rnode =
new RegistryNode(new_handle, alias, name);
89 _handle_registry[index] = rnode;
90 _name_registry[name] = rnode;
92 button_handle = new_handle;
96 RegistryNode *rnode = (*ri).second;
97 nassertr(rnode->_name == (*ri).first,
false);
98 nassertr(rnode->_handle._index >= 0 &&
99 rnode->_handle._index < (
int)_handle_registry.size(),
false);
100 nassertr(_handle_registry[rnode->_handle._index] == rnode,
false);
101 nassertr(rnode->_handle._index != 0,
false);
103 if (button_handle != rnode->_handle) {
106 <<
"Attempt to register button " << name <<
" more than once!\n";
108 button_handle = rnode->_handle;
122 NameRegistry::const_iterator ri;
123 ri = _name_registry.find(name);
125 if (ri != _name_registry.end()) {
126 return (*ri).second->_handle;
143 NameRegistry::const_iterator ri;
144 ri = _name_registry.find(name);
146 if (ri != _name_registry.end()) {
147 return (*ri).second->_handle;
162 if (_handle_registry[ascii_equivalent] == (RegistryNode *)NULL) {
165 return _handle_registry[ascii_equivalent]->_handle;
173 void ButtonRegistry::
174 write(ostream &out)
const {
175 out <<
"ASCII equivalents:\n";
176 for (
int i = 1; i < 128; i++) {
177 if (_handle_registry[i] != (RegistryNode *)NULL) {
179 sprintf(hex,
"%02x", (
unsigned int)i);
180 nassertv(strlen(hex) < 12);
182 out <<
" " << hex <<
" " << _handle_registry[i]->_name <<
"\n";
186 out <<
"\nOther buttons:\n";
187 NameRegistry::const_iterator ri;
188 for (ri = _name_registry.begin(); ri != _name_registry.end(); ++ri) {
189 if (!(*ri).second->_handle.has_ascii_equivalent()) {
190 out <<
" " << (*ri).second->_name;
192 out <<
" (alias " << (*ri).second->_alias <<
")";
211 _handle_registry.reserve(128);
213 for (i = 0; i < 128; i++) {
214 _handle_registry.push_back(NULL);
224 void ButtonRegistry::
225 init_global_pointer() {
235 ButtonRegistry::RegistryNode *ButtonRegistry::
237 nassertr(handle._index != 0, NULL);
239 if (handle._index < 0 ||
240 handle._index >= (
int)_handle_registry.size()) {
242 <<
"Invalid ButtonHandle index " << handle._index
243 <<
"! Is memory corrupt?\n";
244 return (RegistryNode *)NULL;
247 return _handle_registry[handle._index];