/** *** \brief Stores a value in the dictionary with the specified key, maintaining the *** keys in alphabetical order. *** *** If a value with that key already exists in the *** dictionary, it will be replaced with the new value *** \note This is a potential memory leak! **/ bool Dict_putSorted(Dict *d, const char *key, void *value) { bool retVal = false; bool added = false; size_t idx = 0; Pair *p = NULL; Pair *pp = NULL; size_t ii; if (keyToIndex(d, key, &idx)) { p = (Pair *)List_get((List *)d, idx); p->value = value; retVal = true; } else { p = new_Pair(key, value); added = false; if (List_length((List *)d) > 0) { for (ii = 0; ii < List_length((List *)d); ++ii) { pp = (Pair *)List_get((List *)d, ii); if (strcmp(key, pp->key) < 0) { List_insert((List *)d, ii, p); added = true; break; } } } if (!added) retVal = List_append((List *)d, p); } Logging_tracef("++++ Added pointer 0x%x to Dict 0x%x", (unsigned int)value, (unsigned int)d); return retVal; }
BellServer::BellServer(uint32 keyMaster, uint32 *keyVersions, uint8 keyMax) { keyMaster_ = keyMaster; keyVersions_ = keyVersions; keyMax_ = keyMax; printf("BellServer with master key: %08X\n", keyMaster); // Build all keys for all clients for(uint8 i = 0; i < keyMax_; i++) { uint32 clientKey = indexToKey(i); uint32 clientIndex = keyToIndex(clientKey, i); printf("Client %i (version: %i) with key %08X, decrypted key: %i\n", i, getKeyVersion(i), clientKey, clientIndex); if(clientIndex != i) { printf("There is an error in the key algorithm, EXIT!"); exit(1); } // Add it to the list clientBells_[clientKey][0] = NULL; } }
void *Dict_get(Dict *d, const char *key) { void *retVal = NULL; size_t idx = 0; if (keyToIndex(d, key, &idx)) { retVal = ((Pair *)List_get((List *)d, idx))->value; } return retVal; }
bool Dict_remove(Dict *d, const char *key, bool freeData) { bool retVal = false; size_t idx = 0; Pair *p = NULL; if (keyToIndex(d, key, &idx)) { p = (Pair *)List_get((List *)d, idx); if(freeData) mu_free(p->value); mu_free(p->key); retVal = List_remove((List *)d, idx, true); } return retVal; }
/** *** \brief Stores a value in the dictionary with the specified key. *** *** If a value with that key already exists in the dictionary, it will be *** replaced with the new value. *** \note This is a potential memory leak! **/ bool Dict_put(Dict *d, const char *key, void *value) { bool retVal = false; size_t idx = 0; Pair *p = NULL; if(keyToIndex(d, key, &idx)){ p = (Pair *)List_get((List *)d, idx); p->value = value; retVal = true; } else{ p = new_Pair(key, value); retVal = List_append((List *)d, p); } Logging_tracef("++++ Added pointer 0x%x to Dict 0x%x", (unsigned int)value, (unsigned int)d); return retVal; }
//--------------------------------------------------------- // itemDoubleClicked(QListViewItem* item) //! Sets lmaster in edit mode, and opens editor for selected value //--------------------------------------------------------- void LMaster::itemDoubleClicked(QTreeWidgetItem* i) { emit seekTo(((LMasterLViewItem*) i)->tick()); QFontMetrics fm(font()); int fnt_w = fm.width('0'); if (!editedItem && editorColumn == LMASTER_VAL_COL) { editedItem = (LMasterLViewItem*) i; QRect itemRect = view->visualItemRect(editedItem); int x1 = view->columnWidth(LMASTER_BEAT_COL) + view->columnWidth(LMASTER_TIME_COL) + view->columnWidth(LMASTER_TYPE_COL); itemRect.setX(x1); //Qt makes crazy things with itemRect if this is called directly.. if (editingNewItem) { int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth,0 , this); // ddskrjo 0 int h = fm.height() + fw * 2; itemRect.setWidth(view->columnWidth(LMASTER_VAL_COL)); itemRect.setY(1); itemRect.setHeight(h); } // Edit tempo value: if (editedItem->getType() == LMASTER_TEMPO) { tempo_editor->setText(editedItem->text(LMASTER_VAL_COL)); tempo_editor->setGeometry(itemRect); tempo_editor->show(); tempo_editor->setFocus(); tempo_editor->selectAll(); } else if (editedItem->getType() == LMASTER_SIGEVENT) { // Edit signatur value: sig_editor->setValue(((LMasterSigEventItem*)editedItem)->getEvent()->sig); int w = fnt_w * 14; if(w > itemRect.width()) w = itemRect.width(); sig_editor->setGeometry(itemRect.x(), itemRect.y(), w, itemRect.height()); sig_editor->show(); sig_editor->setFocus(); } else if (editedItem->getType() == LMASTER_KEYEVENT) { key_editor->setGeometry(itemRect); key_editor->setCurrentIndex(keyToIndex(dynamic_cast<LMasterKeyEventItem*>(editedItem)->key())); key_editor->show(); key_editor->setFocus(); comboboxTimer->start(); } else { printf("illegal Master list type\n"); } } // Edit tempo or signal position: else if (!editedItem && editorColumn == LMASTER_BEAT_COL) { editedItem = (LMasterLViewItem*) i; // Don't allow movement of initial values: if (editedItem->tick() == 0) { QMessageBox::information(this, tr(LMASTER_MSGBOX_STRING), tr("Reposition of the initial tempo and signature events is not allowed") ); editedItem = 0; } // Everything OK else { pos_editor->setValue(editedItem->tick()); QRect itemRect = view->visualItemRect(editedItem); itemRect.setX(view->indentation()); int w = view->columnWidth(LMASTER_BEAT_COL) - view->indentation(); if(w < (fnt_w * 13)) w = fnt_w * 13; itemRect.setWidth(w); pos_editor->setGeometry(itemRect); pos_editor->show(); pos_editor->setFocus(); } } }
QString keyToString(key_enum key) { return keyStrs[keyToIndex(key)]; }
int main(int argc, char *argv[]) { int index; /* index of last key we pushed in the bitmap font */ SDL_Window *window; SDL_Event event; /* last event received */ SDLMod mod; /* key modifiers of last key we pushed */ SDL_scancode scancode; /* scancode of last key we pushed */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Error initializing SDL: %s", SDL_GetError()); } /* create window */ window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0); /* create renderer */ SDL_CreateRenderer(window, 0, 0); /* load up our font */ loadFont(); /* draw the background, we'll just paint over it */ SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b, bg_color.unused); SDL_RenderFill(NULL); SDL_RenderPresent(); int done = 0; /* loop till we get SDL_Quit */ while (SDL_WaitEvent(&event)) { switch (event.type) { case SDL_QUIT: done = 1; break; case SDL_KEYDOWN: index = keyToIndex(event.key.keysym); scancode = event.key.keysym.scancode; mod = event.key.keysym.mod; if (scancode == SDL_SCANCODE_DELETE) { /* if user hit delete, delete the last character */ backspace(); lastCharWasColon = 0; } else if (lastCharWasColon && scancode == SDL_SCANCODE_0 && (mod & KMOD_SHIFT)) { /* if our last key was a colon and this one is a close paren, the make a hoppy face */ backspace(); drawIndex(32); /* index for happy face */ numChars++; drawCursor(); lastCharWasColon = 0; } else if (index != -1) { /* if we aren't doing a happy face, then just draw the normal character */ drawIndex(index); numChars++; drawCursor(); lastCharWasColon = (event.key.keysym.scancode == SDL_SCANCODE_SEMICOLON && (event.key.keysym.mod & KMOD_SHIFT)); } /* check if the key was a colon */ /* draw our updates to the screen */ SDL_RenderPresent(); break; #ifdef __IPHONEOS__ case SDL_MOUSEBUTTONUP: /* mouse up toggles onscreen keyboard visibility this function is available ONLY on iPhone OS */ SDL_iPhoneKeyboardToggle(window); break; #endif } } cleanup(); return 0; }
/** *** \brief Returns True if an item with the given key exists in the Dict **/ bool Dict_exists(Dict *d, const char *key) { size_t tmp = 0; return keyToIndex(d, key, &tmp); }