LWError LWPGradient::save(LWPSaveState const * ss) const { ss->writeI4(type); ss->writeI4(keyCount()); for (LWPGradientKey * k = head; k; k = k->next) k->save(ss); return 0; }
/*! Returns a key description for the \a index 'th key. \a index must be less than keyCount(). */ QSoftMenuBarProvider::MenuButton QSoftMenuBarProvider::key(int index) const { Q_ASSERT(index < keyCount()); if (d->activeOverride != -1 && d->overrideButtons.at(index).d->index != -1) return d->overrideButtons.at(index); return d->buttons.at(index); }
static T toCaseInsensitiveEnum(const QString& key, bool* ok) { auto enumerator = QMetaEnum::fromType<T>(); for (int i = 0; i < enumerator.keyCount(); i++) { if (key.compare(enumerator.key(i), Qt::CaseInsensitive) == 0) { *ok = true; return static_cast<T>(enumerator.value(i)); } } *ok = false; return static_cast<T>(-1); }
TextureCache::TextureCache() { setUnusedResourceCacheSize(0); setObjectName("TextureCache"); // Expose enum Type to JS/QML via properties // Despite being one-off, this should be fine, because TextureCache is a SINGLETON_DEPENDENCY QObject* type = new QObject(this); type->setObjectName("TextureType"); setProperty("Type", QVariant::fromValue(type)); auto metaEnum = QMetaEnum::fromType<Type>(); for (int i = 0; i < metaEnum.keyCount(); ++i) { type->setProperty(metaEnum.key(i), metaEnum.value(i)); } }
void Object::keyCount() { if (leaf) { cout << key << " : 1\n"; return; } map<string, int> refCount; // the count of the references keyCount(refCount); vector<pair<string, int> > sortedCount; // an organized container for the counts for (map<string, int>::iterator i = refCount.begin(); i != refCount.end(); ++i) { pair<string, int> curr((*i).first, (*i).second); if (2 > curr.second) { continue; } if ((0 == sortedCount.size()) || (curr.second <= sortedCount.back().second)) { sortedCount.push_back(curr); continue; } for (vector<pair<string, int> >::iterator j = sortedCount.begin(); j != sortedCount.end(); ++j) { if (curr.second < (*j).second) { continue; } sortedCount.insert(j, 1, curr); break; } } for (vector<pair<string, int> >::iterator j = sortedCount.begin(); j != sortedCount.end(); ++j) { cout << (*j).first << " : " << (*j).second << "\n"; } }
/* ############################################################################# * * Description encrypt the given buffer and return the encrypted data with * an updated size information * Author Harry Brueckner * Date 2005-03-31 * Arguments char* buffer - buffer to encrypt * int size - size of the buffer * char** newbuffer - pointer to the new buffer which holds the * encrypted data * int* newsize - size of the returned buffer * PASSPHRASE_FN password_cb - callback function pointer used * to get the current passphrase * SHOWERROR_FN showerror_cb - callback function pointer used * to display errors * Return 0 if ok, otherwise 1 */ int gpgEncrypt(char* buffer, int size, char** newbuffer, int* newsize, PASSPHRASE_FN password_cb, SHOWERROR_FN showerror_cb) { gpgme_ctx_t context; gpgme_data_t input, output; gpgme_encrypt_result_t result; gpgme_error_t error; gpgme_key_t* key = NULL; gpgme_key_t tkey = NULL; gpgme_sign_result_t sign_result; int i, keys = 0, showerror = 1; char* agent; char* fpr; char* tmpbuffer = NULL; TRACE(99, "gpgEncrypt()", NULL); /* we set our passphrase callback function */ passphrase_callback = password_cb; /* we initialize the external size data */ newsize[0] = 0; error = gpgme_new(&context); if (!error) { gpgme_set_textmode(context, 1); gpgme_set_armor(context, 1); /* Flawfinder: ignore */ agent = getenv("GPG_AGENT_INFO"); if (!(agent && strchr(agent, ':'))) { retries = 0; gpgme_set_passphrase_cb(context, gpgRequestPassphrase, NULL); } } if (!error) { error = gpgme_data_new_from_mem(&input, buffer, size, 0); } if (!error) { error = gpgme_data_new(&output); } if (!error) { gpgme_signers_clear(context); } if (!error) { /* allocate the keys */ keys = keyCount(); key = memAlloc(__FILE__, __LINE__, sizeof(gpgme_key_t) * (keys + 1)); key[keys] = NULL; signers = 0; for (i = 0; i < keys && !error; i++) { /* add all keys */ fpr = gpgGetFingerprint(keyGet(i), LIST_SECRET); if (fpr) { error = gpgme_get_key(context, fpr, &tkey, LIST_SECRET); if (tkey -> secret); { error = gpgme_signers_add(context, tkey); signers++; } memFreeString(__FILE__, __LINE__, fpr); } fpr = gpgGetFingerprint(keyGet(i), LIST_ALL); if (fpr) { error = gpgme_get_key(context, fpr, &key[i], LIST_ALL); memFreeString(__FILE__, __LINE__, fpr); } } } if (signers > 1) { /* as soon as we get two signers, we must no longer cache anything */ config -> keeppassphrase = 0; clearPassphrase(1); } /* encrypt and sign the data */ if (!error) { error = gpgme_op_encrypt_sign(context, key, GPGME_ENCRYPT_ALWAYS_TRUST, input, output); } /* we don't need the passphrase any longer */ clearPassphrase(0); if (!error) { result = gpgme_op_encrypt_result(context); } if (!error && result -> invalid_recipients) { tmpbuffer = memAlloc(__FILE__, __LINE__, STDBUFFERLENGTH); snprintf(tmpbuffer, STDBUFFERLENGTH, _("Invalid recipient encountered: %s"), result -> invalid_recipients -> fpr); (showerror_cb)(_("GpgMe error"), tmpbuffer); memFree(__FILE__, __LINE__, tmpbuffer, STDBUFFERLENGTH); showerror = 0; error = 1; } if (!error) { sign_result = gpgme_op_sign_result(context); error = gpgCheckSignResult(showerror_cb, sign_result, GPGME_SIG_MODE_NORMAL); showerror = !error; } if (!error) { tmpbuffer = gpgData2Char(output, newsize); } /* free the keys again */ i = 0; while (key && keys && key[i]) { gpgme_key_unref(key[i++]); } memFree(__FILE__, __LINE__, key, sizeof(gpgme_key_t) * (keys + 1)); gpgme_data_release(input); gpgme_data_release(output); gpgme_release(context); *newbuffer = tmpbuffer; if (error) { if (showerror) { (showerror_cb)(_("GpgMe encrypt error"), gpgme_strerror(error)); } return 1; } else return 0; }
uint32_t size(void) const { return keyCount(); }
const value_type& highestValue(void) const { lassert(keyCount()); return mValueToKeys.rbegin()->first; }
const key_type& highestKey(void) const { lassert(keyCount()); return mKeyToValue.rbegin()->first; }