46 NameRegistry::iterator ri;
47 ri = _name_registry.find(name);
49 if (ri == _name_registry.end()) {
54 if (ascii_equivalent !=
'\0') {
55 if (_handle_registry[ascii_equivalent] ==
nullptr) {
56 index = ascii_equivalent;
59 <<
"Attempt to register multiple buttons under ASCII equivalent " 60 << ascii_equivalent <<
"\n";
67 if (util_cat->is_spam()) {
69 <<
"Registering button " << name <<
"\n";
75 index = _handle_registry.size();
76 _handle_registry.push_back(
nullptr);
80 new_handle._index = index;
82 RegistryNode *rnode =
new RegistryNode(new_handle, alias, name);
83 _handle_registry[index] = rnode;
84 _name_registry[name] = rnode;
86 button_handle = new_handle;
90 RegistryNode *rnode = (*ri).second;
91 nassertr(rnode->_name == (*ri).first,
false);
92 nassertr(rnode->_handle._index >= 0 &&
93 rnode->_handle._index < (
int)_handle_registry.size(),
false);
94 nassertr(_handle_registry[rnode->_handle._index] == rnode,
false);
95 nassertr(rnode->_handle._index != 0,
false);
97 if (button_handle != rnode->_handle) {
100 <<
"Attempt to register button " << name <<
" more than once!\n";
102 button_handle = rnode->_handle;
113 NameRegistry::const_iterator ri;
114 ri = _name_registry.find(name);
116 if (ri != _name_registry.end()) {
117 return (*ri).second->_handle;
131 NameRegistry::const_iterator ri;
132 ri = _name_registry.find(name);
134 if (ri != _name_registry.end()) {
135 return (*ri).second->_handle;
138 return ButtonHandle::none();
148 if (_handle_registry[ascii_equivalent] ==
nullptr) {
149 return ButtonHandle::none();
151 return _handle_registry[ascii_equivalent]->_handle;
157 void ButtonRegistry::
158 write(std::ostream &out)
const {
159 out <<
"ASCII equivalents:\n";
160 for (
int i = 1; i < 128; i++) {
161 if (_handle_registry[i] !=
nullptr) {
163 sprintf(hex,
"%02x", (
unsigned int)i);
164 nassertv(strlen(hex) < 12);
166 out <<
" " << hex <<
" " << _handle_registry[i]->_name <<
"\n";
170 out <<
"\nOther buttons:\n";
171 NameRegistry::const_iterator ri;
172 for (ri = _name_registry.begin(); ri != _name_registry.end(); ++ri) {
173 if (!(*ri).second->_handle.has_ascii_equivalent()) {
174 out <<
" " << (*ri).second->_name;
175 if ((*ri).second->_alias != ButtonHandle::none()) {
176 out <<
" (alias " << (*ri).second->_alias <<
")";
192 _handle_registry.reserve(128);
194 for (i = 0; i < 128; i++) {
195 _handle_registry.push_back(
nullptr);
202 void ButtonRegistry::
203 init_global_pointer() {
211 ButtonRegistry::RegistryNode *ButtonRegistry::
213 nassertr(handle._index != 0,
nullptr);
215 if (handle._index < 0 ||
216 handle._index >= (
int)_handle_registry.size()) {
218 <<
"Invalid ButtonHandle index " << handle._index
219 <<
"! Is memory corrupt?\n";
223 return _handle_registry[handle._index];
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.