本文整理汇总了C++中InfallibleTArray::AppendElements方法的典型用法代码示例。如果您正苦于以下问题:C++ InfallibleTArray::AppendElements方法的具体用法?C++ InfallibleTArray::AppendElements怎么用?C++ InfallibleTArray::AppendElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InfallibleTArray
的用法示例。
在下文中一共展示了InfallibleTArray::AppendElements方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: str
already_AddRefed<Promise>
Directory::CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
ErrorResult& aRv)
{
// Only exposed for DeviceStorage.
MOZ_ASSERT(NS_IsMainThread());
RefPtr<Blob> blobData;
InfallibleTArray<uint8_t> arrayData;
bool replace = (aOptions.mIfExists == CreateIfExistsMode::Replace);
// Get the file content.
if (aOptions.mData.WasPassed()) {
auto& data = aOptions.mData.Value();
if (data.IsString()) {
NS_ConvertUTF16toUTF8 str(data.GetAsString());
arrayData.AppendElements(reinterpret_cast<const uint8_t *>(str.get()),
str.Length());
} else if (data.IsArrayBuffer()) {
const ArrayBuffer& buffer = data.GetAsArrayBuffer();
buffer.ComputeLengthAndData();
arrayData.AppendElements(buffer.Data(), buffer.Length());
} else if (data.IsArrayBufferView()){
const ArrayBufferView& view = data.GetAsArrayBufferView();
view.ComputeLengthAndData();
arrayData.AppendElements(view.Data(), view.Length());
} else {
blobData = data.GetAsBlob();
}
}
nsCOMPtr<nsIFile> realPath;
nsresult error = DOMPathToRealPath(aPath, getter_AddRefs(realPath));
RefPtr<FileSystemBase> fs = GetFileSystem(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RefPtr<CreateFileTaskChild> task =
CreateFileTaskChild::Create(fs, realPath, blobData, arrayData, replace,
aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
task->SetError(error);
FileSystemPermissionRequest::RequestForTask(task);
return task->GetPromise();
}
示例2: if
/**
* AdapterPropertiesNotification will be called after enable() but
* before AdapterStateChangeNotification is called. At that moment,
* BluetoothManager and BluetoothAdapter, do not register observer
* yet.
*/
void
BluetoothServiceBluedroid::AdapterPropertiesNotification(
BluetoothStatus aStatus, int aNumProperties,
const BluetoothProperty* aProperties)
{
MOZ_ASSERT(NS_IsMainThread());
InfallibleTArray<BluetoothNamedValue> propertiesArray;
for (int i = 0; i < aNumProperties; i++) {
const BluetoothProperty& p = aProperties[i];
if (p.mType == PROPERTY_BDADDR) {
sAdapterBdAddress = p.mString;
BT_APPEND_NAMED_VALUE(propertiesArray, "Address", sAdapterBdAddress);
} else if (p.mType == PROPERTY_BDNAME) {
sAdapterBdName = p.mString;
BT_APPEND_NAMED_VALUE(propertiesArray, "Name", sAdapterBdName);
} else if (p.mType == PROPERTY_ADAPTER_SCAN_MODE) {
sAdapterDiscoverable =
(p.mScanMode == SCAN_MODE_CONNECTABLE_DISCOVERABLE);
BT_APPEND_NAMED_VALUE(propertiesArray, "Discoverable",
sAdapterDiscoverable);
} else if (p.mType == PROPERTY_ADAPTER_BONDED_DEVICES) {
// We have to cache addresses of bonded devices. Unlike BlueZ,
// Bluedroid would not send another PROPERTY_ADAPTER_BONDED_DEVICES
// event after bond completed.
BT_LOGD("Adapter property: BONDED_DEVICES. Count: %d",
p.mStringArray.Length());
// Whenever reloading paired devices, force refresh
sAdapterBondedAddressArray.Clear();
sAdapterBondedAddressArray.AppendElements(p.mStringArray);
BT_APPEND_NAMED_VALUE(propertiesArray, "PairedDevices",
sAdapterBondedAddressArray);
} else if (p.mType == PROPERTY_UNKNOWN) {
/* Bug 1065999: working around unknown properties */
} else {
BT_LOGD("Unhandled adapter property type: %d", p.mType);
continue;
}
}
NS_ENSURE_TRUE_VOID(propertiesArray.Length() > 0);
DistributeSignal(NS_LITERAL_STRING("PropertyChanged"),
NS_LITERAL_STRING(KEY_ADAPTER),
BluetoothValue(propertiesArray));
// Send reply for SetProperty
if (!sSetPropertyRunnableArray.IsEmpty()) {
DispatchReplySuccess(sSetPropertyRunnableArray[0]);
sSetPropertyRunnableArray.RemoveElementAt(0);
}
}
示例3: str
already_AddRefed<Promise>
Directory::CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
ErrorResult& aRv)
{
nsresult error = NS_OK;
nsString realPath;
nsRefPtr<File> blobData;
InfallibleTArray<uint8_t> arrayData;
bool replace = (aOptions.mIfExists == CreateIfExistsMode::Replace);
// Get the file content.
if (aOptions.mData.WasPassed()) {
auto& data = aOptions.mData.Value();
if (data.IsString()) {
NS_ConvertUTF16toUTF8 str(data.GetAsString());
arrayData.AppendElements(reinterpret_cast<const uint8_t *>(str.get()),
str.Length());
} else if (data.IsArrayBuffer()) {
const ArrayBuffer& buffer = data.GetAsArrayBuffer();
buffer.ComputeLengthAndData();
arrayData.AppendElements(buffer.Data(), buffer.Length());
} else if (data.IsArrayBufferView()){
const ArrayBufferView& view = data.GetAsArrayBufferView();
view.ComputeLengthAndData();
arrayData.AppendElements(view.Data(), view.Length());
} else {
blobData = data.GetAsBlob();
}
}
if (!DOMPathToRealPath(aPath, realPath)) {
error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
}
nsRefPtr<CreateFileTask> task =
new CreateFileTask(mFileSystem, realPath, blobData, arrayData, replace, aRv);
if (aRv.Failed()) {
return nullptr;
}
task->SetError(error);
FileSystemPermissionRequest::RequestForTask(task);
return task->GetPromise();
}
示例4:
void
RectTriangles::AppendRectToCoordArray(InfallibleTArray<coord>& array,
GLfloat x0, GLfloat y0,
GLfloat x1, GLfloat y1)
{
coord* v = array.AppendElements(6);
v[0].x = x0; v[0].y = y0;
v[1].x = x1; v[1].y = y0;
v[2].x = x0; v[2].y = y1;
v[3].x = x0; v[3].y = y1;
v[4].x = x1; v[4].y = y0;
v[5].x = x1; v[5].y = y1;
}