当前位置: 首页>>代码示例>>C++>>正文


C++ Sequence::SetLength方法代码示例

本文整理汇总了C++中Sequence::SetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Sequence::SetLength方法的具体用法?C++ Sequence::SetLength怎么用?C++ Sequence::SetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sequence的用法示例。


在下文中一共展示了Sequence::SetLength方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: path

void
GetDirectoryListingTask::HandlerCallback()
{
  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
  if (mFileSystem->IsShutdown()) {
    mPromise = nullptr;
    return;
  }

  if (HasError()) {
    mPromise->MaybeReject(mErrorValue);
    mPromise = nullptr;
    return;
  }

  size_t count = mTargetBlobImpls.Length();

  Sequence<OwningFileOrDirectory> listing;

  if (!listing.SetLength(count, mozilla::fallible_t())) {
    mPromise->MaybeReject(NS_ERROR_FAILURE);
    mPromise = nullptr;
    return;
  }

  for (unsigned i = 0; i < count; i++) {
    if (mTargetBlobImpls[i]->IsDirectory()) {
      nsAutoString name;
      mTargetBlobImpls[i]->GetName(name);
      nsAutoString path(mTargetRealPath);
      path.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR);
      path.Append(name);
#ifdef DEBUG
      if (XRE_IsParentProcess()) {
        nsCOMPtr<nsIFile> file = mFileSystem->GetLocalFile(path);
        bool exist;
        file->Exists(&exist);
        MOZ_ASSERT(exist);
      }
#endif
      listing[i].SetAsDirectory() = new Directory(mFileSystem, path);
    } else {
      listing[i].SetAsFile() = File::Create(mFileSystem->GetWindow(), mTargetBlobImpls[i]);
    }
  }

  mPromise->MaybeResolve(listing);
  mPromise = nullptr;
}
开发者ID:70599,项目名称:Waterfox,代码行数:49,代码来源:GetDirectoryListingTask.cpp

示例2:

void
FileList::ToSequence(Sequence<OwningFileOrDirectory>& aSequence,
                     ErrorResult& aRv) const
{
  MOZ_ASSERT(aSequence.IsEmpty());
  if (mFilesOrDirectories.IsEmpty()) {
    return;
  }

  if (!aSequence.SetLength(mFilesOrDirectories.Length(),
                           mozilla::fallible_t())) {
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
    return;
  }

  for (uint32_t i = 0; i < mFilesOrDirectories.Length(); ++i) {
    aSequence[i] = mFilesOrDirectories[i];
  }
}
开发者ID:devtools-html,项目名称:gecko-dev,代码行数:19,代码来源:FileList.cpp

示例3: Constructor

/* static */ already_AddRefed<DOMMediaStream>
DOMMediaStream::Constructor(const GlobalObject& aGlobal,
                            const DOMMediaStream& aStream,
                            ErrorResult& aRv)
{
  nsTArray<RefPtr<MediaStreamTrack>> tracks;
  aStream.GetTracks(tracks);

  Sequence<OwningNonNull<MediaStreamTrack>> nonNullTrackSeq;
  if (!nonNullTrackSeq.SetLength(tracks.Length(), fallible)) {
    MOZ_ASSERT(false);
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
    return nullptr;
  }

  for (size_t i = 0; i < tracks.Length(); ++i) {
    nonNullTrackSeq[i] = tracks[i];
  }

  return Constructor(aGlobal, nonNullTrackSeq, aRv);
}
开发者ID:jasonmsoft,项目名称:system-addons,代码行数:21,代码来源:DOMMediaStream.cpp

示例4: fullPath

