本文整理汇总了C++中SortedVector::indexOf方法的典型用法代码示例。如果您正苦于以下问题:C++ SortedVector::indexOf方法的具体用法?C++ SortedVector::indexOf怎么用?C++ SortedVector::indexOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedVector
的用法示例。
在下文中一共展示了SortedVector::indexOf方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toAudioPort
void AudioPort::toAudioPort(struct audio_port *port) const
{
// TODO: update this function once audio_port structure reflects the new profile definition.
// For compatibility reason: flatening the AudioProfile into audio_port structure.
SortedVector<audio_format_t> flatenedFormats;
SampleRateVector flatenedRates;
ChannelsVector flatenedChannels;
for (size_t profileIndex = 0; profileIndex < mProfiles.size(); profileIndex++) {
if (mProfiles[profileIndex]->isValid()) {
audio_format_t formatToExport = mProfiles[profileIndex]->getFormat();
const SampleRateVector &ratesToExport = mProfiles[profileIndex]->getSampleRates();
const ChannelsVector &channelsToExport = mProfiles[profileIndex]->getChannels();
if (flatenedFormats.indexOf(formatToExport) < 0) {
flatenedFormats.add(formatToExport);
}
for (size_t rateIndex = 0; rateIndex < ratesToExport.size(); rateIndex++) {
uint32_t rate = ratesToExport[rateIndex];
if (flatenedRates.indexOf(rate) < 0) {
flatenedRates.add(rate);
}
}
for (size_t chanIndex = 0; chanIndex < channelsToExport.size(); chanIndex++) {
audio_channel_mask_t channels = channelsToExport[chanIndex];
if (flatenedChannels.indexOf(channels) < 0) {
flatenedChannels.add(channels);
}
}
if (flatenedRates.size() > AUDIO_PORT_MAX_SAMPLING_RATES ||
flatenedChannels.size() > AUDIO_PORT_MAX_CHANNEL_MASKS ||
flatenedFormats.size() > AUDIO_PORT_MAX_FORMATS) {
ALOGE("%s: bailing out: cannot export profiles to port config", __FUNCTION__);
return;
}
}
}
port->role = mRole;
port->type = mType;
strlcpy(port->name, mName, AUDIO_PORT_MAX_NAME_LEN);
port->num_sample_rates = flatenedRates.size();
port->num_channel_masks = flatenedChannels.size();
port->num_formats = flatenedFormats.size();
for (size_t i = 0; i < flatenedRates.size(); i++) {
port->sample_rates[i] = flatenedRates[i];
}
for (size_t i = 0; i < flatenedChannels.size(); i++) {
port->channel_masks[i] = flatenedChannels[i];
}
for (size_t i = 0; i < flatenedFormats.size(); i++) {
port->formats[i] = flatenedFormats[i];
}
ALOGV("AudioPort::toAudioPort() num gains %zu", mGains.size());
uint32_t i;
for (i = 0; i < mGains.size() && i < AUDIO_PORT_MAX_GAINS; i++) {
port->gains[i] = mGains[i]->getGain();
}
port->num_gains = i;
}
示例2:
DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) {
DisplayState s;
s.token = token;
ssize_t index = mDisplayStates.indexOf(s);
if (index < 0) {
// we don't have it, add an initialized layer_state to our list
s.what = 0;
index = mDisplayStates.add(s);
}
return mDisplayStates.editItemAt(index);
}
示例3: getLayerStateLocked
layer_state_t* Composer::getLayerStateLocked(
const sp<SurfaceComposerClient>& client, SurfaceID id) {
ComposerState s;
s.client = client->mClient;
s.state.surface = id;
ssize_t index = mComposerStates.indexOf(s);
if (index < 0) {
// we don't have it, add an initialized layer_state to our list
index = mComposerStates.add(s);
}
ComposerState* const out = mComposerStates.editArray();
return &(out[index].state);
}
示例4: recorderCallback
// ----------------------------------------------------------------------------
static void recorderCallback(int event, void* user, void *info) {
audiorecord_callback_cookie *callbackInfo = (audiorecord_callback_cookie *)user;
{
Mutex::Autolock l(sLock);
if (sAudioRecordCallBackCookies.indexOf(callbackInfo) < 0) {
return;
}
callbackInfo->busy = true;
}
switch (event) {
case AudioRecord::EVENT_MARKER: {
JNIEnv *env = AndroidRuntime::getJNIEnv();
if (user != NULL && env != NULL) {
env->CallStaticVoidMethod(
callbackInfo->audioRecord_class,
javaAudioRecordFields.postNativeEventInJava,
callbackInfo->audioRecord_ref, event, 0,0, NULL);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
} break;
case AudioRecord::EVENT_NEW_POS: {
JNIEnv *env = AndroidRuntime::getJNIEnv();
if (user != NULL && env != NULL) {
env->CallStaticVoidMethod(
callbackInfo->audioRecord_class,
javaAudioRecordFields.postNativeEventInJava,
callbackInfo->audioRecord_ref, event, 0,0, NULL);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
} break;
}
{
Mutex::Autolock l(sLock);
callbackInfo->busy = false;
callbackInfo->cond.broadcast();
}
}
示例5: recorderCallback
// ----------------------------------------------------------------------------
static void recorderCallback(int event, void* user, void *info) {
audiorecord_callback_cookie *callbackInfo = (audiorecord_callback_cookie *)user;
{
Mutex::Autolock l(sLock);
if (sAudioRecordCallBackCookies.indexOf(callbackInfo) < 0) {
return;
}
callbackInfo->busy = true;
}
if (event == AudioRecord::EVENT_MORE_DATA) {
// set size to 0 to signal we're not using the callback to read more data
AudioRecord::Buffer* pBuff = (AudioRecord::Buffer*)info;
pBuff->size = 0;
} else if (event == AudioRecord::EVENT_MARKER) {
JNIEnv *env = AndroidRuntime::getJNIEnv();
if (user && env) {
env->CallStaticVoidMethod(
callbackInfo->audioRecord_class,
javaAudioRecordFields.postNativeEventInJava,
callbackInfo->audioRecord_ref, event, 0,0, NULL);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
} else if (event == AudioRecord::EVENT_NEW_POS) {
JNIEnv *env = AndroidRuntime::getJNIEnv();
if (user && env) {
env->CallStaticVoidMethod(
callbackInfo->audioRecord_class,
javaAudioRecordFields.postNativeEventInJava,
callbackInfo->audioRecord_ref, event, 0,0, NULL);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
}
}
{
Mutex::Autolock l(sLock);
callbackInfo->busy = false;
callbackInfo->cond.broadcast();
}
}
示例6: main
int main()
{
Vector<int> v;
v.addElement(4);
v.addElement(5);
v.addElement(6);
assert(v.elementAt(0) == 4);
assert(v.elementAt(2) == 6);
v.removeElement(5);
assert(v.elementAt(1) == 6);
v.insertElementAt(100, 2);
assert(v.elementAt(2) == 100);
printf("passed: Vector\n");
SortedVector<int> sv;
sv.addElement(7);
assert(sv.elementAt(0) == 7);
sv.addElement(6);
assert(sv.elementAt(0) == 6);
assert(sv.elementAt(1) == 7);
sv.addElement(9);
assert(sv.elementAt(2) == 9);
sv.addElement(3);
assert(sv.elementAt(0) == 3);
assert(sv.elementAt(3) == 9);
sv.addElement(1);
sv.removeElement(6);
assert(sv.size() == 4);
assert(sv.elementAt(3) == 9);
assert(sv.indexOf(9) == 3);
assert(sv.indexOf(1) == 0);
int numbers = 100;
while(numbers--){
sv.addElement(numbers%2 ? -numbers : numbers);
}
int maxel = -1000000;
for (int idx = 0; idx < sv.size(); idx++) {
//printf("%d, ", sv.elementAt(idx));
if (sv.elementAt(idx) < maxel) assert(!"sv order failed");
maxel = sv.elementAt(idx);
}
assert(sv.indexOf(10000) == -1);
assert(sv.indexOf(-10000) == -1);
sv.clear();
assert(sv.size() == 0);
sv.addElement(0);
sv.addElement(2);
sv.addElement(2);
sv.addElement(2);
assert(sv.size() == 4);
// undefined assert(sv.indexOf(2) == 1);
assert(sv.elementAt(0) == 0);
assert(sv.elementAt(3) == 2);
printf("passed: SortedVector\n");
}
示例7: createDescriptorFromOps
status_t VendorTagDescriptor::createDescriptorFromOps(const vendor_tag_ops_t* vOps,
/*out*/
sp<VendorTagDescriptor>& descriptor) {
if (vOps == NULL) {
ALOGE("%s: vendor_tag_ops argument was NULL.", __FUNCTION__);
return BAD_VALUE;
}
int tagCount = vOps->get_tag_count(vOps);
if (tagCount < 0 || tagCount > INT32_MAX) {
ALOGE("%s: tag count %d from vendor ops is invalid.", __FUNCTION__, tagCount);
return BAD_VALUE;
}
Vector<uint32_t> tagArray;
LOG_ALWAYS_FATAL_IF(tagArray.resize(tagCount) != tagCount,
"%s: too many (%u) vendor tags defined.", __FUNCTION__, tagCount);
vOps->get_all_tags(vOps, /*out*/tagArray.editArray());
sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
desc->mTagCount = tagCount;
SortedVector<String8> sections;
KeyedVector<uint32_t, String8> tagToSectionMap;
for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
uint32_t tag = tagArray[i];
if (tag < CAMERA_METADATA_VENDOR_TAG_BOUNDARY) {
ALOGE("%s: vendor tag %d not in vendor tag section.", __FUNCTION__, tag);
return BAD_VALUE;
}
const char *tagName = vOps->get_tag_name(vOps, tag);
if (tagName == NULL) {
ALOGE("%s: no tag name defined for vendor tag %d.", __FUNCTION__, tag);
return BAD_VALUE;
}
desc->mTagToNameMap.add(tag, String8(tagName));
const char *sectionName = vOps->get_section_name(vOps, tag);
if (sectionName == NULL) {
ALOGE("%s: no section name defined for vendor tag %d.", __FUNCTION__, tag);
return BAD_VALUE;
}
String8 sectionString(sectionName);
sections.add(sectionString);
tagToSectionMap.add(tag, sectionString);
int tagType = vOps->get_tag_type(vOps, tag);
if (tagType < 0 || tagType >= NUM_TYPES) {
ALOGE("%s: tag type %d from vendor ops does not exist.", __FUNCTION__, tagType);
return BAD_VALUE;
}
desc->mTagToTypeMap.add(tag, tagType);
}
desc->mSections = sections;
for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
uint32_t tag = tagArray[i];
String8 sectionString = tagToSectionMap.valueFor(tag);
// Set up tag to section index map
ssize_t index = sections.indexOf(sectionString);
LOG_ALWAYS_FATAL_IF(index < 0, "index %zd must be non-negative", index);
desc->mTagToSectionMap.add(tag, static_cast<uint32_t>(index));
// Set up reverse mapping
ssize_t reverseIndex = -1;
if ((reverseIndex = desc->mReverseMapping.indexOfKey(sectionString)) < 0) {
KeyedVector<String8, uint32_t>* nameMapper = new KeyedVector<String8, uint32_t>();
reverseIndex = desc->mReverseMapping.add(sectionString, nameMapper);
}
desc->mReverseMapping[reverseIndex]->add(desc->mTagToNameMap.valueFor(tag), tag);
}
descriptor = desc;
return OK;
}