void
GetDirectoryListingTaskChild::HandlerCallback()
{
  mFileSystem->AssertIsOnOwningThread();

  if (mFileSystem->IsShutdown()) {
    mPromise = nullptr;
    return;
  }

  if (HasError()) {
    mPromise->MaybeReject(mErrorValue);
    mPromise = nullptr;
    return;
  }

  size_t count = mTargetData.Length();

  nsAutoString directoryPath;
  ErrorResult error;
  mDirectory->GetPath(directoryPath, error);
  if (NS_WARN_IF(error.Failed())) {
    mPromise->MaybeReject(error.StealNSResult());
    mPromise = nullptr;
    return;
  }

  Sequence<OwningFileOrDirectory> listing;

  if (!listing.SetLength(count, mozilla::fallible_t())) {
    mPromise->MaybeReject(NS_ERROR_OUT_OF_MEMORY);
    mPromise = nullptr;
    return;
  }

  for (unsigned i = 0; i < count; i++) {
    nsCOMPtr<nsIFile> path;
    NS_ConvertUTF16toUTF8 fullPath(mTargetData[i].mPath);
    nsresult rv = NS_NewNativeLocalFile(fullPath, true, getter_AddRefs(path));
    if (NS_WARN_IF(NS_FAILED(rv))) {
      mPromise->MaybeReject(rv);
      mPromise = nullptr;
      return;
    }

#ifdef DEBUG
    nsCOMPtr<nsIFile> rootPath;
    rv = NS_NewLocalFile(mFileSystem->LocalOrDeviceStorageRootPath(), false,
                         getter_AddRefs(rootPath));
    if (NS_WARN_IF(NS_FAILED(rv))) {
      mPromise->MaybeReject(rv);
      mPromise = nullptr;
      return;
    }

    MOZ_ASSERT(FileSystemUtils::IsDescendantPath(rootPath, path));
#endif

    if (mTargetData[i].mType == Directory::FileOrDirectoryPath::eDirectoryPath) {
      RefPtr<Directory> directory =
        Directory::Create(mFileSystem->GetParentObject(), path, mFileSystem);
      MOZ_ASSERT(directory);

      // Propogate mFilter onto sub-Directory object:
      directory->SetContentFilters(mFilters);
      listing[i].SetAsDirectory() = directory;
    } else {
      MOZ_ASSERT(mTargetData[i].mType == Directory::FileOrDirectoryPath::eFilePath);

      RefPtr<File> file =
        File::CreateFromFile(mFileSystem->GetParentObject(), path);
      MOZ_ASSERT(file);

      nsAutoString filePath;
      filePath.Assign(directoryPath);

      // This is specific for unix root filesystem.
      if (!directoryPath.EqualsLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL)) {
        filePath.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
      }

      nsAutoString name;
      file->GetName(name);
      filePath.Append(name);
      file->SetPath(filePath);

      listing[i].SetAsFile() = file;
    }
  }

  mPromise->MaybeResolve(listing);
  mPromise = nullptr;
}
开发者ID:MichaelKohler,项目名称:gecko-dev,代码行数:93,代码来源:GetDirectoryListingTask.cpp

示例5: GetFiles

already_AddRefed<Promise>
DataTransfer::GetFilesAndDirectories(ErrorResult& aRv)
{
  nsCOMPtr<nsINode> parentNode = do_QueryInterface(mParent);
  if (!parentNode) {
    aRv.Throw(NS_ERROR_FAILURE);
    return nullptr;
  }

  nsCOMPtr<nsIGlobalObject> global = parentNode->OwnerDoc()->GetScopeObject();
  MOZ_ASSERT(global);
  if (!global) {
    aRv.Throw(NS_ERROR_FAILURE);
    return nullptr;
  }

  nsRefPtr<Promise> p = Promise::Create(global, aRv);
  if (aRv.Failed()) {
    return nullptr;
  }

  if (!mFiles) {
    GetFiles(aRv);
    if (NS_WARN_IF(aRv.Failed())) {
      return nullptr;
    }
  }

  Sequence<OwningFileOrDirectory> filesAndDirsSeq;

  if (mFiles && mFiles->Length()) {
    if (!filesAndDirsSeq.SetLength(mFiles->Length(), mozilla::fallible_t())) {
      p->MaybeReject(NS_ERROR_OUT_OF_MEMORY);
      return p.forget();
    }

    nsPIDOMWindow* window = parentNode->OwnerDoc()->GetInnerWindow();

    nsRefPtr<OSFileSystem> fs;
    for (uint32_t i = 0; i < mFiles->Length(); ++i) {
      if (mFiles->Item(i)->Impl()->IsDirectory()) {
#if defined(ANDROID) || defined(MOZ_B2G)
        MOZ_ASSERT(false,
                   "Directory picking should have been redirected to normal "
                   "file picking for platforms that don't have a directory "
                   "picker");
#endif
        nsAutoString path;
        mFiles->Item(i)->GetMozFullPathInternal(path, aRv);
        if (aRv.Failed()) {
          return nullptr;
        }
        int32_t leafSeparatorIndex = path.RFind(FILE_PATH_SEPARATOR);
        nsDependentSubstring dirname = Substring(path, 0, leafSeparatorIndex);
        nsDependentSubstring basename = Substring(path, leafSeparatorIndex);
        fs = MakeOrReuseFileSystem(dirname, fs, window);
        filesAndDirsSeq[i].SetAsDirectory() = new Directory(fs, basename);
      } else {
        filesAndDirsSeq[i].SetAsFile() = mFiles->Item(i);
      }
    }
  }

  p->MaybeResolve(filesAndDirsSeq);

  return p.forget();
}
开发者ID:volkanh,项目名称:gecko-dev,代码行数:67,代码来源:DataTransfer.cpp


注:本文中的Sequence::SetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。